Wednesday, January 21, 2015

Update in the spec

There has been some changes in the Arrays specification recently. Namely, the operations on vectors have been removed. The reason is because it has been decided that all the math in the document should be evaluated to a scalar. This requirement eliminates the need of computing vector operations since:

({1,2,3} + {1,2,3})[0] = {1,2,3}[0] + {1,2,3}[0]

Another change is that the need of an implicit dimension on species reference is no longer necessary. This was accomplished by putting an index objects to the species reference that are indexing the species reference id. Each index object math is given the corresponding dimension id of the reaction for the particular array dimension.  

For more information, please refer to the latest specification in the repository or ask questions.


Thursday, August 21, 2014

Project Wrap-up


The Google Summer of Code program is over. I had an amazing time working on this project. I really enjoyed working in this project and I am thankful for this opportunity. I am happy with my results and, hopefully, I can continue to contribute to the community. In summary, this summer I implemented:
  • Arrays package: I implemented the arrays extensions in JSBML, and this allows people to create regular structures more efficiently. I think the extension is quite straightforward to use. I got the impression some people were confused as to what the arrays package is. People might misinterpret the package, thinking that it is a container that can be populated with objects. This is wrong. An arrayed object indicates you have many copies that share similar attributes.
  • Validation: I implemented a routine that validates arrayed models. The most recent specification defines a set of validation rules that models extending arrays must not violate. Just to be clear, the most recent specification is not yet up on the web, but you can find it in the svn repository. I think the specification has come to a stable point, though changes are not discarded. Validation will be required to update on a regular basis to accommodate the changes in validation rules.
  • Flattening: I implemented a routine that flattens out array constructs. Models do not necessarily need to handle arrays if they flatten the model beforehand. This makes arrays support easier. Flattening arrays makes sense because if you say you have an array of species S, you are actually saying that you have n copies of S, where n is the size of the array. You can inline the objects, which eliminates array constructs.
In summary, I would say that the arrays package seemed easy at the beginning. I was able to implement the extension fairly quick, which gave me the false impression I would run out of things to do in the summer. I could not be more wrong! The extension is simple, but flattening and validation can be quite tricky since arrays have many implications on the math.

We, the students who were participating in the program and that were working with the JSBML team, got the opportunity to share our projects with the community at COMBINE. The slides I used can be found here. I think everything went quite well. Yusef and Victor did a really good job; their project were quite amazing and they did great in their presentations.

I thought it would be interesting to create big models in SBML using the arrays package. Without arrays, this task would be very tedious, but I managed to create this models fairly easily. I created these arrayed models in iBioSim. I believe the flattened models could be used for performance analysis; how fast does a certain simulation tool performs. Also, it would be interesting to use the flattened models to test the new implementation of the ASTNode that Victor has done compared to the old structure.


model01
This model has 1000 assignment rules, 1000 parameters x, 1000 parameters y.

model02
This model has 1000 reactions, 1000 species a, 1000 species b, and 1000 species c.

model03
This model has 5000 parameters, 10000 events.

Any comments, suggestions, or questions, please don't hesitate to contact me!

Monday, August 11, 2014

Weekly Log: August 04 - August 10

This week I focused on my final presentation and finishing up the last pieces of the arrays package. I fixed some bugs I found and also finished the compiler I wrote for evaluating vectors. Now that GSoC is coming to an end, I am taking this week to polish my code and improve documentation. However, the main focus of the past week is to prepare myself for the presentation the JSBML students have with the mentors.

Monday, August 4, 2014

Weekly Log: July 28 - August 3

This week I have been mainly working on two things: validation and final presentation. The arrays package turned out to be more difficult than I was anticipating. The package itself is very straightforward, but validating and flattening a model is not so easy mostly because of all the math implications. Last week I changed the flattening routine to reflect two changes: one is that implicit sizes are going to be disallowed and second I had the wrong interpretation of reaction and species reference with dimensions.

By implicit sizes, we mean that if a variable is an array, say X, and we want to give an initial assignment to X, then the right-hand side must be evaluated to a scalar. If the right-hand side evaluates to a vector, then it must be the case that X has Dimension objects where the dimension sizes match the assigned vector dimension sizes.

Reactions and events are kind of tricky so I made a special case for both. The problem of these SBase objects is that they have children that can have Dimension objects or have vector MathML. For instance, events have trigger/delay/priority which can be vectors. In addition, events have event assignment objects that are allowed to have a list of Dimensions. Reactions have KineticLaw objects which can also be a vector. Furthermore, reactions have SpeciesReference objects which can be an array. The tricky part which I hadn't considered was the case where species reference and reaction are arrays and species reference have ids. Since species reference cannot have duplicate id, I had to make the flattened species reference id to take both the parent reaction's index value and the species reference index value to ensure uniqueness.

