source: branches/uq/puq/get_params.py @ 5182

Last change on this file since 5182 was 5182, checked in by mmh, 8 years ago

lots of uq cleanup and enhancements

  • Property svn:executable set to *
File size: 1.9 KB
Line 
1#!/usr/bin/env python
2"""
3This script takes some uq parameters from the command line
4and starts up a PUQ session using them.  The RapptureHost()
5class will not actually execute any jobs.  Job parameters
6are instead saved to a CSV file named params[pid].csv.
7PUQ status is saved into an hdf5 file, as usual.
8"""
9
10import sys
11import os
12from puq import NormalParameter, UniformParameter, Sweep, RapptureHost, Smolyak
13import numpy as np
14from puq.jpickle import unpickle
15
16# Redirect stdout and stderr to files for debugging.
17sys.stdout = open("uq_debug.out", 'w')
18sys.stderr = open("uq_debug.err", 'w')
19
20print sys.argv
21pid, varlist, uq_type, args = sys.argv[1:]
22
23dfile = "driver%s.xml" % pid
24cvsname = "params%s.csv" % pid
25hname = "puq_%s.hdf5" % pid
26
27varlist = unpickle(varlist)
28print "varlist=", varlist
29
30v = {}
31for p in varlist:
32    name, dist = p
33    name = str(name)
34    if dist[0] == u'gaussian':
35        try:
36            kwargs = dist[3]
37        except:
38            kwargs = {}
39        v[name] = NormalParameter(name, name, mean=dist[1], dev=dist[2], **kwargs)
40        print v[name]
41    elif dist[0] == u'uniform':
42        v[name] = UniformParameter(name, name, min=dist[1], max=dist[2])
43    else:
44        print "ERROR: Unknown distribution type: %s" % dist[0]
45        sys.exit(1)
46if uq_type == "smolyak":
47    uq = Smolyak(v.values(), args)
48else:
49    print "ERROR: Unknown UQ type: %s" % uq_type
50    os.chdir('..')
51    sys.exit(1)
52
53# save parameter values to CSV file
54vals = np.column_stack([p.values for p in uq.params])
55names = ['@@'+str(p.name) for p in uq.params]
56np.savetxt(cvsname, vals, delimiter=',', header=','.join(names), comments='')
57
58# This just saves PUQ state into HDF5 file, so later we can have PUQ analyze
59# the results and it knows about the input parameters, UQ method, etc.
60host = RapptureHost('puq', dfile)
61sw = Sweep(uq, host, None)
62host.psweep = sw.psweep
63sw.run(hname, overwrite=True)
64
65print "Finished with get_params.py\n"
Note: See TracBrowser for help on using the repository browser.