Changeset 836


Ignore:
Timestamp:
10/15/15 19:57:49 (7 months ago)
Author:
mmckerns
Message:

enable mystic.model_plotter to take monitor instance

File:
1 edited

Legend:

Unmodified
Added
Removed
  • mystic/mystic/scripts.py

    r835 r836  
    3131    """ 
    3232    try: # if it's a logfile, it might be multi-id 
    33         step, param, cost = logfile_reader(source) 
     33        if isinstance(source, basestring): 
     34            step, param, cost = logfile_reader(source) 
     35        else: 
     36            step = enumerate(source.id) 
     37            if len(source) == source.id.count(None): 
     38                step = [(i,) for (i,j) in step] 
     39            else: 
     40                step = list(step) 
     41            param, cost = source.x, source.y 
    3442    except: # it's not a logfile, so read and return 
    3543        param, cost = read_history(source) 
     
    362370    _solver = None 
    363371 
     372    instance = None 
    364373    # handle the special case where list is provided by sys.argv 
    365374    if isinstance(model, (list,tuple)) and not logfile and not kwds: 
     
    398407 
    399408        # handle logfile if given 
    400         if logfile: model += ' ' + logfile 
     409        if logfile: 
     410            if isinstance(logfile, basestring): 
     411                model += ' ' + logfile 
     412            else: # special case of passing in monitor instance 
     413                instance = logfile 
    401414 
    402415        # process "commandline" arguments 
     
    566579    #FIXME: does grid=False still make sense here...? 
    567580    if reducer: reducer = _reducer or _get_instance(reducer) 
    568     if solver and (not source or not model): 
     581    if solver and (not source or not model): #XXX: not instance? 
    569582        raise RuntimeError('a model and results filename are required') 
    570     elif not source and not model: 
     583    elif not source and not model and not instance: 
    571584        raise RuntimeError('a model or a results file is required') 
    572585    if model: 
     
    585598            initial = [0]*xlen 
    586599        from mystic.monitors import VerboseLoggingMonitor 
    587         itermon = VerboseLoggingMonitor(filename=source, new=True) 
     600        if instance: 
     601            itermon = VerboseLoggingMonitor(new=True) 
     602            itermon.prepend(instance) 
     603        else: 
     604            itermon = VerboseLoggingMonitor(filename=source, new=True) 
    588605        # explicitly constrain parameters 
    589606        model = partial(mask)(model) 
     
    613630        fig = None 
    614631 
     632    if instance: source = instance 
    615633    if source: 
    616634        # params are the parameter trajectories 
     
    703721        else: # special case of passing in monitor instance 
    704722            instance = filename 
    705             cmdargs = ['^1203@magic*key311&'] + shlex.split(cmdargs) 
     723            cmdargs = shlex.split(cmdargs) 
    706724 
    707725    #XXX: note that 'argparse' is new as of python2.7 
Note: See TracChangeset for help on using the changeset viewer.