Finally, I started making the slides for my final presentation. The final presentation will be an important factor to decide whether or not I pass my final Google Summer of Code evaluation. We, the students and mentors, will have a joint meeting next week, so I need to practice my presentation throughout this week. This presentation will serve as a practice for a talk every student will give at COMBINE.

Monday, July 28, 2014

Weekly Log: July 21 - July 27

The flattening routine should in theory work for all SBML core constructs. I have been testing the flattening function this past week. I integrated the flattening routine in a tool called iBioSim, which is a tool being developed at the University of Utah that can be used for the modeling and analysis of SBML models. Within iBioSim, I was able to construct an arrayed model thanks to one of my lab colleagues, Scott Glass, who is responsible for the GUI support for the Arrays package.

Here is a model in iBioSim. In this model, there are two parameters of size n and one rule of size n, where n is a constant parameter of value 10. This parameter is not shown here, because constant parameters are kept in the constants tab. These objects are enclosed by a compartment Cell, but this is irrelevant to this model. iBioSim adds a compartment by default.

I give a initial assignment to Y as shown below.

Y is given a vector as initial assignment. This can be translated as
Y[0] = 0
Y[1] = 1 and so on

Finally, I specify the attributes for the rule:



rule0 is an assignment rule, where X is the LHS and Y is the RHS. This is actually saying that:
X[9-d0] = Y[d0] where d0 is the dimension id for a Dimension object of the assignment rule with array dimension 0. Since the dimension has size 10, d0 can take any value from 0 to 9. When this is simulated, I get the following:

Values of Y

Values of X

You can see that X has the values of Y in reverse order, just like we specified in the assignment rule.

One of the requirements for a package to be fully accepted to the standard is to have at least two tools implement the package. iBioSim has started the implementation, though it is not yet finalized. Hopefully, there will be other tools using the arrays package because I believe it can be very helpful from a modeling standpoint.

Tuesday, July 22, 2014

Weekly Log: July 14 - July 20

I am posting one day late this week so I apologize. I have been working on the flattening routine for the arrays package. I implemented the algorithm and the routine is completed in two passes:

1. Flatten dimension and index objects

Essentially, what I am doing to flatten SBase objects with dimension objects is making n copies of the arrayed sbase, where n is the product of each dimension size. For instance, imagine you have this SBML model. For the sake of simplicity, I would write this in a Java-base syntax:

Parameter size = 2;
Parameter X = new Parameter[size][size];

Essentially, I would turn this into:

Parameter size = 2;
Parameter X_0_0;
Parameter X_0_1;
Parameter X_1_0;
Parameter X_1_1;

If an SBase you are flattening has math associated with it and in the math there is a dimension id, then I replace the dimension id for the actual index value. When there is an assignment, I update the id of the SBaseRef. For example:

Parameter size = 2;
Parameter X = new Parameter[size][size];
Parameter Y = new Parameter[size][size];

for (int i  = 0; i < 2; ++i) 
  for (int i  = 0; i < 2; ++i) 
    X[i][j] = Y[j][i];

The above example would be turned into:

Parameter size = 2;
Parameter X_0_0, X_0_1, X_1_0, X_1_1;
Parameter Y_0_0, Y_0_1, Y_1_0, Y_1_1;
X_0_0 = {{Y_0_0, Y_0_1}, {Y_1_0, Y_1_1}}[0][0];
X_0_1 = {{Y_0_0, Y_0_1}, {Y_1_0, Y_1_1}}[1][0];
X_1_0 = {{Y_0_0, Y_0_1}, {Y_1_0, Y_1_1}}[0][1];
X_1_1 = {{Y_0_0, Y_0_1}, {Y_1_0, Y_1_1}}[1][1];

Last, I update the Metaid of each SBase.


2. Flatten vector and selector math

After I flatten dimension and index objects, I evaluate vector and selector MathML objects to be just a scalar value. In the above example, the assignments would be turned into:

X_0_0 = Y_0_0;
X_0_1 = Y_1_0;
X_1_0 = Y_0_1;
X_1_1 = Y_1_1;

Vectors are also evaluated and at the end you end up with scalars only.

Here is an example in SBML:

