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

Last change on this file since 5168 was 5168, checked in by mmh, 10 years ago

cleanup

  • Property svn:executable set to *
File size: 1.8 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    print "name=", name
35    print "dist=", dist
36    if dist[0] == u'gaussian':
37        v[name] = NormalParameter(name, name, mean=dist[1], dev=dist[2])
38    elif dist[0] == u'uniform':
39        v[name] = UniformParameter(name, name, min=dist[1], max=dist[2])
40    else:
41        print "ERROR: Unknown distribution type: %s" % dist[0]
42        sys.exit(1)
43if uq_type == "smolyak":
44    uq = Smolyak(v.values(), args)
45else:
46    print "ERROR: Unknown UQ type: %s" % uq_type
47    os.chdir('..')
48    sys.exit(1)
49
50# save parameter values to CSV file
51vals = np.column_stack([p.values for p in uq.params])
52names = ['@@'+str(p.name) for p in uq.params]
53np.savetxt(cvsname, vals, delimiter=',', header=','.join(names), comments='')
54
55# This just saves PUQ state into HDF5 file, so later we can have PUQ analyze
56# the results and it knows about the input parameters, UQ method, etc.
57sw = Sweep(uq, RapptureHost('puq', dfile), None)
58sw.run(hname, overwrite=True)
59
60print "Finished with get_params.py\n"
Note: See TracBrowser for help on using the repository browser.