Changeset 5182


Ignore:
Timestamp:
Apr 2, 2015 7:12:40 AM (5 years ago)
Author:
mmh
Message:

lots of uq cleanup and enhancements

Location:
branches/uq
Files:
8 edited

Legend:

Unmodified
Added
Removed
  • branches/uq/gui/scripts/analyzer.tcl

    r5169 r5182  
    501501# ----------------------------------------------------------------------
    502502itcl::body Rappture::Analyzer::reset {{when -eventually}} {
    503     puts "RESET $when"
    504503    if {$when == "-eventually"} {
    505504        after cancel [list catch [itcl::code $this reset -now]]
     
    507506        return
    508507    }
    509 
    510     puts "RESET contains [$_resultset contains [$_tool xml object]]"
    511     puts [$_tool xml object]
    512508
    513509    # check to see if simulation is really needed
  • branches/uq/gui/scripts/probdisteditor.tcl

    r5179 r5182  
    334334        uniform {
    335335            if {![info exists _value(min)] || ![info exists _value(max)]} {
    336                 # puts "UNIFORM min=$min max=$max"
    337                 if {$min != "" && $max != ""} {
    338                     set _value(min) $min
    339                     set _value(max) $max
    340                 } elseif {$min != ""} {
    341                     set _value(min) $min
    342                     set _value(max) [expr $min + 1]
    343                 } elseif {$max != ""} {
    344                     set _value(max) $max
    345                     set _value(min) [expr $max - 1]
     336                set _value(max) [expr $_value(central) * 1.1]
     337                set _value(min) [expr $_value(central) * 0.9]
     338                if {$_value(central) == 0.0} {
     339                    set _value(max) 1.0
    346340                }
    347341                set _uvalue(min) $_value(min)$_units
  • branches/uq/gui/scripts/resultset.tcl

    r5169 r5182  
    1 # -*- mode: tcl; indent-tabs-mode: nil -*-
     1# -*- mode: tcl; indent-tabs-mode: nil -*- 
    22# ----------------------------------------------------------------------
    33#  COMPONENT: ResultSet - set of XML objects for simulated results
     
    4040    private variable _notify         ;# info used for notify command
    4141}
    42 
     42                                                                               
    4343# ----------------------------------------------------------------------
    4444# CONSTRUCTOR
     
    189189# ----------------------------------------------------------------------
    190190itcl::body Rappture::ResultSet::diff {option args} {
    191     puts "ResultSet::diff $option $args"
    192     flush stdout
    193191    switch -- $option {
    194192        names {
     
    200198            }
    201199            set col [lindex $args 0]
    202             puts "col=$col"
     200
    203201            set which "all"
    204202            if {[llength $args] > 1} {
     
    308306# ----------------------------------------------------------------------
    309307itcl::body Rappture::ResultSet::contains {xmlobj} {
    310     puts "CONTAINS [$_results size]"
    311308    # no results? then this must be new
    312309    if {[$_results size] == 0} {
     
    319316    # is a column to represent the quantity with the difference.
    320317    #
    321     puts "CONTAINS A"
    322318    set xmlobj0 [$_results get -format xmlobj end]
    323     puts "CONTAINS B $xmlobj0 , $xmlobj"
    324     puts "DIFF IS [$xmlobj0 diff $xmlobj]"
    325     flush stdout
    326319    foreach {op vpath oldval newval} [$xmlobj0 diff $xmlobj] {
    327         puts "$op $vpath $oldval $newval"
    328         flush stdout
    329320        if {[$xmlobj get $vpath.about.diffs] == "ignore"} {
    330321            continue
     
    337328        if {[$_results column names $vpath] == ""} {
    338329            # no column for this quantity yet
    339             puts "NO COLUMN"
    340330            return 0
    341331        }
    342332    }
    343     puts "CONTAINS F"
     333
    344334    #
    345335    # If we got this far, then look through existing results for
     
    367357        }
    368358    }
    369     puts "CONTAINS Z"
     359
    370360    # must be some differences
    371361    return 0
  • branches/uq/gui/scripts/uq.tcl

    r5168 r5182  
    6868        button $fr.cancel -text Cancel -command  [itcl::code $this _setWaitVariable 0]
    6969        set _go $fr.go
    70         button $_go -text Continue -command  [itcl::code $this _setWaitVariable 1]
     70        button $_go -text "Launch Jobs" -command  [itcl::code $this _setWaitVariable 1]
    7171        _set_text $inner
    7272
  • branches/uq/lang/tcl/scripts/library.tcl

    r5169 r5182  
    10511051}
    10521052
     1053# ----------------------------------------------------------------------
     1054# USAGE: uq_get_vars [$tfile]
     1055#
     1056# Scans number nodes in the input section for UQ parameters.
     1057#
     1058# Returns a string in JSON so it can easily be passed to PUQ. Strips units
     1059# because PUQ does not need or recognize them.
     1060#
     1061# For example, 2 parameters, one gaussian and one uniform might return:
     1062# [["height",["gaussian",100,10,{"min":0}]],["velocity",["uniform",80,90]]]
     1063#
     1064# Returns "" if there are no UQ parameters.
     1065#
     1066# If tfile is specified, write a template file out.
     1067# ----------------------------------------------------------------------
    10531068itcl::body Rappture::LibraryObj::uq_get_vars {{tfile ""}} {
    1054     set varlist ""
     1069    set varlist \[
    10551070
    10561071    if {$tfile == ""} {
     
    10631078    }
    10641079
     1080    set first 1
    10651081    set n [$node selectNodes /run/input//number]
    10661082    foreach _n $n {
     
    10691085        if {[string equal -length 8 $val "uniform "] ||
    10701086            [string equal -length 9 $val "gaussian "]} {
     1087
     1088            if {$first == 1} {
     1089                set first 0
     1090            } else {
     1091                append varlist ,
     1092            }
     1093
    10711094            set unode [$_n selectNodes units/text()]
    10721095            if {"" != $unode} {
     
    10751098                -context $units -to $units -units off]
    10761099            }
     1100
     1101            set v \[\"[$_n getAttribute id]\",
     1102            #set val \"[lindex $val 0]\",[lindex $val 1],[lindex $val 2]
     1103            set fmt "\[\"%s\",%.16g,%.16g"
     1104            set val [format $fmt [lindex $val 0] [lindex $val 1] [lindex $val 2]]
     1105            append v $val
     1106
     1107            if {[string equal -length 9 [$x nodeValue] "gaussian "]} {
     1108                set minv ""
     1109                set min_node [$_n selectNodes min/text()]
     1110                if {"" != $min_node} {
     1111                    set minv [$min_node nodeValue]
     1112                    if {$unode != ""} {
     1113                        set minv [Rappture::Units::convert $minv -context $units -units off]
     1114                    }
     1115                }
     1116
     1117                set maxv ""
     1118                set max_node [$_n selectNodes max/text()]
     1119                if {"" != $max_node} {
     1120                    set maxv [$max_node nodeValue]
     1121                    if {$unode != ""} {
     1122                        set maxv [Rappture::Units::convert $maxv -context $units -units off]
     1123                    }
     1124                }
     1125
     1126                if {$minv != "" || $maxv != ""} {
     1127                    append v ",{"
     1128                    if {$minv != ""} {
     1129                        append v "\"min\":$minv"
     1130                        if {$maxv != ""} {append v ,}
     1131                    }
     1132                    if {$maxv != ""} {
     1133                        append v "\"max\":$maxv"
     1134                    }
     1135                    append v "}"
     1136                }
     1137            }
     1138
    10771139            if {$tfile != ""} {
    1078               $x nodeValue @@[$_n getAttribute id]
    1079             }
    1080             lappend varlist [list [$_n getAttribute id] $val]
    1081         }
    1082     }
     1140                $x nodeValue @@[$_n getAttribute id]
     1141            }
     1142            append varlist $v\]\]
     1143        }
     1144    }
     1145    append varlist \]
    10831146
    10841147    if {$tfile != ""} {
     
    10891152        $doc delete
    10901153    }
     1154    if {$varlist == "\[\]"} {set varlist ""}
     1155    puts "uq_get_vars returning $varlist"
    10911156    return $varlist
    10921157}
  • branches/uq/lang/tcl/scripts/task.tcl

    r5169 r5182  
    407407            # UQ. Collect data from all jobs and put it in one xml run file.
    408408            #file delete -force -- run_uq.xml
    409             set res [exec puq_analyze.py puq_[pid].hdf5]
    410             append result "\n" $res
     409            # set res [exec puq_analyze.py puq_[pid].hdf5]
     410            if {[catch {exec puq_analyze.py puq_[pid].hdf5} res]} {
     411                set fp [open "uq_debug.err" r]
     412                set rdata [read $fp]
     413                close $fp
     414                puts "PUQ analysis failed: $res\n$rdata"
     415                error "UQ analysis failed: $res\n$rdata"
     416            } else {
     417                append result "\n" $res
     418            }
    411419        }
    412420        if {[regexp {=RAPPTURE-RUN=>([^\n]+)} $result match file]} {
     
    648656# and get a CSV file containing the parameter values to use for the runs.
    649657itcl::body Rappture::Task::_get_params {varlist uq_type uq_args} {
    650     puts "tcl get_params $varlist uq_type=$uq_type args=$uq_args"
    651     # convert tcl list of variables to json so python can read it
    652     proc varlist2py {inlist} {
    653         set ovar "\["
    654         set first 1
    655         foreach a $inlist {
    656             foreach {var val} $a break
    657             if {$first == 1} {
    658                 append ovar \[\"$var\",
    659                 set first 0
    660             } else {
    661                 append ovar \],\[\"$var\",
    662             }
    663             switch [lindex $val 0] {
    664                 gaussian {
    665                     append ovar "\[\"gaussian\",[lindex $val 1],[lindex $val 2]\]"
    666                 }
    667                 uniform {
    668                     append ovar "\[\"uniform\",[lindex $val 1],[lindex $val 2]\]"
    669                 }
    670                 default {
    671                     append ovar $val
    672                 }
    673             }
    674         }
    675         append ovar "\]\]"
    676         return $ovar
    677     }
    678 
    679     set varlist [varlist2py $varlist]
    680658    set pid [pid]
    681659    puts "get_params.py $pid $varlist $uq_type $uq_args"
    682     exec get_params.py $pid $varlist $uq_type $uq_args
     660    if {[catch {exec get_params.py $pid $varlist $uq_type $uq_args}]} {
     661        set fp [open "uq_debug.err" r]
     662        set rdata [read $fp]
     663        close $fp
     664        puts "get_params.py failed: $rdata"
     665        error "get_params.py: $rdata"
     666    }
    683667    return params[pid].csv
    684668}
  • branches/uq/puq/get_params.py

    r5169 r5182  
    3232    name, dist = p
    3333    name = str(name)
    34     print "name=", name
    35     print "dist=", dist
    3634    if dist[0] == u'gaussian':
    37         v[name] = NormalParameter(name, name, mean=dist[1], dev=dist[2])
     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]
    3841    elif dist[0] == u'uniform':
    3942        v[name] = UniformParameter(name, name, min=dist[1], max=dist[2])
  • branches/uq/puq/puq_analyze.py

    r5169 r5182  
    3333
    3434
    35 # do some name substitution for better labels
    36 def subs_names(varl):
     35# variable names to labels
     36def subs_names(varl, h5):
    3737    varlist = []
    3838    for v in varl:
    39         varlist.append(str(v[0]))
     39        try:
     40            lab = h5['/input/params/%s' % v[0]].attrs['label']
     41        except:
     42            lab = str(v[0])
     43        varlist.append(lab)
    4044    return varlist
    4145
    4246
    43 def plot_resp1(io, resp, name):
     47def plot_resp1(io, resp, name, h5):
    4448    print 'plot_resp1', name
    45     varlist = subs_names(resp.vars)
     49    varlist = subs_names(resp.vars, h5)
     50    try:
     51        tname = h5['/output/data/%s' % name].attrs['description']
     52    except:
     53        tname = name
     54    ydata = h5['/output/data/%s' % name].value
     55    xdata = h5['/input/param_array'].value.T[0]
     56
     57    title = '%s (Response)' % (tname)
    4658    curve = 'output.curve(response-%s)' % name
    47     io.put(curve + '.about.label', '%s Response for %s' % (name, varlist[0]))
     59    io.put(curve + '.about.label', title)
     60    io.put(curve + '.about.group', title)
    4861    io.put(curve + '.xaxis.label', varlist[0])
    49     io.put(curve + '.yaxis.label', name)
     62    io.put(curve + '.yaxis.label', tname)
    5063    x = np.linspace(*resp.vars[0][1], num=50)
    5164    y = np.array(resp.eval(x))
     
    5366        io.put(curve + '.component.xy', "%s %s\n" % (a, b), append=1)
    5467
    55 
    56 def plot_resp2(io, resp, name, varl):
     68    # scatter plot sampled data on response surface
     69    curve = 'output.curve(response-%s-scatter)' % name
     70    io.put(curve + '.about.label', 'Data Points')
     71    io.put(curve + '.about.group', title)
     72    io.put(curve + '.about.type', 'scatter')
     73    io.put(curve + '.xaxis.label', varlist[0])
     74    io.put(curve + '.yaxis.label', tname)
     75    for a, b in zip(xdata, ydata):
     76        io.put(curve + '.component.xy', "%s %s\n" % (a, b), append=1)
     77
     78
     79def plot_resp2(io, resp, name, varl, h5):
    5780    numpoints = 50
    5881    m2d = 'output.mesh('+varl[0][0]+varl[1][0]+')'
     
    6790    io.put(m2d+'.grid.yaxis.max', '%g' % (varl[1][1][1]))
    6891
    69     varlist = subs_names(varl)
     92    varlist = subs_names(varl, h5)
    7093    fname = 'output.field(response-'+name+varlist[0]+varlist[1]+')'
    7194    io.put(fname + '.about.xaxis.label', varlist[0])
    7295    io.put(fname + '.about.yaxis.label', varlist[1])
    73     title = name + ' Response (%s)' % ' vs '.join(varlist)
     96    try:
     97        tname = h5['/output/data/%s' % name].attrs['description']
     98    except:
     99        tname = name
     100    title = tname + ' (Response %s)' % ' vs '.join(varlist)
    74101    io.put(fname + '.about.label', title)
    75102    io.put(fname + '.component.mesh', m2d)
     
    77104    x = np.linspace(*varl[0][1], num=numpoints)
    78105    y = np.linspace(*varl[1][1], num=numpoints)
    79     pts = np.array([(b,a) for a,b in product(y,x)])
     106    pts = np.array([(b, a) for a, b in product(y, x)])
    80107    allpts = np.empty((numpoints**2, len(resp.vars)))
    81108    for i, v in enumerate(resp.vars):
    82109        if v[0] == varl[0][0]:
    83             allpts[:,i] = pts[:,0]
     110            allpts[:, i] = pts[:, 0]
    84111        elif v[0] == varl[1][0]:
    85             allpts[:,i] = pts[:,1]
     112            allpts[:, i] = pts[:, 1]
    86113        else:
    87             allpts[:,i] = np.mean(v[1])
     114            allpts[:, i] = np.mean(v[1])
    88115    pts = np.array(resp.evala(allpts))
    89116    for z in pts:
    90117        io.put(fname + '.component.values', '%g\n' % z, append=1)
    91118
    92 def plot_resp3(io, resp, name, varl):
     119
     120def plot_resp3(io, resp, name, varl, h5):
    93121    numpoints = 40
    94122    m3d = 'output.mesh(m3d)'
     
    108136    io.put(m3d+'.grid.zaxis.max', '1')
    109137
    110     varlist = subs_names(varl)
     138    varlist = subs_names(varl, h5)
     139    try:
     140        tname = h5['/output/data/%s' % name].attrs['description']
     141    except:
     142        tname = name
    111143    fname = 'output.field(response-'+name+varlist[0]+varlist[1]+varlist[2]+')'
    112144    io.put(fname + '.about.xaxis.label',
    113         '{%s [%.3g - %.3g]}' %
    114         (varlist[0], varl[0][1][0], varl[0][1][1]))
     145                   '{%s [%.3g - %.3g]}' %
     146                   (varlist[0], varl[0][1][0], varl[0][1][1]))
    115147    io.put(fname + '.about.yaxis.label',
    116         '{%s [%.3g - %.3g]}' %
    117         (varlist[1], varl[1][1][0], varl[1][1][1]))
     148                   '{%s [%.3g - %.3g]}' %
     149                   (varlist[1], varl[1][1][0], varl[1][1][1]))
    118150    io.put(fname + '.about.zaxis.label',
    119         '{%s [%.3g - %.3g]}' %
    120         (varlist[2], varl[2][1][0], varl[2][1][1]))
    121 
    122     title = name + ' Response (%s)' % ' vs '.join(varlist)
     151                   '{%s [%.3g - %.3g]}' %
     152                   (varlist[2], varl[2][1][0], varl[2][1][1]))
     153    title = tname + ' (Response %s)' % ' vs '.join(varlist)
    123154    io.put(fname + '.about.label', title)
    124155    io.put(fname + '.component.mesh', m3d)
    125     #io.put(fname + '.about.description', '3D Field Description')
     156    io.put(fname + '.about.description', '3D Field Description')
    126157    io.put(fname + '.about.view', 'vtkvolume')
    127158    x = np.linspace(*varl[0][1], num=numpoints)
     
    130161
    131162    # generate points in the right order, with x changing fastest
    132     pts = np.array([(c,b,a) for a,b,c in product(z,y,x)])
     163    pts = np.array([(c, b, a) for a, b, c in product(z, y, x)])
    133164    allpts = np.empty((numpoints**3, len(resp.vars)))
    134165    for i, v in enumerate(resp.vars):
    135166        if v[0] == varl[0][0]:
    136             allpts[:,i] = pts[:,0]
     167            allpts[:, i] = pts[:, 0]
    137168        elif v[0] == varl[1][0]:
    138             allpts[:,i] = pts[:,1]
     169            allpts[:, i] = pts[:, 1]
    139170        elif v[0] == varl[2][0]:
    140             allpts[:,i] = pts[:,2]
     171            allpts[:, i] = pts[:, 2]
    141172        else:
    142             allpts[:,i] = np.mean(v[1])
     173            allpts[:, i] = np.mean(v[1])
    143174    pts = np.array(resp.evala(allpts))
    144175    for z in pts:
     
    146177
    147178
    148 def plot_resp(io, resp, name):
     179def plot_resp(io, resp, name, h5):
    149180    if resp is not None:
    150181        if len(resp.vars) == 1:
    151             plot_resp1(io, resp, name)
     182            plot_resp1(io, resp, name, h5)
    152183            return
    153184        if len(resp.vars) >= 3:
    154185            for v1, v2, v3 in combinations(resp.vars, 3):
    155                 plot_resp3(io, resp, name, [v1,v2,v3])
     186                plot_resp3(io, resp, name, [v1, v2, v3], h5)
    156187
    157188        # plot all combinations of 2 variables
    158189        for v1, v2 in combinations(resp.vars, 2):
    159             plot_resp2(io, resp, name, [v1,v2])
     190            plot_resp2(io, resp, name, [v1, v2], h5)
    160191
    161192
     
    197228
    198229
    199 
    200 def dist(x1,y1, x2,y2, x3,y3): # x3,y3 is the point
     230def dist(x1, y1, x2, y2, x3, y3): # x3,y3 is the point
    201231    diffx = x2-x1
    202232    diffy = y2-y1
     
    345375    plot_pdf_curve(xvals, vname, 95, desc)
    346376
    347 #for vname in acurves:
     377# for vname in acurves:
    348378#    desc = h5['/output/data/%s.x[0]' % vname].attrs['description']
    349379#    plot_pdf_acurve(h5, acurves, vname, 0, desc)
     
    354384# If more than one variable, display sensitivity.
    355385# Curves have indexed variables, so skip them.
    356 if ['[' in x for x in h5[uqtype]].count(False):
     386if len(h5['/input/params']) > 1 and ['[' in x for x in h5[uqtype]].count(False):
    357387    for v in h5[uqtype]:
    358388        if '[' in v:
    359389            continue
    360         lab = h5['/output/data/%s' % v].attrs['description']
     390        desc = h5['/output/data/%s' % v].attrs['description']
    361391        sens = unpickle(h5['/%s/%s/sensitivity' % (uqtype, v)].value)
    362392        elem = xml.SubElement(dout, 'histogram', {'id': 'sens-%s' % v})
    363393        about = xml.SubElement(elem, 'about')
    364         xml.SubElement(about, 'label').text = '%s Sensitivity' % lab
     394        xml.SubElement(about, 'label').text = '%s (Sensitivity)' % desc
    365395        xml.SubElement(elem, 'type').text = 'scatter'
    366396        xaxis = xml.SubElement(elem, 'xaxis')
     
    377407            except:
    378408                pass
    379             pts += "%s %s\n" % (n, name[1]['ustar'])
     409            pts += "\"%s\" %s\n" % (n, name[1]['ustar'])
    380410        xy.text = pts
    381411
     
    393423    rs = unpickle(h5['/%s/%s/response' % (uqtype, v)].value)
    394424    print 'Plotting response', v
    395     plot_resp(io, rs, v)
     425    plot_resp(io, rs, v, h5)
    396426
    397427Rappture.result(io)
Note: See TracChangeset for help on using the changeset viewer.