Fixed resuming

This commit is contained in:
Benoît Sierro
2021-05-27 13:21:36 +02:00
parent 70f8ba1cc9
commit f88995aa6a
6 changed files with 31 additions and 11 deletions

View File

@@ -52,6 +52,12 @@ def create_parser():
"data_dir", "data_dir",
help="path to the directory where the initial_config.toml and the data is stored", help="path to the directory where the initial_config.toml and the data is stored",
) )
resume_parser.add_argument(
"configs",
nargs="*",
default=[],
help="list of subsequent config files (excluding the resumed one)",
)
resume_parser.set_defaults(func=resume_sim) resume_parser.set_defaults(func=resume_sim)
merge_parser = subparsers.add_parser("merge", help="merge simulation results") merge_parser = subparsers.add_parser("merge", help="merge simulation results")
@@ -99,9 +105,11 @@ def prep_ray(args):
def resume_sim(args): def resume_sim(args):
method = prep_ray(args) method = prep_ray(args)
sim = resume_simulations(args.data_dir, args.id, method=method) sim = resume_simulations(args.data_dir, method=method)
sim.run() sim.run()
run_simulation_sequence(*args.configs, method=method, prev_data_folder=sim.data_folder)
if __name__ == "__main__": if __name__ == "__main__":

View File

@@ -50,5 +50,5 @@ done
############################################################################################## ##############################################################################################
#### call your code below #### call your code below
scgenerator run {configs_list} scgenerator {command} {configs_list}
exit exit

View File

@@ -175,7 +175,7 @@ def validate_config_sequence(*configs: os.PathLike) -> Dict[str, Any]:
Parameters Parameters
---------- ----------
configs : os.PathLike configs : os.PathLike
sequence of paths to toml config files sequence of paths to toml config files. The first element may be a folder containing data intead
Returns Returns
------- -------
@@ -184,6 +184,8 @@ def validate_config_sequence(*configs: os.PathLike) -> Dict[str, Any]:
""" """
previous = None previous = None
for config in configs: for config in configs:
if (p := Path(config)).is_dir():
config = p / "initial_config.toml"
dico = io.load_toml(config) dico = io.load_toml(config)
previous = override_config(dico, previous) previous = override_config(dico, previous)
validate(previous) validate(previous)

View File

@@ -710,8 +710,13 @@ class RaySimulations(Simulations, priority=2):
self.p_bars.print() self.p_bars.print()
def run_simulation_sequence(*config_files: os.PathLike, method=None, final_name: str = None): def run_simulation_sequence(
prev = None *config_files: os.PathLike,
method=None,
final_name: str = None,
prev_data_folder: os.PathLike = None,
):
prev = prev_data_folder
for config_file in config_files: for config_file in config_files:
sim = new_simulation(config_file, prev, method) sim = new_simulation(config_file, prev, method)
sim.run() sim.run()
@@ -738,10 +743,9 @@ def new_simulation(
return _new_simulations(param_seq, task_id, method) return _new_simulations(param_seq, task_id, method)
def resume_simulations( def resume_simulations(data_folder: str, method: Type[Simulations] = None) -> Simulations:
data_folder: str, task_id: int = 0, method: Type[Simulations] = None
) -> Simulations:
task_id = np.random.randint(1e9, 1e12)
config = io.load_toml(os.path.join(data_folder, "initial_config.toml")) config = io.load_toml(os.path.join(data_folder, "initial_config.toml"))
io.set_data_folder(task_id, data_folder) io.set_data_folder(task_id, data_folder)
param_seq = initialize.RecoveryParamSequence(config, task_id) param_seq = initialize.RecoveryParamSequence(config, task_id)

View File

@@ -34,6 +34,9 @@ def create_parser():
default=f"source {os.path.expanduser('~/anaconda3/etc/profile.d/conda.sh')} && conda activate sc", default=f"source {os.path.expanduser('~/anaconda3/etc/profile.d/conda.sh')} && conda activate sc",
help="commands to run to setup the environement (default : activate the sc environment with conda)", help="commands to run to setup the environement (default : activate the sc environment with conda)",
) )
parser.add_argument(
"--command", default="run", choices=["run", "resume"], help="command to run"
)
return parser return parser
@@ -47,6 +50,9 @@ def copy_starting_files():
def main(): def main():
command_map = dict(run="Propagate", resume="Resuming")
parser = create_parser() parser = create_parser()
template = Paths.gets("submit_job_template") template = Paths.gets("submit_job_template")
args = parser.parse_args() args = parser.parse_args()
@@ -69,13 +75,13 @@ def main():
) )
job_name = f"supercontinuum {final_config['name']}" job_name = f"supercontinuum {final_config['name']}"
submit_sh = template.format( submit_sh = template.format(
job_name=job_name, configs_list=" ".join(args.configs), **vars(args) job_name=job_name, configs_list=" ".join(f'"{c}"' for c in args.configs), **vars(args)
) )
with open(file_name, "w") as file: with open(file_name, "w") as file:
file.write(submit_sh) file.write(submit_sh)
subprocess.run(["sbatch", "--test-only", file_name]) subprocess.run(["sbatch", "--test-only", file_name])
submit = input( submit = input(
f"Propagate {sim_num} pulses from configs {args.configs} with {args.cpus_per_node} cpus" f"{command_map[args.command]} {sim_num} pulses from configs {args.configs} with {args.cpus_per_node} cpus"
+ f" per node on {args.nodes} nodes for {format_time(args.time)} ? (y/[n])\n" + f" per node on {args.nodes} nodes for {format_time(args.time)} ? (y/[n])\n"
) )
if submit.lower() in ["y", "yes"]: if submit.lower() in ["y", "yes"]:

View File

@@ -32,7 +32,7 @@ class Spectrum(np.ndarray):
class Pulse(Sequence): class Pulse(Sequence):
def __init__(self, path: str, ensure_2d=True): def __init__(self, path: str, ensure_2d=True):
self.logger = get_logger(__name__) self.logger = get_logger(__name__)
self.path = path self.path = str(path)
self.__ensure_2d = ensure_2d self.__ensure_2d = ensure_2d
if not os.path.isdir(self.path): if not os.path.isdir(self.path):