Arrayed model:
<?xml version='1.0' encoding='UTF-8' standalone='no'?>
<sbml xmlns="http://www.sbml.org/sbml/level3/version1/core" level="3" arrays:required="true" xmlns:arrays="http://www.sbml.org/sbml/level3/version1/arrays/version1" version="1">
  <model>
    <listOfParameters>
      <parameter id="n" value="10"/>
      <parameter id="X" value="1">
        <arrays:listOfDimensions xmlns:arrays="http://www.sbml.org/sbml/level3/version1/arrays/version1">
          <arrays:dimension arrays:id="i" arrays:size="n" arrays:arrayDimension="0"/>
        </arrays:listOfDimensions>
      </parameter>
      <parameter id="Y" value="2">
        <arrays:listOfDimensions xmlns:arrays="http://www.sbml.org/sbml/level3/version1/arrays/version1">
          <arrays:dimension arrays:id="i" arrays:size="n" arrays:arrayDimension="0"/>
        </arrays:listOfDimensions>
      </parameter>
    </listOfParameters>
    <listOfInitialAssignments>
      <initialAssignment symbol="X">
        <math xmlns="http://www.w3.org/1998/Math/MathML">        
          <vector>
            <cn type="integer"> 1 </cn>
            <cn type="integer"> 2 </cn>
            <cn type="integer"> 3 </cn>
            <cn type="integer"> 4 </cn>
            <cn type="integer"> 5 </cn>
            <cn type="integer"> 6 </cn>
            <cn type="integer"> 7 </cn>
            <cn type="integer"> 8 </cn>
            <cn type="integer"> 9 </cn>
            <cn type="integer"> 10 </cn>
          </vector>
        </math>
              <arrays:listOfDimensions xmlns:arrays="http://www.sbml.org/sbml/level3/version1/arrays/version1">
          <arrays:dimension arrays:id="i" arrays:size="n" arrays:arrayDimension="0"/>
        </arrays:listOfDimensions>
      </initialAssignment>
    </listOfInitialAssignments>
    <listOfRules>
      <assignmentRule variable="Y">
        <math xmlns="http://www.w3.org/1998/Math/MathML">        
          <apply>
            <selector/>
            <ci> X </ci>
            <ci> i </ci>
          </apply>
        </math>
              <arrays:listOfDimensions xmlns:arrays="http://www.sbml.org/sbml/level3/version1/arrays/version1">
          <arrays:dimension arrays:id="i" arrays:size="n" arrays:arrayDimension="0"/>
        </arrays:listOfDimensions>
        <arrays:listOfIndices xmlns:arrays="http://www.sbml.org/sbml/level3/version1/arrays/version1">
          <arrays:index arrays:referencedAttribute="variable" arrays:arrayDimension="0">
            <math xmlns="http://www.w3.org/1998/Math/MathML">            
              <apply>
                <minus/>
                <cn type="integer"> 9 </cn>
                <ci> i </ci>
              </apply>
            </math>
                    </arrays:index>
        </arrays:listOfIndices>
      </assignmentRule>
    </listOfRules>
  </model>

</sbml>

