oh-my-batch 0.5.1__py3-none-any.whl → 0.5.3__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
oh_my_batch/batch.py CHANGED
@@ -2,7 +2,6 @@ import shlex
2
2
  import os
3
3
 
4
4
  from .util import split_list, ensure_dir, expand_globs, mode_translate
5
- from .assets import get_asset
6
5
 
7
6
 
8
7
  class BatchMaker:
oh_my_batch/combo.py CHANGED
@@ -1,5 +1,6 @@
1
1
  from itertools import product
2
2
  from string import Template
3
+ import traceback
3
4
  import random
4
5
  import json
5
6
  import os
@@ -164,7 +165,7 @@ class ComboMaker:
164
165
  return self
165
166
 
166
167
  def make_files(self, file: str, template: str, delimiter='@', mode=None, encoding='utf-8',
167
- extra_vars_from_file=None):
168
+ extra_vars_from_file=None, ignore_error=False):
168
169
  """
169
170
  Make files from template against each combo
170
171
  The template file can include variables with delimiter.
@@ -181,6 +182,7 @@ class ComboMaker:
181
182
  :param mode: File mode, e.g. 755, 644, ...
182
183
  :param encoding: File encoding
183
184
  :param extra_vars_from_file: Load extra variables from json file, which can be used in template
185
+ :param ignore_error: If True, ignore error when making files
184
186
  """
185
187
  _delimiter = delimiter
186
188
 
@@ -189,24 +191,31 @@ class ComboMaker:
189
191
 
190
192
  combos = self._make_combos()
191
193
  for i, combo in enumerate(combos):
192
- _template = template.format(i=i, **combo)
193
- with open(_template, 'r') as f:
194
- template_text = f.read()
195
-
196
- if extra_vars_from_file is not None:
197
- _vars_file = extra_vars_from_file.format(i=i, **combo)
198
- with open(_vars_file, 'r') as f:
199
- extra_vars = json.load(f)
200
- else:
201
- extra_vars = {}
202
- text = _Template(template_text).safe_substitute(combo, **extra_vars)
203
- _file = file.format(i=i, **combo)
204
- ensure_dir(_file)
205
-
206
- with open(_file, 'w', encoding=encoding) as f:
207
- f.write(text)
208
- if mode is not None:
209
- os.chmod(_file, mode_translate(str(mode)))
194
+ try:
195
+ _template = template.format(i=i, **combo)
196
+ with open(_template, 'r') as f:
197
+ template_text = f.read()
198
+
199
+ if extra_vars_from_file is not None:
200
+ _vars_file = extra_vars_from_file.format(i=i, **combo)
201
+ with open(_vars_file, 'r') as f:
202
+ extra_vars = json.load(f)
203
+ else:
204
+ extra_vars = {}
205
+ text = _Template(template_text).safe_substitute(combo, **extra_vars)
206
+ _file = file.format(i=i, **combo)
207
+ ensure_dir(_file)
208
+
209
+ with open(_file, 'w', encoding=encoding) as f:
210
+ f.write(text)
211
+ if mode is not None:
212
+ os.chmod(_file, mode_translate(str(mode)))
213
+ except Exception as e:
214
+ if ignore_error:
215
+ print(f"Error during making file, ignore: {e}")
216
+ traceback.print_exc()
217
+ else:
218
+ raise e
210
219
  return self
211
220
 
212
221
  def print(self, *line: str, file: str = '', mode=None, encoding='utf-8'):
@@ -254,6 +263,9 @@ class ComboMaker:
254
263
  return self
255
264
 
256
265
  def show_combos(self):
266
+ """
267
+ Show all combos in a human-readable format for debugging
268
+ """
257
269
  combos = self._make_combos()
258
270
  if not combos:
259
271
  print("No combos")
oh_my_batch/job.py CHANGED
@@ -87,14 +87,15 @@ class BaseJobManager:
87
87
  break
88
88
 
89
89
  time.sleep(interval)
90
+
91
+ error = False
90
92
  for job in jobs:
91
- error = False
92
93
  if not JobState.is_success(job['state']):
93
94
  logger.error('Job %s failed', job['script'])
94
95
  error = True
95
- if error:
96
+ if error and not wait:
96
97
  raise RuntimeError('Some jobs failed')
97
-
98
+
98
99
  def wait(self, *job_ids, timeout=None, interval=10):
