Skip to content

Commit

Permalink
fixes to build logic. NOAA-GFDL#98
Browse files Browse the repository at this point in the history
  • Loading branch information
Nicholas Hannah committed Oct 27, 2016
1 parent e702bc3 commit cb5cc8d
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 27 deletions.
32 changes: 9 additions & 23 deletions tools/tests/experiment.py
Original file line number Diff line number Diff line change
Expand Up @@ -92,10 +92,7 @@ def __init__(self, id, compiler='gnu', build='repro', memory_type='dynamic'):
if self.variation is not None:
self.path = os.path.join(self.path, self.variation)

# Path to executable, may not exist yet.
rel_path = 'build/{}/{}/{}/MOM6'.format(self.compiler,
self.model_name, build)
self.exec_path = os.path.join(_mom_examples_path, rel_path)
self.exec_path = None

# Lists of available and unfinished diagnostics.
self.available_diags = self._parse_available_diags()
Expand All @@ -108,9 +105,8 @@ def __init__(self, id, compiler='gnu', build='repro', memory_type='dynamic'):
# It helps with testing and human readability if this is sorted.
self.available_diags.sort(key=lambda d: d.full_name)

# Whether this experiment has been built, run. Want to try to avoid
# Whether this experiment has been run. Want to try to avoid
# repeating this if possible.
self.has_built = False
self.has_run = False
# Another thing to avoid repeating.
self.has_dumped_diags = False
Expand All @@ -136,33 +132,22 @@ def _parse_available_diags(self):
diags.extend([Diagnostic(m, d, self.path) for m, d in matches])
return diags

def force_build_model(self):
"""
Do a clean build of the configuration.
"""

ret = self.model.build_shared(self.compiler, self.build)
if ret == 0:
ret = self.model.build_model(self.compiler, self.build,
self.memory_type)
if ret == 0:
self.has_built = True

return ret

def build_model(self):
"""
Build the configuration for this experiment.
"""
if not self.has_built:
return self.force_build_model()

if not self.exec_path:
ret, exe = self.model.build(self.compiler, self.build,
self.memory_type)
assert(ret == 0)
self.exec_path = exe

def run(self):
"""
Run the experiment if it hasn't already.
"""

self.build_model()
if not self.has_run:
return self.force_run()

Expand All @@ -171,6 +156,7 @@ def force_run(self):
Run the experiment.
"""

self.build_model()
assert(os.path.exists(self.exec_path))

ret = 0
Expand Down
12 changes: 8 additions & 4 deletions tools/tests/model.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,8 +51,11 @@ def __init__(self, name, mom_dir):
self.site = 'raijin'

def build(self, compiler, build, memory_type):
self.build_shared(compiler, build)
self.build_model(compiler, build, memory_type)
sret, shared_dir = self.build_shared(compiler, build)
mret, model_dir = self.build_model(compiler, build, memory_type)
exe = os.path.join(model_dir, 'MOM6')

return sret + mret, exe

def build_shared(self, compiler, build):
saved_path = os.getcwd()
Expand All @@ -75,7 +78,7 @@ def build_shared(self, compiler, build):
with open(os.path.join(shared_dir, 'build.out'), 'w') as f:
f.write(output)

return ret
return ret, shared_dir


def build_model(self, compiler='gnu', build='REPRO', memory_type='dynamic'):
Expand Down Expand Up @@ -113,4 +116,5 @@ def build_model(self, compiler='gnu', build='REPRO', memory_type='dynamic'):
with open(os.path.join(model_dir, 'build.out'), 'w') as f:
f.write(output)

return ret
return ret, model_dir

0 comments on commit cb5cc8d

Please sign in to comment.