Changeset 3285 for branches

Show
Ignore:
Timestamp:
01/26/12 21:07:12 (4 months ago)
Author:
erkn
Message:

Store output files (except mcstas.dat) in sub-directory to avoid overwriting results

Location:
branches/mcxtrace-1.0/src/mcrun2
Files:
1 added
3 modified

Legend:

Unmodified
Added
Removed
  • branches/mcxtrace-1.0/src/mcrun2/main.py

    r3278 r3285  
    66from optparse import OptionParser, OptionGroup, OptionValueError 
    77from decimal import Decimal, InvalidOperation 
     8from datetime import datetime 
    89 
    910from mcstas import McStas 
     
    1112 
    1213LOG = logging.getLogger('mcstas') 
     14 
     15# File path friendly date format (avoid ':' and white space) 
     16DATE_FORMAT_PATH = "%Y%d%m_%H%M%S" 
    1317 
    1418 
     
    7781 
    7882    add('--optimise-file', 
    79         metavar='FILE', default='mcstas.dat', 
     83        metavar='FILE', default='./mcstas.dat', 
    8084        help='store optimisation results in FILE ' 
    8185             '(defaults to: "mcstas.dat")') 
     
    171175def expand_options(options): 
    172176    ''' Add extra options based on previous choices ''' 
     177    # MPI 
    173178    if options.mpi > 0: 
    174179        options.use_mpi = True 
     
    178183        options.use_mpi = False 
    179184        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)') 
    180192 
    181193 
     
    236248        handler.setLevel(logging.DEBUG) 
    237249 
     250    # Inform user of what is happening 
     251    # TODO: More info? 
     252    LOG.info('Using directory: "%s"' % options.dir) 
     253 
    238254    # Extract instrument and parameters 
    239255    if len(args) == 0: 
     
    250266 
    251267    (fixed_params, intervals) = get_parameters(options) 
     268 
     269    # Indicate end of setup / start of computations 
     270    LOG.info('<') 
    252271 
    253272    # Set fixed parameters 
  • branches/mcxtrace-1.0/src/mcrun2/mcstas.py

    r3279 r3285  
    100100        if not options.force_compile and isfile(self.binpath) \ 
    101101               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)) 
    103103            return  # skip 
    104104        LOG.info('Recompiling: %s', self.binpath) 
     
    118118        Process(options.cc).run(args) 
    119119 
    120     def run(self, pipe=False): 
     120    def run(self, pipe=False, extra_opts=None): 
    121121        ''' Run simulation ''' 
    122122        args = [] 
     123        extra_opts = extra_opts or {} 
     124 
    123125        options = self.options 
    124126        mpi = self.options.use_mpi 
     
    127129        proxy_opts_val = ['seed', 'ncount', 'dir', 'file', 'format'] 
    128130        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) 
    130134            if val is not None: 
    131135                args.extend(['--%s' % opt, str(val)]) 
     
    135139                            'no-output-files', 'info'] 
    136140        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) 
    138144            if val: 
    139145                args.append('--%s' % opt) 
  • branches/mcxtrace-1.0/src/mcrun2/optimisation.py

    r3279 r3285  
    1  
     1from os import mkdir 
    22import logging 
    33LOG = logging.getLogger('mcstas.optimisation') 
     
    101101 
    102102    def run(self): 
     103        LOG.info('Running Scanner, result file is "%s"' % self.outfile) 
     104 
    103105        fid = open(self.outfile, 'w') 
    104106        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) 
    105112 
    106113        for i, point in enumerate(self.points): 
     
    112119 
    113120            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 
    116124            LOG.info(', '.join('%s: %s' % (a, to_string(b)) 
    117125                               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 
    119131            dets = sorted(McStasResult(out).get_detectors(), 
    120132                          key=lambda x: x.name)