Skip to content

Commit e0af992

Browse files
authored
Merge pull request #2276 from mccode-dev/mcrun-scan-by-seed
mcrun/mxrun: feature addition - scan by seed
2 parents 5a7a909 + 03b9019 commit e0af992

File tree

2 files changed

+16
-3
lines changed

2 files changed

+16
-3
lines changed

tools/Python/mcrun/mcrun.py

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,10 @@ def add_mcrun_options(parser):
9595
type=int, metavar='NP',
9696
help='Set number of scan points')
9797

98+
add('--seeds',
99+
metavar='SEEDS',
100+
help='Set range of seeds to scan (each must be: SEED != 0)')
101+
98102
add('-L', '--list',
99103
action='store_true',
100104
help='Use a fixed list of points for linear scanning')
@@ -541,6 +545,9 @@ def main():
541545
mcstas.prepare(options)
542546

543547
(fixed_params, intervals) = get_parameters(options)
548+
# Add --seeds as an 'interval', to allow scanning simulation seed
549+
if options.seeds:
550+
intervals['--seed']=options.seeds.split(',')
544551

545552
# Indicate end of setup / start of computations
546553
LOG.info('===')
@@ -561,6 +568,10 @@ def main():
561568
if options.list and options.numpoints:
562569
raise OptionValueError('--numpoints cannot be used with --list')
563570

571+
# Can't both do list and --seeds scanning
572+
if options.list and options.seeds:
573+
raise OptionValueError('--seeds cannot be used with --list')
574+
564575
if options.list:
565576
if len(intervals) == 0:
566577
raise OptionValueError(
@@ -569,7 +580,7 @@ def main():
569580
points = len(pointlist[0])
570581
if not (all(map(lambda i: len(i) == points, intervals.values()))):
571582
raise OptionValueError(
572-
'All variables much have an equal amount of points.')
583+
'All variables must have an equal amount of points.')
573584
interval_points = LinearInterval.from_list(
574585
points, intervals)
575586

tools/Python/mcrun/optimisation.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,9 @@ def build_header(options, params, intervals, detectors):
3737
# Date format: Fri Aug 26 12:21:39 2011
3838
date = datetime.strftime(datetime.now(), '%a %b %d %H %M %Y')
3939

40-
xvars = ', '.join(params)
40+
# Strip header keys of -- (to make --seed -> seed
41+
hdrparams = {key.lstrip('-') for key in params}
42+
xvars = ', '.join(hdrparams)
4143
lst = intervals[list(params)[0]]
4244
xmin = min(lst)
4345
xmax = max(lst)
@@ -56,7 +58,7 @@ def build_header(options, params, intervals, detectors):
5658

5759
scantype = 'multiarray_1d(%d)' % N
5860

59-
variables = list(params)
61+
variables = list(hdrparams)
6062
for detector in detectors:
6163
variables += [detector + '_I', detector + '_ERR']
6264

0 commit comments

Comments
 (0)