Changeset 5169 for branches/uq
- Timestamp:
- Mar 26, 2015, 6:48:40 AM (9 years ago)
- Location:
- branches/uq
- Files:
-
- 6 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/uq/gui/scripts/analyzer.tcl
r5168 r5169 107 107 itcl::body Rappture::Analyzer::constructor {tool args} { 108 108 set _tool $tool 109 puts "Analyzer init" 109 110 110 # use this to store all simulation results 111 111 set _resultset [Rappture::ResultSet ::\#auto] … … 420 420 return 421 421 } 422 }423 424 lappend args -uq_type [$uq type]425 lappend args -uq_args [$uq args] 426 puts " args=$args"422 lappend args -uq_type [$uq type] 423 lappend args -uq_args [$uq args] 424 } 425 426 puts "simulate args=$args" 427 427 428 428 # simulation is needed -- go to simulation page … … 501 501 # ---------------------------------------------------------------------- 502 502 itcl::body Rappture::Analyzer::reset {{when -eventually}} { 503 puts "RESET $when" 503 504 if {$when == "-eventually"} { 504 505 after cancel [list catch [itcl::code $this reset -now]] … … 506 507 return 507 508 } 509 510 puts "RESET contains [$_resultset contains [$_tool xml object]]" 511 puts [$_tool xml object] 508 512 509 513 # check to see if simulation is really needed … … 1123 1127 } 1124 1128 1125 1126 1129 # 1127 1130 # Break up the remaining lines according to =RAPPTURE-ERROR=> messages. -
branches/uq/gui/scripts/resultset.tcl
r3827 r5169 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 stdout 191 193 switch -- $option { 192 194 names { … … 198 200 } 199 201 set col [lindex $args 0] 200 202 puts "col=$col" 201 203 set which "all" 202 204 if {[llength $args] > 1} { … … 306 308 # ---------------------------------------------------------------------- 307 309 itcl::body Rappture::ResultSet::contains {xmlobj} { 310 puts "CONTAINS [$_results size]" 308 311 # no results? then this must be new 309 312 if {[$_results size] == 0} { … … 316 319 # is a column to represent the quantity with the difference. 317 320 # 321 puts "CONTAINS A" 318 322 set xmlobj0 [$_results get -format xmlobj end] 323 puts "CONTAINS B $xmlobj0 , $xmlobj" 324 puts "DIFF IS [$xmlobj0 diff $xmlobj]" 325 flush stdout 319 326 foreach {op vpath oldval newval} [$xmlobj0 diff $xmlobj] { 327 puts "$op $vpath $oldval $newval" 328 flush stdout 320 329 if {[$xmlobj get $vpath.about.diffs] == "ignore"} { 321 330 continue … … 328 337 if {[$_results column names $vpath] == ""} { 329 338 # no column for this quantity yet 339 puts "NO COLUMN" 330 340 return 0 331 341 } 332 342 } 333 343 puts "CONTAINS F" 334 344 # 335 345 # If we got this far, then look through existing results for … … 357 367 } 358 368 } 359 369 puts "CONTAINS Z" 360 370 # must be some differences 361 371 return 0 -
branches/uq/lang/tcl/scripts/library.tcl
r5102 r5169 70 70 } 71 71 set fname [file join $Rappture::installdir lib library.xml] 72 73 72 set fid [::open $fname r] 74 73 set info [read $fid] … … 215 214 public method remove {{path ""}} 216 215 public method xml {{path ""}} 217 public method uq_get_vars {{t emplate 0}}216 public method uq_get_vars {{tfile ""}} 218 217 219 218 public method diff {libobj} … … 691 690 # ---------------------------------------------------------------------- 692 691 itcl::body Rappture::LibraryObj::diff {libobj} { 692 693 puts "Library DIFF $libobj" 693 694 set rlist "" 694 695 … … 697 698 set otherv [Rappture::entities $libobj input] 698 699 700 puts "thisv=$thisv\n" 701 puts "otherv=$otherv\n" 702 699 703 # scan through values for this object, and compare against other one 700 704 foreach path $thisv { 705 puts "path=$path" 701 706 set i [lsearch -exact $otherv $path] 702 707 if {$i < 0} { … … 704 709 lappend rlist - $path $raw "" 705 710 } else { 711 puts "tvalue=[value $this $path]" 712 puts "ovalue=[value $libobj $path]" 706 713 foreach {traw tnorm} [value $this $path] break 707 714 foreach {oraw onorm} [value $libobj $path] break 715 puts "tnorm=$tnorm onorm=$onorm traw=$traw oraw=$oraw" 708 716 if {![string equal $tnorm $onorm]} { 709 717 lappend rlist c $path $traw $oraw … … 718 726 lappend rlist + $path "" $oraw 719 727 } 728 puts "LDIFF returning $rlist" 720 729 return $rlist 721 730 } … … 740 749 # ---------------------------------------------------------------------- 741 750 itcl::body Rappture::LibraryObj::value {libobj path} { 751 puts "VALUE $path [$libobj element -as type $path]" 742 752 switch -- [$libobj element -as type $path] { 743 753 structure { … … 771 781 # then normalize to default units 772 782 set units [$libobj get $path.units] 783 puts "val=$val units=$units" 773 784 if {"" != $units} { 774 set val [Rappture::Units:: convert $val \785 set val [Rappture::Units::mconvert $val \ 775 786 -context $units -to $units -units off] 776 787 } … … 1040 1051 } 1041 1052 1042 itcl::body Rappture::LibraryObj::uq_get_vars {{t emplate 0}} {1053 itcl::body Rappture::LibraryObj::uq_get_vars {{tfile ""}} { 1043 1054 set varlist "" 1044 set n [$_node selectNodes /run/input//number] 1055 1056 if {$tfile == ""} { 1057 set node $_node 1058 } else { 1059 set fid [::open $tfile r] 1060 set doc [dom parse [read $fid]] 1061 set node [$doc documentElement] 1062 close $fid 1063 } 1064 1065 set n [$node selectNodes /run/input//number] 1045 1066 foreach _n $n { 1046 1067 set x [$_n selectNodes current/text()] … … 1054 1075 -context $units -to $units -units off] 1055 1076 } 1056 if {$t emplate != 0} {1077 if {$tfile != ""} { 1057 1078 $x nodeValue @@[$_n getAttribute id] 1058 1079 } … … 1060 1081 } 1061 1082 } 1083 1084 if {$tfile != ""} { 1085 set fid [open $tfile w] 1086 puts $fid "<?xml version=\"1.0\"?>" 1087 puts $fid [$node asXML] 1088 close $fid 1089 $doc delete 1090 } 1062 1091 return $varlist 1063 1092 } -
branches/uq/lang/tcl/scripts/task.tcl
r5168 r5169 173 173 # if there are any args, use them to override parameters 174 174 set _outputcb "" 175 set uq_type "" 175 176 foreach {path val} $args { 176 177 if {$path == "-output"} { … … 211 212 } result] 212 213 213 # This will turn the driver xml into a template 214 # and return a list of the UQ variables and their PDFs. 215 set uq_varlist [$_xmlobj uq_get_vars 1] 216 217 if {$uq_varlist != ""} { 218 # write out the template file for submit 214 if {$uq_type != ""} { 215 # Copy xml into a new file 219 216 set tfile "template[pid].xml" 220 set status [catch { 221 set fid [open $tfile w] 222 puts $fid "<?xml version=\"1.0\"?>" 223 puts $fid [$_xmlobj xml] 224 close $fid 225 } result] 217 set fid [open $tfile w] 218 puts $fid "<?xml version=\"1.0\"?>" 219 puts $fid [$_xmlobj xml] 220 close $fid 221 222 # Return a list of the UQ variables and their PDFs. 223 # Also turns $tfile into a template file. 224 set uq_varlist [$_xmlobj uq_get_vars $tfile] 226 225 } 227 226 … … 239 238 } 240 239 241 if {$uq_ varlist== ""} {240 if {$uq_type == ""} { 242 241 regsub -all @driver $cmd $file cmd 243 242 … … 404 403 if {$status == 0} { 405 404 set result [string trim $job(output)] 406 puts "result=$result" 407 if {$uq_ varlist!= ""} {405 406 if {$uq_type != ""} { 408 407 # UQ. Collect data from all jobs and put it in one xml run file. 409 file delete -force -- run_uq.xml410 exec puq_analyze.py puq_[pid].hdf5411 append result "\n" "=RAPPTURE-RUN=>run_uq.xml"408 #file delete -force -- run_uq.xml 409 set res [exec puq_analyze.py puq_[pid].hdf5] 410 append result "\n" $res 412 411 } 413 412 if {[regexp {=RAPPTURE-RUN=>([^\n]+)} $result match file]} { -
branches/uq/puq/get_params.py
r5168 r5169 55 55 # This just saves PUQ state into HDF5 file, so later we can have PUQ analyze 56 56 # the results and it knows about the input parameters, UQ method, etc. 57 sw = Sweep(uq, RapptureHost('puq', dfile), None) 57 host = RapptureHost('puq', dfile) 58 sw = Sweep(uq, host, None) 59 host.psweep = sw.psweep 58 60 sw.run(hname, overwrite=True) 59 61 -
branches/uq/puq/puq_analyze.py
r5168 r5169 11 11 from puq.jpickle import unpickle 12 12 import xml.etree.ElementTree as xml 13 from itertools import product, combinations 13 14 14 15 # Redirect stdout and stderr to files for debugging. … … 16 17 sys.stdout = open("uq_debug.out", 'a') 17 18 sys.stderr = open("uq_debug.err", 'a') 19 18 20 19 21 # Restore the state of a PUQ session from a HDF5 file. … … 29 31 sw.psweep.reinit() 30 32 return sw 33 34 35 # do some name substitution for better labels 36 def subs_names(varl): 37 varlist = [] 38 for v in varl: 39 varlist.append(str(v[0])) 40 return varlist 41 42 43 def plot_resp1(io, resp, name): 44 print 'plot_resp1', name 45 varlist = subs_names(resp.vars) 46 curve = 'output.curve(response-%s)' % name 47 io.put(curve + '.about.label', '%s Response for %s' % (name, varlist[0])) 48 io.put(curve + '.xaxis.label', varlist[0]) 49 io.put(curve + '.yaxis.label', name) 50 x = np.linspace(*resp.vars[0][1], num=50) 51 y = np.array(resp.eval(x)) 52 for a, b in zip(x, y): 53 io.put(curve + '.component.xy', "%s %s\n" % (a, b), append=1) 54 55 56 def plot_resp2(io, resp, name, varl): 57 numpoints = 50 58 m2d = 'output.mesh('+varl[0][0]+varl[1][0]+')' 59 io.put(m2d+'.about.label', '2D Mesh') 60 io.put(m2d+'.dim', '2') 61 io.put(m2d+'.hide', 'yes') 62 io.put(m2d+'.grid.xaxis.numpoints', '%s' % numpoints) 63 io.put(m2d+'.grid.yaxis.numpoints', '%s' % numpoints) 64 io.put(m2d+'.grid.xaxis.min', '%g' % (varl[0][1][0])) 65 io.put(m2d+'.grid.xaxis.max', '%g' % (varl[0][1][1])) 66 io.put(m2d+'.grid.yaxis.min', '%g' % (varl[1][1][0])) 67 io.put(m2d+'.grid.yaxis.max', '%g' % (varl[1][1][1])) 68 69 varlist = subs_names(varl) 70 fname = 'output.field(response-'+name+varlist[0]+varlist[1]+')' 71 io.put(fname + '.about.xaxis.label', varlist[0]) 72 io.put(fname + '.about.yaxis.label', varlist[1]) 73 title = name + ' Response (%s)' % ' vs '.join(varlist) 74 io.put(fname + '.about.label', title) 75 io.put(fname + '.component.mesh', m2d) 76 io.put(fname + '.about.view', 'heightmap') 77 x = np.linspace(*varl[0][1], num=numpoints) 78 y = np.linspace(*varl[1][1], num=numpoints) 79 pts = np.array([(b,a) for a,b in product(y,x)]) 80 allpts = np.empty((numpoints**2, len(resp.vars))) 81 for i, v in enumerate(resp.vars): 82 if v[0] == varl[0][0]: 83 allpts[:,i] = pts[:,0] 84 elif v[0] == varl[1][0]: 85 allpts[:,i] = pts[:,1] 86 else: 87 allpts[:,i] = np.mean(v[1]) 88 pts = np.array(resp.evala(allpts)) 89 for z in pts: 90 io.put(fname + '.component.values', '%g\n' % z, append=1) 91 92 def plot_resp3(io, resp, name, varl): 93 numpoints = 40 94 m3d = 'output.mesh(m3d)' 95 io.put(m3d+'.about.label', '3D Mesh') 96 io.put(m3d+'.dim', '3') 97 io.put(m3d+'.hide', 'yes') 98 io.put(m3d+'.grid.xaxis.numpoints', '%s' % numpoints) 99 io.put(m3d+'.grid.yaxis.numpoints', '%s' % numpoints) 100 io.put(m3d+'.grid.zaxis.numpoints', '%s' % numpoints) 101 102 # for now, scale to [0,1] 103 io.put(m3d+'.grid.xaxis.min', '0') 104 io.put(m3d+'.grid.xaxis.max', '1') 105 io.put(m3d+'.grid.yaxis.min', '0') 106 io.put(m3d+'.grid.yaxis.max', '1') 107 io.put(m3d+'.grid.zaxis.min', '0') 108 io.put(m3d+'.grid.zaxis.max', '1') 109 110 varlist = subs_names(varl) 111 fname = 'output.field(response-'+name+varlist[0]+varlist[1]+varlist[2]+')' 112 io.put(fname + '.about.xaxis.label', 113 '{%s [%.3g - %.3g]}' % 114 (varlist[0], varl[0][1][0], varl[0][1][1])) 115 io.put(fname + '.about.yaxis.label', 116 '{%s [%.3g - %.3g]}' % 117 (varlist[1], varl[1][1][0], varl[1][1][1])) 118 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) 123 io.put(fname + '.about.label', title) 124 io.put(fname + '.component.mesh', m3d) 125 #io.put(fname + '.about.description', '3D Field Description') 126 io.put(fname + '.about.view', 'vtkvolume') 127 x = np.linspace(*varl[0][1], num=numpoints) 128 y = np.linspace(*varl[1][1], num=numpoints) 129 z = np.linspace(*varl[2][1], num=numpoints) 130 131 # 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)]) 133 allpts = np.empty((numpoints**3, len(resp.vars))) 134 for i, v in enumerate(resp.vars): 135 if v[0] == varl[0][0]: 136 allpts[:,i] = pts[:,0] 137 elif v[0] == varl[1][0]: 138 allpts[:,i] = pts[:,1] 139 elif v[0] == varl[2][0]: 140 allpts[:,i] = pts[:,2] 141 else: 142 allpts[:,i] = np.mean(v[1]) 143 pts = np.array(resp.evala(allpts)) 144 for z in pts: 145 io.put(fname + '.component.values', '%g\n' % z, append=1) 146 147 148 def plot_resp(io, resp, name): 149 if resp is not None: 150 if len(resp.vars) == 1: 151 plot_resp1(io, resp, name) 152 return 153 if len(resp.vars) >= 3: 154 for v1, v2, v3 in combinations(resp.vars, 3): 155 plot_resp3(io, resp, name, [v1,v2,v3]) 156 157 # plot all combinations of 2 variables 158 for v1, v2 in combinations(resp.vars, 2): 159 plot_resp2(io, resp, name, [v1,v2]) 31 160 32 161 … … 68 197 69 198 199 70 200 def dist(x1,y1, x2,y2, x3,y3): # x3,y3 is the point 71 201 diffx = x2-x1 … … 87 217 88 218 return np.sqrt(dx*dx + dy*dy) 219 89 220 90 221 # Plots advanced probability curves … … 220 351 # plot_pdf_acurve(h5, acurves, vname, 95, desc) 221 352 353 354 # If more than one variable, display sensitivity. 355 # Curves have indexed variables, so skip them. 356 if ['[' in x for x in h5[uqtype]].count(False): 357 for v in h5[uqtype]: 358 if '[' in v: 359 continue 360 lab = h5['/output/data/%s' % v].attrs['description'] 361 sens = unpickle(h5['/%s/%s/sensitivity' % (uqtype, v)].value) 362 elem = xml.SubElement(dout, 'histogram', {'id': 'sens-%s' % v}) 363 about = xml.SubElement(elem, 'about') 364 xml.SubElement(about, 'label').text = '%s Sensitivity' % lab 365 xml.SubElement(elem, 'type').text = 'scatter' 366 xaxis = xml.SubElement(elem, 'xaxis') 367 xml.SubElement(xaxis, 'label').text = 'Parameters' 368 yaxis = xml.SubElement(elem, 'yaxis') 369 xml.SubElement(yaxis, 'label').text = 'Sensitivity' 370 comp = xml.SubElement(elem, 'component') 371 xy = xml.SubElement(comp, 'xy') 372 pts = '' 373 for name in sens: 374 n = name[0] 375 try: 376 n = h5['/input/params/%s' % n].attrs['label'] 377 except: 378 pass 379 pts += "%s %s\n" % (n, name[1]['ustar']) 380 xy.text = pts 381 222 382 with open('run_uq.xml', 'w') as f: 223 383 f.write("<?xml version=\"1.0\"?>\n") 224 384 dtree.write(f) 225 385 226 with open('run_uq2.xml', 'w') as f: 227 f.write("<?xml version=\"1.0\"?>\n") 228 dtree.write(f) 386 387 import Rappture 388 io = Rappture.library('run_uq.xml') 389 390 for v in h5[uqtype]: 391 if '[' in v: 392 continue 393 rs = unpickle(h5['/%s/%s/response' % (uqtype, v)].value) 394 print 'Plotting response', v 395 plot_resp(io, rs, v) 396 397 Rappture.result(io) 398 229 399 h5.close()
Note: See TracChangeset
for help on using the changeset viewer.