This article details the enhancement of translation capabilities from the QSP Designer model to a SimBiology-compatible model script. This improvement relaxes certain model restrictions when exporting to SimBiology.
Expanding Export Capabilities in QSP Designer
One of QSP Designer's standout features is its ability to export created models to various programming and scripting languages, including Matlab, Lua, C, C++, SimBiology, and Julia. While most of these exports allow models to utilize the full range of QSP Designer's modeling capabilities, exporting to SimBiology has been restricted if certain modeling features are used.
The restrictions for exporting to SimBiology include, but are not limited to:
Conditional assignments
Event nodes
Parameterized or indexed stoichiometry expressions
This project enhances QSP Designer's translation capabilities, relaxing these restrictions to enable accurate translation of models containing the aforementioned features to SimBiology.
Changes to the User Interface
No explicit changes have been made to the user interface. However, exporting models with the aforementioned modeling features now:
No longer displays an error message.
No longer prevents the export from proceeding.
Changes to Code Generation
Conditional Assignments
An example of conditional assignment code generation is as follows:
The assignment is translated to the following code in the SimBiology script:
addrule(model, 'p1 = (a > 0) * (a + b) + (!(a > 0)) * (a + c)', 'repeatedAssignment');
If the assignment is initial-only, “repeatedAssignment” would be replaced with “initialAssignment.”
Events
An example of event code generation is as follows:
The event is translated to the following code in the SimBiology script:
e1 = addevent(ModelObj, 'Tumor_cell < one_cell', 'flag = 0');
Parameterized or Indexed Stoichiometry Expressions
No new SimBiology code is generated directly; however, the code generation pipeline in QSP Designer has been enhanced to statically evaluate stoichiometry expressions prior to export. This means that if the stoichiometry value can be determined during the code-generation stage, it is now calculated and applied as part of the generated expression. Previously, only strict numerical constants could be used in stoichiometry expressions.
Consider the following example: an index “a” with 8 index values.
The graph implicitly unrolls the reaction lin_deconj into 8 reactions.
The stoichiometry expression connecting the reaction lin_deconj to the species DXd_in is as follows:
The stoichiometry expression is not a numerical constant; however, the expression 8 - ZERO_BASED(a) can be statically evaluated (and is constant-in-time), resulting in 8 different stoichiometries for the unrolled reactions. These stoichiometries, in order, are: 8, 7, 6, 5, 4, 3, 2, 1.
Previously, these stoichiometries were not statically evaluated during code generation, which disallowed their use in SimBiology exports. Now, this evaluation occurs, allowing the SimBiology code to be generated with the following reaction definitions:
Observe the descending stoichiometries on the right-hand side of the reaction rate definitions, which correspond to the statically evaluated stoichiometries in the QSP Designer model.
This functionality applies to all cases where the stoichiometry expression can be statically evaluated. Any parameters may be used as part of the expression, provided the overall expression can be statically evaluated and is guaranteed to be constant-in-time.




