Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

nexus: forbid bundling sims that depend on each other #247

Merged
merged 1 commit into from
Jun 2, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 25 additions & 0 deletions nexus/library/bundle.py
Original file line number Diff line number Diff line change
Expand Up @@ -110,11 +110,36 @@ def __init__(self,*sims,**kwargs):

def bundle_dependencies(self):
deps = []
sim_ids = set()
depsim_ids = set()
for sim in self.sims:
sim_ids.add(sim.simid)
depsim_ids |= sim.downstream_simids()
for d in sim.dependencies:
deps.append((d.sim,'other'))
#end for
#end for
# guard against dependencies within the bundle
internal_deps = sim_ids & depsim_ids
if len(internal_deps)>0:
sims = dict()
for sim in self.sims:
sims[sim.simid]=sim
#end for
msg = 'attempted to bundle simulations that depend on each other\nsimulations can only be bundled if they can be executed simultaneously\nbundle identifier, simid, and directory:\n {0:<8} {1:>4} {2}\n'.format(self.identifier,self.simid,self.locdir)
msg+='sims in the bundle that can remain:\n'
for simid in sorted(sim_ids-internal_deps):
sim = sims[simid]
msg +=' {0:<8} {1:>4} {2}\n'.format(sim.identifier,sim.simid,sim.locdir)
#end for
msg+='sims in the bundle that need to be removed:\n'
for simid in sorted(internal_deps):
sim = sims[simid]
msg +=' {0:<8} {1:>4} {2}\n'.format(sim.identifier,sim.simid,sim.locdir)
#end for
msg+='please remove the necessary sims from the bundle and try again\nthe excluded sims can likely be bundled separately'
self.error(msg,'bundle')
#end if
self.depends(*deps)
#end def bundle_dependencies

Expand Down
12 changes: 12 additions & 0 deletions nexus/library/simulation.py
Original file line number Diff line number Diff line change
Expand Up @@ -828,6 +828,18 @@ def get_dependencies(self):
#end def get_dependencies


def downstream_simids(self,simids=None):
if simids is None:
simids = set()
#end if
for sim in self.dependents:
simids.add(sim.simid)
sim.downstream_simids(simids)
#end for
return simids
#end def downstream_simids


def copy_file(self,sourcefile,dest):
src = os.path.dirname(os.path.abspath(sourcefile))
dst = os.path.abspath(dest)
Expand Down