diff-grok 1.0.8

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (136) hide show
  1. package/.eslintrc.json +45 -0
  2. package/.github/scripts/bump-js-api-version.sh +106 -0
  3. package/.github/scripts/check-output.sh +20 -0
  4. package/.github/scripts/iac-cfn-deploy.sh +90 -0
  5. package/.github/scripts/slack_api_request.sh +65 -0
  6. package/.github/scripts/test_package.sh +270 -0
  7. package/.github/workflows/libraries.yaml +305 -0
  8. package/LICENSE +21 -0
  9. package/README.MD +396 -0
  10. package/eslintrc.json +45 -0
  11. package/images/acid-prod.gif +0 -0
  12. package/index.js +6 -0
  13. package/index.js.map +1 -0
  14. package/index.ts +15 -0
  15. package/package.json +45 -0
  16. package/src/examples/basic-use.js +40 -0
  17. package/src/examples/basic-use.js.map +1 -0
  18. package/src/examples/basic-use.ts +44 -0
  19. package/src/examples/check-methods.js +45 -0
  20. package/src/examples/check-methods.js.map +1 -0
  21. package/src/examples/check-methods.ts +62 -0
  22. package/src/examples/corr-probs.js +130 -0
  23. package/src/examples/corr-probs.js.map +1 -0
  24. package/src/examples/corr-probs.ts +151 -0
  25. package/src/examples/cyclic-model.js +100 -0
  26. package/src/examples/cyclic-model.js.map +1 -0
  27. package/src/examples/cyclic-model.ts +110 -0
  28. package/src/examples/e5.js +30 -0
  29. package/src/examples/e5.js.map +1 -0
  30. package/src/examples/e5.ts +29 -0
  31. package/src/examples/hires.js +29 -0
  32. package/src/examples/hires.js.map +1 -0
  33. package/src/examples/hires.ts +29 -0
  34. package/src/examples/index.js +17 -0
  35. package/src/examples/index.js.map +1 -0
  36. package/src/examples/index.ts +18 -0
  37. package/src/examples/model-updates.js +112 -0
  38. package/src/examples/model-updates.js.map +1 -0
  39. package/src/examples/model-updates.ts +122 -0
  40. package/src/examples/orego.js +19 -0
  41. package/src/examples/orego.js.map +1 -0
  42. package/src/examples/orego.ts +19 -0
  43. package/src/examples/pipeline-use.js +87 -0
  44. package/src/examples/pipeline-use.js.map +1 -0
  45. package/src/examples/pipeline-use.ts +98 -0
  46. package/src/examples/pollution.js +110 -0
  47. package/src/examples/pollution.js.map +1 -0
  48. package/src/examples/pollution.ts +110 -0
  49. package/src/examples/robertson.js +14 -0
  50. package/src/examples/robertson.js.map +1 -0
  51. package/src/examples/robertson.ts +13 -0
  52. package/src/examples/scripting.js +31 -0
  53. package/src/examples/scripting.js.map +1 -0
  54. package/src/examples/scripting.ts +36 -0
  55. package/src/examples/vdpol.js +13 -0
  56. package/src/examples/vdpol.js.map +1 -0
  57. package/src/examples/vdpol.ts +12 -0
  58. package/src/pipeline/basic-pipeline-creator.js +21 -0
  59. package/src/pipeline/basic-pipeline-creator.js.map +1 -0
  60. package/src/pipeline/basic-pipeline-creator.ts +24 -0
  61. package/src/pipeline/constants.js +21 -0
  62. package/src/pipeline/constants.js.map +1 -0
  63. package/src/pipeline/constants.ts +21 -0
  64. package/src/pipeline/index.js +8 -0
  65. package/src/pipeline/index.js.map +1 -0
  66. package/src/pipeline/index.ts +7 -0
  67. package/src/pipeline/input.js +45 -0
  68. package/src/pipeline/input.js.map +1 -0
  69. package/src/pipeline/input.ts +55 -0
  70. package/src/pipeline/loops-pipeline-creator.js +107 -0
  71. package/src/pipeline/loops-pipeline-creator.js.map +1 -0
  72. package/src/pipeline/loops-pipeline-creator.ts +138 -0
  73. package/src/pipeline/output.js +146 -0
  74. package/src/pipeline/output.js.map +1 -0
  75. package/src/pipeline/output.ts +196 -0
  76. package/src/pipeline/pipeline-creator.js +10 -0
  77. package/src/pipeline/pipeline-creator.js.map +1 -0
  78. package/src/pipeline/pipeline-creator.ts +16 -0
  79. package/src/pipeline/pipeline.js +71 -0
  80. package/src/pipeline/pipeline.js.map +1 -0
  81. package/src/pipeline/pipeline.ts +104 -0
  82. package/src/pipeline/updates-pipeline-creator.js +98 -0
  83. package/src/pipeline/updates-pipeline-creator.js.map +1 -0
  84. package/src/pipeline/updates-pipeline-creator.ts +125 -0
  85. package/src/scripting-tools/constants.js +53 -0
  86. package/src/scripting-tools/constants.js.map +1 -0
  87. package/src/scripting-tools/constants.ts +51 -0
  88. package/src/scripting-tools/index.js +4 -0
  89. package/src/scripting-tools/index.js.map +1 -0
  90. package/src/scripting-tools/index.ts +7 -0
  91. package/src/scripting-tools/model-error.js +17 -0
  92. package/src/scripting-tools/model-error.js.map +1 -0
  93. package/src/scripting-tools/model-error.ts +19 -0
  94. package/src/scripting-tools/scripting-tools.js +1032 -0
  95. package/src/scripting-tools/scripting-tools.js.map +1 -0
  96. package/src/scripting-tools/scripting-tools.ts +1375 -0
  97. package/src/solver-tools/callbacks/callback-base.js +10 -0
  98. package/src/solver-tools/callbacks/callback-base.js.map +1 -0
  99. package/src/solver-tools/callbacks/callback-base.ts +8 -0
  100. package/src/solver-tools/callbacks/callback-tools.js +14 -0
  101. package/src/solver-tools/callbacks/callback-tools.js.map +1 -0
  102. package/src/solver-tools/callbacks/callback-tools.ts +20 -0
  103. package/src/solver-tools/callbacks/iter-checker-callback.js +16 -0
  104. package/src/solver-tools/callbacks/iter-checker-callback.js.map +1 -0
  105. package/src/solver-tools/callbacks/iter-checker-callback.ts +21 -0
  106. package/src/solver-tools/callbacks/time-checker-callback.js +17 -0
  107. package/src/solver-tools/callbacks/time-checker-callback.js.map +1 -0
  108. package/src/solver-tools/callbacks/time-checker-callback.ts +19 -0
  109. package/src/solver-tools/index.js +6 -0
  110. package/src/solver-tools/index.js.map +1 -0
  111. package/src/solver-tools/index.ts +6 -0
  112. package/src/solver-tools/lin-alg-tools.js +56 -0
  113. package/src/solver-tools/lin-alg-tools.js.map +1 -0
  114. package/src/solver-tools/lin-alg-tools.ts +75 -0
  115. package/src/solver-tools/mrt-method.js +210 -0
  116. package/src/solver-tools/mrt-method.js.map +1 -0
  117. package/src/solver-tools/mrt-method.ts +269 -0
  118. package/src/solver-tools/ros34prw-method.js +257 -0
  119. package/src/solver-tools/ros34prw-method.js.map +1 -0
  120. package/src/solver-tools/ros34prw-method.ts +335 -0
  121. package/src/solver-tools/ros3prw-method.js +233 -0
  122. package/src/solver-tools/ros3prw-method.js.map +1 -0
  123. package/src/solver-tools/ros3prw-method.ts +304 -0
  124. package/src/solver-tools/solver-defs.js +58 -0
  125. package/src/solver-tools/solver-defs.js.map +1 -0
  126. package/src/solver-tools/solver-defs.ts +100 -0
  127. package/src/worker-tools/index.js +3 -0
  128. package/src/worker-tools/index.js.map +1 -0
  129. package/src/worker-tools/index.ts +2 -0
  130. package/src/worker-tools/scripting.js +68 -0
  131. package/src/worker-tools/scripting.js.map +1 -0
  132. package/src/worker-tools/scripting.ts +95 -0
  133. package/src/worker-tools/solving.js +48 -0
  134. package/src/worker-tools/solving.js.map +1 -0
  135. package/src/worker-tools/solving.ts +60 -0
  136. package/tsconfig.json +71 -0
