Changeset 801


Ignore:
Timestamp:
06/27/15 14:10:35 (11 months ago)
Author:
mmckerns
Message:

windows comparibility in getch, and pathos; added better read_import

Location:
mystic
Files:
12 edited

Legend:

Unmodified
Added
Removed
  • mystic/examples/TEST_ffitPP.py

    r799 r801  
    4343 
    4444if __name__ == '__main__': 
     45    from pathos.helpers import freeze_support 
     46    freeze_support() # help Windows use multiprocessing 
    4547    solution = main() 
    4648    print_solution(solution) 
  • mystic/examples/TEST_ffitPP_b.py

    r799 r801  
    7171 
    7272if __name__ == '__main__': 
     73    from pathos.helpers import freeze_support 
     74    freeze_support() # help Windows use multiprocessing 
    7375 
    7476    # number of local processors 
  • mystic/examples/buckshot_example06.py

    r799 r801  
    2525from mystic.models.poly import chebyshev8coeffs 
    2626 
    27 # if available, use a multiprocessing worker pool 
     27# if available, use a pathos worker pool 
    2828try: 
    2929    from pathos.pools import ProcessPool as Pool 
     
    6868 
    6969if __name__ == '__main__': 
     70    from pathos.helpers import freeze_support 
     71    freeze_support() # help Windows use multiprocessing 
    7072 
    7173    print "Powell's Method" 
  • mystic/examples/lattice_example06.py

    r799 r801  
    2525from mystic.models.poly import chebyshev8coeffs 
    2626 
    27 # if available, use a multiprocessing worker pool 
     27# if available, use a pathos worker pool 
    2828try: 
    2929    from pathos.pools import ProcessPool as Pool 
     
    6868 
    6969if __name__ == '__main__': 
     70    from pathos.helpers import freeze_support 
     71    freeze_support() # help Windows use multiprocessing 
    7072 
    7173    print "Powell's Method" 
  • mystic/examples/mpmap_desolve.py

    r799 r801  
    4949 
    5050if __name__=='__main__': 
     51    from pathos.helpers import freeze_support 
     52    freeze_support() # help Windows use multiprocessing 
     53 
    5154    def print_solution(func): 
    5255        print poly1d(func) 
  • mystic/examples/mpmap_desolve_rosen.py

    r799 r801  
    5050 
    5151if __name__=='__main__': 
     52    from pathos.helpers import freeze_support 
     53    freeze_support() # help Windows use multiprocessing 
     54 
    5255    def print_solution(func): 
    5356        print func 
  • mystic/examples/test_twistedgaussian3.py

    r799 r801  
    2121 
    2222def scemmap(Q): 
     23    from test_twistedgaussian import scem 
    2324    Cs, As, Sk, Sak, target, cn = Q 
    2425    niter = 1000 
     
    3334    # if available, use a multiprocessing worker pool 
    3435    try: 
     36        from pathos.helpers import freeze_support 
     37        freeze_support() # help Windows use multiprocessing 
    3538        from pathos.pools import ProcessPool as Pool 
    3639        map = Pool().map 
  • mystic/mystic/abstract_solver.py

    r795 r801  
    668668        """save solver state to a restart file""" 
    669669        import dill 
     670        fd = None 
    670671        if filename is None: # then check if already has registered file 
    671672            if self._state is None: # then create a new one 
    672                 import tempfile 
    673                 self._state = tempfile.mkstemp(suffix='.pkl')[-1] 
     673                import os, tempfile 
     674                fd, self._state = tempfile.mkstemp(suffix='.pkl') 
     675                os.close(fd) 
    674676            filename = self._state 
    675677        self._state = filename 
  • mystic/mystic/munge.py

    r792 r801  
    4646        params, cost = raw_to_support(params, cost) 
    4747    except: 
    48         exec "from %s import params" % source 
    49         exec "from %s import cost" % source 
     48        params, cost = read_import(source+'.py', 'params', 'cost') 
    5049    return params, cost 
    5150 
     
    145144 
    146145def read_raw_file(file_in): 
    147   import re 
    148   file_in = re.sub('\.py*.$', '', file_in)  #XXX: strip off .py* extension 
    149   exec "from %s import params as steps" % file_in 
    150   exec "from %s import cost as energy" % file_in 
    151   return steps, energy 
     146  steps, energy = read_import(file_in, "params", "cost") 
     147  return steps, energy  # was 'from file_in import params as steps', etc 
     148 
     149def read_import(file, *targets): 
     150  "import the targets; targets are name strings" 
     151  import re, os, sys 
     152  _dir, file = os.path.split(file) 
     153  file = re.sub('\.py*.$', '', file) #XXX: strip .py* extension 
     154  curdir = os.path.abspath(os.curdir) 
     155  sys.path.append('.') 
     156  results = [] 
     157  try: 
     158    if _dir: os.chdir(_dir) 
     159    if len(targets): 
     160      for target in targets: 
     161        exec "from %s import %s" % (file, target) 
     162        exec "results.append(%s)" % target 
     163    else: 
     164        exec "import %s" % file 
     165        exec "results.append(%s)" % file 
     166  except ImportError: 
     167    raise RuntimeError('File: %s not found' % file) 
     168  finally: 
     169    if _dir: os.chdir(curdir) 
     170    sys.path.pop() 
     171  if not len(results): return None 
     172  return results[-1] if (len(results) == 1) else results 
    152173 
    153174def read_converge_file(file_in): 
  • mystic/mystic/tools.py

    r793 r801  
    236236       if str is not None: 
    237237          print str 
    238        subprocess.call('stty raw', shell=True) 
     238       if sys.platform[:3] != 'win': 
     239          raw,cooked = 'stty raw','stty cooked' 
     240       else: 
     241          raw,cooked = '','' 
     242       subprocess.call(raw, shell=True) 
    239243       a = sys.stdin.read(1) 
    240        subprocess.call('stty cooked', shell=True) 
     244       subprocess.call(cooked, shell=True) 
    241245       return a 
    242246    else: 
  • mystic/scripts/support_hypercube_scenario.py

    r776 r801  
    343343    npts = parsed_opts.dim 
    344344    if "None" == npts: # npts may have been logged 
    345       import re 
    346       file = re.sub('\.py*.$', '', parsed_args[0]) #XXX: strip .py* extension 
    347       exec "from %s import npts" % file 
     345      from mystic.munge import read_import 
     346      npts = read_import(parsed_args[0], 'npts') 
    348347    else: npts = tuple(int(i) for i in dim.split(",")) # format is "1,1,1" 
    349348  except: 
  • mystic/tests/test_symbolic_basic.py

    r781 r801  
    128128 
    129129    x0 = [1., 1., 1.] 
    130     assert almostEqual(pf(cn(x0)), 0.0, tol=1e-7) 
     130    assert almostEqual(pf(cn(x0)), 0.0, tol=1e-2) 
    131131    #XXX: implement: wrap_constraint( as_constraint(pf), sum, ctype='inner') ? 
    132132 
Note: See TracChangeset for help on using the changeset viewer.