[kepler-users] IterateOverArray - Type conversion problem

Christopher Brooks cxh at eecs.berkeley.edu
Thu Jan 12 11:06:28 PST 2012


Hi Muhannad,
I *am* confused then, but no worries on this, we will get to the bottom 
of this.

I see no connection between the HelloWorld.java file and the model that 
you sent.
In other words, the IterateOverArray.xml file does not mention the 
HelloWorld class.

You say the HelloWorld.java file implements the contents of the 
"Composite Actor" of the model in
IterateOverArray.xml file.  If this message does not answer your 
question then could you send me that model?

Also, if you send the model, if you can give me step by step 
instructions on how to replicate the error, then I can take a look. I 
would need really detailed instructions.

However, I *may* have answered your question.

I've attached a model that may replicate the problem.  To create the 
model, I opened IterateOverArray.xml
in Ptolemy and did Graph -> Instantiate Entity.  For the classname, I 
typed in org.helloworld.HelloWorld
and hit ok.  This created a HelloWorld composite.  I then dragged the 
connections from the original CompositeActor to the HelloWorld, saved 
the model as IterateOverArrayHelloWorld.xml and ran the model and got a 
stack trace similar to yours.

I took a look at your HelloWorld.java and the CGISimple.java file that I 
sent and noticed that your HelloWorld.java file instantiates 
MirrorPorts, whereas CGISimple.java instantiates 
IterateOverArray.IteratePorts.  I changed HelloWorld.java
to use IterateoOverArray.IteratePort:

         //mpInput = new MirrorPort(iter, "input"); mpInput.setInput(true);
         mpInput = new IterateOverArray.IteratePort(iter, "input");
         //mpOutput = new MirrorPort(iter, "output"); 
mpOutput.setOutput(true);
         mpOutput = new IterateOverArray.IteratePort(iter, "output");
...
     //private MirrorPort mpInput;
     //private MirrorPort mpOutput;

     private IterateOverArray.IteratePort mpInput;
     private IterateOverArray.IteratePort mpOutput;

After recompiling HelloWorld.java, the model runs.

Does this answer your question, or did answer and entirely different 
question? :-)

_Christopher


