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
@@ -0,0 +1,104 @@
1
+ import {IVP2WebWorker, solveIvp} from '../worker-tools';
2
+ import {PipelineCreator} from './pipeline-creator';
3
+ import {BasicModelPipelineCreator} from './basic-pipeline-creator';
4
+ import {IVP} from '../scripting-tools';
5
+ import {UpdatesModelPipelineCreator} from './updates-pipeline-creator';
6
+ import {CyclicModelPipelineCreator} from './loops-pipeline-creator';
7
+
8
+
9
+ /** Solution step wrapper */
10
+ export type Wrapper = {
11
+ preproc: string | null,
12
+ out: string | null,
13
+ postproc: string | null,
14
+ };
15
+
16
+ /** Solution pipeline */
17
+ export type Pipeline = {
18
+ wrappers: Wrapper[],
19
+ out: string | null,
20
+ };
21
+
22
+ /** Return concatenated arrays */
23
+ function concat(arr1: Float64Array, arr2: Float64Array): Float64Array {
24
+ const result = new Float64Array(arr1.length + arr2.length);
25
+ result.set(arr1, 0);
26
+ result.set(arr2, arr1.length);
27
+ return result;
28
+ }
29
+
30
+ /** Apply pipeline to initial value problem with the source inputs, and return a solution */
31
+ export function applyPipeline(pipeline: Pipeline, ivp: IVP2WebWorker, sourceInputs: Float64Array): Float64Array[] {
32
+ let solution: Float64Array[] = [];
33
+ let currentSolution: Float64Array[];
34
+ let func: Function;
35
+ let inputs = new Float64Array(sourceInputs);
36
+ const wrappers = pipeline.wrappers;
37
+ let step: Wrapper;
38
+ let isFirstSolverCall = true;
39
+
40
+ const stepsCount = wrappers.length;
41
+
42
+ if (stepsCount < 1)
43
+ throw new Error(`Incorrect solution pipeline: ${stepsCount} steps.`);
44
+
45
+ // Perform pipeline steps
46
+ for (let idx = 0; idx < stepsCount; ++idx) {
47
+ step = wrappers[idx];
48
+
49
+ // Pre-processing
50
+ if (step.preproc !== null) {
51
+ func = new Function(step.preproc);
52
+ inputs = func(solution, inputs);
53
+ //console.log('Pre');
54
+ }
55
+
56
+ //console.log(inputs);
57
+
58
+ // Solving a problem
59
+ currentSolution = solveIvp(ivp, inputs);
60
+
61
+ // Output from solution
62
+ if (step.out !== null) {
63
+ func = new Function(step.out);
64
+ currentSolution = func(currentSolution, inputs);
65
+ }
66
+
67
+ if (isFirstSolverCall) {
68
+ solution = currentSolution;
69
+ isFirstSolverCall = false;
70
+ } else
71
+ currentSolution.forEach((arr, kdx) => solution[kdx] = concat(solution[kdx], arr));
72
+
73
+ // Post-processing
74
+ if (step.postproc !== null) {
75
+ func = new Function(step.postproc);
76
+ inputs = func(solution, inputs);
77
+ //console.log('Pro');
78
+ }
79
+
80
+ //console.log(inputs);
81
+ }
82
+
83
+ // Compute final output
84
+ const out = pipeline.out;
85
+
86
+ if (out !== null) {
87
+ func = new Function(out);
88
+
89
+ return func(solution, sourceInputs);
90
+ }
91
+
92
+ return solution;
93
+ } // performPipeline
94
+
95
+ /** Return pipeline creator specified by the initial value problem */
96
+ export function getPipelineCreator(ivp: IVP): PipelineCreator {
97
+ if (ivp.updates !== null)
98
+ return new UpdatesModelPipelineCreator(ivp);
99
+
100
+ if (ivp.loop !== null)
101
+ return new CyclicModelPipelineCreator(ivp);
102
+
103
+ return new BasicModelPipelineCreator(ivp);
104
+ }
@@ -0,0 +1,98 @@
1
+ import { MATH_CONSTS, MATH_FUNCS, POW_IDX } from '../scripting-tools/scripting-tools';
2
+ import { getOutputCode } from './output';
3
+ import { PipelineCreator } from './pipeline-creator';
4
+ import { argName2IdxMap, ARG, ARG_COL_IDX, CORRECTION_FACTOR, DEFAULT_CORRECTION } from './constants';
5
+ /** Pipeline creator for model with updates */
6
+ export class UpdatesModelPipelineCreator extends PipelineCreator {
7
+ constructor(ivp) {
8
+ super(ivp);
9
+ if (ivp.updates === null)
10
+ throw new Error('Incorrect use of UpdatesModelPipelineCreator: model has no updates');
11
+ }
12
+ /** Return computations pipeline */
13
+ getPipeline(inputs) {
14
+ if (this.ivp.updates === null)
15
+ throw new Error('Incorrect use of UpdatesModelPipelineCreator: model has no updates');
16
+ const wrappers = [{
17
+ preproc: null,
18
+ out: null,
19
+ postproc: null,
20
+ }];
21
+ this.ivp.updates.forEach((update) => {
22
+ const lines = [];
23
+ // Used math funcs
24
+ this.ivp.usedMathFuncs.forEach((idx) => {
25
+ if (idx !== POW_IDX)
26
+ lines.push(`const ${MATH_FUNCS[idx]} = (x) => Math.${MATH_FUNCS[idx]}(x);`);
27
+ else
28
+ lines.push(`const pow = (x, y) => Math.pow(x, y);`);
29
+ });
30
+ // Used math consts
31
+ this.ivp.usedMathConsts.forEach((idx) => lines.push(`const ${MATH_CONSTS[idx]} = Math.${MATH_CONSTS[idx]};`));
32
+ // Model constants
33
+ if (this.ivp.consts !== null)
34
+ this.ivp.consts.forEach((input, name) => lines.push(`const ${name} = ${input.value};`));
35
+ lines.push('const inputs = new Float64Array(arguments[1]);');
36
+ lines.push('const solution = arguments[0];');
37
+ // Arguments
38
+ argName2IdxMap.forEach((idx, name) => lines.push(`let ${name} = inputs[${idx}];`));
39
+ // Functions
40
+ lines.push('const lastIdx = solution[0].length - 1;');
41
+ this.ivp.deqs.solutionNames.forEach((name, idx) => {
42
+ lines.push(`let ${name} = solution[${idx + 1}][lastIdx];`);
43
+ });
44
+ // Parameters
45
+ if (this.ivp.params !== null) {
46
+ const shift = argName2IdxMap.size + this.ivp.deqs.solutionNames.length;
47
+ let idx = 0;
48
+ this.ivp.params.forEach((_, name) => {
49
+ lines.push(`let ${name} = inputs[${idx + shift}];`);
50
+ ++idx;
51
+ });
52
+ }
53
+ // Updates
54
+ update.updates.forEach((expr) => lines.push(`${expr};`));
55
+ // Argument update
56
+ lines.push(`const duration = ${update.durationFormula};`);
57
+ lines.push(`${ARG.START} = ${ARG.FINISH};`);
58
+ lines.push(`${ARG.FINISH} += duration;`);
59
+ // Input vector update
60
+ argName2IdxMap.forEach((idx, name) => lines.push(`inputs[${idx}] = ${name};`));
61
+ this.ivp.deqs.solutionNames.forEach((name, idx) => {
62
+ lines.push(`inputs[${idx + argName2IdxMap.size}] = ${name};`);
63
+ });
64
+ if (this.ivp.params !== null) {
65
+ const shift = argName2IdxMap.size + this.ivp.deqs.solutionNames.length;
66
+ let idx = 0;
67
+ this.ivp.params.forEach((_, name) => {
68
+ lines.push(`inputs[${idx + shift}] = ${name};`);
69
+ ++idx;
70
+ });
71
+ }
72
+ lines.push('return inputs;');
73
+ wrappers.push({
74
+ preproc: lines.join('\n'),
75
+ out: null,
76
+ postproc: null,
77
+ });
78
+ });
79
+ wrappers[wrappers.length - 1].postproc = this.getArgumentCorrectionCode();
80
+ return {
81
+ wrappers: wrappers,
82
+ out: getOutputCode(this.ivp),
83
+ };
84
+ } // getPipeline
85
+ /** Return code for correction of an argument */
86
+ getArgumentCorrectionCode() {
87
+ return `const arg = arguments[0][${ARG_COL_IDX}];
88
+ const length = arg.length;
89
+ const step = arg[1] - arg[0];
90
+ const correction = Math.min(step * ${CORRECTION_FACTOR}, ${DEFAULT_CORRECTION});
91
+ for (let i = 0; i < length - 1; ++i) {
92
+ if (arg[i + 1] - arg[i] < step)
93
+ arg[i] -= correction;
94
+ }
95
+ return arguments[0];`;
96
+ } // getArgumentCorrectionCode
97
+ } // UpdatesModelPipelineCreator
98
+ //# sourceMappingURL=updates-pipeline-creator.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"updates-pipeline-creator.js","sour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CAAC;gBAEZ,IAAI,CAAC,GAAG,CAAC,MAAM,CAAC,OAAO,CAAC,CAAC,CAAC,EAAE,IAAI,EAAE,EAAE;oBAClC,KAAK,CAAC,IAAI,CAAC,UAAU,GAAG,GAAG,KAAK,OAAO,IAAI,GAAG,CAAC,CAAC;oBAChD,EAAE,GAAG,CAAC;gBACR,CAAC,CAAC,CAAC;YACL,CAAC;YAED,KAAK,CAAC,IAAI,CAAC,gBAAgB,CAAC,CAAC;YAE7B,QAAQ,CAAC,IAAI,CAAC;gBACZ,OAAO,EAAE,KAAK,CAAC,IAAI,CAAC,IAAI,CAAC;gBACzB,GAAG,EAAE,IAAI;gBACT,QAAQ,EAAE,IAAI;aACf,CAAC,CAAC;QACL,CAAC,CAAC,CAAC;QAEH,QAAQ,CAAC,QAAQ,CAAC,MAAM,GAAG,CAAC,CAAC,CAAC,QAAQ,GAAG,IAAI,CAAC,yBAAyB,EAAE,CAAC;QAE1E,OAAO;YACL,QAAQ,EAAE,QAAQ;YAClB,GAAG,EAAE,aAAa,CAAC,IAAI,CAAC,GAAG,CAAC;SAC7B,CAAC;IACJ,CAAC,CAAC,cAAc;IAEhB,gDAAgD;IACxC,yBAAyB;QAC/B,OAAO,4BAA4B,WAAW;;;yCAGT,iBAAiB,KAAK,kBAAkB;;;;;yBAKxD,CAAC;IACxB,CAAC,CAAC,4BAA4B;CAC/B,CAAC,8BAA8B"}
@@ -0,0 +1,125 @@
1
+ import {IVP} from '../scripting-tools';
2
+ import {MATH_CONSTS, MATH_FUNCS, POW_IDX} from '../scripting-tools/scripting-tools';
3
+ import {getOutputCode} from './output';
4
+ import {Pipeline, Wrapper} from './pipeline';
5
+ import {PipelineCreator} from './pipeline-creator';
6
+
7
+ import {argName2IdxMap, ARG, ARG_COL_IDX, CORRECTION_FACTOR, DEFAULT_CORRECTION} from './constants';
8
+
9
+ /** Pipeline creator for model with updates */
10
+ export class UpdatesModelPipelineCreator extends PipelineCreator {
11
+ constructor(ivp: IVP) {
12
+ super(ivp);
13
+
14
+ if (ivp.updates === null)
15
+ throw new Error('Incorrect use of UpdatesModelPipelineCreator: model has no updates');
16
+ }
17
+
18
+ /** Return computations pipeline */
19
+ public getPipeline(inputs: Float64Array): Pipeline {
20
+ if (this.ivp.updates === null)
21
+ throw new Error('Incorrect use of UpdatesModelPipelineCreator: model has no updates');
22
+
23
+ const wrappers: Wrapper[] = [{
24
+ preproc: null,
25
+ out: null,
26
+ postproc: null,
27
+ }];
28
+
29
+ this.ivp.updates.forEach((update) => {
30
+ const lines: string[] = [];
31
+
32
+ // Used math funcs
33
+ this.ivp.usedMathFuncs.forEach((idx) => {
34
+ if (idx !== POW_IDX)
35
+ lines.push(`const ${MATH_FUNCS[idx]} = (x) => Math.${MATH_FUNCS[idx]}(x);`);
36
+ else
37
+ lines.push(`const pow = (x, y) => Math.pow(x, y);`);
38
+ });
39
+
40
+ // Used math consts
41
+ this.ivp.usedMathConsts.forEach((idx) => lines.push(`const ${MATH_CONSTS[idx]} = Math.${MATH_CONSTS[idx]};`));
42
+
43
+ // Model constants
44
+ if (this.ivp.consts !== null)
45
+ this.ivp.consts.forEach((input, name) => lines.push(`const ${name} = ${input.value};`));
46
+
47
+ lines.push('const inputs = new Float64Array(arguments[1]);');
48
+ lines.push('const solution = arguments[0];');
49
+
50
+ // Arguments
51
+ argName2IdxMap.forEach((idx, name) => lines.push(`let ${name} = inputs[${idx}];`));
52
+
53
+ // Functions
54
+ lines.push('const lastIdx = solution[0].length - 1;');
55
+
56
+ this.ivp.deqs.solutionNames.forEach((name, idx) => {
57
+ lines.push(`let ${name} = solution[${idx + 1}][lastIdx];`);
58
+ });
59
+
60
+ // Parameters
61
+ if (this.ivp.params !== null) {
62
+ const shift = argName2IdxMap.size + this.ivp.deqs.solutionNames.length;
63
+ let idx = 0;
64
+
65
+ this.ivp.params.forEach((_, name) => {
66
+ lines.push(`let ${name} = inputs[${idx + shift}];`);
67
+ ++idx;
68
+ });
69
+ }
70
+
71
+ // Updates
72
+ update.updates.forEach((expr) => lines.push(`${expr};`));
73
+
74
+ // Argument update
75
+ lines.push(`const duration = ${update.durationFormula};`);
76
+ lines.push(`${ARG.START} = ${ARG.FINISH};`);
77
+ lines.push(`${ARG.FINISH} += duration;`);
78
+
79
+ // Input vector update
80
+ argName2IdxMap.forEach((idx, name) => lines.push(`inputs[${idx}] = ${name};`));
81
+
82
+ this.ivp.deqs.solutionNames.forEach((name, idx) => {
83
+ lines.push(`inputs[${idx + argName2IdxMap.size}] = ${name};`);
84
+ });
85
+
86
+ if (this.ivp.params !== null) {
87
+ const shift = argName2IdxMap.size + this.ivp.deqs.solutionNames.length;
88
+ let idx = 0;
89
+
90
+ this.ivp.params.forEach((_, name) => {
91
+ lines.push(`inputs[${idx + shift}] = ${name};`);
92
+ ++idx;
93
+ });
94
+ }
95
+
96
+ lines.push('return inputs;');
97
+
98
+ wrappers.push({
99
+ preproc: lines.join('\n'),
100
+ out: null,
101
+ postproc: null,
102
+ });
103
+ });
104
+
105
+ wrappers[wrappers.length - 1].postproc = this.getArgumentCorrectionCode();
106
+
107
+ return {
108
+ wrappers: wrappers,
109
+ out: getOutputCode(this.ivp),
110
+ };
111
+ } // getPipeline
112
+
113
+ /** Return code for correction of an argument */
114
+ private getArgumentCorrectionCode(): string {
115
+ return `const arg = arguments[0][${ARG_COL_IDX}];
116
+ const length = arg.length;
117
+ const step = arg[1] - arg[0];
118
+ const correction = Math.min(step * ${CORRECTION_FACTOR}, ${DEFAULT_CORRECTION});
119
+ for (let i = 0; i < length - 1; ++i) {
120
+ if (arg[i + 1] - arg[i] < step)
121
+ arg[i] -= correction;
122
+ }
123
+ return arguments[0];`;
124
+ } // getArgumentCorrectionCode
125
+ } // UpdatesModelPipelineCreator
@@ -0,0 +1,53 @@
1
+ // Control constants
2
+ export const CONTROL_TAG = '#';
3
+ export const CONTROL_TAG_LEN = CONTROL_TAG.length;
4
+ export const DF_NAME = 'df';
5
+ export const MAX_LINE_CHART = 4;
6
+ /** Control expressions for the problem specifying */
7
+ export var CONTROL_EXPR;
8
+ (function (CONTROL_EXPR) {
9
+ CONTROL_EXPR["NAME"] = "#name";
10
+ CONTROL_EXPR["TAGS"] = "#tags";
11
+ CONTROL_EXPR["DESCR"] = "#description";
12
+ CONTROL_EXPR["DIF_EQ"] = "#equations";
13
+ CONTROL_EXPR["EXPR"] = "#expressions";
14
+ CONTROL_EXPR["ARG"] = "#argument";
15
+ CONTROL_EXPR["INITS"] = "#inits";
16
+ CONTROL_EXPR["CONSTS"] = "#constants";
17
+ CONTROL_EXPR["PARAMS"] = "#parameters";
18
+ CONTROL_EXPR["TOL"] = "#tolerance";
19
+ CONTROL_EXPR["LOOP"] = "#loop";
20
+ CONTROL_EXPR["UPDATE"] = "#update";
21
+ CONTROL_EXPR["RUN_ON_OPEN"] = "#meta.runOnOpen";
22
+ CONTROL_EXPR["RUN_ON_INPUT"] = "#meta.runOnInput";
23
+ CONTROL_EXPR["OUTPUT"] = "#output";
24
+ CONTROL_EXPR["COMMENT"] = "#comment";
25
+ CONTROL_EXPR["SOLVER"] = "#meta.solver";
26
+ CONTROL_EXPR["INPUTS"] = "#meta.inputs";
27
+ })(CONTROL_EXPR || (CONTROL_EXPR = {}));
28
+ ;
29
+ /** Loop consts */
30
+ export var LOOP;
31
+ (function (LOOP) {
32
+ LOOP[LOOP["MIN_LINES_COUNT"] = 1] = "MIN_LINES_COUNT";
33
+ LOOP[LOOP["COUNT_IDX"] = 0] = "COUNT_IDX";
34
+ LOOP["COUNT_NAME"] = "_count";
35
+ LOOP[LOOP["MIN_COUNT"] = 1] = "MIN_COUNT";
36
+ })(LOOP || (LOOP = {}));
37
+ ;
38
+ /** UPDATE consts */
39
+ export var UPDATE;
40
+ (function (UPDATE) {
41
+ UPDATE[UPDATE["MIN_LINES_COUNT"] = 1] = "MIN_LINES_COUNT";
42
+ UPDATE[UPDATE["DURATION_IDX"] = 0] = "DURATION_IDX";
43
+ UPDATE["DURATION"] = "_duration";
44
+ })(UPDATE || (UPDATE = {}));
45
+ ;
46
+ /** Ranges of the solver options */
47
+ export const SOLVER_OPTIONS_RANGES = new Map([
48
+ ['maxTime', { min: 1, max: 10000 }],
49
+ ['scale', { min: 0.5, max: 1 }],
50
+ ]);
51
+ export const TINY = 0.0001;
52
+ export const STEP_RATIO = 0.5;
53
+ //# sourceMappingURL=constants.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"constants.js","sourceRoot":"","sources":["constants.ts"],"names":[],"mappings":"AAAA,oBAAoB;AACpB,MAAM,CAAC,MAAM,WAAW,GAAG,GAAG,CAAC;AAC/B,MAAM,CAAC,MAAM,eAAe,GAAG,WAAW,CAAC,MAAM,CAAC;AAClD,MAAM,CAAC,MAAM,OAAO,GAAG,IAAI,CAAC;AAC5B,MAAM,CAAC,MAAM,cAAc,GAAG,CAAC,CAAC;AAEhC,qDAAqD;AACrD,MAAM,CAAN,IAAY,YAmBX;AAnBD,WAAY,YAAY;IACpB,8BAAc,CAAA;IACd,8BAAc,CAAA;IACd,sCAAsB,CAAA;IACtB,qCAAqB,CAAA;IACrB,qCAAqB,CAAA;IACrB,iCAAiB,CAAA;IACjB,gCAAgB,CAAA;IAChB,qCAAqB,CAAA;IACrB,sCAAsB,CAAA;IACtB,kCAAkB,CAAA;IAClB,8BAAc,CAAA;IACd,kCAAkB,CAAA;IAClB,+CAA+B,CAAA;IAC/B,iDAAiC,CAAA;IACjC,kCAAkB,CAAA;IAClB,oCAAoB,CAAA;IACpB,uCAAuB,CAAA;IACvB,uCAAuB,CAAA;AAC3B,CAAC,EAnBW,YAAY,KAAZ,YAAY,QAmBvB;AAAA,CAAC;AAEF,kBAAkB;AAClB,MAAM,CAAN,IAAY,IAKX;AALD,WAAY,IAAI;IACd,qDAAmB,CAAA;IACnB,yCAAa,CAAA;IACb,6BAAqB,CAAA;IACrB,yCAAa,CAAA;AACf,CAAC,EALW,IAAI,KAAJ,IAAI,QAKf;AAAA,CAAC;AAEF,oBAAoB;AACpB,MAAM,CAAN,IAAY,MAIX;AAJD,WAAY,MAAM;IAChB,yDAAmB,CAAA;IACnB,mDAAgB,CAAA;IAChB,gCAAsB,CAAA;AACxB,CAAC,EAJW,MAAM,KAAN,MAAM,QAIjB;AAAA,CAAC;AAEF,mCAAmC;AACnC,MAAM,CAAC,MAAM,qBAAqB,GAAG,IAAI,GAAG,CAAC;IAC3C,CAAC,SAAS,EAAE,EAAC,GAAG,EAAE,CAAC,EAAE,GAAG,EAAE,KAAK,EAAC,CAAC;IACjC,CAAC,OAAO,EAAE,EAAC,GAAG,EAAE,GAAG,EAAE,GAAG,EAAE,CAAC,EAAC,CAAC;CAC9B,CAAC,CAAC;AAEH,MAAM,CAAC,MAAM,IAAI,GAAG,MAAM,CAAC;AAC3B,MAAM,CAAC,MAAM,UAAU,GAAG,GAAG,CAAC"}
@@ -0,0 +1,51 @@
1
+ // Control constants
2
+ export const CONTROL_TAG = '#';
3
+ export const CONTROL_TAG_LEN = CONTROL_TAG.length;
4
+ export const DF_NAME = 'df';
5
+ export const MAX_LINE_CHART = 4;
6
+
7
+ /** Control expressions for the problem specifying */
8
+ export enum CONTROL_EXPR {
9
+ NAME = '#name',
10
+ TAGS = '#tags',
11
+ DESCR = '#description',
12
+ DIF_EQ = '#equations',
13
+ EXPR = '#expressions',
14
+ ARG = '#argument',
15
+ INITS = '#inits',
16
+ CONSTS = '#constants',
17
+ PARAMS = '#parameters',
18
+ TOL = '#tolerance',
19
+ LOOP = '#loop',
20
+ UPDATE = '#update',
21
+ RUN_ON_OPEN = '#meta.runOnOpen',
22
+ RUN_ON_INPUT = '#meta.runOnInput',
23
+ OUTPUT = '#output',
24
+ COMMENT = '#comment',
25
+ SOLVER = '#meta.solver',
26
+ INPUTS = '#meta.inputs',
27
+ };
28
+
29
+ /** Loop consts */
30
+ export enum LOOP {
31
+ MIN_LINES_COUNT = 1,
32
+ COUNT_IDX = 0,
33
+ COUNT_NAME = '_count',
34
+ MIN_COUNT = 1,
35
+ };
36
+
37
+ /** UPDATE consts */
38
+ export enum UPDATE {
39
+ MIN_LINES_COUNT = 1,
40
+ DURATION_IDX = 0,
41
+ DURATION = '_duration',
42
+ };
43
+
44
+ /** Ranges of the solver options */
45
+ export const SOLVER_OPTIONS_RANGES = new Map([
46
+ ['maxTime', {min: 1, max: 10000}],
47
+ ['scale', {min: 0.5, max: 1}],
48
+ ]);
49
+
50
+ export const TINY = 0.0001;
51
+ export const STEP_RATIO = 0.5;
@@ -0,0 +1,4 @@
1
+ export { DF_NAME, CONTROL_EXPR, MAX_LINE_CHART } from './constants';
2
+ export { 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, getFunc4worker } from './scripting-tools';
3
+ export { ModelError } from './model-error';
4
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,OAAO,EAAE,YAAY,EAAE,cAAc,EAAC,MAAM,aAAa,CAAC;AAElE,OAAO,EAAC,MAAM,EAAE,cAAc,EAAE,eAAe,EAAE,SAAS,EAAc,SAAS,EAC/E,UAAU,EAAE,WAAW,EAAE,YAAY,EAAE,aAAa,EAAE,WAAW,EAAE,WAAW,EAC9E,cAAc,EAAE,cAAc,EAAE,uBAAuB,EAAE,cAAc,EAAC,MAAM,mBAAmB,CAAC;AAEpG,OAAO,EAAC,UAAU,EAAC,MAAM,eAAe,CAAC"}
@@ -0,0 +1,7 @@
1
+ export {DF_NAME, CONTROL_EXPR, MAX_LINE_CHART} from './constants';
2
+
3
+ export {getIVP, getScriptLines, getScriptParams, getJScode, IVP, Input, SCRIPTING,
4
+ BRACE_OPEN, BRACE_CLOSE, BRACKET_OPEN, BRACKET_CLOSE, ANNOT_SEPAR, CONTROL_SEP,
5
+ STAGE_COL_NAME, ARG_INPUT_KEYS, DEFAULT_SOLVER_SETTINGS, getFunc4worker} from './scripting-tools';
6
+
7
+ export {ModelError} from './model-error';
@@ -0,0 +1,17 @@
1
+ /** Diff Studio model error */
2
+ export class ModelError extends Error {
3
+ constructor(message, helpUrl, toHighlight) {
4
+ super(message);
5
+ this.toHighlight = undefined;
6
+ this.helpUrl = helpUrl;
7
+ this.toHighlight = toHighlight;
8
+ }
9
+ getHelpUrl() {
10
+ return this.helpUrl;
11
+ }
12
+ getToHighlight() {
13
+ return this.toHighlight;
14
+ }
15
+ }
16
+ ; // ModelError
17
+ //# sourceMappingURL=model-error.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"model-error.js","sourceRoot":"","sources":["model-error.ts"],"names":[],"mappings":"AAAA,8BAA8B;AAC9B,MAAM,OAAO,UAAW,SAAQ,KAAK;IAInC,YAAY,OAAe,EAAE,OAAe,EAAE,WAAoB;QAChE,KAAK,CAAC,OAAO,CAAC,CAAC;QAHT,gBAAW,GAAuB,SAAS,CAAC;QAIlD,IAAI,CAAC,OAAO,GAAG,OAAO,CAAC;QACvB,IAAI,CAAC,WAAW,GAAG,WAAW,CAAC;IACjC,CAAC;IAEM,UAAU;QACf,OAAO,IAAI,CAAC,OAAO,CAAC;IACtB,CAAC;IAEM,cAAc;QACnB,OAAO,IAAI,CAAC,WAAW,CAAC;IAC1B,CAAC;CACF;AAAA,CAAC,CAAC,aAAa"}
@@ -0,0 +1,19 @@
1
+ /** Diff Studio model error */
2
+ export class ModelError extends Error {
3
+ private helpUrl: string;
4
+ private toHighlight: string | undefined = undefined;
5
+
6
+ constructor(message: string, helpUrl: string, toHighlight?: string) {
7
+ super(message);
8
+ this.helpUrl = helpUrl;
9
+ this.toHighlight = toHighlight;
10
+ }
11
+
12
+ public getHelpUrl() {
13
+ return this.helpUrl;
14
+ }
15
+
16
+ public getToHighlight() {
17
+ return this.toHighlight;
18
+ }
19
+ }; // ModelError