package/README.MD ADDED
@@ -0,0 +1,396 @@
1
+ # Diff Grok
2
+
3
+ A lightweight TypeScript library for solving initial value problem ([IVP](https://en.wikipedia.org/wiki/Initial_value_problem)) for ordinary differential equations ([ODEs](https://en.wikipedia.org/wiki/Ordinary_differential_equation)) using numerical methods. This library focuses on solving [stiff equations](https://en.wikipedia.org/wiki/Stiff_equation).
4
+
5
+ ## Features
6
+
7
+ * Solving both [stiff](https://en.wikipedia.org/wiki/Stiff_equation) and non-stiff equations
8
+ * Fast computations
9
+ * A set of Rosenbrock–Wanner-type methods:
10
+ * The modified Rosenbrock triple ([MRT](https://doi.org/10.1137/S1064827594276424))
11
+ * The [ROS3PRw](https://doi.org/10.1016/j.cam.2015.03.010) method
12
+ * The [ROS34PRw](https://doi.org/10.1016/j.cam.2015.03.010) method
13
+ * Scripting:
14
+ * declarative specification of models
15
+ * auto-generated JavaScript code
16
+ * Integration with the [Datagrok](https://datagrok.ai) platform
17
+ * Zero dependencies
18
+
19
+ ## Installation
20
+
21
+ ```bash
22
+ npm i diff-grok
23
+ ```
24
+
25
+ ## Solving
26
+
27
+ ### General
28
+
29
+ To find numerical solution of a problem:
30
+
31
+ $$\frac{dy}{dt} = f(t, y)$$
32
+ $$y(t_{0}) = y_0$$
33
+
34
+ on the segment $[t_0, t_1]$ with the step $h$:
35
+
36
+ 1. Import `ODEs` and a desired numerical method:
37
+
38
+ * `mrt` - the [MRT](https://doi.org/10.1137/S1064827594276424) method
39
+ * `ros3prw`- the [ROS3PRw](https://doi.org/10.1016/j.cam.2015.03.010) method
40
+ * `ros34prw` - the [ROS34PRw](https://doi.org/10.1016/j.cam.2015.03.010) method
41
+
42
+ 2. Specify `ODEs` object that defines a problem:
43
+
44
+ * `name` - name of a model
45
+ * `arg` - independent variable specification. This is in object with fields:
46
+ * `name` - name of the argument, $t$
47
+ * `start` - initial value of the argument, $t_0$
48
+ * `finish` - final value of the argument, $t_1$
49
+ * `step` - solution grid step, $h$
50
+ * `initial` - initial values, $y_0$
51
+ * `func` - right-hand side of the system, $f(t, y)$. This is a function `(t: number, y: Float64Array, output: Float64Array) => void`:
52
+ * `t` - value of independent variable $t$
53
+ * `y` - values of $y$
54
+ * `output` - output values of $f(t, y)$
55
+
56
+ * `tolerance` - numerical tolerance
57
+ * `solutionColNames` - names of solutions, i.e. names of the vector $y$ elements
58
+
59
+ 3. Call numerical method. It returns `Float64Array`-arrays with values of an argument and approximate solutions.
60
+
61
+ Diff Grok is designed to provide fast computations. Check [performance](#performance) for the details.
62
+
63
+ ### Example
64
+
65
+ Consider the following problem:
66
+
67
+ $$\begin{cases}
68
+ \frac{dx}{dt} = x + y - t \\
69
+ \frac{dy}{dt} = x y + t \\
70
+ x(0) = 1 \\
71
+ y(0) = -1
72
+ \end{cases}$$
73
+
74
+ To solve it on the segment $[0, 2]$ with the step $0.01$ using the [MRT](https://doi.org/10.1137/S1064827594276424) method with the tolerance $10^{-7}$, we start with imports:
75
+
76
+ ```typescript
77
+ import {ODEs, mrt} from '@datagrok-ai/diff-studio-tools';
78
+ ```
79
+
80
+ Next, we create
81
+
82
+ ```typescript
83
+ const task: ODEs = {
84
+ name: 'Example', // name of your model
85
+ arg: {
86
+ name: 't', // name of the argument
87
+ start: 0, // initial value of the argument
88
+ finish: 2, // final value of the argument
89
+ step: 0.01, // solution grid step
90
+ },
91
+ initial: [1, -1], // initial values
92
+ func: (t: number, y: Float64Array, output: Float64Array) => { // right-hand side of the system
93
+ output[0] = y[0] + y[1] - t; // 1-st equation
94
+ output[1] = y[0] * y[1] + t; // 2-nd equation
95
+ },
96
+ tolerance: 1e-7, // tolerance
97
+ solutionColNames: ['x', 'y'], // names of solution functions
98
+ };
99
+ ```
100
+
101
+ Finally, we call the specified numerical method to solve `task`:
102
+
103
+ ```typescript
104
+ const solution = mrt(task);
105
+ ```
106
+
107
+ Currently, `solution` contains:
108
+
109
+ * `solution[0]` - values of $t$, i.e. the range $0..2$ with the step $0.01$
110
+ * `solution[1]` - values of $x(t)$ at the points of this range
111
+ * `solution[2]` - values of $y(t)$ at the points of the same range
112
+
113
+ Find this example in [basic-use.ts](./src/examples/basic-use.ts).
114
+
115
+ ## Performance
116
+
117
+ The following [classic problems](https://archimede.uniba.it/~testset/testsetivpsolvers/?page_id=26#ODE) are used to evaluate efficiency of Diff Grok methods:
118
+
119
+ * [Rober](https://archimede.uniba.it/~testset/report/rober.pdf)
120
+ * a stiff system of 3 nonlinear ODEs
121
+ * describes the kinetics of an autocatalytic reaction given by Robertson
122
+ * [robertson.ts](./src/examples/robertson.ts)
123
+ * [HIRES](https://archimede.uniba.it/~testset/report/hires.pdf)
124
+ * a stiff system of 8 non-linear equations
125
+ * explains the `High Irradiance Responses' (HIRES) of photomorphogenesis on the basis of phytochrome, by means of a chemical reaction involving eight reactants
126
+ * [hires.ts](./src/examples/hires.ts)
127
+ * [VDPOL](https://archimede.uniba.it/~testset/report/vdpol.pdf)
128
+ * a system of 2 ODEs proposed by B. van der Pol
129
+ * describes the behaviour of nonlinear vacuum tube circuits
130
+ * [vdpol.ts](./src/examples/vdpol.ts)
131
+ * [OREGO](https://archimede.uniba.it/~testset/report/orego.pdf)
132
+ * a stiff system of 3 non-linear equations
133
+ * simulates Belousov-Zhabotinskii reaction
134
+ * [orego.ts](./src/examples/orego.ts)
135
+ * [E5](https://archimede.uniba.it/~testset/report/e5.pdf)
136
+ * a stiff system of 4 non-linear ODEs
137
+ * represents a chemical pyrolysis model
138
+ * [e5.ts](./src/examples/e5.ts)
139
+ * [Pollution](https://archimede.uniba.it/~testset/report/pollu.pdf)
140
+ * a stiff system of 20 non-linear equations
141
+ * describes a chemical reaction part of the air pollution model designed at The Dutch National Institute of Public Health and Environmental Protection
142
+ * [pollution.ts](./src/examples/pollution.ts)
143
+
144
+ The MRT, ROS3PRw and ROS34PRw methods demonstrate the following time performance (AMD Ryzen 5 5600H 3.30 GHz CPU):
145
+
146
+ |Problem|Segment|Points|Tolerance|MRT, ms|ROS3PRw, ms|ROS34PRw, ms|
147
+ |-|-|-|-|-|-|-|
148
+ |[Rober](https://archimede.uniba.it/~testset/report/rober.pdf)|[0, 10E+11]|40K|1E-7|103|446|285|
149
+ |[HIRES](https://archimede.uniba.it/~testset/report/hires.pdf)|[0, 321.8122]|32K|1E-10|222|362|215|
150
+ |[VDPOL](https://archimede.uniba.it/~testset/report/vdpol.pdf)|[0, 2000]|20K|1E-12|963|1576|760|
151
+ |[OREGO](https://archimede.uniba.it/~testset/report/orego.pdf)|[0, 360]|36K|1E-8|381|483|199|
152
+ |[E5](https://archimede.uniba.it/~testset/report/e5.pdf)|[0, 10E+13]|40K|1E-6|14|17|8|
153
+ |[Pollution](https://archimede.uniba.it/~testset/report/pollu.pdf)|[0, 60]|30K|1E-6|36|50|23|
154
+
155
+ Run [check-methods.ts](./src/examples/check-methods.ts) to check results.
156
+
157
+ ## Scripting
158
+
159
+ The library provides tools for declarative specifying models defined by IVPs. This feature enables a development of "no-code" modeling tools seamlessly integrated with the [Datagrok](https://datagrok.ai) platform.
160
+
161
+ ### Model components and syntax
162
+
163
+ Each **model** has a simple declarative syntax.
164
+
165
+ #### Core blocks
166
+
167
+ These blocks define the basic mathematical model and are required for any model:
168
+
169
+ 1. `#name`: Add a model identifier
170
+
171
+ ```python
172
+ #name: Problem
173
+ ```
174
+
175
+ 1. `#equations`: Define the system of ODEs to solve. Diff Grok supports any number of equations with single or multi-letter variable names
176
+
177
+ ```python
178
+ #equations:
179
+ dx/dt = x + y + exp(t)
180
+ dy/dt = x - y - cos(t)
181
+ ```
182
+
183
+ 1. `#argument`: Defines
184
+ * independent variable
185
+ * its initial value (`initial`)
186
+ * final value (`final`), and
187
+ * grid step (`step`)
188
+
189
+ The solver calculates values at each step interval across the specified [_initial,final_] range.
190
+
191
+ ```python
192
+ #argument: t
193
+ initial = 0
194
+ final = 1
195
+ step = 0.01
196
+ ```
197
+
198
+ 1. `#inits`: Defines initial values for functions being solved
199
+
200
+ ```python
201
+ #inits:
202
+ x = 2
203
+ y = 5
204
+ ```
205
+
206
+ #### Comments
207
+
208
+ * `#comment`: Write a comment in any place of your model
209
+
210
+ ```python
211
+ #comment:
212
+ You can provide any text here. The lib ignores it.
213
+ ```
214
+
215
+ * Place comments right in formulas using `//`
216
+
217
+ ```python
218
+ #equations:
219
+ dx/dt = x + y + exp(t) // 1-st equation
220
+ dy/dt = x - y - cos(t) // 2-nd equation
221
+ ```
222
+
223
+ #### Model parameters
224
+
225
+ These blocks define values used in equations. Choose type based on intended use:
226
+
227
+ * `#parameters`: Generate UI controls for model exploration
228
+
229
+ ```python
230
+ #parameters:
231
+ P1 = 1
232
+ P2 = -1
233
+
234
+ ```
235
+
236
+ * `#constants`: Use for fixed values in equations that don't require UI controls
237
+
238
+ ```python
239
+ #constants:
240
+ C1 = 1
241
+ C2 = 3
242
+ ```
243
+
244
+ #### Auxiliary calculations
245
+
246
+ This block defines mathematical functions using `#parameters`, `#constants`,
247
+ `#argument`, and other functions. These are direct calculations (no ODEs involved). Use them to break
248
+ down complex calculations and simplify your equations.
249
+
250
+ * `#expressions`
251
+
252
+ ```python
253
+ #expressions:
254
+ E1 = C1 * t + P1
255
+ E2 = C2 * cos(2 * t) + P2
256
+ ```
257
+
258
+ ### JS-code generation
259
+
260
+ To transform any model to JavaScript code with an appropriate specification of `ODEs` object, follow the steps:
261
+
262
+ 1. Import the parsing and code generating tools:
263
+
264
+ ```typescript
265
+ import {getIVP, getJScode} from '@datagrok-ai/diff-studio-tools';
266
+ ```
267
+
268
+ 2. Define a string with a model specification, use a simple [model syntax](#model-components-and-syntax):
269
+
270
+ ```typescript
271
+ const model = `
272
+ #name: Example
273
+ #equations:
274
+ dx/dt = x + y - cos(t)
275
+ dy/dt = x - y + sin(t)
276
+ ...
277
+ `;
278
+ ```
279
+
280
+ 3. Parse formulas:
281
+
282
+ ```typescript
283
+ const ivp = getIVP(model);
284
+ ```
285
+
286
+ The method `getIVP` parses formulas and returns `IVP` object specifying a model.
287
+
288
+ 4. Generate JS-code:
289
+
290
+ ```typescript
291
+ const lines = getJScode(ivp);
292
+ ```
293
+
294
+ The method `getJScode` transforms `IVP` object to JavaScript code. It returns an array of strings with this code.
295
+
296
+ Find this example in [scripting.ts](./src/examples/scripting.ts).
297
+
298
+ ### Pipelines
299
+
300
+ Diff Grok **pipeline** is a powerful feature for complex process simulation and model analysis in webworkers. It wraps the main solver with a set of actions that perform pre- and post-processing of a model inputs & outputs. In addition, they provide an output customization.
301
+
302
+ 1. Start with imports:
303
+
304
+ ```typescript
305
+ import * as DGL from '@datagrok/diff-grok';
306
+ ```
307
+
308
+ 2. Define your model:
309
+
310
+ ```typescript
311
+ const model = `#name: My model
312
+ #equations:
313
+ dx/dt = ...
314
+ dy/dt = ...
315
+ ...
316
+
317
+ #inits:
318
+ x = 2
319
+ y = 3
320
+ ...
321
+ ```
322
+
323
+ 3. Generate IVP-objects:
324
+
325
+ * for the main thread computations:
326
+
327
+ ```typescript
328
+ const ivp = DGL.getIVP(model);
329
+ ```
330
+
331
+ * for computations in workers:
332
+ ```typescript
333
+ const ivpWW = DGL.getIvp2WebWorker(ivp);
334
+ ```
335
+
336
+ 4. Set model inputs:
337
+
338
+ ```typescript
339
+ const inputs = {
340
+ x: 2,
341
+ y: 30,
342
+ ...
343
+ };
344
+ ```
345
+
346
+ 5. Create typed input array:
347
+
348
+ ```typescript
349
+ const inputVector = DGL.getInputVector(inputs, ivp);
350
+ ```
351
+
352
+ 6. Get a pipeline:
353
+
354
+ ```typescript
355
+ const creator = DGL.getPipelineCreator(ivp);
356
+ const pipeline = creator.getPipeline(inputVector);
357
+ ```
358
+
359
+ You can pass `pipeline`, `ivpWW`, and `inputVector` to webworkers.
360
+
361
+ 7. Apply pipeline to perform computations:
362
+
363
+ ```typescript
364
+ const solution = DGL.applyPipeline(pipeline, ivpWW, inputVector);
365
+ ```
366
+
367
+ Find complete examples in these files:
368
+
369
+ * [pipeline-use.ts](./src/examples/pipeline-use.ts) - A basic example demonstrating pipeline usage
370
+ * [model-updates.ts](./src/examples/model-updates.ts) - A simulation of a multi-stage process using pipelines
371
+ * [cyclic-model.ts](./src/examples/cyclic-model.ts) - A simulation of a cyclic process using pipelines
372
+
373
+ ## Integration with Datagrok
374
+
375
+ [Datagrok](https://datagrok.ai) is a platform enabling powerful scientific computing capabilities. It provides next-generation environment for leveraging interactive visualizations, data access, machine learning, and enterprise features to enable developing, publishing, discovering, and using scientific applications.
376
+
377
+ The library is seamlessly integrated to Datagrok via the [Diff Studio](https://github.com/datagrok-ai/public/tree/master/packages/DiffStudio) package. It provides
378
+
379
+ * Numerical solving IVPs directly in the browser
380
+ * "No-code" models development
381
+ * Solving both stiff and non-stiff systems of ODEs
382
+ * Automatic generation of user interfaces
383
+ * Interactive visualization and model exploration
384
+ * Sensitivity analysis and parameters optimization
385
+ * Sharing models and computational results
386
+
387
+ Run the Diff Studio [app](https://public.datagrok.ai/apps/DiffStudio) and check interactive modeling:
388
+
389
+ ![DiffStudio](images/acid-prod.gif)
390
+
391
+ Learn more
392
+
393
+ * Diff Studio application [docs](https://datagrok.ai/help/compute/diff-studio)
394
+ * Diff Studio example [models](https://datagrok.ai/help/compute/models)
395
+ * [Parameters optimization](https://datagrok.ai/help/compute/function-analysis#parameter-optimization)
396
+ * [Sensitivity analysis](https://datagrok.ai/help/compute/function-analysis#sensitivity-analysis)
package/eslintrc.json ADDED
@@ -0,0 +1,45 @@
1
+ {
2
+ "env": {
3
+ "browser": true,
4
+ "es2022": true
5
+ },
6
+ "extends": [
7
+ "google"
8
+ ],
9
+ "parser": "@typescript-eslint/parser",
10
+ "parserOptions": {
11
+ "ecmaVersion": 12,
12
+ "sourceType": "module"
13
+ },
14
+ "plugins": [
15
+ "@typescript-eslint"
16
+ ],
17
+ "rules": {
18
+ "no-unused-vars": "off",
19
+ "@typescript-eslint/no-unused-vars": ["warn", { "varsIgnorePattern": "^(_|ui$|grok$|DG$)", "argsIgnorePattern": "^_"}],
20
+ "indent": [
21
+ "error",
22
+ 2
23
+ ],
24
+ "max-len": [
25
+ "error",
26
+ 120
27
+ ],
28
+ "require-jsdoc": "off",
29
+ "valid-jsdoc": "off",
30
+ "spaced-comment": "off",
31
+ "linebreak-style": "off",
32
+ "curly": [
33
+ "error",
34
+ "multi-or-nest"
35
+ ],
36
+ "brace-style": [
37
+ "error",
38
+ "1tbs",
39
+ {
40
+ "allowSingleLine": true
41
+ }
42
+ ],
43
+ "block-spacing": 2
44
+ }
45
+ }
Binary file
package/index.js ADDED
@@ -0,0 +1,6 @@
1
+ export { mrt, ros3prw, ros34prw, CallbackAction, DEFAULT_OPTIONS, getCallback } from './src/solver-tools';
2
+ export { perfProbs, corrProbs } from './src/examples';
3
+ export { DF_NAME, CONTROL_EXPR, MAX_LINE_CHART, getIVP, getScriptLines, getScriptParams, getJScode, SCRIPTING, BRACE_OPEN, BRACE_CLOSE, BRACKET_OPEN, BRACKET_CLOSE, ANNOT_SEPAR, CONTROL_SEP, STAGE_COL_NAME, ARG_INPUT_KEYS, DEFAULT_SOLVER_SETTINGS, ModelError, getFunc4worker } from './src/scripting-tools';
4
+ export { getIvp2WebWorker, solveIvp } from './src/worker-tools';
5
+ export { applyPipeline, getOutputCode, getOutputNames, PipelineCreator, BasicModelPipelineCreator, getInputVector, getPipelineCreator, CyclicModelPipelineCreator, UpdatesModelPipelineCreator } from './src/pipeline';
6
+ //# sourceMappingURL=index.js.map
package/index.js.map ADDED
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAO,GAAG,EAAE,OAAO,EAAE,QAAQ,EAAE,cAAc,EAAE,eAAe,EACnE,WAAW,EAAe,MAAM,oBAAoB,CAAC;AAEvD,OAAO,EAAC,SAAS,EAAE,SAAS,EAAc,MAAM,gBAAgB,CAAC;AAEjE,OAAO,EAAC,OAAO,EAAE,YAAY,EAAE,cAAc,EAAE,MAAM,EAAE,cAAc,EAAE,eAAe,EAAE,SAAS,EACnF,SAAS,EAAE,UAAU,EAAE,WAAW,EAAE,YAAY,EAAE,aAAa,EAAE,WAAW,EACxF,WAAW,EAAE,cAAc,EAAE,cAAc,EAAE,uBAAuB,EAAE,UAAU,EAChF,cAAc,EAAC,MAAM,uBAAuB,CAAC;AAE/C,OAAO,EAAgB,gBAAgB,EAAE,QAAQ,EAAC,MAAM,oBAAoB,CAAC;AAE7E,OAAO,EAAoB,aAAa,EAAE,aAAa,EAAE,cAAc,EAAE,eAAe,EACtF,yBAAyB,EAAE,cAAc,EAAE,kBAAkB,EAAE,0BAA0B,EACzF,2BAA2B,EAAC,MAAM,gBAAgB,CAAC"}
package/index.ts ADDED
@@ -0,0 +1,15 @@
1
+ export {ODEs, mrt, ros3prw, ros34prw, CallbackAction, DEFAULT_OPTIONS, SolverOptions,
2
+ getCallback, SolverMethod} from './src/solver-tools';
3
+
4
+ export {perfProbs, corrProbs, CorrProblem} from './src/examples';
5
+
6
+ export {DF_NAME, CONTROL_EXPR, MAX_LINE_CHART, getIVP, getScriptLines, getScriptParams, getJScode,
7
+ IVP, Input, SCRIPTING, BRACE_OPEN, BRACE_CLOSE, BRACKET_OPEN, BRACKET_CLOSE, ANNOT_SEPAR,
8
+ CONTROL_SEP, STAGE_COL_NAME, ARG_INPUT_KEYS, DEFAULT_SOLVER_SETTINGS, ModelError,
9
+ getFunc4worker} from './src/scripting-tools';
10
+
11
+ export {IVP2WebWorker, getIvp2WebWorker, solveIvp} from './src/worker-tools';
12
+
13
+ export {Pipeline, Wrapper, applyPipeline, getOutputCode, getOutputNames, PipelineCreator,
14
+ BasicModelPipelineCreator, getInputVector, getPipelineCreator, CyclicModelPipelineCreator,
15
+ UpdatesModelPipelineCreator} from './src/pipeline';
package/package.json ADDED
@@ -0,0 +1,45 @@
1
+ {
2
+ "name": "diff-grok",
3
+ "author": {
4
+ "name": "Viktor Makarichev",
5
+ "email": "vmakarichev@datagrok.ai"
6
+ },
7
+ "publishConfig": {
8
+ "access": "public"
9
+ },
10
+ "license": "MIT",
11
+ "version": "1.0.8",
12
+ "description": "Tools for solving initial value problem for ordinary differential equations",
13
+ "keywords": [
14
+ "initial value problem",
15
+ "ordinary differential equations",
16
+ "Rosenbrock-Wanner method"
17
+ ],
18
+ "devDependencies": {
19
+ "@types/wu": "^2.1.44",
20
+ "eslint-plugin-vue": "^9.29.0",
21
+ "@typescript-eslint/eslint-plugin": "^5.62.0",
22
+ "@typescript-eslint/parser": "^5.62.0",
23
+ "css-loader": "^6.7.3",
24
+ "eslint": "^8.56.0",
25
+ "eslint-config-eslint": "^9.0.0",
26
+ "eslint-config-google": "^0.14.0",
27
+ "eslint-plugin-react": "^7.33.2",
28
+ "style-loader": "^3.3.2",
29
+ "ts-loader": "^9.2.6",
30
+ "typescript": "^5.6.3",
31
+ "typescript-eslint": "^8.10.0"
32
+ },
33
+ "scripts": {
34
+ "link": "npm link",
35
+ "build-diff-studio": "git clean -f -X -d ./src && tsc",
36
+ "build": "tsc",
37
+ "lint": "eslint \"./src/**/*.ts\"",
38
+ "lint-fix": "eslint \"./src/**/*.ts\" --fix"
39
+ },
40
+ "repository": {
41
+ "type": "git",
42
+ "url": "git@github.com:datagrok-ai/DiffGrok.git",
43
+ "directory": ""
44
+ }
45
+ }
@@ -0,0 +1,40 @@
1
+ /** Example. Solve the following initial value problem
2
+
3
+ dx / dt = x + y - t
4
+ dy / dt = x * y + t
5
+ x(0) = 1
6
+ y(0) = -1
7
+
8
+ on [0, 2] with the step 0.01.
9
+ */
10
+ import { mrt } from '../../index';
11
+ // Declare the problem
12
+ const task = {
13
+ name: 'Example', // name of your model
14
+ arg: {
15
+ name: 't', // name of the argument
16
+ start: 0, // initial value of the argument
17
+ finish: 2, // final value of the argument
18
+ step: 0.01, // solution grid step
19
+ },
20
+ initial: [1, -1], // initial values
21
+ func: (t, y, output) => {
22
+ output[0] = y[0] + y[1] - t; // 1-st equation
23
+ output[1] = y[0] * y[1] + t; // 2-nd equation
24
+ },
25
+ tolerance: 1e-7, // tolerance
26
+ solutionColNames: ['x', 'y'], // names of solution functions
27
+ };
28
+ try {
29
+ // Solve the problem
30
+ const solution = mrt(task);
31
+ // Output results
32
+ console.log(task.arg.name, ' ', task.solutionColNames[0], ' ', task.solutionColNames[1]);
33
+ const length = solution[0].length;
34
+ for (let i = 0; i < length; ++i)
35
+ console.log(solution[0][i], ' ', solution[1][i], ' ', solution[2][i]);
36
+ }
37
+ catch (err) {
38
+ console.log('Solver failed: ', err instanceof Error ? err.message : 'Unknown problem!');
39
+ }
40
+ //# sourceMappingURL=basic-use.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"basic-use.js","sourceRoot":"","sources":["basic-use.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAEH,OAAO,EAAO,GAAG,EAAC,MAAM,aAAa,CAAC;AAEtC,sBAAsB;AACtB,MAAM,IAAI,GAAS;IACjB,IAAI,EAAE,SAAS,EAAE,qBAAqB;IACtC,GAAG,EAAE;QACH,IAAI,EAAE,GAAG,EAAE,uBAAuB;QAClC,KAAK,EAAE,CAAC,EAAE,gCAAgC;QAC1C,MAAM,EAAE,CAAC,EAAE,8BAA8B;QACzC,IAAI,EAAE,IAAI,EAAE,qBAAqB;KAClC;IACD,OAAO,EAAE,CAAC,CA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CAAC,CAAC,CAAC,GAAG,CAAC,OAAO,CAAC,CAAC,CAAC,kBAAkB,CAAC,CAAC;AAC1F,CAAC"}
@@ -0,0 +1,44 @@
1
+ /** Example. Solve the following initial value problem
2
+
3
+ dx / dt = x + y - t
4
+ dy / dt = x * y + t
5
+ x(0) = 1
6
+ y(0) = -1
7
+
8
+ on [0, 2] with the step 0.01.
9
+ */
10
+
11
+ import {ODEs, mrt} from '../../index';
12
+
13
+ // Declare the problem
14
+ const task: ODEs = {
15
+ name: 'Example', // name of your model
16
+ arg: {
17
+ name: 't', // name of the argument
18
+ start: 0, // initial value of the argument
19
+ finish: 2, // final value of the argument
20
+ step: 0.01, // solution grid step
21
+ },
22
+ initial: [1, -1], // initial values
23
+ func: (t: number, y: Float64Array, output: Float64Array) => { // right-hand side of the system
24
+ output[0] = y[0] + y[1] - t; // 1-st equation
25
+ output[1] = y[0] * y[1] + t; // 2-nd equation
26
+ },
27
+ tolerance: 1e-7, // tolerance
28
+ solutionColNames: ['x', 'y'], // names of solution functions
29
+ };
30
+
31
+ try {
32
+ // Solve the problem
33
+ const solution = mrt(task);
34
+
35
+ // Output results
36
+ console.log(task.arg.name, ' ', task.solutionColNames[0], ' ', task.solutionColNames[1]);
37
+
38
+ const length = solution[0].length;
39
+
40
+ for (let i = 0; i < length; ++i)
41
+ console.log(solution[0][i], ' ', solution[1][i], ' ', solution[2][i]);
42
+ } catch (err) {
43
+ console.log('Solver failed: ', err instanceof Error ? err.message : 'Unknown problem!');
44
+ }
@@ -0,0 +1,45 @@
1
+ // A script for checking performance
2
+ import { corrProbs, mrt, ros3prw, ros34prw, perfProbs } from '../../index';
3
+ /** Return numerical solution error: maximum absolute deviation between approximate & exact solutions */
4
+ function getError(method, corProb) {
5
+ let error = 0;
6
+ // Get numerical solution
7
+ const approxSolution = method(corProb.odes);
8
+ const exact = corProb.exact;
9
+ const arg = approxSolution[0];
10
+ const pointsCount = arg.length;
11
+ const funcsCount = approxSolution.length - 1;
12
+ // Compute error
13
+ for (let i = 0; i < pointsCount; ++i) {
14
+ const exactSolution = exact(arg[i]);
15
+ for (let j = 0; j < funcsCount; ++j)
16
+ error = Math.max(error, Math.abs(exactSolution[j] - approxSolution[j + 1][i]));
17
+ }
18
+ return error;
19
+ }
20
+ const methods = new Map([
21
+ ['MRT', mrt],
22
+ ['ROS3PRw', ros3prw],
23
+ ['ROS34PRw', ros34prw],
24
+ ]);
25
+ console.log('Performance:\n');
26
+ methods.forEach((method, name) => {
27
+ console.log(' ', name);
28
+ perfProbs.forEach((odes) => {
29
+ const start = Date.now();
30
+ method(odes);
31
+ const finish = Date.now();
32
+ console.log(` ${odes.name}: ${finish - start} ms.`);
33
+ });
34
+ console.log();
35
+ });
36
+ console.log('Correctness (maximum absolute deviation):\n');
37
+ methods.forEach((method, name) => {
38
+ console.log(' ', name);
39
+ corrProbs.forEach((problem) => {
40
+ const error = getError(method, problem);
41
+ console.log(` ${problem.odes.name}: ${error}`);
42
+ });
43
+ console.log();
44
+ });
45
+ //# sourceMappingURL=check-methods.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"check-methods.js","sourceRoot":"","sources":["check-methods.ts"],"names":[],"mappings":"AAAA,oCAAoC;AAEpC,OAAO,EAAO,SAAS,EAAe,GAAG,EAAE,OAAO,EAAE,QAAQ,EAAE,SAAS,EAAC,MAAM,aAAa,CAAC;AAE5F,wGAAwG;AACxG,SAAS,QAAQ,CAAC,MAAsC,EAAE,OAAoB;IAC5E,IAAI,KAAK,GAAG,CAAC,CAAC;IAEd,yBAAyB;IACzB,MAAM,cAAc,GAAG,MAAM,CAAC,OAAO,CAAC,IAAI,CAAC,CAAC;IAE5C,MAAM,KAAK,GAAG,OAAO,CAAC,KAAK,CAAC;IAE5B,MAAM,GAAG,GAAG,cAAc,CAAC,CAAC,CAAC,CAAC;IAE9B,MAAM,WAAW,GAAG,GAAG,CAAC,MAAM,CAAC;IAC/B,MAAM,UAAU,GAAG,cAAc,CAAC,MAAM,GAAG,CAAC,CA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