Changeset 5182
- Timestamp:
- Apr 2, 2015 7:12:40 AM (9 years ago)
- Location:
- branches/uq
- Files:
-
- 8 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/uq/gui/scripts/analyzer.tcl
r5169 r5182 501 501 # ---------------------------------------------------------------------- 502 502 itcl::body Rappture::Analyzer::reset {{when -eventually}} { 503 puts "RESET $when"504 503 if {$when == "-eventually"} { 505 504 after cancel [list catch [itcl::code $this reset -now]] … … 507 506 return 508 507 } 509 510 puts "RESET contains [$_resultset contains [$_tool xml object]]"511 puts [$_tool xml object]512 508 513 509 # check to see if simulation is really needed -
branches/uq/gui/scripts/probdisteditor.tcl
r5179 r5182 334 334 uniform { 335 335 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 346 340 } 347 341 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 -*- 2 2 # ---------------------------------------------------------------------- 3 3 # COMPONENT: ResultSet - set of XML objects for simulated results … … 40 40 private variable _notify ;# info used for notify command 41 41 } 42 42 43 43 # ---------------------------------------------------------------------- 44 44 # CONSTRUCTOR … … 189 189 # ---------------------------------------------------------------------- 190 190 itcl::body Rappture::ResultSet::diff {option args} { 191 puts "ResultSet::diff $option $args"192 flush stdout193 191 switch -- $option { 194 192 names { … … 200 198 } 201 199 set col [lindex $args 0] 202 puts "col=$col" 200 203 201 set which "all" 204 202 if {[llength $args] > 1} { … … 308 306 # ---------------------------------------------------------------------- 309 307 itcl::body Rappture::ResultSet::contains {xmlobj} { 310 puts "CONTAINS [$_results size]"311 308 # no results? then this must be new 312 309 if {[$_results size] == 0} { … … 319 316 # is a column to represent the quantity with the difference. 320 317 # 321 puts "CONTAINS A"322 318 set xmlobj0 [$_results get -format xmlobj end] 323 puts "CONTAINS B $xmlobj0 , $xmlobj"324 puts "DIFF IS [$xmlobj0 diff $xmlobj]"325 flush stdout326 319 foreach {op vpath oldval newval} [$xmlobj0 diff $xmlobj] { 327 puts "$op $vpath $oldval $newval"328 flush stdout329 320 if {[$xmlobj get $vpath.about.diffs] == "ignore"} { 330 321 continue … … 337 328 if {[$_results column names $vpath] == ""} { 338 329 # no column for this quantity yet 339 puts "NO COLUMN"340 330 return 0 341 331 } 342 332 } 343 puts "CONTAINS F" 333 344 334 # 345 335 # If we got this far, then look through existing results for … … 367 357 } 368 358 } 369 puts "CONTAINS Z" 359 370 360 # must be some differences 371 361 return 0 -
branches/uq/gui/scripts/uq.tcl
r5168 r5182 68 68 button $fr.cancel -text Cancel -command [itcl::code $this _setWaitVariable 0] 69 69 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] 71 71 _set_text $inner 72 72 -
branches/uq/lang/tcl/scripts/library.tcl
r5169 r5182 1051 1051 } 1052 1052 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 # ---------------------------------------------------------------------- 1053 1068 itcl::body Rappture::LibraryObj::uq_get_vars {{tfile ""}} { 1054 set varlist ""1069 set varlist \[ 1055 1070 1056 1071 if {$tfile == ""} { … … 1063 1078 } 1064 1079 1080 set first 1 1065 1081 set n [$node selectNodes /run/input//number] 1066 1082 foreach _n $n { … … 1069 1085 if {[string equal -length 8 $val "uniform "] || 1070 1086 [string equal -length 9 $val "gaussian "]} { 1087 1088 if {$first == 1} { 1089 set first 0 1090 } else { 1091 append varlist , 1092 } 1093 1071 1094 set unode [$_n selectNodes units/text()] 1072 1095 if {"" != $unode} { … … 1075 1098 -context $units -to $units -units off] 1076 1099 } 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 1077 1139 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 \] 1083 1146 1084 1147 if {$tfile != ""} { … … 1089 1152 $doc delete 1090 1153 } 1154 if {$varlist == "\[\]"} {set varlist ""} 1155 puts "uq_get_vars returning $varlist" 1091 1156 return $varlist 1092 1157 } -
branches/uq/lang/tcl/scripts/task.tcl
r5169 r5182 407 407 # UQ. Collect data from all jobs and put it in one xml run file. 408 408 #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 } 411 419 } 412 420 if {[regexp {=RAPPTURE-RUN=>([^\n]+)} $result match file]} { … … 648 656 # and get a CSV file containing the parameter values to use for the runs. 649 657 itcl::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 it652 proc varlist2py {inlist} {653 set ovar "\["654 set first 1655 foreach a $inlist {656 foreach {var val} $a break657 if {$first == 1} {658 append ovar \[\"$var\",659 set first 0660 } 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 $val672 }673 }674 }675 append ovar "\]\]"676 return $ovar677 }678 679 set varlist [varlist2py $varlist]680 658 set pid [pid] 681 659 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 } 683 667 return params[pid].csv 684 668 } -
branches/uq/puq/get_params.py
r5169 r5182 32 32 name, dist = p 33 33 name = str(name) 34 print "name=", name35 print "dist=", dist36 34 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] 38 41 elif dist[0] == u'uniform': 39 42 v[name] = UniformParameter(name, name, min=dist[1], max=dist[2]) -
branches/uq/puq/puq_analyze.py
r5169 r5182 33 33 34 34 35 # do some name substitution for betterlabels36 def subs_names(varl ):35 # variable names to labels 36 def subs_names(varl, h5): 37 37 varlist = [] 38 38 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) 40 44 return varlist 41 45 42 46 43 def plot_resp1(io, resp, name ):47 def plot_resp1(io, resp, name, h5): 44 48 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) 46 58 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) 48 61 io.put(curve + '.xaxis.label', varlist[0]) 49 io.put(curve + '.yaxis.label', name)62 io.put(curve + '.yaxis.label', tname) 50 63 x = np.linspace(*resp.vars[0][1], num=50) 51 64 y = np.array(resp.eval(x)) … … 53 66 io.put(curve + '.component.xy', "%s %s\n" % (a, b), append=1) 54 67 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 79 def plot_resp2(io, resp, name, varl, h5): 57 80 numpoints = 50 58 81 m2d = 'output.mesh('+varl[0][0]+varl[1][0]+')' … … 67 90 io.put(m2d+'.grid.yaxis.max', '%g' % (varl[1][1][1])) 68 91 69 varlist = subs_names(varl )92 varlist = subs_names(varl, h5) 70 93 fname = 'output.field(response-'+name+varlist[0]+varlist[1]+')' 71 94 io.put(fname + '.about.xaxis.label', varlist[0]) 72 95 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) 74 101 io.put(fname + '.about.label', title) 75 102 io.put(fname + '.component.mesh', m2d) … … 77 104 x = np.linspace(*varl[0][1], num=numpoints) 78 105 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)]) 80 107 allpts = np.empty((numpoints**2, len(resp.vars))) 81 108 for i, v in enumerate(resp.vars): 82 109 if v[0] == varl[0][0]: 83 allpts[:, i] = pts[:,0]110 allpts[:, i] = pts[:, 0] 84 111 elif v[0] == varl[1][0]: 85 allpts[:, i] = pts[:,1]112 allpts[:, i] = pts[:, 1] 86 113 else: 87 allpts[:, i] = np.mean(v[1])114 allpts[:, i] = np.mean(v[1]) 88 115 pts = np.array(resp.evala(allpts)) 89 116 for z in pts: 90 117 io.put(fname + '.component.values', '%g\n' % z, append=1) 91 118 92 def plot_resp3(io, resp, name, varl): 119 120 def plot_resp3(io, resp, name, varl, h5): 93 121 numpoints = 40 94 122 m3d = 'output.mesh(m3d)' … … 108 136 io.put(m3d+'.grid.zaxis.max', '1') 109 137 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 111 143 fname = 'output.field(response-'+name+varlist[0]+varlist[1]+varlist[2]+')' 112 144 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])) 115 147 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])) 118 150 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) 123 154 io.put(fname + '.about.label', title) 124 155 io.put(fname + '.component.mesh', m3d) 125 #io.put(fname + '.about.description', '3D Field Description')156 io.put(fname + '.about.description', '3D Field Description') 126 157 io.put(fname + '.about.view', 'vtkvolume') 127 158 x = np.linspace(*varl[0][1], num=numpoints) … … 130 161 131 162 # 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)]) 133 164 allpts = np.empty((numpoints**3, len(resp.vars))) 134 165 for i, v in enumerate(resp.vars): 135 166 if v[0] == varl[0][0]: 136 allpts[:, i] = pts[:,0]167 allpts[:, i] = pts[:, 0] 137 168 elif v[0] == varl[1][0]: 138 allpts[:, i] = pts[:,1]169 allpts[:, i] = pts[:, 1] 139 170 elif v[0] == varl[2][0]: 140 allpts[:, i] = pts[:,2]171 allpts[:, i] = pts[:, 2] 141 172 else: 142 allpts[:, i] = np.mean(v[1])173 allpts[:, i] = np.mean(v[1]) 143 174 pts = np.array(resp.evala(allpts)) 144 175 for z in pts: … … 146 177 147 178 148 def plot_resp(io, resp, name ):179 def plot_resp(io, resp, name, h5): 149 180 if resp is not None: 150 181 if len(resp.vars) == 1: 151 plot_resp1(io, resp, name )182 plot_resp1(io, resp, name, h5) 152 183 return 153 184 if len(resp.vars) >= 3: 154 185 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) 156 187 157 188 # plot all combinations of 2 variables 158 189 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) 160 191 161 192 … … 197 228 198 229 199 200 def dist(x1,y1, x2,y2, x3,y3): # x3,y3 is the point 230 def dist(x1, y1, x2, y2, x3, y3): # x3,y3 is the point 201 231 diffx = x2-x1 202 232 diffy = y2-y1 … … 345 375 plot_pdf_curve(xvals, vname, 95, desc) 346 376 347 # for vname in acurves:377 # for vname in acurves: 348 378 # desc = h5['/output/data/%s.x[0]' % vname].attrs['description'] 349 379 # plot_pdf_acurve(h5, acurves, vname, 0, desc) … … 354 384 # If more than one variable, display sensitivity. 355 385 # Curves have indexed variables, so skip them. 356 if ['[' in x for x in h5[uqtype]].count(False):386 if len(h5['/input/params']) > 1 and ['[' in x for x in h5[uqtype]].count(False): 357 387 for v in h5[uqtype]: 358 388 if '[' in v: 359 389 continue 360 lab= h5['/output/data/%s' % v].attrs['description']390 desc = h5['/output/data/%s' % v].attrs['description'] 361 391 sens = unpickle(h5['/%s/%s/sensitivity' % (uqtype, v)].value) 362 392 elem = xml.SubElement(dout, 'histogram', {'id': 'sens-%s' % v}) 363 393 about = xml.SubElement(elem, 'about') 364 xml.SubElement(about, 'label').text = '%s Sensitivity' % lab394 xml.SubElement(about, 'label').text = '%s (Sensitivity)' % desc 365 395 xml.SubElement(elem, 'type').text = 'scatter' 366 396 xaxis = xml.SubElement(elem, 'xaxis') … … 377 407 except: 378 408 pass 379 pts += " %s%s\n" % (n, name[1]['ustar'])409 pts += "\"%s\" %s\n" % (n, name[1]['ustar']) 380 410 xy.text = pts 381 411 … … 393 423 rs = unpickle(h5['/%s/%s/response' % (uqtype, v)].value) 394 424 print 'Plotting response', v 395 plot_resp(io, rs, v )425 plot_resp(io, rs, v, h5) 396 426 397 427 Rappture.result(io)
Note: See TracChangeset
for help on using the changeset viewer.