Skip to content

Commit e1d03ea

Browse files
committed
Merge branch 'fix-parallel-evaluation'.
* Use "BASIC" evaluatortype for parallel calculations.
2 parents 19d0aa6 + e539aeb commit e1d03ea

2 files changed

Lines changed: 39 additions & 2 deletions

File tree

src/diffpy/srreal/parallel.py

Lines changed: 22 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,9 @@ def createParallelCalculator(pqobj, ncpu, pmap):
3535
ncpu -- number of parallel jobs
3636
pmap -- a parallel map function used to submit job to workers
3737
38+
The ``pqobj.evaluatortype`` is reset to 'BASIC' because other
39+
evaluator types are not supported within parallel calculations.
40+
3841
Return a proxy calculator instance that has the same interface,
3942
but executes the calculation in parallel split among ncpu jobs.
4043
'''
@@ -63,6 +66,8 @@ def __init__(self, pqobj, ncpu, pmap):
6366
object.__setattr__(self, 'pqobj', pqobj)
6467
object.__setattr__(self, 'ncpu', ncpu)
6568
object.__setattr__(self, 'pmap', pmap)
69+
# parallel calculations support only the BASIC evaluation
70+
self.pqobj.evaluatortype = 'BASIC'
6671
return
6772

6873

@@ -116,6 +121,23 @@ def parallel_eval(stru):
116121
restore_eval()
117122
return rv
118123

124+
125+
@property
126+
def evaluatortype(self):
127+
"""str : Type of evaluation procedure.
128+
129+
Parallel calculations allow only the 'BASIC' type.
130+
"""
131+
return self.pqobj.evaluatortype
132+
133+
@evaluatortype.setter
134+
def evaluatortype(self, value):
135+
if value != "BASIC":
136+
emsg = "Parallel calculations require 'BASIC' evaluatortype."
137+
raise ValueError(emsg)
138+
self.pqobj.evaluatortype = value
139+
return
140+
119141
# class ParallelPairQuantity
120142

121143
# Create proxy method and properties to the wrapped PairQuantity
@@ -167,8 +189,6 @@ def _parallelData(kwd):
167189
'''Helper for calculating and fetching raw results from a worker node.
168190
'''
169191
pqobj = kwd['pqobj']
170-
if pqobj.evaluatortype == 'OPTIMIZED':
171-
pqobj = copy.copy(pqobj)
172192
pqobj._setupParallelRun(kwd['cpuindex'], kwd['ncpu'])
173193
pqobj.eval()
174194
return pqobj._getParallelData()

src/diffpy/srreal/tests/testparallel.py

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,22 @@ def pool(self):
4040
self._pool = multiprocessing.Pool(processes=self.ncpu)
4141
return self._pool
4242

43+
44+
def test_parallel_evaluatortype(self):
45+
"""check handling of the evaluatortype property
46+
"""
47+
from diffpy.srreal.pdfcalculator import PDFCalculator
48+
pdfc = PDFCalculator()
49+
self.assertEqual('OPTIMIZED', pdfc.evaluatortype)
50+
ppdfc = createParallelCalculator(pdfc, 2, map)
51+
self.assertEqual('BASIC', ppdfc.evaluatortype)
52+
self.assertEqual('BASIC', pdfc.evaluatortype)
53+
ppdfc.evaluatortype = 'BASIC'
54+
self.assertRaises(ValueError,
55+
setattr, ppdfc, 'evaluatortype', 'OPTIMIZED')
56+
return
57+
58+
4359
def test_parallel_pdf(self):
4460
"""check parallel PDFCalculator
4561
"""
@@ -68,6 +84,7 @@ def test_parallel_pdf(self):
6884
self.assertTrue(numpy.allclose(g0a, g2a))
6985
return
7086

87+
7188
def test_parallel_bonds(self):
7289
"""check parallel BondCalculator
7390
"""

0 commit comments

Comments
 (0)