Changeset 903
- Timestamp:
- Feb 23, 2008 8:16:38 PM (16 years ago)
- Location:
- trunk
- Files:
-
- 6 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/gui/scripts/analyzer.tcl
r822 r903 52 52 public method simulate {args} 53 53 public method reset {{when -eventually}} 54 public method load { file}54 public method load {xmlobj} 55 55 public method clear {} 56 56 public method download {option args} … … 77 77 78 78 private common job ;# array var used for blt::bgexec jobs 79 80 # resources file tells us the results directory 81 public common _resultdir "" 82 public proc setResultDir {path} { set _resultdir $path } 83 } 84 85 # must use this name -- plugs into Rappture::resources::load 86 proc analyzer_init_resources {} { 87 Rappture::resources::register \ 88 results_directory Rappture::Analyzer::setResultDir 89 } 90 79 } 80 91 81 itk::usual Analyzer { 92 82 keep -background -cursor foreground -font … … 354 344 } 355 345 356 # read back the results from run.xml346 # load results from run.xml into analyzer 357 347 if {$status == 0 && $result != "ABORT"} { 358 if {[regexp {=RAPPTURE-RUN=>([^\n]+)} $result match file]} { 359 set status [catch {load $file} msg] 360 if {$status != 0} { 361 global errorInfo 362 set result "$msg\n$errorInfo" 363 } 364 365 # if there's a results_directory defined in the resources 366 # file, then move the run.xml file there for storage 367 if {"" != $_resultdir} { 368 catch { 369 if {![file exists $_resultdir]} { 370 _mkdir $_resultdir 371 } 372 file rename -force -- $file $_resultdir 373 } 374 } 375 } else { 376 set status 1 377 set result "Can't find result file in output.\nDid you call Rappture::result in your simulator?" 378 } 348 set status [catch {load $result} result] 379 349 } 380 350 … … 441 411 442 412 # ---------------------------------------------------------------------- 443 # USAGE: load < file>444 # 445 # Loads the data from the given < file> into the appropriate results413 # USAGE: load <xmlobj> 414 # 415 # Loads the data from the given <xmlobj> into the appropriate results 446 416 # sets. If necessary, new results sets are created to store the data. 447 417 # ---------------------------------------------------------------------- 448 itcl::body Rappture::Analyzer::load { file} {418 itcl::body Rappture::Analyzer::load {xmlobj} { 449 419 # only show the last result? then clear first 450 420 if {[$_tool xml get tool.analyzer] == "last"} { … … 452 422 } 453 423 454 # try to load new results from the given file455 set xmlobj [Rappture::library $file]456 424 lappend _runs $xmlobj 457 425 -
trunk/gui/scripts/tool.tcl
r775 r903 40 40 41 41 public common _resources 42 public proc setAppName {name} { set _resources(-appname) $name } 43 public proc setHubName {name} { set _resources(-hubname) $name } 44 public proc setHubURL {name} { set _resources(-huburl) $name } 45 public proc setSession {name} { set _resources(-session) $name } 46 public proc setJobPrt {name} { set _resources(-jobprotocol) $name } 42 public proc setAppName {name} { set _resources(-appname) $name } 43 public proc setHubName {name} { set _resources(-hubname) $name } 44 public proc setHubURL {name} { set _resources(-huburl) $name } 45 public proc setSession {name} { set _resources(-session) $name } 46 public proc setJobPrt {name} { set _resources(-jobprotocol) $name } 47 public proc setResultDir {name} { set _resources(-resultdir) $name } 47 48 } 48 49 … … 50 51 proc tool_init_resources {} { 51 52 Rappture::resources::register \ 52 application_name Rappture::Tool::setAppName \ 53 application_id Rappture::Tool::setAppId \ 54 hub_name Rappture::Tool::setHubName \ 55 hub_url Rappture::Tool::setHubURL \ 56 session_token Rappture::Tool::setSession \ 57 job_protocol Rappture::Tool::setJobPrt 53 application_name Rappture::Tool::setAppName \ 54 application_id Rappture::Tool::setAppId \ 55 hub_name Rappture::Tool::setHubName \ 56 hub_url Rappture::Tool::setHubURL \ 57 session_token Rappture::Tool::setSession \ 58 job_protocol Rappture::Tool::setJobPrt \ 59 results_directory Rappture::Tool::setResultDir 58 60 } 59 61 … … 263 265 # 264 266 if {$status == 0} { 265 set file [string trim $job(output)] 266 return [list $status $file] 267 set result [string trim $job(output)] 268 if {[regexp {=RAPPTURE-RUN=>([^\n]+)} $result match file]} { 269 set status [catch {Rappture::library $file} result] 270 if {$status != 0} { 271 global errorInfo 272 set result "$result\n$errorInfo" 273 } 274 275 # if there's a results_directory defined in the resources 276 # file, then move the run.xml file there for storage 277 if {[info exists _resources(-resultdir)] 278 && "" != $_resources(-resultdir)} { 279 catch { 280 if {![file exists $_resources(-resultdir)]} { 281 _mkdir $_resources(-resultdir) 282 } 283 file rename -force -- $file $_resources(-resultdir) 284 } 285 } 286 } else { 287 set status 1 288 set result "Can't find result file in output.\nDid you call Rappture 289 ::result in your simulator?" 290 } 291 return [list $status $result] 267 292 } elseif {"" != $job(output) || "" != $job(error)} { 268 293 return [list $status [string trim "$job(output)\n$job(error)"]] -
trunk/optimizer/examples/simple.tcl
r899 r903 7 7 # to drive development and testing. 8 8 # 9 # Run this as: tclsh simple.tcl ?-tool path/to/tool.xml?9 # Run this as: wish simple.tcl ?-tool path/to/tool.xml? 10 10 # 11 11 # ====================================================================== … … 16 16 # redistribution of this file, and for a DISCLAIMER OF ALL WARRANTIES. 17 17 # ====================================================================== 18 package require BLT 18 19 package require Itcl 19 20 package require Rappture 20 21 package require RapptureGUI 21 22 package require RapptureOptimizer 23 24 set popsize 100 ;# size of each population for genetic algorithm 22 25 23 26 # ---------------------------------------------------------------------- … … 43 46 44 47 # ---------------------------------------------------------------------- 48 # Create some plotting stuff so we can watch the progress of the 49 # optimization as it runs. 50 # ---------------------------------------------------------------------- 51 blt::graph .space 52 .space xaxis configure -title "x1" -min -2 -max 2 53 .space yaxis configure -title "x2" -min -2 -max 2 54 .space legend configure -hide no 55 pack .space -side left -expand yes -fill both 56 57 blt::graph .value 58 .value xaxis configure -title "job number" -min 0 59 .value yaxis configure -title "f(x1,x2)" -logscale yes -max 1 60 .value legend configure -hide yes 61 pack .value -side left -expand yes -fill both 62 63 set colors {magenta purple blue DeepSkyBlue cyan green yellow Gold orange tomato red FireBrick black} 64 65 for {set pop [expr [llength $colors]-1]} {$pop >= 0} {incr pop -1} { 66 blt::vector x1vec$pop 67 blt::vector x2vec$pop 68 .space element create spots$pop -xdata x1vec$pop -ydata x2vec$pop \ 69 -color [lindex $colors $pop] -linewidth 0 -label "Population #$pop" 70 71 blt::vector jobvec$pop 72 blt::vector fvec$pop 73 .value element create line$pop -xdata jobvec$pop -ydata fvec$pop \ 74 -color [lindex $colors $pop] -symbol none 75 } 76 77 set jobnumber 0 78 proc add_to_plot {xmlobj} { 79 global jobnumber popsize 80 set pop [expr {$jobnumber/$popsize}] 81 x1vec$pop append [$xmlobj get input.number(x1).current] 82 x2vec$pop append [$xmlobj get input.number(x2).current] 83 jobvec$pop append $jobnumber 84 fvec$pop append [$xmlobj get output.number(f).current] 85 incr jobnumber 86 } 87 88 # ---------------------------------------------------------------------- 45 89 # Create an optimization context and configure the parameters used 46 90 # for optimization... … … 50 94 optim add number input.number(x1) -min -2 -max 2 51 95 optim add number input.number(x2) -min -2 -max 2 52 optim configure -operation minimize -popsize 100 -maxruns 20096 optim configure -operation minimize -popsize $popsize -maxruns 1000 53 97 54 98 set status [optim perform \ 55 99 -fitness output.number(f).current \ 56 -updatecommand {puts "checking"}]100 -updatecommand add_to_plot] 57 101 58 102 puts "done: $status" -
trunk/optimizer/src/plugin_pgapack.c
r899 r903 111 111 PGASetPopReplaceType(ctx, dataPtr->popRepl); 112 112 PGASetCrossoverType(ctx, PGA_CROSSOVER_UNIFORM); 113 114 /* stop if any of these are true */ 115 PGASetStoppingRuleType(ctx, PGA_STOP_MAXITER); 116 PGASetStoppingRuleType(ctx, PGA_STOP_NOCHANGE); 117 PGASetStoppingRuleType(ctx, PGA_STOP_TOOSIMILAR); 113 118 114 119 PGASetUserFunction(ctx, PGA_USERFUNCTION_CREATESTRING, PgapCreateString); -
trunk/optimizer/src/rp_optimizer_tcl.c
r899 r903 416 416 case RP_OPTIMPARAM_NUMBER: 417 417 optSpecPtr = rpOptimNumberOpts; 418 if (option == NULL) { 419 /* no particular option value? then include type */ 420 if (Tcl_ListObjAppendElement(interp, rrval, 421 Tcl_NewStringObj("number",-1)) != TCL_OK) { 422 Tcl_DecrRefCount(rrval); 423 Tcl_DecrRefCount(rval); 424 return TCL_ERROR; 425 } 426 } 418 427 break; 419 428 case RP_OPTIMPARAM_STRING: 420 429 optSpecPtr = rpOptimStringOpts; 430 if (option == NULL) { 431 /* no particular option value? then include type */ 432 if (Tcl_ListObjAppendElement(interp, rrval, 433 Tcl_NewStringObj("string",-1)) != TCL_OK) { 434 Tcl_DecrRefCount(rrval); 435 Tcl_DecrRefCount(rval); 436 return TCL_ERROR; 437 } 438 } 421 439 break; 422 440 default: … … 638 656 } 639 657 Tcl_SetResult(interp, envPtr->pluginDefn->name, TCL_STATIC); 658 659 /* if the -tool was specified, then add it as a second element */ 660 toolDataPtr = (RpOptimToolData*)envPtr->toolData; 661 if (toolDataPtr->toolPtr) { 662 Tcl_AppendElement(interp, 663 Tcl_GetStringFromObj(toolDataPtr->toolPtr, (int*)NULL)); 664 } 640 665 return TCL_OK; 641 666 } … … 671 696 { 672 697 RpOptimStatus result = RP_OPTIM_SUCCESS; 698 Tcl_Obj *xmlObj = NULL; 673 699 RpOptimToolData *toolDataPtr = (RpOptimToolData*)envPtr->toolData; 674 700 Tcl_Interp *interp = toolDataPtr->interp; 701 675 702 int n, status; 676 703 #define MAXBUILTIN 10 … … 678 705 int rc; Tcl_Obj **rv; 679 706 Tcl_Obj *dataPtr; 680 char *out;707 Tcl_DString buffer; 681 708 682 709 /* … … 730 757 fprintf(stderr, "== JOB FAILED: malformed result: expected {status output}\n"); 731 758 } else { 732 out = Tcl_GetStringFromObj(rv[1], (int*)NULL);733 759 if (status != 0) { 734 760 result = RP_OPTIM_FAILURE; 735 761 fprintf(stderr, "== JOB FAILED with status code %d:\n%s\n", 736 status, out);762 status, Tcl_GetStringFromObj(rv[1], (int*)NULL)); 737 763 } else { 738 764 /* … … 745 771 * xmlobj get fitnessExpr 746 772 */ 747 getcmd[0] = rv[1]; 773 xmlObj = rv[1]; 774 /* hang onto this for -updatecommand below */ 775 Tcl_IncrRefCount(xmlObj); 776 777 getcmd[0] = xmlObj; 748 778 getcmd[1] = Tcl_NewStringObj("get",-1); 749 779 getcmd[2] = Tcl_NewStringObj(envPtr->fitnessExpr,-1); … … 786 816 */ 787 817 if (toolDataPtr->updateCmdPtr) { 788 status = Tcl_GlobalEvalObj(toolDataPtr->interp, 789 toolDataPtr->updateCmdPtr); 818 Tcl_DStringInit(&buffer); 819 Tcl_DStringAppend(&buffer, 820 Tcl_GetStringFromObj(toolDataPtr->updateCmdPtr, (int*)NULL), -1); 821 Tcl_DStringAppendElement(&buffer, 822 (xmlObj != NULL) ? Tcl_GetStringFromObj(xmlObj, (int*)NULL): ""); 823 824 status = Tcl_GlobalEval(toolDataPtr->interp, 825 Tcl_DStringValue(&buffer)); 790 826 791 827 if (status == TCL_ERROR) { … … 793 829 } 794 830 else if (status == TCL_BREAK || status == TCL_RETURN) { 795 return RP_OPTIM_ABORTED; 796 } 797 } 798 return RP_OPTIM_SUCCESS; 831 result = RP_OPTIM_ABORTED; 832 } 833 Tcl_DStringFree(&buffer); 834 } 835 836 if (xmlObj) { 837 Tcl_DecrRefCount(xmlObj); /* done with this now */ 838 } 839 return result; 799 840 } -
trunk/optimizer/tests/aaa.test
r898 r903 67 67 ctxt add number input.temperature -min 0 -max 1 68 68 ctxt get 69 } {input.temperature -min 0.0 -max 1.0}69 } {input.temperature number -min 0.0 -max 1.0} 70 70 71 71 test aaa-2.2 {add a parameter with a bad type} { … … 87 87 test aaa-2.6 {add doesn't add parameter when there's an error} { 88 88 ctxt get 89 } {input.temperature -min 0.0 -max 1.0}89 } {input.temperature number -min 0.0 -max 1.0} 90 90 91 91 test aaa-2.7 {add a string parameter} { 92 92 ctxt add string input.choice -values {a b c} 93 93 ctxt get input.choice 94 } { -values {a b c}}94 } {string -values {a b c}} 95 95 96 96 test aaa-2.8 {add a string parameter with a missing option} { … … 104 104 test aaa-2.10 {add doesn't add parameter when there's an error} { 105 105 ctxt get 106 } {{input.temperature -min 0.0 -max 1.0} {input.choice -values {a b c}}} 106 } {{input.temperature number -min 0.0 -max 1.0} {input.choice string -values {a b c}}} 107 108 test aaa-2.11 {add another number and return } { 109 ctxt add number input.temporary -min -5 -max 5 110 lsort [ctxt get input.temp*] 111 } {{input.temperature number -min 0.0 -max 1.0} {input.temporary number -min -5.0 -max 5.0}} 112 113 test aaa-2.12 {query -min values for multiple parameters} { 114 lsort [ctxt get input.temp* -min] 115 } {{input.temperature 0.0} {input.temporary -5.0}} 107 116 108 117 # cleanup
Note: See TracChangeset
for help on using the changeset viewer.