restage 0.8.0__py3-none-any.whl → 0.8.1__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.
restage/splitrun.py CHANGED
@@ -1,6 +1,8 @@
1
1
  from __future__ import annotations
2
2
 
3
3
  from pathlib import Path
4
+ from typing import Optional
5
+
4
6
  from .tables import SimulationEntry, InstrEntry
5
7
 
6
8
  def mcpl_parameters_split(s: str) -> list[tuple[str, str]]:
@@ -13,6 +15,8 @@ def si_int(s: str) -> int:
13
15
  'Ki': 2 ** 10, 'Mi': 2 ** 20, 'Gi': 2 ** 30, 'Ti': 2 ** 40, 'Pi': 2 ** 50
14
16
  }
15
17
  def int_mult(x: str, mult: int = 1):
18
+ if len(x) == 0 and mult > 1:
19
+ return mult
16
20
  return int(x) * mult if x.isnumeric() else int(float(x) * mult)
17
21
 
18
22
  def do_parse():
@@ -24,7 +28,7 @@ def si_int(s: str) -> int:
24
28
  return int_mult(s)
25
29
  value = do_parse()
26
30
  if value < 0:
27
- logger.info('Negative value encountered')
31
+ raise ValueError(f'Negative {value=} encountered')
28
32
  elif value > 2**53:
29
33
  logger.info(
30
34
  'McStas/McXtrace parse integer inputs as doubles,'
@@ -33,6 +37,17 @@ def si_int(s: str) -> int:
33
37
  )
34
38
  return value
35
39
 
40
+ def si_int_limits(s: str) -> tuple[Optional[int], int, Optional[int]]:
41
+ low, high = None, None
42
+ min_seps, max_seps = (']', '-', '}'), ('[', '+', '{')
43
+ if any(x in s for x in min_seps):
44
+ low, s = s.split(next(x for x in min_seps if x in s), maxsplit=1)
45
+ low = si_int(low)
46
+ if any(x in s for x in max_seps):
47
+ s, high = s.split(next(x for x in max_seps if x in s), maxsplit=1)
48
+ high = si_int(high)
49
+ return low, si_int(s), high
50
+
36
51
  def make_splitrun_parser():
37
52
  from argparse import ArgumentParser
38
53
  parser = ArgumentParser('splitrun')
@@ -40,7 +55,8 @@ def make_splitrun_parser():
40
55
  aa('instrument', type=str, default=None,
41
56
  help='Instrument `.instr` file name or serialised HDF5 or JSON Instr object')
42
57
  aa('parameters', nargs='*', type=str, default=None)
43
- aa('-n', '--ncount', type=si_int, default=None, help='Number of neutrons to simulate')
58
+ aa('-n', '--ncount', type=si_int_limits, default=None, metavar='[MIN-]COUNT[+MAX]',
59
+ help='COUNT {number}[kMGTP] target, MIN MAX replace missing --nmin --nmax')
44
60
  aa('-m', '--mesh', action='store_true', default=False, help='N-dimensional mesh scan')
45
61
  aa('-d', '--dir', type=str, default=None, help='Output directory')
46
62
  aa('-s', '--seed', type=int, default=None, help='Random number generator seed')
@@ -49,16 +65,16 @@ def make_splitrun_parser():
49
65
  help='Enable gravitation for all trajectories')
50
66
  aa('--bufsiz', type=si_int, default=None, help='Monitor_nD list/buffer-size')
51
67
  aa('--format', type=str, default=None, help='Output data files using FORMAT')
52
- aa('--nmin', type=int, default=None,
53
- help='Minimum number of particles to simulate during first instrument simulations')
54
- aa('--nmax', type=int, default=None,
55
- help='Maximum number of particles to simulate during first instrument simulations')
68
+ aa('--nmin', type=si_int, default=None, metavar='MIN',
69
+ help='MIN {number}[kMGTP] rays per first-instrument simulation')
70
+ aa('--nmax', type=si_int, default=None, metavar='MAX',
71
+ help='MAX {number}[kMGTP] rays per first-instrument simulation')
56
72
  aa('--dryrun', action='store_true', default=False,
57
73
  help='Do not run any simulations, just print the commands')