Flatten model:
<?xml version='1.0' encoding='UTF-8' standalone='no'?>
<sbml xmlns="http://www.sbml.org/sbml/level3/version1/core" level="3" arrays:required="true" xmlns:arrays="http://www.sbml.org/sbml/level3/version1/arrays/version1" version="1">
  <model>
    <listOfParameters>
      <parameter id="n" value="10"/>
      <parameter id="X_0" value="1"/>
      <parameter id="X_1" value="1"/>
      <parameter id="X_2" value="1"/>
      <parameter id="X_3" value="1"/>
      <parameter id="X_4" value="1"/>
      <parameter id="X_5" value="1"/>
      <parameter id="X_6" value="1"/>
      <parameter id="X_7" value="1"/>
      <parameter id="X_8" value="1"/>
      <parameter id="X_9" value="1"/>
      <parameter id="Y_0" value="2"/>
      <parameter id="Y_1" value="2"/>
      <parameter id="Y_2" value="2"/>
      <parameter id="Y_3" value="2"/>
      <parameter id="Y_4" value="2"/>
      <parameter id="Y_5" value="2"/>
      <parameter id="Y_6" value="2"/>
      <parameter id="Y_7" value="2"/>
      <parameter id="Y_8" value="2"/>
      <parameter id="Y_9" value="2"/>
    </listOfParameters>
    <listOfInitialAssignments>
      <initialAssignment symbol="X_0">
        <math xmlns="http://www.w3.org/1998/Math/MathML">        
          <cn type="integer"> 1 </cn>
        </math>
            </initialAssignment>
      <initialAssignment symbol="X_1">
        <math xmlns="http://www.w3.org/1998/Math/MathML">        
          <cn type="integer"> 2 </cn>
        </math>
            </initialAssignment>
      <initialAssignment symbol="X_2">
        <math xmlns="http://www.w3.org/1998/Math/MathML">        
          <cn type="integer"> 3 </cn>
        </math>
            </initialAssignment>
      <initialAssignment symbol="X_3">
        <math xmlns="http://www.w3.org/1998/Math/MathML">        
          <cn type="integer"> 4 </cn>
        </math>
            </initialAssignment>
      <initialAssignment symbol="X_4">
        <math xmlns="http://www.w3.org/1998/Math/MathML">        
          <cn type="integer"> 5 </cn>
        </math>
            </initialAssignment>
      <initialAssignment symbol="X_5">
        <math xmlns="http://www.w3.org/1998/Math/MathML">        
          <cn type="integer"> 6 </cn>
        </math>
            </initialAssignment>
      <initialAssignment symbol="X_6">
        <math xmlns="http://www.w3.org/1998/Math/MathML">        
          <cn type="integer"> 7 </cn>
        </math>
            </initialAssignment>
      <initialAssignment symbol="X_7">
        <math xmlns="http://www.w3.org/1998/Math/MathML">        
          <cn type="integer"> 8 </cn>
        </math>
            </initialAssignment>
      <initialAssignment symbol="X_8">
        <math xmlns="http://www.w3.org/1998/Math/MathML">        
          <cn type="integer"> 9 </cn>
        </math>
            </initialAssignment>
      <initialAssignment symbol="X_9">
        <math xmlns="http://www.w3.org/1998/Math/MathML">        
          <cn type="integer"> 10 </cn>
        </math>
            </initialAssignment>
    </listOfInitialAssignments>
    <listOfRules>
      <assignmentRule variable="Y_9">
        <math xmlns="http://www.w3.org/1998/Math/MathML">        
          <ci> X_0 </ci>
        </math>
            </assignmentRule>
      <assignmentRule variable="Y_8">
        <math xmlns="http://www.w3.org/1998/Math/MathML">        
          <ci> X_1 </ci>
        </math>
            </assignmentRule>
      <assignmentRule variable="Y_7">
        <math xmlns="http://www.w3.org/1998/Math/MathML">        
          <ci> X_2 </ci>
        </math>
            </assignmentRule>
      <assignmentRule variable="Y_6">
        <math xmlns="http://www.w3.org/1998/Math/MathML">        
          <ci> X_3 </ci>
        </math>
            </assignmentRule>
      <assignmentRule variable="Y_5">
        <math xmlns="http://www.w3.org/1998/Math/MathML">        
          <ci> X_4 </ci>
        </math>
            </assignmentRule>
      <assignmentRule variable="Y_4">
        <math xmlns="http://www.w3.org/1998/Math/MathML">        
          <ci> X_5 </ci>
        </math>
            </assignmentRule>
      <assignmentRule variable="Y_3">
        <math xmlns="http://www.w3.org/1998/Math/MathML">        
          <ci> X_6 </ci>
        </math>
            </assignmentRule>
      <assignmentRule variable="Y_2">
        <math xmlns="http://www.w3.org/1998/Math/MathML">        
          <ci> X_7 </ci>
        </math>
            </assignmentRule>
      <assignmentRule variable="Y_1">
        <math xmlns="http://www.w3.org/1998/Math/MathML">        
          <ci> X_8 </ci>
        </math>
            </assignmentRule>
      <assignmentRule variable="Y_0">
        <math xmlns="http://www.w3.org/1998/Math/MathML">        
          <ci> X_9 </ci>
        </math>
            </assignmentRule>
    </listOfRules>
  </model>

</sbml>


Monday, July 14, 2014

Weekly Log: July 7 - July 13

This week I continued working on the compiler that evaluates vectors. I implemented a few of the functions that were missing and I think I am somewhat close to finishing up everything on the compiler.

After the last meeting with my mentor, Nico Rodriguez, we decided to put the validation aside for a little bit and start the implementation of the flattening routine.  Arrays is just syntactic sugar for the modeling language; you can construct models that would behave exactly the same using other constructs. For this reason,  flattening makes a lot of sense in the context of the arrays package. Note that the flattening routine is important for the arrays package because it would allow many tools to simulate arrayed models without much effort.

In a previous meeting, we discussed an algorithm for the arrays package. Chris Myers, one of my mentors, helped me solidify the algorithm. I started the implementation, and I am testing the code. I will post details and the results in the next blog post.