99
100
  """
100
101
  Wait for jobs to finish
@@ -135,7 +136,7 @@ class BaseJobManager:
135
136
 
136
137
  def _update_state(self, jobs: List[dict]):
137
138
  raise NotImplementedError
138
-
139
+
139
140
  def _submit_job(self, job: dict, submit_opts: str):
140
141
  raise NotImplementedError
141
142
 
@@ -170,7 +171,7 @@ class Slurm(BaseJobManager):
170
171
  break
171
172
  else:
172
173
  logger.error('Job %s not found in sacct output', job['id'])
173
- return jobs
174
+ return jobs
174
175
 
175
176
  def _submit_job(self, job:dict, submit_opts:str):
176
177
  submit_cmd = f'{self._sbatch_bin} {submit_opts} {job["script"]}'
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: oh-my-batch
3
- Version: 0.5.1
3
+ Version: 0.5.3
4
4
  Summary:
5
5
  License: GPL
6
6
  Author: weihong.xu
@@ -37,6 +37,9 @@ pip install oh-my-batch
37
37
 
38
38
  ## Examples
39
39
  * [TESLA workflow](./examples/tesla/): A customizable active learning workflow for training machine learning potentials.
40
+ * [TESLA PIMD workflow](./examples/tesla-pimd/): A customizable active learning workflow for training machine learning potentials with path integral molecular dynamics.
41
+ * [LAMMPS benchmark](./examples/lammps-benchmark/): Find out the best MPI and OpenMP setup for LAMMPS through benchmarking.
42
+
40
43
 
41
44
  ## Use cases
42
45
 
@@ -2,14 +2,14 @@ oh_my_batch/__init__.py,sha256=BsRNxZbqDWfaIZJGxzIDqCubRWztMGFDceW08TECuFs,98
2
2
  oh_my_batch/__main__.py,sha256=sWyFZMwWNvhkanwZSJRGfBBDoIevhC028dTSB67i6yI,61
3
3
  oh_my_batch/assets/__init__.py,sha256=Exub46UbQaz2V2eXpQeiVfnThQpXaNeuyjlGY6gBSZc,130
4
4
  oh_my_batch/assets/functions.sh,sha256=LaiavZBu84D7C1r-dWhf91vPTuHXCMV1DQZUIPVQnjE,1001
5
- oh_my_batch/batch.py,sha256=1aVLP2KAbfNo0Asw7khh5HGCrh1PbYLNXLmiR-sWWcs,3988
5
+ oh_my_batch/batch.py,sha256=i3q1zY2li-YyN_99zjlpNJlZqqF5PSO3hwW1e0_N2VE,3958
6
6
  oh_my_batch/cli.py,sha256=Jyz8q2pUYke3mfJS6F_G9S9hApddgXxQw1BsN6Kfkjc,553
7
- oh_my_batch/combo.py,sha256=umbm85W_5zefUn6CwU_hf6fBEJTWgGbpKfAjSgpiEHE,10381
8
- oh_my_batch/job.py,sha256=8qFYscHGzIQhX-HrAGxCCv7h2T8Ls1Fj0gmNEBdP5Go,7227
7
+ oh_my_batch/combo.py,sha256=2d-vbKnn_UGKfnOp85le2vxiqj_qJXoIB4dAYJ8So_4,10885
8
+ oh_my_batch/job.py,sha256=xESyUEvcoCaIaPCB6u6_BlGkyFATEIbHqQQCQEYwrsg,7228
9
9
  oh_my_batch/misc.py,sha256=G_iOovRCrShBJJCc82QLN0CvMqW4adOefEoY1GedEiw,452
10
10
  oh_my_batch/util.py,sha256=5ve2QcviuF0UHFLrsXmjMTj0ogXJ4g05q1y-yWCFuOk,2409
11
- oh_my_batch-0.5.1.dist-info/LICENSE,sha256=OXLcl0T2SZ8Pmy2_dmlvKuetivmyPd5m1q-Gyd-zaYY,35149
12
- oh_my_batch-0.5.1.dist-info/METADATA,sha256=z8wggFpwrZ1vdM-opqc3jj0bQU3MMdDK4CcT9wRgAso,5174
13
- oh_my_batch-0.5.1.dist-info/WHEEL,sha256=sP946D7jFCHeNz5Iq4fL4Lu-PrWrFsgfLXbbkciIZwg,88
14
- oh_my_batch-0.5.1.dist-info/entry_points.txt,sha256=ZY2GutSoNjjSyJ4qO2pTeseKUFgoTYdvmgkuZZkwi68,77
15
- oh_my_batch-0.5.1.dist-info/RECORD,,
11
+ oh_my_batch-0.5.3.dist-info/LICENSE,sha256=OXLcl0T2SZ8Pmy2_dmlvKuetivmyPd5m1q-Gyd-zaYY,35149
12
+ oh_my_batch-0.5.3.dist-info/METADATA,sha256=sseM5qgmRwDIt7R5BhrJa7Xmh40nOPvXxEukeP5FS0Y,5468
13
+ oh_my_batch-0.5.3.dist-info/WHEEL,sha256=sP946D7jFCHeNz5Iq4fL4Lu-PrWrFsgfLXbbkciIZwg,88
14
+ oh_my_batch-0.5.3.dist-info/entry_points.txt,sha256=ZY2GutSoNjjSyJ4qO2pTeseKUFgoTYdvmgkuZZkwi68,77
15
+ oh_my_batch-0.5.3.dist-info/RECORD,,