|
3 | 3 | import datetime
|
4 | 4 | from functools import partial
|
5 | 5 | import importlib
|
| 6 | +import os |
6 | 7 | from os import PathLike
|
| 8 | +import pathlib |
7 | 9 | import time
|
8 | 10 |
|
9 | 11 | from scipy.optimize import OptimizeResult
|
@@ -226,9 +228,10 @@ def autosave_function_restartable(
|
226 | 228 | projector_method,
|
227 | 229 | signal_reset_descent_dir,
|
228 | 230 | ) -> None:
|
229 |
| - with h5py.File( |
230 |
| - f"{str(filename)}.restartable", "w", libver=("earliest", "v110") |
231 |
| - ) as f: |
| 231 | + state_filename = os.environ.get("VARIPEPS_STATE_FILE") |
| 232 | + if state_filename is None: |
| 233 | + state_filename = f"{str(filename)}.restartable" |
| 234 | + with h5py.File(state_filename, "w", libver=("earliest", "v110")) as f: |
232 | 235 | grp = f.create_group("unitcell")
|
233 | 236 | unitcell.save_to_group(grp, True)
|
234 | 237 |
|
@@ -1098,19 +1101,46 @@ def random_noise(a):
|
1098 | 1101 | runtime_std = np.std(flatten_runtime)
|
1099 | 1102 |
|
1100 | 1103 | remaining_slurm_time = slurm_data["TimeLimit"] - slurm_data["RunTime"]
|
| 1104 | + |
| 1105 | + if ( |
| 1106 | + remaining_time_correction := os.environ.get( |
| 1107 | + "VARIPEPS_REMAINING_TIME_CORRECTION" |
| 1108 | + ) |
| 1109 | + ) is not None: |
| 1110 | + try: |
| 1111 | + remaining_time_correction = int(remaining_time_correction) |
| 1112 | + remaining_slurm_time -= datetime.timedelta( |
| 1113 | + seconds=remaining_time_correction |
| 1114 | + ) |
| 1115 | + except (TypeError, ValueError): |
| 1116 | + pass |
| 1117 | + |
1101 | 1118 | time_of_one_step = datetime.timedelta(
|
1102 | 1119 | seconds=runtime_mean + 3 * runtime_std
|
1103 | 1120 | )
|
1104 | 1121 |
|
1105 | 1122 | if remaining_slurm_time < time_of_one_step:
|
1106 |
| - SlurmUtils.generate_restart_scripts( |
1107 |
| - f"{str(autosave_filename)}.restart.slurm", |
1108 |
| - f"{str(autosave_filename)}.restart.py", |
1109 |
| - f"{str(autosave_filename)}.restartable", |
1110 |
| - slurm_data, |
1111 |
| - ) |
| 1123 | + if ( |
| 1124 | + restart_needed_filename := os.environ.get( |
| 1125 | + "VARIPEPS_NEED_RESTART_FILE" |
| 1126 | + ) |
| 1127 | + ) is not None: |
| 1128 | + pathlib.Path(restart_needed_filename).touch() |
| 1129 | + |
| 1130 | + if ( |
| 1131 | + varipeps_config.slurm_restart_mode |
| 1132 | + is Slurm_Restart_Mode.WRITE_RESTART_SCRIPT |
| 1133 | + or varipeps_config.slurm_restart_mode |
| 1134 | + is Slurm_Restart_Mode.AUTOMATIC_RESTART |
| 1135 | + ): |
| 1136 | + SlurmUtils.generate_restart_scripts( |
| 1137 | + f"{str(autosave_filename)}.restart.slurm", |
| 1138 | + f"{str(autosave_filename)}.restart.py", |
| 1139 | + f"{str(autosave_filename)}.restartable", |
| 1140 | + slurm_data, |
| 1141 | + ) |
1112 | 1142 |
|
1113 |
| - slurm_restart_written = True |
| 1143 | + slurm_restart_written = True |
1114 | 1144 |
|
1115 | 1145 | if (
|
1116 | 1146 | varipeps_config.slurm_restart_mode
|
|
0 commit comments