<html xmlns:v="urn:schemas-microsoft-com:vml" xmlns:o="urn:schemas-microsoft-com:office:office" xmlns:w="urn:schemas-microsoft-com:office:word" xmlns:m="http://schemas.microsoft.com/office/2004/12/omml" xmlns="http://www.w3.org/TR/REC-html40"><head><meta http-equiv=Content-Type content="text/html; charset=utf-8"><meta name=Generator content="Microsoft Word 12 (filtered medium)"><style><!--
/* Font Definitions */
@font-face
        {font-family:Wingdings;
        panose-1:5 0 0 0 0 0 0 0 0 0;}
@font-face
        {font-family:"Cambria Math";
        panose-1:2 4 5 3 5 4 6 3 2 4;}
@font-face
        {font-family:Calibri;
        panose-1:2 15 5 2 2 2 4 3 2 4;}
@font-face
        {font-family:Tahoma;
        panose-1:2 11 6 4 3 5 4 4 2 4;}
@font-face
        {font-family:Consolas;
        panose-1:2 11 6 9 2 2 4 3 2 4;}
/* Style Definitions */
p.MsoNormal, li.MsoNormal, div.MsoNormal
        {margin:0in;
        margin-bottom:.0001pt;
        font-size:12.0pt;
        font-family:"Times New Roman","serif";
        color:black;}
a:link, span.MsoHyperlink
        {mso-style-priority:99;
        color:blue;
        text-decoration:underline;}
a:visited, span.MsoHyperlinkFollowed
        {mso-style-priority:99;
        color:purple;
        text-decoration:underline;}
pre
        {mso-style-priority:99;
        mso-style-link:"HTML Preformatted Char";
        margin:0in;
        margin-bottom:.0001pt;
        font-size:10.0pt;
        font-family:"Courier New";
        color:black;}
p.MsoListParagraph, li.MsoListParagraph, div.MsoListParagraph
        {mso-style-priority:34;
        margin-top:0in;
        margin-right:0in;
        margin-bottom:0in;
        margin-left:.5in;
        margin-bottom:.0001pt;
        font-size:12.0pt;
        font-family:"Times New Roman","serif";
        color:black;}
span.HTMLPreformattedChar
        {mso-style-name:"HTML Preformatted Char";
        mso-style-priority:99;
        mso-style-link:"HTML Preformatted";
        font-family:Consolas;
        color:black;}
