[kepler-dev] Re: [kepler-cvs] kepler/src/org/sdm/spa ArrayToSequence.java

xiaowen xin2 at llnl.gov
Wed Jul 7 14:58:25 PDT 2004


Hi Steve,

Thanks much for your suggestion and help in better understanding how I 
might implement the actor without writing Java code!  I haven't used the 
SampleDelay actor before, but now I see how I can use it to get the 
behavior I want.

I've spent some time thinking about how I can work in the reset 
functionality and I think I've got a solution.

            ---------
reset  --> | count | ---> count
update --> ---------

For each element the workflow processes, Count first takes in a reset 
token, outputs a count token, then takes in an update token.

So except for the first iteration, we can think of it as taking in the 
update token for (element n) and the reset token for (element n+1) at 
the same time, then outputting the count token for (element n+1).

The way to take care of the first iteration is to use a SampleDelay 
actor to produce an extra update token.

I've attached a workflow demonstrating what I mean.  If you get a 
chance, will you please take a look at it and tell me what you think?


Thanks!
Xiaowen


Stephen Andrew Neuendorffer wrote:

> There is always a tension between 'write a new actor' and 'cobble 
> together existing actors'.
> Without saying which is better, I'll show how you could have done this 
> without writing any Java code:
> I'll ignore the reset, to make it a little simpler and allow this to be 
> built using SDF, instead of something more
> complex.  Although it is sometimes a mindbend, building simple actors 
> like this using dataflow can be
> like a warmup exercise for building more complex dataflow models.
> 
> Accumulate is like a SampleDelay actor, in a feedback loop with an adder.
> 
> <relation name="relation" class="ptolemy.actor.TypedIORelation">
> </relation>
> <relation name="relation2" class="ptolemy.actor.TypedIORelation">
>     <vertex name="vertex1" value="[285.0, 210.0]">
>     </vertex>
> </relation>
> <entity name="AddSubtract" class="ptolemy.actor.lib.AddSubtract">
>     <property name="_location" class="ptolemy.kernel.util.Location" 
> value="[230.0, 210.0]">
>     </property>
> </entity>
> <port name="port" class="ptolemy.actor.TypedIOPort">
>     <property name="input"/>
>     <property name="_location" class="ptolemy.kernel.util.Location" 
> value="[140.0, 200.0]">
>     </property>
> </port>
> <property name="SDF Director" 
> class="ptolemy.domains.sdf.kernel.SDFDirector">
>     <property name="_location" class="ptolemy.kernel.util.Location" 
> value="[175.0, 145.0]">
>     </property>
> </property>
> <relation name="relation4" class="ptolemy.actor.TypedIORelation">
>     <vertex name="vertex1" value="[360.0, 275.0]">
>     </vertex>
> </relation>
> <port name="port2" class="ptolemy.actor.TypedIOPort">
>     <property name="output"/>
>     <property name="_location" class="ptolemy.kernel.util.Location" 
> value="[400.0, 210.0]">
>     </property>
> </port>
> <entity name="SampleDelay" class="ptolemy.domains.sdf.lib.SampleDelay">
>     <property name="_icon" class="ptolemy.vergil.icon.BoxedValueIcon">
>         <property name="attributeName" 
> class="ptolemy.kernel.util.StringAttribute" value="initialOutputs">
>         </property>
>         <property name="displayWidth" 
> class="ptolemy.data.expr.Parameter" value="20">
>         </property>
>     </property>
>     <property name="_location" class="ptolemy.kernel.util.Location" 
> value="[315.0, 245.0]">
>     </property>
> </entity>
>     <link port="port" relation="relation"/>
>     <link port="port2" relation="relation2"/>
>     <link port="AddSubtract.plus" relation="relation"/>
>     <link port="AddSubtract.minus" relation="relation4"/>
>     <link port="AddSubtract.output" relation="relation2"/>
>     <link port="SampleDelay.input" relation="relation2"/>
>     <link port="SampleDelay.output" relation="relation4"/>
> 
> 
> Depending on where you tap the output, you will get either a first 
> output of zero, or a first output equal to the first input.
> If you tap in such a place where the first output is always zero (with 
> the SampleDelay connected directly to the output port),
> then SDF is smart enough to recognize this and output the zero during 
> initialization.
> 
> <relation name="relation" class="ptolemy.actor.TypedIORelation">
> </relation>
> <relation name="relation2" class="ptolemy.actor.TypedIORelation">
>     <vertex name="vertex1" value="[285.0, 210.0]">
>     </vertex>
> </relation>
> <entity name="AddSubtract" class="ptolemy.actor.lib.AddSubtract">
>     <property name="_location" class="ptolemy.kernel.util.Location" 
> value="[230.0, 210.0]">
>     </property>
> </entity>
> <property name="SDF Director" 
> class="ptolemy.domains.sdf.kernel.SDFDirector">
>     <property name="_location" class="ptolemy.kernel.util.Location" 
> value="[175.0, 145.0]">
>     </property>
> </property>
> <port name="port" class="ptolemy.actor.TypedIOPort">
>     <property name="input"/>
>     <property name="_location" class="ptolemy.kernel.util.Location" 
> value="[140.0, 200.0]">
>     </property>
> </port>
> <relation name="relation4" class="ptolemy.actor.TypedIORelation">
>     <vertex name="vertex1" value="[360.0, 275.0]">
>     </vertex>
> </relation>
> <port name="port2" class="ptolemy.actor.TypedIOPort">
>     <property name="output"/>
>     <property name="_location" class="ptolemy.kernel.util.Location" 
> value="[400.0, 275.0]">
>     </property>
> </port>
> <entity name="SampleDelay" class="ptolemy.domains.sdf.lib.SampleDelay">
>     <property name="_icon" class="ptolemy.vergil.icon.BoxedValueIcon">
>         <property name="attributeName" 
> class="ptolemy.kernel.util.StringAttribute" value="initialOutputs">
>         </property>
>         <property name="displayWidth" 
> class="ptolemy.data.expr.Parameter" value="20">
>         </property>
>     </property>
>     <property name="_location" class="ptolemy.kernel.util.Location" 
> value="[315.0, 245.0]">
>     </property>
> </entity>
>     <link port="port" relation="relation"/>
>     <link port="port2" relation="relation4"/>
>     <link port="AddSubtract.plus" relation="relation"/>
>     <link port="AddSubtract.minus" relation="relation4"/>
>     <link port="AddSubtract.output" relation="relation2"/>
>     <link port="SampleDelay.input" relation="relation2"/>
>     <link port="SampleDelay.output" relation="relation4"/>
> 
> Interestingly enough, if you take an Accumulate actor and feed it's 
> output into a SampleDelay, then the first output will
> always be zero, and it will break feedback loops!  This is behaviorally 
> identical as the previous example, at the expense of duplication of state.
> This is a form of what is called retiming in the hardware design world.
> 
> <relation name="relation" class="ptolemy.actor.TypedIORelation">
> </relation>
> <relation name="relation2" class="ptolemy.actor.TypedIORelation">
>     <vertex name="vertex1" value="[285.0, 210.0]">
>     </vertex>
> </relation>
> <relation name="relation3" class="ptolemy.actor.TypedIORelation">
> </relation>
> <entity name="AddSubtract" class="ptolemy.actor.lib.AddSubtract">
>     <property name="_location" class="ptolemy.kernel.util.Location" 
> value="[230.0, 210.0]">
>     </property>
> </entity>
> <port name="port" class="ptolemy.actor.TypedIOPort">
>     <property name="input"/>
>     <property name="_location" class="ptolemy.kernel.util.Location" 
> value="[140.0, 200.0]">
>     </property>
> </port>
> <property name="SDF Director" 
> class="ptolemy.domains.sdf.kernel.SDFDirector">
>     <property name="_location" class="ptolemy.kernel.util.Location" 
> value="[175.0, 145.0]">
>     </property>
> </property>
> <relation name="relation4" class="ptolemy.actor.TypedIORelation">
>     <vertex name="vertex1" value="[360.0, 275.0]">
>     </vertex>
> </relation>
> <entity name="SampleDelay2" class="ptolemy.domains.sdf.lib.SampleDelay">
>     <property name="_icon" class="ptolemy.vergil.icon.BoxedValueIcon">
>         <property name="attributeName" 
> class="ptolemy.kernel.util.StringAttribute" value="initialOutputs">
>         </property>
>         <property name="displayWidth" 
> class="ptolemy.data.expr.Parameter" value="20">
>         </property>
>     </property>
>     <property name="_location" class="ptolemy.kernel.util.Location" 
> value="[415.0, 210.0]">
>     </property>
> </entity>
> <port name="port2" class="ptolemy.actor.TypedIOPort">
>     <property name="output"/>
>     <property name="_location" class="ptolemy.kernel.util.Location" 
> value="[500.0, 210.0]">
>     </property>
> </port>
> <entity name="SampleDelay" class="ptolemy.domains.sdf.lib.SampleDelay">
>     <property name="_icon" class="ptolemy.vergil.icon.BoxedValueIcon">
>         <property name="attributeName" 
> class="ptolemy.kernel.util.StringAttribute" value="initialOutputs">
>         </property>
>         <property name="displayWidth" 
> class="ptolemy.data.expr.Parameter" value="20">
>         </property>
>     </property>
>     <property name="_location" class="ptolemy.kernel.util.Location" 
> value="[315.0, 245.0]">
>     </property>
> </entity>
>     <link port="port" relation="relation"/>
>     <link port="port2" relation="relation3"/>
>     <link port="AddSubtract.plus" relation="relation"/>
>     <link port="AddSubtract.minus" relation="relation4"/>
>     <link port="AddSubtract.output" relation="relation2"/>
>     <link port="SampleDelay.input" relation="relation2"/>
>     <link port="SampleDelay.output" relation="relation4"/>
>     <link port="SampleDelay2.input" relation="relation2"/>
>     <link port="SampleDelay2.output" relation="relation3"/>
> 
> As near as I can tell, you could implement your count actor as the 
> following (disregarding the reset input, which makes it more complex...  
> Implementing reset could be done in an SR model)
> 
> <entity name="Const" class="ptolemy.actor.lib.Const">
>     <doc>Create a constant sequence</doc>
>     <property name="_icon" class="ptolemy.vergil.icon.BoxedValueIcon">
>         <property name="attributeName" 
> class="ptolemy.kernel.util.StringAttribute" value="value">
>         </property>
>         <property name="displayWidth" 
> class="ptolemy.data.expr.Parameter" value="60">
>         </property>
>     </property>
>     <property name="_location" class="ptolemy.kernel.util.Location" 
> value="[210.0, 200.0]">
>     </property>
> </entity>
> <relation name="relation" class="ptolemy.actor.TypedIORelation">
> </relation>
> <relation name="relation2" class="ptolemy.actor.TypedIORelation">
> </relation>
> <entity name="Accumulator" class="ptolemy.actor.lib.Accumulator">
>     <property name="_location" class="ptolemy.kernel.util.Location" 
> value="[305.0, 210.0]">
>     </property>
> </entity>
> <relation name="relation3" class="ptolemy.actor.TypedIORelation">
> </relation>
> <relation name="relation4" class="ptolemy.actor.TypedIORelation">
> </relation>
> <property name="SDF Director" 
> class="ptolemy.domains.sdf.kernel.SDFDirector">
>     <property name="_location" class="ptolemy.kernel.util.Location" 
> value="[175.0, 145.0]">
>     </property>
> </property>
> <port name="port" class="ptolemy.actor.TypedIOPort">
>     <property name="input"/>
>     <property name="_location" class="ptolemy.kernel.util.Location" 
> value="[140.0, 200.0]">
>     </property>
> </port>
> <entity name="SampleDelay2" class="ptolemy.domains.sdf.lib.SampleDelay">
>     <property name="_icon" class="ptolemy.vergil.icon.BoxedValueIcon">
>         <property name="attributeName" 
> class="ptolemy.kernel.util.StringAttribute" value="initialOutputs">
>         </property>
>         <property name="displayWidth" 
> class="ptolemy.data.expr.Parameter" value="20">
>         </property>
>     </property>
>     <property name="_location" class="ptolemy.kernel.util.Location" 
> value="[385.0, 210.0]">
>     </property>
> </entity>
> <port name="port2" class="ptolemy.actor.TypedIOPort">
>     <property name="output"/>
>     <property name="_location" class="ptolemy.kernel.util.Location" 
> value="[470.0, 210.0]">
>     </property>
> </port>
>     <link port="port" relation="relation"/>
>     <link port="port2" relation="relation3"/>
>     <link port="SampleDelay2.input" relation="relation4"/>
>     <link port="SampleDelay2.output" relation="relation3"/>
>     <link port="Const.output" relation="relation2"/>
>     <link port="Const.trigger" relation="relation"/>
>     <link port="Accumulator.input" relation="relation2"/>
>     <link port="Accumulator.output" relation="relation4"/>

-------------- next part --------------
A non-text attachment was scrubbed...
Name: my-count.xml
Type: text/xml
Size: 13514 bytes
Desc: not available
URL: <http://mercury.nceas.ucsb.edu/kepler/pipermail/kepler-dev/attachments/20040707/96969fb2/attachment.xml>


More information about the Kepler-dev mailing list