- Timestamp:
- 01/26/12 21:07:12 (4 months ago)
- Location:
- branches/mcxtrace-1.0/src/mcrun2
- Files:
-
- 1 added
- 3 modified
-
__init__.py (added)
-
main.py (modified) (7 diffs)
-
mcstas.py (modified) (4 diffs)
-
optimisation.py (modified) (3 diffs)
Legend:
- Unmodified
- Added
- Removed
-
branches/mcxtrace-1.0/src/mcrun2/main.py
r3278 r3285 6 6 from optparse import OptionParser, OptionGroup, OptionValueError 7 7 from decimal import Decimal, InvalidOperation 8 from datetime import datetime 8 9 9 10 from mcstas import McStas … … 11 12 12 13 LOG = logging.getLogger('mcstas') 14 15 # File path friendly date format (avoid ':' and white space) 16 DATE_FORMAT_PATH = "%Y%d%m_%H%M%S" 13 17 14 18 … … 77 81 78 82 add('--optimise-file', 79 metavar='FILE', default=' mcstas.dat',83 metavar='FILE', default='./mcstas.dat', 80 84 help='store optimisation results in FILE ' 81 85 '(defaults to: "mcstas.dat")') … … 171 175 def expand_options(options): 172 176 ''' Add extra options based on previous choices ''' 177 # MPI 173 178 if options.mpi > 0: 174 179 options.use_mpi = True … … 178 183 options.use_mpi = False 179 184 options.cc = 'gcc' 185 # Output DIR 186 if options.dir is None: 187 # use unique directory when unspecified 188 options.dir = "./mcstas-%s" % (datetime.strftime(datetime.now(), 189 DATE_FORMAT_PATH)) 190 # alert the user 191 LOG.info('No output directory specified (--dir)') 180 192 181 193 … … 236 248 handler.setLevel(logging.DEBUG) 237 249 250 # Inform user of what is happening 251 # TODO: More info? 252 LOG.info('Using directory: "%s"' % options.dir) 253 238 254 # Extract instrument and parameters 239 255 if len(args) == 0: … … 250 266 251 267 (fixed_params, intervals) = get_parameters(options) 268 269 # Indicate end of setup / start of computations 270 LOG.info('<') 252 271 253 272 # Set fixed parameters -
branches/mcxtrace-1.0/src/mcrun2/mcstas.py
r3279 r3285 100 100 if not options.force_compile and isfile(self.binpath) \ 101 101 and modified(self.path) < modified(self.binpath): 102 LOG.info('Using existing binary: %s', self.binpath)102 LOG.info('Using existing binary: %s', basename(self.binpath)) 103 103 return # skip 104 104 LOG.info('Recompiling: %s', self.binpath) … … 118 118 Process(options.cc).run(args) 119 119 120 def run(self, pipe=False ):120 def run(self, pipe=False, extra_opts=None): 121 121 ''' Run simulation ''' 122 122 args = [] 123 extra_opts = extra_opts or {} 124 123 125 options = self.options 124 126 mpi = self.options.use_mpi … … 127 129 proxy_opts_val = ['seed', 'ncount', 'dir', 'file', 'format'] 128 130 for opt in proxy_opts_val: 129 val = getattr(options, opt.replace('-', '_')) 131 # try extra_opts before options 132 default = getattr(options, opt.replace('-', '_')) 133 val = extra_opts.get(opt, default) 130 134 if val is not None: 131 135 args.extend(['--%s' % opt, str(val)]) … … 135 139 'no-output-files', 'info'] 136 140 for opt in proxy_opts_flags: 137 val = getattr(options, opt.replace('-', '_')) 141 # try extra_opts before optionts 142 default = getattr(options, opt.replace('-', '_')) 143 val = extra_opts.get(opt, default) 138 144 if val: 139 145 args.append('--%s' % opt) -
branches/mcxtrace-1.0/src/mcrun2/optimisation.py
r3279 r3285 1 1 from os import mkdir 2 2 import logging 3 3 LOG = logging.getLogger('mcstas.optimisation') … … 101 101 102 102 def run(self): 103 LOG.info('Running Scanner, result file is "%s"' % self.outfile) 104 103 105 fid = open(self.outfile, 'w') 104 106 wrote_header = False 107 108 # create top level 109 # each run will be in "dir/1", "dir/2", ... 110 mcstas_dir = self.mcstas.options.dir 111 mkdir(mcstas_dir) 105 112 106 113 for i, point in enumerate(self.points): … … 112 119 113 120 is_decimal = lambda x: type(x) == Decimal 114 to_string = lambda x: is_decimal(x) and '%.4f' % x \ 115 or x 121 to_string = (lambda x: is_decimal(x) 122 and '%.4f' % x or x) 123 116 124 LOG.info(', '.join('%s: %s' % (a, to_string(b)) 117 125 for (a, b) in point.items())) 118 out = self.mcstas.run(pipe=True) 126 127 # Change sub-directory as an extra option (dir/1 -> dir/2) 128 current_dir = '%s/%i' % (mcstas_dir, i) 129 out = self.mcstas.run(pipe=True, extra_opts={'dir': current_dir}) 130 119 131 dets = sorted(McStasResult(out).get_detectors(), 120 132 key=lambda x: x.name)