58
74
  aa('--parallel', action='store_true', default=False,
59
- help='Use MPI multi-process parallelism (primary instrument only at the moment)')
75
+ help='Use MPI multi-process parallelism')
60
76
  aa('--gpu', action='store_true', default=False,
61
- help='Use GPU OpenACC parallelism (primary instrument only at the moment)')
77
+ help='Use GPU OpenACC parallelism')
62
78
  aa('--process-count', type=int, default=0,
63
79
  help='MPI process count, 0 == System Default')
64
80
  # splitrun controlling parameters
@@ -131,6 +147,19 @@ def parse_splitrun(parser):
131
147
  args.mcpl_input_parameters = dict(args.mcpl_input_parameters)
132
148
  if args.mcpl_output_parameters is not None:
133
149
  args.mcpl_output_parameters = dict(args.mcpl_output_parameters)
150
+
151
+ if args.ncount is not None:
152
+ nmin, ncount, nmax = args.ncount
153
+ if args.nmin and nmin and args.nmin != nmin:
154
+ raise ValueError(f'Invalid repeated nmin specification: {nmin} != {args.nmin}')
155
+ if args.nmax and nmax and args.nmax != nmax:
156
+ raise ValueError(f'Invalid repeated nmax specification: {nmax} != {args.nmax}')
157
+ if nmin and not args.nmin:
158
+ args.nmin = nmin
159
+ if nmax and not args.nmax:
160
+ args.nmax = nmax
161
+ args.ncount = ncount
162
+
134
163
  parameters = parse_scan_parameters(args.parameters)
135
164
  precision = parse_splitrun_precision(args.P)
136
165
  return args, parameters, precision
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: restage
3
- Version: 0.8.0
3
+ Version: 0.8.1
4
4
  Author-email: Gregory Tucker <gregory.tucker@ess.eu>
5
5
  License: BSD-3-Clause
6
6
  Classifier: License :: OSI Approved :: BSD License
@@ -10,12 +10,12 @@ restage/mcpl.py,sha256=u7ixerJs4lqKSW2MYndZ2Xpsk8O0S-ZVo735YIy86gc,3223
10
10
  restage/range.py,sha256=TjOf4DSKfgoAIcrWQvv6MrtksQpnGJHdsEjVI5K-UfI,8116
11
11
  restage/run.py,sha256=bTcQIN9edKMXU_eFdX3E_mtJjwemoARrIUmZqzEGf0E,1475
12
12
  restage/scan.py,sha256=Yx8OQSBG6I2_64sW0LIDb0glVKwWoxUQQznASXgDZFQ,1432
13
- restage/splitrun.py,sha256=X44IOMokFswANvmF-FbyjmSOMLn73-WvJ-onHar4nnA,26369
13
+ restage/splitrun.py,sha256=M1P4jGHLezSFhvtB4Cgi0TKOzeyuGVigVu56pR7B4ok,27456
14
14
  restage/tables.py,sha256=vQf0GkM7ojQbWee_P_Xqfx0-lXLym7x6kyam8CWpB5s,16373
15
15
  restage/config/__init__.py,sha256=zFRT9QXgpUJpBncELCQ6by1-kjYp8Li1yJDfqxkHxAA,965
16
16
  restage/config/default.yaml,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
17
- restage-0.8.0.dist-info/METADATA,sha256=gCTXdsYwPUr3I490LQGA51h2Cr6GOkZcojAwEK2y2YM,7434
18
- restage-0.8.0.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
19
- restage-0.8.0.dist-info/entry_points.txt,sha256=vYNOPxJ4PzG-1GGFSd08jFxhrtKUWAdWzjJQeFBzFJE,116
20
- restage-0.8.0.dist-info/top_level.txt,sha256=iM_pb-taTZ0S2WMoDnt_qDMZoNMjmM19z3tTCuVm1IE,8
21
- restage-0.8.0.dist-info/RECORD,,
17
+ restage-0.8.1.dist-info/METADATA,sha256=VpQQbxeX9gs8-AwoScUmZCy8WVcNPQFh1o6Xb-Yto-o,7434
18
+ restage-0.8.1.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
19
+ restage-0.8.1.dist-info/entry_points.txt,sha256=vYNOPxJ4PzG-1GGFSd08jFxhrtKUWAdWzjJQeFBzFJE,116
20
+ restage-0.8.1.dist-info/top_level.txt,sha256=iM_pb-taTZ0S2WMoDnt_qDMZoNMjmM19z3tTCuVm1IE,8
21
+ restage-0.8.1.dist-info/RECORD,,