<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
  <meta content="text/html;charset=ISO-8859-1" http-equiv="Content-Type">
  <title></title>
</head>
<body bgcolor="#ffffff" text="#000000">
Tom,<br>
some additional comments are in line<br>
Rick<br>
<br>
Tom Parris wrote:
<blockquote
 cite="mid:6b796de60911241007r2cbfded1ja35849541bf4d41d@mail.gmail.com"
 type="cite">Rick,<br>
  <br>
Thanks!  This is very helpful.  I'll read the Ptolemy document more
thoroughly and try again.<br>
  <br>
The basic challenge I'm having is translating from java examples to
python. I've been experimenting with the optional methods.   In the
Java examples I've been looking at (e.g., Repeat, DownSample) the
constructor method is used to: create and set parameters, and sets the
input_tokenConsumptionRate and output_tokenConsumptionRate.  The same
is true for SDFTranformer (from which these examples are subclassed).
That is what led me to try the same in Python (with the __init__
method).  <br>
  <br>
</blockquote>
the initialize(0 and preinitialize() methods provide support for what
you would normally do in __init__(). preinitialize() is called just
once in each run, however, there are circumstances where initialize()
may be called more than once ... I don;t understand what those
circumstances are. In practice, I use preinitialize() to read true
parameters (those defined in "Configure Actor") and store them into
Python instance attributes.
<blockquote
 cite="mid:6b796de60911241007r2cbfded1ja35849541bf4d41d@mail.gmail.com"
 type="cite">The other challenge I'm having is reading n elements from
an input port, but only consuming m elements (where 0<=m<=n) in
order to implement sliding window actors.  Given the code for
IOPort.java, I'm not convinced this is even possible. It looks (to the
untrained eye) that every call to get implicitly pops tokens off the
channel.<br>
</blockquote>
You must read all tokens from a port on each fire. My suggestion is to
read the all of the tokens and either store the extras in a Python
attribute or just ignore them.<br>
<blockquote
 cite="mid:6b796de60911241007r2cbfded1ja35849541bf4d41d@mail.gmail.com"
 type="cite"><br>
I'll work both challenges some more and get back to you offline if I
still need help.<br>
  <br>
-- Tom<br>
  <br>
  <div class="gmail_quote">On Tue, Nov 24, 2009 at 11:04 AM, Rick Moore
  <span dir="ltr"><<a moz-do-not-send="true"
 href="mailto:rem63@cornell.edu">rem63@cornell.edu</a>></span> wrote:<br>
  <blockquote class="gmail_quote"
 style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">
    <div bgcolor="#ffffff" text="#000000">
Tom,<br>
    <br>
I ran your workflow and both ports had the correct values ... but your
script doesn't currently do anything with the blocksize except print it
to stdout (which in kepler is the console). And that works as well.<br>
    <br>
A PythonActor doesn't communicate with it's scripts through the
standard Python __init__ method. Rather it expects the Python scripts
to implement the same methods that a Java actor might implement. Of
course, you already use fire(), but there are several other optional
methods available :<br>
    <br>
def preinitialize(self) ... set port types and/or scheduling
information ...<br>
def initialize(self) ... initialize local variables ...<br>
def prefire(self) ... determine whether firing should proceed ... a
good place to check whether the execution environment is valid<br>
      if you use it, it must return True to proceed,  False if there is
