@@ -28,28 +28,65 @@ def setupSystem(scu):
28
28
if 'cacheDir' in baseSystemConfig :
29
29
subSystemConfig ['cacheDir' ] = os .path .join (baseSystemConfig ['cacheDir' ], 'cache' , '%d-%d' % tag )
30
30
31
- localLocator = Kernel .SeisLocator25D (subSystemConfig ['geom' ])
32
31
localSystem [tag ] = Kernel .SeisFDFDKernel (subSystemConfig , locator = localLocator )
33
32
34
33
return tag
35
34
35
+ # def blockOnTag(fn):
36
+ # from IPython.parallel.error import UnmetDependency
37
+ # def checkForSystem(*args, **kwargs):
38
+ # if not args[0] in localSystem:
39
+ # raise UnmetDependency
40
+
41
+ # return fn(*args, **kwargs)
42
+
43
+ # return checkForSystem
44
+
45
+
46
+ @interactive
47
+ def setupCommon ():
48
+ global baseSystemConfig
49
+
50
+ localLocator = Kernel .SeisLocator25D (subSystemConfig ['geom' ])
51
+
52
+ @interactive
53
+ def clearFromTag (tag ):
54
+ return localSystem [tag ].clear ()
55
+
36
56
@interactive
57
+ # @blockOnTag
37
58
def forwardFromTagAccumulate (tag , isrc ):
59
+
38
60
from IPython .parallel .error import UnmetDependency
39
61
if not tag in localSystem :
40
62
raise UnmetDependency
41
63
42
64
resultTracker ((tag [0 ], isrc ), localSystem [tag ].forward (isrc , True ))
43
65
44
66
@interactive
67
+ # @blockOnTag
45
68
def forwardFromTagAccumulateAll (tag , isrcs ):
69
+
46
70
from IPython .parallel .error import UnmetDependency
47
71
if not tag in localSystem :
48
72
raise UnmetDependency
49
73
50
74
for isrc in isrcs :
51
75
forwardFromTagAccumulate (tag , isrc )
52
76
77
+ # @interactive
78
+ # @blockOnTag
79
+ # def backpropFromTagAccumulate(tag, isrc):
80
+
81
+
82
+
83
+ # @interactive
84
+ # @blockOnTag
85
+ # def backpropFromTagAccumulateAll(tag, isrcs):
86
+
87
+ # for isrc in isrcs:
88
+ # backpropFromTagAccumulate(tag, isrc)
89
+
53
90
@interactive
54
91
def hasSystem (tag ):
55
92
global localSystem
@@ -112,20 +149,15 @@ def getChunks(problems, chunks=1):
112
149
nproblems = len (problems )
113
150
return (problems [i * nproblems // chunks : (i + 1 )* nproblems // chunks ] for i in range (chunks ))
114
151
115
- def cdSame (profile = None ):
152
+ def cdSame (rc ):
116
153
import os
117
- from IPython .parallel import Client
118
154
119
- if profile :
120
- rc = Client (profile = profile )
121
- else :
122
- rc = Client ()
123
155
dview = rc [:]
124
156
125
-
126
157
home = os .getenv ('HOME' )
127
158
cwd = os .getcwd ()
128
159
160
+ @interactive
129
161
def cdrel (relpath ):
130
162
import os
131
163
home = os .getenv ('HOME' )
@@ -168,6 +200,7 @@ def __init__(self, systemConfig, **kwargs):
168
200
169
201
Problem .BaseProblem .__init__ (self , mesh , ** kwargs )
170
202
203
+
171
204
splitkeys = ['freqs' , 'nky' ]
172
205
173
206
subConfigSettings = {}
@@ -182,11 +215,13 @@ def __init__(self, systemConfig, **kwargs):
182
215
pupdate = {'profile' : self .systemConfig ['profile' ]}
183
216
else :
184
217
pupdate = {}
185
- if not cdSame (** pupdate ):
186
- print ('Could not change all workers to the same directory as the client!' )
187
218
188
219
pclient = Client (** pupdate )
189
220
221
+
222
+ if not cdSame (pclient ):
223
+ print ('Could not change all workers to the same directory as the client!' )
224
+
190
225
self .par = {
191
226
'pclient' : pclient ,
192
227
'dview' : pclient [:],
@@ -211,6 +246,7 @@ def __init__(self, systemConfig, **kwargs):
211
246
212
247
self ._rebuildSystem ()
213
248
249
+
214
250
def _getHandles (self , systemConfig , subConfigSettings ):
215
251
216
252
pclient = self .par ['pclient' ]
@@ -221,12 +257,11 @@ def _getHandles(self, systemConfig, subConfigSettings):
221
257
nsp = len (subConfigs )
222
258
223
259
# Set up dictionary for subproblem objects and push base configuration for the system
224
- #setupCache(systemConfig)
225
260
dview ['localSystem' ] = {}
226
261
dview ['baseSystemConfig' ] = systemConfig
227
262
dview ['resultTracker' ] = commonReducer ()
228
- #localSystem = Reference('localSystem' )
229
- #resultTracker = Reference('resultTracker')
263
+ dview . execute ( "localLocator = Kernel.SeisLocator25D(baseSystemConfig['geom'])" )
264
+
230
265
231
266
# Create a function to get a subproblem forward modelling function
232
267
dview ['forwardFromTag' ] = lambda tag , isrc , dOnly = True : localSystem [tag ].forward (isrc , dOnly )
@@ -238,6 +273,7 @@ def _getHandles(self, systemConfig, subConfigSettings):
238
273
239
274
dview ['forwardFromTagAccumulate' ] = forwardFromTagAccumulate
240
275
dview ['forwardFromTagAccumulateAll' ] = forwardFromTagAccumulateAll
276
+ dview ['clearFromTag' ] = clearFromTag
241
277
242
278
dview .wait ()
243
279
@@ -285,25 +321,17 @@ def _gen25DSubConfigs(self, freqs, nky, cmin):
285
321
286
322
# Fields
287
323
def forwardAccumulate (self , isrcs = None ):
324
+ G = self .systemSolve (Reference ('forwardFromTagAccumulateAll' ), isrcs )
325
+
326
+ return G
327
+
328
+ def systemSolve (self , fnRef , isrcs = None , clearRef = Reference ('clearFromTag' )):
288
329
289
330
dview = self .par ['dview' ]
290
331
lview = self .par ['lview' ]
291
332
292
333
chunksPerWorker = self .systemConfig .get ('chunksPerWorker' , 1 )
293
334
294
- # Create a function to save forward modelling results to the tracker
295
- dview .execute ("setupFromTag = lambda tag: None" )
296
- #dview['setupFromTag'] = lambda tag: None
297
- #setupFromTag = Reference('setupFromTag')
298
-
299
- #forwardFromTagAccumulate = Reference('forwardFromTagAccumulate')
300
-
301
- #forwardFromTagAccumulateAll = Reference('forwardFromTagAccumulateAll')
302
-
303
- dview .execute ("clearFromTag = lambda tag: localSystem[tag].clear()" )
304
- #dview['clearFromTag'] = lambda tag: localSystem[tag].clear()
305
- #clearFromTag = Reference('clearFromTag')
306
-
307
335
G = networkx .DiGraph ()
308
336
309
337
mainNode = 'Beginning'
@@ -330,17 +358,11 @@ def forwardAccumulate(self, isrcs=None):
330
358
for ltags in systemsOnWorkers :
331
359
tags = tags .union (set (ltags ))
332
360
333
- startJobs = {wid : [] for wid in xrange (len (ids ))}
334
- systemJobs = {}
335
- endJobs = {wid : [] for wid in xrange (len (ids ))}
336
- endNodes = {wid : [] for wid in xrange (len (ids ))}
361
+ endNodes = {}
337
362
tailNodes = []
338
363
339
364
for tag in tags :
340
365
341
- startJobsLocal = []
342
- endJobsLocal = []
343
-
344
366
tagNode = 'Head: %d, %d' % tag
345
367
G .add_edge (mainNode , tagNode )
346
368
@@ -350,83 +372,60 @@ def forwardAccumulate(self, isrcs=None):
350
372
systems = systemsOnWorkers [i ]
351
373
rank = ids [i ]
352
374
353
- try :
354
- jobdeps = {'after' : endJobs [i ][- 1 ]}
355
- except IndexError :
356
- jobdeps = {}
357
-
358
375
if tag in systems :
359
376
relIDs .append (i )
360
- with lview .temp_flags (block = False , ** jobdeps ):
361
- job = lview .apply (depend (hasSystemRank , tag , rank )(Reference ('setupFromTag' )), tag )
362
- startJobsLocal .append (job )
363
- startJobs [i ].append (job )
364
- label = 'Setup: %d, %d, %d' % (tag [0 ],tag [1 ],i )
365
- G .add_node (label , job = job )
366
- G .add_edge (tagNode , label )
367
- if 'after' in jobdeps :
368
- G .add_edge (endNodes [i ][- 1 ], label )
369
-
370
- tagNode = 'Init: %d, %d' % tag
371
- for i in relIDs :
372
- label = 'Setup: %d, %d, %d' % (tag [0 ],tag [1 ],i )
373
- G .add_edge (label , tagNode )
374
377
375
- systemJobs [tag ] = []
378
+ systemJobs = []
379
+ endNodes [tag ] = []
376
380
systemNodes = []
377
381
378
- with lview .temp_flags (block = False , after = startJobsLocal ):
382
+ with lview .temp_flags (block = False ):
379
383
iworks = 0
380
384
for work in getChunks (isrcslist , int (round (chunksPerWorker * len (relIDs )))):
381
385
if work :
382
- job = lview .apply (Reference ( 'forwardFromTagAccumulateAll' ) , tag , work )
383
- systemJobs [ tag ] .append (job )
386
+ job = lview .apply (fnRef , tag , work )
387
+ systemJobs .append (job )
384
388
label = 'Compute: %d, %d, %d' % (tag [0 ], tag [1 ], iworks )
385
389
systemNodes .append (label )
386
390
G .add_node (label , job = job )
387
391
G .add_edge (tagNode , label )
388
392
iworks += 1
389
393
390
- tagNode = 'Wrap: %d, %d' % tag
391
- for label in systemNodes :
392
- G .add_edge (label , tagNode )
394
+ if self .systemConfig .get ('ensembleClear' , False ): # True for ensemble ending, False for individual ending
395
+ tagNode = 'Wrap: %d, %d' % tag
396
+ for label in systemNodes :
397
+ G .add_edge (label , tagNode )
393
398
394
- relIDs = []
395
- for i in xrange (len (ids )):
396
-
397
- systems = systemsOnWorkers [i ]
398
- rank = ids [i ]
399
+ for i in relIDs :
399
400
400
- if tag in systems :
401
- relIDs .append (i )
402
- with lview .temp_flags (block = False , after = systemJobs [tag ]):
403
- job = lview .apply (depend (hasSystemRank , tag , rank )(Reference ('clearFromTag' )), tag )
404
- endJobsLocal .append (job )
405
- endJobs [i ].append (job )
406
- label = 'Wrap: %d, %d, %d' % (tag [0 ],tag [1 ],i )
401
+ rank = ids [i ]
402
+
403
+ with lview .temp_flags (block = False , after = systemJobs ):
404
+ job = lview .apply (depend (hasSystemRank , tag , rank )(clearRef ), tag )
405
+ label = 'Wrap: %d, %d, %d' % (tag [0 ],tag [1 ], i )
407
406
G .add_node (label , job = job )
408
- endNodes [i ].append (label )
407
+ endNodes [tag ].append (label )
409
408
G .add_edge (tagNode , label )
409
+ else :
410
+
411
+ for i , sjob in enumerate (systemJobs ):
412
+ with lview .temp_flags (block = False , follow = sjob ):
413
+ job = lview .apply (clearRef , tag )
414
+ label = 'Wrap: %d, %d, %d' % (tag [0 ],tag [1 ],i )
415
+ G .add_node (label , job = job )
416
+ endNodes [tag ].append (label )
417
+ G .add_edge (systemNodes [i ], label )
410
418
411
419
tagNode = 'Tail: %d, %d' % tag
412
- for i in relIDs :
413
- label = 'Wrap: %d, %d, %d' % (tag [0 ],tag [1 ],i )
420
+ for label in endNodes [tag ]:
414
421
G .add_edge (label , tagNode )
415
422
tailNodes .append (tagNode )
416
423
417
424
endNode = 'End'
418
425
for node in tailNodes :
419
426
G .add_edge (node , endNode )
420
427
421
- jobs = {
422
- 'startJobs' : startJobs ,
423
- 'systemJobs' : systemJobs ,
424
- 'endJobs' : endJobs ,
425
- }
426
-
427
- # finaljob dependent on endJobs
428
-
429
- return jobs , G
428
+ return G
430
429
431
430
def _rebuildSystem (self , c = None ):
432
431
if c is not None :
0 commit comments