@datagrok/diff-studio
v1.1.5
Published
WebAutoSolver tools for solving ODEs in a browser.
Downloads
87
Keywords
Readme
Diff Studio
Diff Studio is a package for the Datagrok platform. It provides in-browser tools for solving initial value problem for systems of ordinary differential equations (ODE) and its interactive exploration.
- Go to Apps and run Diff Studio
- Enter formulas or modify template
- Press F5 or go to Run tab
The solver takes a set of the differential equations in a declarative form, and creates a UI that solves the equations, visualizes the results, and lets you change parameters on the fly.
Quick start
Datagrok provides intuitive tools for the rapid solving ODEs.
- Run the solver:
- Go to Apps and run Diff Studio
- Go to Run tab to launch computations
- Modify a template:
- Edit formulas or add new ones
- Press F5 or go to Run tab
- Cahnge inputs and explore your model
- Use an advanced template:
- Click on the "Open" icon on the top panel
- Select Templates > Advanced...
- Modify formulas and press F5
- Save model in a local file:
- Click on the "Save" icon on the top panel
- Click
Save as Local File...
to save model to a local file. Find the ivp-file in Downloads. You can open and edit this file using any text editor - Click
Save to My Files...
to save model to your platform files (Browse > Files > My files)
- Drag-n-drop:
- Drag ivp-file with equations right into the browser
- Load equations from a local file:
- Click on the "Open" icon on the top panel
- Select From file...
- Select a file with formulas
- Explore model:
- Click on the "Run sensitivity analysis" icon
- Analyze the relationship between inputs and outputs using one of the following methods:
- Fit parameters:
- Click on the "Fit inputs" icon
- Find input conditions leading to specified output constraints
Create model from template
Start from one of these templates:
| Template | Features|
|----------|---------|
| Basic
| the simplest model|
| Advanced
| extra math features, including expressions, constants, parameters and tolerance specification|
| Extended
| the annotating feature for extended UI generation |
Use cases
The solver has built-in use cases. Get access to them via the context menu. You can use them as a template.
Chem reactions
- simulates mass-action kinetics
- illustrates annotation of inputs
Robertson's model
- Robertson's chemical reaction model
- stiff equations example
- shows how Datagrok solves complicated ODEs
Fermentation
- models the kinetics of the biochemical reactions in fermentation
- shows the usage of
min
andmax
in inputs annotation
PK
- pharmacokinetic (PK) simulation
- demonstrates the usage of the
meta.solver
feature for numerical solver management
PK-PD
- simulates pharmacokinetics (PK), pharmacodynamics (PD), and their relationship
- illustrates the usage of the
loop
feature for dosing specification
Acid production
- models gluconic acid production by Aspergillus niger
- shows the usage of the
update
feature for multi-stage simulation
Nimotuzumab
- models population pharmacokinetic for nimotuzumab
- demonstrates the
output
feature
Bioreactor
- simulates the bioreactor processes
- shows how to use
meta.inputs
to specify a table with pre-defined model inputs
Pollution
- describes a chemical reaction part of the air pollution model consisting of 25 reaction and 20 reacting compounds
- demonstrates the simulation of processes described by a stiff system of ODEs
Datagrok's ODEs suite has tools for solving both stiff and non-stiff equations. It provides a numerical solution.
Model structure
A model defines initial value problem. It contains name, differential equations, initial values and argument specifications:
#name: My ODEs
#equations:
dx/dt = x + y + exp(t)
dy/dt = x - y - cos(t)
#argument: t
initial = 0
final = 1
step = 0.01
#inits:
x = 2
y = 5
Use the following sections to specify various problems:
|Control block|Features|
|-------------|--------|
|#name
|Defines a name|
|#equations
|Differential equation specification|
|#argument
|Independent variable specification|
|#inits
|Initial values specification|
|#constants
|Constants specification|
|#parameters
|Parameters specification|
|#expressions
|Defines auxiliary compuations|
|#output
|Defines output columns and their captions|
|#tags
|Specifies tags (model
, app
, etc.)|
|#description
|Defines description of the model|
|#comment
|Specifies comments block|
|#meta.solver
|Defines the solver settings|
|#meta.inputs
|Path to the table with pre-defined model inputs|
Annotations
The Run tab of Diff Studio provides UI for interactive model exploration. Use annotations to improve usability. Append them, when defining parameters, initial values and argument.
Group inputs by specifying their category
:
#parameters:
P1 = 1 {category: Parameters}
P2 = -1 {category: Parameters}
Define the desired caption
:
#argument: t
start = 0 {caption: Initial; category: Time}
finish = 2 {caption: Final; category: Time}
step = 0.01 {caption: Step; category: Time}
Specify min
, max
and step
values to get sliders and clickers for the rapid model exploration:
#inits:
x = 2 {min: 0; max: 5}
y = 0 {min: -2; max: 2; step: 0.1}
Provide hints in brackets [ ]
:
P1 = 1 {category: Parameters} [P1 parameter tooltip]
Solver management
You can manage the solver of ODEs. Specify its settings in the #meta.solver
-line:
- the numerical method (
method
) - the maximum number of iterations (
maxIterations
) - the maximum computation time (
maxTimeMs
)
Diff Studio implements the following Rosenbrock–Wanner methods for solving ODEs:
|Method|Value|
|-------------|--------|
|the modified Rosenbrock triple (MRT)|'mrt'
|
|the ROS3PRw method|'ros3prw'
|
|the ROS34PRw method|'ros34prw'
|
By default, Diff Studio uses ROS34PRw. You may specify the method as follows:
#meta.solver: {method: 'mrt'}
To check correctness of formulas, set the maximum number of iterations:
#meta.solver: {method: 'mrt'; maxIterations: 1}
Diff Studio alerts you if computations take too long. The default time limit is 5 seconds. To customize it, set the maximum computation time (in milliseconds):
#meta.solver: {method: 'mrt'; maxTimeMs: 50}
Lookup tables
Lookup tables are pre-defined sets of model input values. They're organized as follows:
||x|y|...| |-----|-----|-----|---| |Set 1|1|2|...| |Set 2|3|4|...|
To use a lookup table:
- Create a CSV file with your table and add it to your project
- Add the
#meta.inputs
-line to your model and specify a CSV file with a lookup table - To improve usability, define
caption
,category
and a tooltip:
#meta.inputs: table {choices: OpenFile("System:AppData/DiffStudio/inputs.csv"); caption: Mode; category: Settings} [Hint]
Performance
Diff Studio solvers ensure fast in-browser intergration of ODEs. The following classic problems illustrate their efficiency:
- Rober
- a stiff system of 3 nonlinear ODEs
- describes the kinetics of an autocatalytic reaction given by Robertson
- HIRES
- a stiff system of 8 non-linear equations
- explains the `High Irradiance Responses' (HIRES) of photomorphogenesis on the basis of phytochrome, by means of a chemical reaction involving eight reactants
- VDPOL
- a system of 2 ODEs proposed by B. van der Pol
- describes the behaviour of nonlinear vacuum tube circuits
- OREGO
- a stiff system of 3 non-linear equations
- simulates Belousov-Zhabotinskii reaction
- E5
- a stiff system of 4 non-linear ODEs
- represents a chemical pyrolysis model
- Pollution
- a stiff system of 20 non-linear equations
- describes a chemical reaction part of the air pollution model designed at The Dutch National Institute of Public Health and Environmental Protection
The MRT, ROS3PRw and ROS34PRw methods demonstrate the following time performance (AMD Ryzen 5 5600H 3.30 GHz CPU):
|Problem|Segment|Points|Tolerance|MRT, ms|ROS3PRw, ms|ROS34PRw, ms| |-|-|-|-|-|-|-| |Rober|[0, 10E+11]|40K|1E-7|125|1066|507| |HIRES|[0, 321.8122]|32K|1E-10|626|931|489| |VDPOL|[0, 2000]|20K|1E-12|1124|2884|904| |OREGO|[0, 360]|36K|1E-8|947|1131|440| |E5|[0, 10E+13]|40K|1E-6|24|52|18| |Pollution|[0, 60]|30K|1E-6|71|139|32|
This table compares the efficiency of the methods when solving each test problem on a fixed segment and providing solutions at a specified number of points with a given tolerance.
Export to JavaScript script
Once you are satisfied with the result, you can convert your model to a Datagrok application. To do so:
- Click JS button on the top panel
- Click SAVE button
- Script is created, and can be found in the "Scripts" section of the platform
Improve usability. Use #tags: model
to add your model to Model Catalog
. Provide a description in the #description
-line:
#name: Bioreaction
#tags: model
#description: Complex bioreaction simulation
Apply scripting tools to get:
- non-elementary and special functions' use
- Datagrok packages' functions call
Find more features in Diff Studio docs.
See also