<html>
  <head>
    <meta content="text/html; charset=ISO-8859-1"
      http-equiv="Content-Type">
  </head>
  <body bgcolor="#FFFFFF" text="#000000">
    <div class="moz-cite-prefix">Hi Jonathan,<br>
      <br>
    </div>
    Ptolemy has a Python actor that uses Jython<br>
    <br>
    <a class="moz-txt-link-freetext" href="http://ptolemy.eecs.berkeley.edu/ptolemyII/ptIIfaq.htm#Scripting">http://ptolemy.eecs.berkeley.edu/ptolemyII/ptIIfaq.htm#Scripting</a>
    says:<br>
    <br>
    <blockquote type="cite">
      <meta http-equiv="content-type" content="text/html;
        charset=ISO-8859-1">
      <dt> <a name="Scripting"><b>5.9 Is there a scripting interface to
            Ptolemy II ?</b></a>
      </dt>
      <dd> The PythonScript actor includes and interface to
        <a href="http://www.jython.org/#in_browser" target="_top">Jython</a>,
        a Java implementation of Python. The PythonScript actor allows
        the user to define an actor on the fly by defining the <code>fire()</code>
        and other methods in Python. Using an interpreted language in
        this context instead of defining actors in Java means that we
        need not recompile and restart
        Ptolemy II to make a change to an actor. The tradeoff is that a
        PythonScript actor will run more slowly than a similar actor
        implemented in Java. <br>
        For details, see
        <a
href="http://ptolemy.eecs.berkeley.edu/ptolemyII/ptIIlatest/ptII/doc/codeDoc/ptolemy/actor/lib/python/PythonScript.html"
          target="_top"><code>http://ptolemy.eecs.berkeley.edu/ptolemyII/ptIIlatest/ptII/doc/codeDoc/ptolemy/actor/lib/python/PythonScript.html</code></a>
        <p>The Ptolemy II test suite uses Jacl, a Java implementation of
          Tcl
          as a scripting language. With Jacl, we can build and run
          models
          using an interpreted scripting environment without compilation
          and avoiding the usual edit/compile/run loop. <br>
          For details, see the Testing link in <a
href="http://ptolemy.eecs.berkeley.edu/ptolemyII/ptIIlatest/ptII/doc/coding/index.htm"
            target="_top"><code>http://ptolemy.eecs.berkeley.edu/ptolemyII/ptIIlatest/ptII/doc/coding/</code></a>
        </p>
      </dd>
    </blockquote>
    <br>
    I'm not that up on how Jython accesses Java objects, but in theory
    one could write an actor that gets the container object, then finds
    a parameter and then calls setExpression o the parameter.  This
    could happen at runtime.  However, this is difficult to get right. 
    The SetVariable actor does something similar and it is not an easy
    actor to write.  A Jython-based actor that set parameter values in
    the container would need to be very similar to SetVariable.  See
<a class="moz-txt-link-freetext" href="http://ptolemy.eecs.berkeley.edu/ptolemyII/ptII8.0/ptII/doc/codeDoc/ptolemy/actor/lib/SetVariable.html">http://ptolemy.eecs.berkeley.edu/ptolemyII/ptII8.0/ptII/doc/codeDoc/ptolemy/actor/lib/SetVariable.html</a><br>
    <br>
    If you are trying to do a parameter sweep, then
    <a class="moz-txt-link-freetext" href="http://ptolemy.eecs.berkeley.edu/ptolemyII/ptIIfaq.htm#parameterSweeps">http://ptolemy.eecs.berkeley.edu/ptolemyII/ptIIfaq.htm#parameterSweeps</a>
    says:<br>
    <br>
    <blockquote type="cite">
      <meta http-equiv="content-type" content="text/html;
        charset=ISO-8859-1">
      <dt> <a name="parameterSweeps"><b>4.11 How do a do a parameter
            sweep?</b></a>
      </dt>
      <dd> A Parameter Sweep is when a model is run a number of times
        with different parameters to perhaps find an optimal solution.
        For details, see <a