span.EmailStyle20
        {mso-style-type:personal-reply;
        font-family:"Calibri","sans-serif";
        color:#1F497D;}
.MsoChpDefault
        {mso-style-type:export-only;
        font-size:10.0pt;}
@page WordSection1
        {size:8.5in 11.0in;
        margin:1.0in 1.0in 1.0in 1.0in;}
div.WordSection1
        {page:WordSection1;}
/* List Definitions */
@list l0
        {mso-list-id:1758791766;
        mso-list-type:hybrid;
        mso-list-template-ids:766904248 180799774 67698691 67698693 67698689 67698691 67698693 67698689 67698691 67698693;}
@list l0:level1
        {mso-level-start-at:5;
        mso-level-number-format:bullet;
        mso-level-text:;
        mso-level-tab-stop:none;
        mso-level-number-position:left;
        text-indent:-.25in;
        font-family:Wingdings;
        mso-fareast-font-family:Calibri;
        mso-bidi-font-family:"Times New Roman";}
@list l0:level2
        {mso-level-tab-stop:1.0in;
        mso-level-number-position:left;
        text-indent:-.25in;}
@list l0:level3
        {mso-level-tab-stop:1.5in;
        mso-level-number-position:left;
        text-indent:-.25in;}
@list l0:level4
        {mso-level-tab-stop:2.0in;
        mso-level-number-position:left;
        text-indent:-.25in;}
@list l0:level5
        {mso-level-tab-stop:2.5in;
        mso-level-number-position:left;
        text-indent:-.25in;}
@list l0:level6
        {mso-level-tab-stop:3.0in;
        mso-level-number-position:left;
        text-indent:-.25in;}
@list l0:level7
        {mso-level-tab-stop:3.5in;
        mso-level-number-position:left;
        text-indent:-.25in;}
@list l0:level8
        {mso-level-tab-stop:4.0in;
        mso-level-number-position:left;
        text-indent:-.25in;}
@list l0:level9
        {mso-level-tab-stop:4.5in;
        mso-level-number-position:left;
        text-indent:-.25in;}
ol
        {margin-bottom:0in;}
ul
        {margin-bottom:0in;}
--></style><!--[if gte mso 9]><xml>
<o:shapedefaults v:ext="edit" spidmax="1026" />
</xml><![endif]--><!--[if gte mso 9]><xml>
<o:shapelayout v:ext="edit">
<o:idmap v:ext="edit" data="1" />
</o:shapelayout></xml><![endif]--></head><body bgcolor=white lang=EN-US link=blue vlink=purple><div class=WordSection1><p class=MsoNormal><span style='font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1F497D'>Beth,<o:p></o:p></span></p><p class=MsoNormal><span style='font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1F497D'><o:p> </o:p></span></p><p class=MsoNormal><span style='font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1F497D'>For your first example, I have a similar use case with some Fortran programs that use namelists for I/O.<o:p></o:p></span></p><p class=MsoNormal><span style='font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1F497D'><o:p> </o:p></span></p><p class=MsoNormal><span style='font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1F497D'>> For other web data streams, the type signature changes.  Here we currently set the output port type to an empty record so at least the type solver knows it’s a record, but then we can’t connect this output to a RecordDisassembler – it would throw an exception when the model is executed</span><span style='font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1F497D'><o:p></o:p></span></p><p class=MsoNormal><span style='font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1F497D'><o:p> </o:p></span></p><p class=MsoNormal><span style='font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1F497D'>Are you saying there’s no way to connect to a RecordDisassembler, or there’s no way to connect to it without manually forcing the output port types (which can lead to runtime errors)?  I have found the latter to be true, but maybe we are talking about different things.<o:p></o:p></span></p><p class=MsoNormal style='mso-margin-top-alt:auto;mso-margin-bottom-alt:auto'><span style='font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1F497D'>> Also like you mentioned for objects, JSON is fairly close to a Ptolemy record, but like Java types, the JSON types are not exactly the same as Ptolemy types.  (For example, it looks possible that JSON arrays could contain mixed types in the same array).  We don’t have a good solution for that yet…  right now we are just extracting Ptolemy types and hoping for the best. </span><o:p></o:p></p><p class=MsoNormal><span style='font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1F497D'>I was thinking along the lines of a general tool to handle standard Java data type conversions.  Take that tool and extend it to speak Ptolemy and perhaps JSON types too.  For example, maybe we could teach <a href="http://transmorph.sourceforge.net">http://transmorph.sourceforge.net</a> how to deal with Ptolemy tokens/types.  If you want JSON support, you can initialize it with a different set of converters than the default.  There would one place for all of the standard Java data type conversions including generics (via TypeReferences to work around type erasure) and convert to/from Ptolemy types.  For example, it would be able to handle converting back and forth between a Map<String,Map<String,Double>> and a RecordToken or a List<List<Integer>> and ArrayToken or IntMatrixToken.  It could be useful on simple cases too like int[] to/from ArrayToken.<o:p></o:p></span></p><p class=MsoNormal><span style='font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1F497D'><o:p> </o:p></span></p><p class=MsoNormal><span style='font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1F497D'>That type of code is ugly, but it would help with quickly creating actors that interface with existing code.<o:p></o:p></span></p><p class=MsoNormal><span style='font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1F497D'><o:p> </o:p></span></p><div><div style='border:none;border-top:solid #B5C4DF 1.0pt;padding:3.0pt 0in 0in 0in'><p class=MsoNormal><b><span style='font-size:10.0pt;font-family:"Tahoma","sans-serif";color:windowtext'>From:</span></b><span style='font-size:10.0pt;font-family:"Tahoma","sans-serif";color:windowtext'> Christopher Brooks [mailto:cxh@eecs.berkeley.edu] <br><b>Sent:</b> Wednesday, April 04, 2012 12:05 PM<br><b>To:</b> Hogan, D. (GE Energy)<br><b>Cc:</b> kepler-dev@kepler-project.org; ptango@chess.eecs.berkeley.edu<br><b>Subject:</b> Re: [Ptango] Re: [kepler-dev] ObjectToRecord related questions<o:p></o:p></span></p></div></div><p class=MsoNormal><o:p> </o:p></p><p class=MsoNormal><br>Beth Latronico asked me to forward on the following about this issue.<br><br>Beth writes:<br><br><o:p></o:p></p><p class=MsoNormal style='mso-margin-top-alt:auto;mso-margin-bottom-alt:auto'><span style='font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1F497D'>We ran into a similar problem trying to build an actor which reads information in JSON from a web page and outputs a RecordToken.  Here’s a summary of the discussion and a sample model in case this is helpful for your situation!</span><o:p></o:p></p><p class=MsoNormal style='mso-margin-top-alt:auto;mso-margin-bottom-alt:auto'><span style='font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1F497D'>Actor:  ptolemy.actor.lib.conversions.JSONToRecord</span><o:p></o:p></p><p class=MsoNormal style='mso-margin-top-alt:auto;mso-margin-bottom-alt:auto'><span style='font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1F497D'>Test model:  ptolemy.actor.lib.conversions.test.auto.JSONToRecord1.xml</span><o:p></o:p></p><p class=MsoNormal style='mso-margin-top-alt:auto;mso-margin-bottom-alt:auto'><span style='font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1F497D'> </span><o:p></o:p></p><p class=MsoNormal style='mso-margin-top-alt:auto;mso-margin-bottom-alt:auto'><span style='font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1F497D'>Ideally we wanted to be able to set the type of the output to a RecordType including all of the fields and types of those fields (vs. an empty Record), so that we could use the RecordDisassembler.  However, since the type solver only runs once and runs during preinitialize(), this means we need to get the type information somehow ahead of time, and that the type signature cannot change during execution.  (It’s OK if the data changes).  </span><o:p></o:p></p><p class=MsoNormal style='mso-margin-top-alt:auto;mso-margin-bottom-alt:auto'><span style='font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1F497D'> </span><o:p></o:p></p><p class=MsoNormal style='mso-margin-top-alt:auto;mso-margin-bottom-alt:auto'><span style='font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1F497D'>For some web data streams, this seems OK – the type signature is always the same – so we pull some sample data in preinitialize() to determine the type, and then check the type signature in fire() to make sure it has not changed.  This assumes that we know the URL of the data source, the URL remains fixed and that sample data is available before the model executes.</span><o:p></o:p></p><p class=MsoNormal style='mso-margin-top-alt:auto;mso-margin-bottom-alt:auto'><span style='font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1F497D'> </span><o:p></o:p></p><p class=MsoNormal style='mso-margin-top-alt:auto;mso-margin-bottom-alt:auto'><span style='font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1F497D'>For other web data streams, the type signature changes.  Here we currently set the output port type to an empty record so at least the type solver knows it’s a record, but then we can’t connect this output to a RecordDisassembler – it would throw an exception when the model is executed. </span><o:p></o:p></p><p class=MsoNormal style='mso-margin-top-alt:auto;mso-margin-bottom-alt:auto'><span style='font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1F497D'>Token value = new RecordToken();</span><o:p></o:p></p><p class=MsoNormal style='mso-margin-top-alt:auto;mso-margin-bottom-alt:auto'><span style='font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1F497D'>output.setTypeEquals(value.getType());</span><o:p></o:p></p><p class=MsoNormal style='mso-margin-top-alt:auto;mso-margin-bottom-alt:auto'><span style='font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1F497D'> </span><o:p></o:p></p><p class=MsoNormal style='mso-margin-top-alt:auto;mso-margin-bottom-alt:auto'><span style='font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1F497D'>So, we’re debating on whether 1) these two cases should be split into different actors, and 2) if it’s appropriate to use RecordDisassembler or should we create some new actors that can handle loosely-typed records.</span><o:p></o:p></p><p class=MsoNormal style='mso-margin-top-alt:auto;mso-margin-bottom-alt:auto'><span style='font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1F497D'> </span><o:p></o:p></p><p class=MsoNormal style='mso-margin-top-alt:auto;mso-margin-bottom-alt:auto'><span style='font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1F497D'>Also like you mentioned for objects, JSON is fairly close to a Ptolemy record, but like Java types, the JSON types are not exactly the same as Ptolemy types.  (For example, it looks possible that JSON arrays could contain mixed types in the same array).  We don’t have a good solution for that yet…  right now we are just extracting Ptolemy types and hoping for the best.  </span><o:p></o:p></p><p class=MsoNormal style='mso-margin-top-alt:auto;mso-margin-bottom-alt:auto'><span style='font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1F497D'> </span><o:p></o:p></p><p class=MsoNormal style='mso-margin-top-alt:auto;mso-margin-bottom-alt:auto'><span style='font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1F497D'>Unfortunately there are more questions than answers at the moment, but hope the discussion highlights some of the issues!</span><o:p></o:p></p><p class=MsoNormal style='mso-margin-top-alt:auto;mso-margin-bottom-alt:auto'><span style='font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1F497D'> </span><o:p></o:p></p><p class=MsoNormal style='mso-margin-top-alt:auto;mso-margin-bottom-alt:auto'><span style='font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1F497D'>Best,</span><o:p></o:p></p><p class=MsoNormal><span style='font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1F497D'>Beth</span><o:p></o:p></p><p class=MsoNormal>Marten Lohstroh suggested that we could have a flag that when set required strict typing.  Certain actors could record the type information in a manner similar to how the Test actor works.  The Test actor has a shared parameter called "trainingMode".  When trainingMode is true, the known good results of the TestActor is recorded.  In a similar manner, certain actors could record the type information when trainingMode was set to true.<br><br><br>_Christopher<br><br>On 4/2/12 6:05 PM, Edward A. Lee wrote: <o:p></o:p></p><p class=MsoNormal><br>Ptolemy II is statically typed, so after a model is preinitialized, <br>the types of all ports must be known. The type system is described in <br>chapter 5 of this document: <br><br><a href="http://www.eecs.berkeley.edu/Pubs/TechRpts/2008/EECS-2008-29.html">http://www.eecs.berkeley.edu/Pubs/TechRpts/2008/EECS-2008-29.html</a> <br><br>and also in this paper: <br><br><a href="http://chess.eecs.berkeley.edu/pubs/665.html">http://chess.eecs.berkeley.edu/pubs/665.html</a> <br><br>For Record types, the most general record type is the empty record type. <br>That is, a record type {fieldName = double}, for example, is also <br>an instance of {}, the empty record type. Moreover, a record of <br>type {a = int, b = double} is also an instance of {a = int}. <br><br>So, for example, if you know that your output record will contain <br>a field named "a" of type "int", then you can force the output type <br>to be {a = int} (right click on the actor, select Configure Ports, <br>and enter "{a = int}" in the type field). As long as there is actually <br>such a field, in the record, this will work. But if you run the model <br>and there is no such field, I believe you will get a run-time type <br>error (which is probably what you want). <br><br>Edward <br><br><br>On 4/2/12 1:51 PM, Hogan, D. (GE Energy) wrote: <br><br><o:p></o:p></p><p class=MsoNormal>I have an actor that uses the structure of a file generated at runtime <br>to create an output record.  The actor is working, but I have a few <br>questions on ObjectToRecord since it is similar. <br><br>In ObjectToRecord, it does not change the type and lists it as fixme. <br>The documentation for RecordType mentions using setTypeAtMost(new <br>RecordType(new String[0], new Type[0])) when you want to specify a <br>record without specifying the fields.  Should I use that?  Is there a <br>better way to specify it is a record and the field names/types are <br>discovered at runtime?  Since unknown matches that type constraint, what <br>is the best way to handle this? <br><br>ObjectToRecord doesn't try to convert between standard Java types and <br>Ptolemy types.  I noticed there is a <br>ptolemy.data.expr.ConversionUtilities, but it looks limited to the <br>expression language needs.  Is there another conversion in Kepler? <br><br>_______________________________________________ <br>Kepler-dev mailing list <br><a href="mailto:Kepler-dev@kepler-project.org">Kepler-dev@kepler-project.org</a> <br><a href="http://lists.nceas.ucsb.edu/kepler/mailman/listinfo/kepler-dev">http://lists.nceas.ucsb.edu/kepler/mailman/listinfo/kepler-dev</a> <o:p></o:p></p><p class=MsoNormal><br><br><o:p></o:p></p><pre>-- <o:p></o:p></pre><pre>Christopher Brooks, PMP                       University of California<o:p></o:p></pre><pre>CHESS Executive Director                      US Mail: 337 Cory Hall<o:p></o:p></pre><pre>Programmer/Analyst CHESS/Ptolemy/Trust        Berkeley, CA 94720-1774<o:p></o:p></pre><pre>ph: 510.643.9841                                (Office: 545Q Cory)<o:p></o:p></pre><pre>home: (F-Tu) 707.665.0131 cell: 707.332.0670 <o:p></o:p></pre></div></body></html>