@datagrok/diff-studio
v1.2.3
Published
WebAutoSolver tools for solving ODEs in a browser.
Downloads
248
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 > Compute and run Diff Studio
- Enter formulas or modify template
- Run computations and explore your model
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 > Compute
- Run Diff Studio
- Modify inputs and explore computations
- Modify equations:
- Turn on the Edit toggle on the top panel
- Edit formulas or add new ones
- Click Refresh or press F5 to apply changes
- Use templates:
- Click Open icon on the top panel
- Go to Templates and select one of them
- Once you have completed your model, turn off the Edit toggle
- Save model:
- Click the Save button on the top panel to save model to your platform files (Browse > Files > My files)
- Click Download to save model to a local file. Find the ivp-file in Downloads. You can open and edit this file using any text editor
- Drag-n-drop:
- Drag ivp-file with equations right into the browser
- Load model:
- Click Open on the top panel
- Select Import... to load model from local file
- My Models contains models from your platform files
- Find last called models in Recent
- Explore examples in Library. They cover all possibilities of Diff Studio
- Analyze model
- Turn off the Edit toggle on the top panel
- Click the Fit icon to optimize inputs
- Click the Sensitivity icon to run sensitivity analysis
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|103|446|285| |HIRES|[0, 321.8122]|32K|1E-10|222|362|215| |VDPOL|[0, 2000]|20K|1E-12|963|1576|760| |OREGO|[0, 360]|36K|1E-8|381|483|199| |E5|[0, 10E+13]|40K|1E-6|14|17|8| |Pollution|[0, 60]|30K|1E-6|36|50|23|
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:
- Turn on the Edit toggle on the top panel
- Click </> icon. Script editor opens in a new view
- 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