href="http://chess.eecs.berkeley.edu/ptexternal/wiki/Main/ParameterSweeps#in_browser"
          target="_top">http://chess.eecs.berkeley.edu/ptexternal/wiki/Main/ParameterSweeps</a>.
      </dd>
    </blockquote>
    Another idea is to have Jython set the parameters and then run the
    model.  We do similar things using Tcl in the test case.  See
    ptolemy/moml/test/MoMLParser.tcl<br>
    <br>
    This test from ptolemy/actor/lib/test/Test.xml loads a .xml file and
    runs it<br>
    <br>
    <blockquote type="cite">test Test-3.0 {Test case where training and
      we get no data} {<br>
          # Thomas Mandl pointed out this bug and supplied a
      fix                              <br>
          set workspace [java::new ptolemy.kernel.util.Workspace
      "Test3_0"]<br>
          set parser [java::new ptolemy.moml.MoMLParser $workspace]<br>
          $parser reset<br>
          $parser purgeAllModelRecords<br>
          $parser setMoMLFilters [java::null]<br>
          $parser addMoMLFilters \<br>
                  [java::call ptolemy.moml.filter.BackwardCompatibility
      allFilters]<br>
      <br>
          $parser addMoMLFilter [java::new \<br>
                  ptolemy.moml.filter.RemoveGraphicalClasses]<br>
          #set model3_0
      \                                                                   
       <br>
          #    [java::cast ptolemy.actor.TypedCompositeActor [$parser
      parseFile BooleanSwitch\<br>
      _RegressionTest.xml]]                                                                 
       <br>
          set model3_0 \<br>
               [java::cast ptolemy.actor.TypedCompositeActor [$parser
      parseFile BooleanSwitch\<br>
      _RegressionTest_WrongTrainingValues.xml]]<br>
          set manager [java::new ptolemy.actor.Manager $workspace
      "test3_0Manager"]<br>
          $model3_0 setManager $manager<br>
          $manager execute<br>
      <br>
          # Get the corrrectValues parameter, which should be
      {}                              <br>
          set test2 [$model3_0 getEntity Test2]<br>
          set correctValues [java::cast ptolemy.data.expr.Parameter
      [$test2 getAttribute corr\<br>
      ectValues]]<br>
      <br>
          list [$correctValues getExpression]<br>
      <br>
      } {{{}}}</blockquote>
    <br>
    Later in that file we get the Test2 entity<br>
    <blockquote type="cite">   set test2 [$model3_0 getEntity Test2]<br>
    </blockquote>
    and the get the "correctValues" parameter<br>
    <blockquote type="cite">    set correctValues [java::cast
      ptolemy.data.expr.Parameter [$test2 getAttribute correctValues]]</blockquote>
    To get the value of the correctValues parameter, call
    "$correctValues getExpression".<br>
    <br>
    To set the value<br>
    $correctValues setExpression "{1,2}"<br>
    <br>
    It is probably possible to do something similar in Jython, where you
    instantiate the model by calling the parser  set the variables and
    run it.  You could use the Recorder actor to get the outputs of the
    model, or write the data using ExpressionWriter or LineWriter.<br>
    <br>
    _Christopher<br>
    <br>
    On 10/21/13 10:51 AM, Jonathan Boright wrote:<br>
    <blockquote
cite="mid:CAFEwxXKSPxuRn8ppkA53FyRTK-Ypexw0FZUEO4m8d66nPLz3cw@mail.gmail.com"
      type="cite">
      <div dir="ltr">Hi All, 
        <div><br>
        </div>
        <div>I'm wondering if there is a way to set workflow parameters
          using python code? I see the ParameterSet actor, but I'd like
          to set parameters dynamically using python instead of using a
          static text file... </div>
        <div><br>
        </div>
        <div>Thanks for your help.</div>
        <div><br>
        </div>
        <div>Jon</div>
        <div><br>
        </div>
        <div><br clear="all">
          <div>---------------------------------<br>
            Jonathan Boright<br>
            Research Scientist<br>
            ISciences, LLC<br>
            61 Main Street, Suite 200<br>
            Burlington, VT 05401<br>
            <br>
          </div>
        </div>
      </div>
      <br>
      <fieldset class="mimeAttachmentHeader"></fieldset>
      <br>
      <pre wrap="">_______________________________________________
Kepler-users mailing list
<a class="moz-txt-link-abbreviated" href="mailto:Kepler-users@kepler-project.org">Kepler-users@kepler-project.org</a>
<a class="moz-txt-link-freetext" href="http://lists.nceas.ucsb.edu/kepler/mailman/listinfo/kepler-users">http://lists.nceas.ucsb.edu/kepler/mailman/listinfo/kepler-users</a>
</pre>
    </blockquote>
    <br>
    <br>
    <pre class="moz-signature" cols="72">-- 
Christopher Brooks, PMP                       University of California
Academic Program Manager & Software Engineer  US Mail: 337 Cory Hall
CHESS/iCyPhy/Ptolemy/TerraSwarm               Berkeley, CA 94720-1774
<a class="moz-txt-link-abbreviated" href="mailto:cxh@eecs.berkeley.edu">cxh@eecs.berkeley.edu</a>, 707.332.0670           (Office: 545Q Cory)
</pre>
  </body>
</html>