On 1/12/12 10:44 AM, Ali, Muhannad wrote:
> Hi Christopher,
>
> Thank you for your reply .. I'm afraid I am not that familiar with 
> what you described about Ptolemy. I guess the problem is much simpler.
>
> Actually the Java Code replicates only the "Composite Actor" in the 
> model shown in IterateOverArray.xml. The other actors and director are 
> to be added from Kepler after running it using the new developed 
> "HelloWorld" module, got it?
>
> The question is, although I "replicated" the composite actor 
> (programmatically), it did not work properly as when I designed it 
> using Kepler GUI?
>
> Best regards,
>
> Muhannad
>
> On Jan 12, 2012, at 7:28 PM, Christopher Brooks wrote:
>
>> Hi Muhannad,
>> I'm slightly confused, but attached is some overly complex code that 
>> implements the model along with the steps I used to create that code.
>>
>> You included a model called IterateOverArray.xml and you are trying 
>> to write Java code (HelloWorld.java) that replicates the 
>> functionality of that model, right?
>>
>> However, you did not include the model that runs your java code.
>> The stack trace below is from a test run of a model that uses your 
>> HelloWorld.java,
>>
>> I would need to see your test driver to get much further, but 
>> attached is some code that could help you.
>>
>> Ptolemy II does have a code generator that generates Java code that 
>> constructs a TypedComposite.
>> This code generator is called "copernicus".  See the Ptolemy II faq 
>> for details about the code generators.
>> http://ptolemy.berkeley.edu/ptolemyII/ptIIfaq.htm#CodeGen
>>
>> To follow the steps below, you would need to work from a Ptolemy II tree.
>> However, you don't have to run copernicus, you could just look at the 
>> .java file that is attached and
>> not actually *do* the steps below.
>>
>> Under Mac OS X, to create the $PTII/bin/copernicus shell script, 
>> these steps might work:
>>   cd kepler/ptII/src
>>   export PTII=`pwd`
>>   ./configure
>>   ant
>>   cd bin; make
>>
>> I was able to generate Java code that calls the Ptolemy methods for 
>> your model, though it was not easy.
>>
>> 1) To simplify the output, I stripped out the graphical xml 
>> attributes of the model.  I did this by running:
>> java -classpath $PTII ptolemy.moml.filter.RemoveGraphicalClasses 
>> IterateOverArray.xml > ISimple.xml
>>
>> 2) I then edited the model and removed a bunch of Kepler specific 
>> attributes.
>> There is a significant bug in Kepler where the documentation is 
>> replicated for each actor, see
>> http://bugzilla.ecoinformatics.org/show_bug.cgi?id=4168
>>
>> 3) Eventually, I ended up with ISimple.xml, which is attached.
>>
>> 4) I ran the copernicus code generator with
>>   $PTII/bin/copernicus -shallow ISimple.xml
>> This created $PTII/ptolemy/copernicus/shallow/cg/ISimple, which 
>> contains a .class file for the model.
>>
>> 5) I changed to that directory and ran:
>> make jodeDecompile
>>
>> 6) That created a CGISimple.java file, which I then edited.
>> The issue is that the copernicus code generator seems to change 
>> Display actors to Discard actors.
>> Probably the RemoveGraphicalClassesFilter is running.
>>
>> My solution was to edit CGISimple.java and change
>>   import ptolemy.actor.lib.Discard;
>> to
>>   import ptolemy.actor.lib.gui.Display;
>>
>> and
>>  Discard discard = new Discard(this, "Display2");
>> to
>>  Display discard = new Display(this, "Display2");
>>
>> See the attached CGISimple.java file for the code.
>> Unfortunately, it is difficult to see the forest for the trees 
>> because I believe that the .xml file had many of the properties for 
>> the actors set, and/or the copernicus code generator just blindly 
>> creates code to instantiate everything.
>>
>> Anyway, it is difficult to see what to do, but it should give you an 
>> idea.
>>
>> 7) I then recompiled the code.  Unfortunately, the makefile has a bug
>>  javac -classpath $PTII:. ISimple/CGISimple.java
>>
>> 8) I then ran the code:
>>  java -classpath .:${PTvII} 
>> ptolemy.actor.gui.CompositeActorApplication -class ISimple.CGISimple
>>
>> _Christopher
>>
>> On 1/12/12 9:14 AM, Ali, Muhannad wrote:
>>>
>>> Hello,
>>>
>>> I need to develop a composite actor (programmatically) using 
>>> eclipse. Before I code it, I designed it on Kepler canvas (see file 
>>> IterateOverArray.xml attached) in order to test the functionality 
>>> and then encapsulate it in my own composite actor. When I designed 
>>> it, it worked perfectly but when I coded it and tried to run the 
>>> program .. I always get the following error:
>>>
>>> "
>>> ptolemy.kernel.util.IllegalActionException: Conversion is not 
>>> supported from ptolemy.data.ArrayToken '{"1 - 1"}' to the type 
>>> string because the type of the token is higher or incomparable with 
>>> the given type.
>>> at ptolemy.data.StringToken.convert(StringToken.java:172)
>>> at ptolemy.data.type.BaseType$StringType.convert(BaseType.java:615)
>>> at ptolemy.data.ArrayToken.<init>(ArrayToken.java:151)
>>> at 
>>> ptolemy.actor.lib.hoc.IterateOverArray$IterateDirector.transferOutputs(IterateOverArray.java:706)
>>> at ptolemy.actor.CompositeActor.fire(CompositeActor.java:469)
>>> at ptolemy.actor.CompositeActor.iterate(CompositeActor.java:1069)
>>> at 
>>> ptolemy.actor.sched.StaticSchedulingDirector.fire(StaticSchedulingDirector.java:188)
>>> at ptolemy.actor.CompositeActor.fire(CompositeActor.java:458)
>>> at ptolemy.actor.Manager.iterate(Manager.java:742)
>>> at ptolemy.actor.Manager.execute(Manager.java:351)
>>> at ptolemy.actor.Manager.run(Manager.java:1111)
>>> at ptolemy.actor.Manager$PtolemyRunThread.run(Manager.java:1641
>>> "
>>>
>>> My code is:
>>>
>>> "
>>> package org.helloworld;
>>>
>>> import ptolemy.actor.TypedCompositeActor;
>>> import ptolemy.actor.TypedIOPort;
>>> import ptolemy.actor.TypedIORelation;
>>> import ptolemy.actor.lib.ElementsToArray;
>>> import ptolemy.actor.lib.Expression;
>>> import ptolemy.actor.lib.hoc.IterateOverArray;
>>> import ptolemy.actor.lib.hoc.MirrorPort;
>>> import ptolemy.kernel.CompositeEntity;
>>> import ptolemy.kernel.util.IllegalActionException;
>>> import ptolemy.kernel.util.NameDuplicationException;
>>>
>>> public class HelloWorld extends TypedCompositeActor {
>>>
>>> public HelloWorld(CompositeEntity container, String name)
>>> throws NameDuplicationException, IllegalActionException {
>>> super(container, name);
>>>
>>> params = new TypedIOPort(this, "params", true, false);
>>> params.setMultiport(true);
>>>
>>> output = new TypedIOPort(this, "output", false, true);
>>>
>>> elems2Arr = new ElementsToArray(this, "elems2Arr");
>>> relation1 = new TypedIORelation(this, "realtion1");
>>> params.link(relation1);
>>> elems2Arr.input.link(relation1);
>>>
>>> iter = new IterateOverArray(this, "iter");
>>> mpInput = new MirrorPort(iter, "input"); mpInput.setInput(true);
>>> mpOutput = new MirrorPort(iter, "output"); mpOutput.setOutput(true);
>>> exp = new Expression(iter, "exp");
>>> exp.expression.setExpression("input + ' - ' + iterationCount");
>>> relation2 = new TypedIORelation(this, "realtion2");
>>> elems2Arr.output.link(relation2);
>>> iter.getPort("input").link(relation2);
>>>
>>> relation3 = new TypedIORelation(this, "realtion3");
>>> iter.getPort("output").link(relation3);
>>> output.link(relation3);
>>> }
>>>
>>> public TypedIOPort params;
>>> public TypedIOPort output;
>>>
>>> private MirrorPort mpInput;
>>> private MirrorPort mpOutput;
>>>
>>> private ElementsToArray elems2Arr;
>>> private IterateOverArray iter;
>>> private Expression exp;
>>>
>>> private TypedIORelation relation1;
>>> private TypedIORelation relation2;
>>> private TypedIORelation relation3;
>>>
>>>
>>> @Override
>>> public void fire() throws IllegalActionException {
>>> super.fire();
>>> }
>>>
>>> }
>>> "
>>>
>>>
>>> I guess the problem is related to the director inside 
>>> IterateOverArray actor .. any help please?
>>>
>>>
>>> Thank you!
>>>
>>> Muhannad Ali
>>>
>>>
>>>
>>>
>>> _______________________________________________
>>> Kepler-users mailing list
>>> Kepler-users at kepler-project.org
>>> http://lists.nceas.ucsb.edu/kepler/mailman/listinfo/kepler-users
>>
>> -- 
>> Christopher Brooks, PMP                       University of California
>> CHESS Executive Director                      US Mail: 337 Cory Hall
>> Programmer/Analyst CHESS/Ptolemy/Trust        Berkeley, CA 94720-1774
>> ph: 510.643.9841                                (Office: 545Q Cory)
>> home: (F-Tu) 707.665.0131 cell: 707.332.0670
>> <ISimple.xml><CGISimple.java>
>
>
>
> _______________________________________________
> Kepler-users mailing list
> Kepler-users at kepler-project.org
> http://lists.nceas.ucsb.edu/kepler/mailman/listinfo/kepler-users

-- 
Christopher Brooks, PMP                       University of California
CHESS Executive Director                      US Mail: 337 Cory Hall
Programmer/Analyst CHESS/Ptolemy/Trust        Berkeley, CA 94720-1774
ph: 510.643.9841                                (Office: 545Q Cory)
home: (F-Tu) 707.665.0131 cell: 707.332.0670

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.nceas.ucsb.edu/kepler/pipermail/kepler-users/attachments/20120112/0a9ffa93/attachment-0001.html>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: IterateOverArrayHelloWorld.xml
Type: text/xml
Size: 27889 bytes
Desc: not available
URL: <http://lists.nceas.ucsb.edu/kepler/pipermail/kepler-users/attachments/20120112/0a9ffa93/attachment-0001.xml>
-------------- next part --------------
An embedded and charset-unspecified text was scrubbed...
Name: HelloWorld.java
URL: <http://lists.nceas.ucsb.edu/kepler/pipermail/kepler-users/attachments/20120112/0a9ffa93/attachment-0001.ksh>


More information about the Kepler-users mailing list