1 from .Configuration
import Configuration
8 Represents a run of OpenMPCD, and its results.
13 Enumerates the state of a run.
16 * `Ready`, if the run is ready for execution or job
18 * `Submitted`, if the run has been submitted to the job
20 * `Running`, if the run is currently being executed,
21 * `Completed`, if the run has finished executing.
34 def __init__(self, rundir, pathTranslatorsServerToLocal = []):
39 The directory the run is saved in.
40 @param[in] pathTranslatorsServerToLocal
41 A list of functions that translate server paths to local
54 Returns the rundir path.
62 Returns a string that can be used to identify this particular run.
64 @throw Exception Throws if `self.getState() != self.RunState.Completed`.
68 raise Exception(
"Run not yet completed")
71 revision = open(self.
rundir +
"/git-revision").read()
73 seed = open(self.
rundir +
"/rngSeed.txt").read()
75 assert revision.count(
"\n") == 0
76 assert seed.count(
"\n") == 0
78 return configHash +
":" + revision +
":" + metadataHash +
":" + seed
83 Returns the run state as an instance of `RunState`.
89 if not os.path.isfile(self.
rundir +
"/config.txt"):
90 raise Exception(
"No configuration file found")
92 if os.path.isfile(self.
rundir +
"/metadata.txt"):
95 if glob.glob(self.
rundir +
"/input/srun-*.out"):
101 if os.path.exists(self.
rundir +
"/input/jobid"):
104 if os.path.isfile(self.
rundir +
"/input/job.slrm"):
107 raise Exception(self.
rundir +
" does not seem to be a rundir")
112 Returns whether this run has been executed by a job script in another
118 return os.path.isfile(self.
rundir +
"/input/parent-job-path.txt")
123 Returns the number of runs that run in parallel on this job.
129 with open(topRun.getPath() +
"/input/job.slrm",
"r")
as jobfile:
131 if line.startswith(
"srun"):
141 Returns the configuration instance for this run.
152 Returns the number of sweeps that have been performed after the warmup
153 phase, as configured in `mpc.warmupSteps`, or `0` if the run has not
159 metadataPath = self.
rundir +
"/metadata.txt"
161 if not os.path.isfile(metadataPath):
164 config = yaml.safe_load(open(metadataPath,
"r"))
165 return config[
"numberOfCompletedSweeps"]
168 def _getSHA256ByFilePath(self, path):
170 Returns the SHA256 hash of the file at `path`, as a string of
171 hexadecimal digits (with lowercase letters).
176 return hashlib.sha256(open(path,
"r").read()).hexdigest()
179 def _applyPathTranslatorsServerToLocal(self, s):
181 Applies all path translators in `self.pathTranslatorsServerToLocal` on
182 the given string, and returns the result.
187 ret = translator(ret)
192 def _getParentRun(self):
194 For runs that are part of a job that runs multiple executions in
195 parallel, return the run that contains the job script; otherwise, return
200 with open(self.
rundir +
"/input/parent-job-path.txt",
"r")
as f:
202 parentRun =
Run(rundir)