1.1.5 • Published 8 months ago

@datagrok/diff-studio v1.1.5

Weekly downloads
-
License
-
Repository
github
Last release
8 months ago

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:

TemplateFeatures
Basicthe simplest model
Advancedextra math features, including expressions, constants, parameters and tolerance specification
Extendedthe 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
  • 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 and max 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 blockFeatures
#nameDefines a name
#equationsDifferential equation specification
#argumentIndependent variable specification
#initsInitial values specification
#constantsConstants specification
#parametersParameters specification
#expressionsDefines auxiliary compuations
#outputDefines output columns and their captions
#tagsSpecifies tags (model, app, etc.)
#descriptionDefines description of the model
#commentSpecifies comments block
#meta.solverDefines the solver settings
#meta.inputsPath 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:

MethodValue
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:

xy...
Set 112...
Set 234...

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):

ProblemSegmentPointsToleranceMRT, msROS3PRw, msROS34PRw, ms
Rober0, 10E+1140K1E-71251066507
HIRES0, 321.812232K1E-10626931489
VDPOL0, 200020K1E-1211242884904
OREGO0, 36036K1E-89471131440
E50, 10E+1340K1E-6245218
Pollution0, 6030K1E-67113932

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:

  1. Click JS button on the top panel
  2. Click SAVE button
  3. 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