some problem ... no return value is the same as False<br>
      the fire(0 method will be called only if prefire() returns True<br>
def postfire(self) ... update persistent state and/or determine whether
firing should continue to next iteration<br>
     if you use it, it must return True to proceed,  False if there is
some problem ... no return value is the same as False<br>
     returning False will terminate the workflow<br>
def wrapup(self) ... cleanup and display final results ...<br>
     I use this to reset to the initial state after the last iteration<br>
    <br>
Designing actors is discussed in detail in chapter 5 of the document at<br>
    <a moz-do-not-send="true"
 href="http://www.eecs.berkeley.edu/Pubs/TechRpts/2008/EECS-2008-28.pdf"
 target="_blank">http://www.eecs.berkeley.edu/Pubs/TechRpts/2008/EECS-2008-28.pdf</a><br>
    <br>
If you want, I can help you in more detail off list.<br>
    <br>
Rick Moore<br>
Information Science<br>
Cornell University<br>
    <br>
"Once in a while you will be shown the light in the strangest of
places, if you look at it right"<br>
from Scarlet Begonias by the Grateful Dead <br>
    <br>
Tom Parris wrote:
    <blockquote type="cite">
      <div>
      <div class="h5"><span style="font-family: courier new,monospace;">Dear
Keplerites:</span><br style="font-family: courier new,monospace;">
      <br style="font-family: courier new,monospace;">
      <span style="font-family: courier new,monospace;">I have been
making
steady progress understanding how to write actors for Kepler using the
PythonScript actor.  However, I have hit a stumbling block in my
attempts to set input_tokenConsumptionRate.  </span><br
 style="font-family: courier new,monospace;">
      <br style="font-family: courier new,monospace;">
      <span style="font-family: courier new,monospace;">To illustrate
my
problem, I have attached a simple workflow with an actor titled
"IntTokenSum" written with the PythonScript actor.  This actor is
designed to add some number of integer tokens from it's "input" port.
 The number of tokens is defined by the "windowsize" port.  The number
of tokens to consume with each "fire" is defined with the "blocksize"
port.   The current version works as desired with the exception of the
blocksize input prot (it always takes on the value of the windowsize
input port).</span><br style="font-family: courier new,monospace;">
      <br style="font-family: courier new,monospace;">
      <span style="font-family: courier new,monospace;">Q1: As the
script
is currently configured, the windowsize parameter works as advertised.
 However, I can't seem to get the blocksize parameter to work.  I've
tried a number of approaches to setting the input_tokenConsumptionRate
per the java code for several actors (e.g., DownSample).  But now I'm
wondering if that is the correct approach.  Perhaps its the call to
self.input.get that needs to be changed.  Correct output on Display2
should be the sequence: 1, 3, 5, 7, 9, 11, 13, 15, 17</span>.<br
 style="font-family: courier new,monospace;">
      <br style="font-family: courier new,monospace;">
      <span style="font-family: courier new,monospace;">Q2: I'd also
like
to use an actor along these lines under the SDF director with
portparameters for windowsize and blocksize.  But can't figure out how
to to this with the PythonScript actor.  Is this possible?  If so, I
would welcome guidance.</span><br
 style="font-family: courier new,monospace;">
      <br style="font-family: courier new,monospace;">
      <span style="font-family: courier new,monospace;">Q3: Finally, it
should be fairly easy to make this actor polymorphic.  I think this can
be done by changing the line:</span><br
 style="font-family: courier new,monospace;">
      <br style="font-family: courier new,monospace;">
      <span style="font-family: courier new,monospace;">   val = val +
it.intValue()</span><br style="font-family: courier new,monospace;">
      <br style="font-family: courier new,monospace;">
      <span style="font-family: courier new,monospace;">to</span><br
 style="font-family: courier new,monospace;">
      <br style="font-family: courier new,monospace;">
      <span style="font-family: courier new,monospace;">   val =
it.add(val)</span><br style="font-family: courier new,monospace;">
      <br style="font-family: courier new,monospace;">
      <span style="font-family: courier new,monospace;">But I am not
sure
how to initialize val to the additive identity (generalized notion of
zero).</span><br style="font-family: courier new,monospace;">
      <br style="font-family: courier new,monospace;">
      </div>
      </div>
      <pre><pre><hr size="4" width="90%">
_______________________________________________
Kepler-users mailing list
<a moz-do-not-send="true" href="mailto:Kepler-users@kepler-project.org"
 target="_blank">Kepler-users@kepler-project.org</a>
<a moz-do-not-send="true"
 href="http://mercury.nceas.ucsb.edu/kepler/mailman/listinfo/kepler-user"
 target="_blank">http://mercury.nceas.ucsb.edu/kepler/mailman/listinfo/kepler-user</a>
</pre></pre>
    </blockquote>
    </div>
  </blockquote>
  </div>
</blockquote>
</body>
</html>