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.
- package/.eslintrc.json +45 -0
- package/.github/scripts/bump-js-api-version.sh +106 -0
- package/.github/scripts/check-output.sh +20 -0
- package/.github/scripts/iac-cfn-deploy.sh +90 -0
- package/.github/scripts/slack_api_request.sh +65 -0
- package/.github/scripts/test_package.sh +270 -0
- package/.github/workflows/libraries.yaml +305 -0
- package/LICENSE +21 -0
- package/README.MD +396 -0
- package/eslintrc.json +45 -0
- package/images/acid-prod.gif +0 -0
- package/index.js +6 -0
- package/index.js.map +1 -0
- package/index.ts +15 -0
- package/package.json +45 -0
- package/src/examples/basic-use.js +40 -0
- package/src/examples/basic-use.js.map +1 -0
- package/src/examples/basic-use.ts +44 -0
- package/src/examples/check-methods.js +45 -0
- package/src/examples/check-methods.js.map +1 -0
- package/src/examples/check-methods.ts +62 -0
- package/src/examples/corr-probs.js +130 -0
- package/src/examples/corr-probs.js.map +1 -0
- package/src/examples/corr-probs.ts +151 -0
- package/src/examples/cyclic-model.js +100 -0
- package/src/examples/cyclic-model.js.map +1 -0
- package/src/examples/cyclic-model.ts +110 -0
- package/src/examples/e5.js +30 -0
- package/src/examples/e5.js.map +1 -0
- package/src/examples/e5.ts +29 -0
- package/src/examples/hires.js +29 -0
- package/src/examples/hires.js.map +1 -0
- package/src/examples/hires.ts +29 -0
- package/src/examples/index.js +17 -0
- package/src/examples/index.js.map +1 -0
- package/src/examples/index.ts +18 -0
- package/src/examples/model-updates.js +112 -0
- package/src/examples/model-updates.js.map +1 -0
- package/src/examples/model-updates.ts +122 -0
- package/src/examples/orego.js +19 -0
- package/src/examples/orego.js.map +1 -0
- package/src/examples/orego.ts +19 -0
- package/src/examples/pipeline-use.js +87 -0
- package/src/examples/pipeline-use.js.map +1 -0
- package/src/examples/pipeline-use.ts +98 -0
- package/src/examples/pollution.js +110 -0
- package/src/examples/pollution.js.map +1 -0
- package/src/examples/pollution.ts +110 -0
- package/src/examples/robertson.js +14 -0
- package/src/examples/robertson.js.map +1 -0
- package/src/examples/robertson.ts +13 -0
- package/src/examples/scripting.js +31 -0
- package/src/examples/scripting.js.map +1 -0
- package/src/examples/scripting.ts +36 -0
- package/src/examples/vdpol.js +13 -0
- package/src/examples/vdpol.js.map +1 -0
- package/src/examples/vdpol.ts +12 -0
- package/src/pipeline/basic-pipeline-creator.js +21 -0
- package/src/pipeline/basic-pipeline-creator.js.map +1 -0
- package/src/pipeline/basic-pipeline-creator.ts +24 -0
- package/src/pipeline/constants.js +21 -0
- package/src/pipeline/constants.js.map +1 -0
- package/src/pipeline/constants.ts +21 -0
- package/src/pipeline/index.js +8 -0
- package/src/pipeline/index.js.map +1 -0
- package/src/pipeline/index.ts +7 -0
- package/src/pipeline/input.js +45 -0
- package/src/pipeline/input.js.map +1 -0
- package/src/pipeline/input.ts +55 -0
- package/src/pipeline/loops-pipeline-creator.js +107 -0
- package/src/pipeline/loops-pipeline-creator.js.map +1 -0
- package/src/pipeline/loops-pipeline-creator.ts +138 -0
- package/src/pipeline/output.js +146 -0
- package/src/pipeline/output.js.map +1 -0
- package/src/pipeline/output.ts +196 -0
- package/src/pipeline/pipeline-creator.js +10 -0
- package/src/pipeline/pipeline-creator.js.map +1 -0
- package/src/pipeline/pipeline-creator.ts +16 -0
- package/src/pipeline/pipeline.js +71 -0
- package/src/pipeline/pipeline.js.map +1 -0
- package/src/pipeline/pipeline.ts +104 -0
- package/src/pipeline/updates-pipeline-creator.js +98 -0
- package/src/pipeline/updates-pipeline-creator.js.map +1 -0
- package/src/pipeline/updates-pipeline-creator.ts +125 -0
- package/src/scripting-tools/constants.js +53 -0
- package/src/scripting-tools/constants.js.map +1 -0
- package/src/scripting-tools/constants.ts +51 -0
- package/src/scripting-tools/index.js +4 -0
- package/src/scripting-tools/index.js.map +1 -0
- package/src/scripting-tools/index.ts +7 -0
- package/src/scripting-tools/model-error.js +17 -0
- package/src/scripting-tools/model-error.js.map +1 -0
- package/src/scripting-tools/model-error.ts +19 -0
- package/src/scripting-tools/scripting-tools.js +1032 -0
- package/src/scripting-tools/scripting-tools.js.map +1 -0
- package/src/scripting-tools/scripting-tools.ts +1375 -0
- package/src/solver-tools/callbacks/callback-base.js +10 -0
- package/src/solver-tools/callbacks/callback-base.js.map +1 -0
- package/src/solver-tools/callbacks/callback-base.ts +8 -0
- package/src/solver-tools/callbacks/callback-tools.js +14 -0
- package/src/solver-tools/callbacks/callback-tools.js.map +1 -0
- package/src/solver-tools/callbacks/callback-tools.ts +20 -0
- package/src/solver-tools/callbacks/iter-checker-callback.js +16 -0
- package/src/solver-tools/callbacks/iter-checker-callback.js.map +1 -0
- package/src/solver-tools/callbacks/iter-checker-callback.ts +21 -0
- package/src/solver-tools/callbacks/time-checker-callback.js +17 -0
- package/src/solver-tools/callbacks/time-checker-callback.js.map +1 -0
- package/src/solver-tools/callbacks/time-checker-callback.ts +19 -0
- package/src/solver-tools/index.js +6 -0
- package/src/solver-tools/index.js.map +1 -0
- package/src/solver-tools/index.ts +6 -0
- package/src/solver-tools/lin-alg-tools.js +56 -0
- package/src/solver-tools/lin-alg-tools.js.map +1 -0
- package/src/solver-tools/lin-alg-tools.ts +75 -0
- package/src/solver-tools/mrt-method.js +210 -0
- package/src/solver-tools/mrt-method.js.map +1 -0
- package/src/solver-tools/mrt-method.ts +269 -0
- package/src/solver-tools/ros34prw-method.js +257 -0
- package/src/solver-tools/ros34prw-method.js.map +1 -0
- package/src/solver-tools/ros34prw-method.ts +335 -0
- package/src/solver-tools/ros3prw-method.js +233 -0
- package/src/solver-tools/ros3prw-method.js.map +1 -0
- package/src/solver-tools/ros3prw-method.ts +304 -0
- package/src/solver-tools/solver-defs.js +58 -0
- package/src/solver-tools/solver-defs.js.map +1 -0
- package/src/solver-tools/solver-defs.ts +100 -0
- package/src/worker-tools/index.js +3 -0
- package/src/worker-tools/index.js.map +1 -0
- package/src/worker-tools/index.ts +2 -0
- package/src/worker-tools/scripting.js +68 -0
- package/src/worker-tools/scripting.js.map +1 -0
- package/src/worker-tools/scripting.ts +95 -0
- package/src/worker-tools/solving.js +48 -0
- package/src/worker-tools/solving.js.map +1 -0
- package/src/worker-tools/solving.ts +60 -0
- package/tsconfig.json +71 -0
|
@@ -0,0 +1,138 @@
|
|
|
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, LOOP_MIN_COUNT} from './constants';
|
|
8
|
+
|
|
9
|
+
/** Pipeline creator for cyclic model */
|
|
10
|
+
export class CyclicModelPipelineCreator extends PipelineCreator {
|
|
11
|
+
constructor(ivp: IVP) {
|
|
12
|
+
super(ivp);
|
|
13
|
+
|
|
14
|
+
if (ivp.loop === null)
|
|
15
|
+
throw new Error('Incorrect use of CyclicModelPipelineCreator: model has no loop');
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
/** Return computations pipeline */
|
|
19
|
+
public getPipeline(inputs: Float64Array): Pipeline {
|
|
20
|
+
if (this.ivp.loop === null)
|
|
21
|
+
throw new Error('Incorrect use of CyclicModelPipelineCreator: model has no loop');
|
|
22
|
+
|
|
23
|
+
const argSize = argName2IdxMap.size;
|
|
24
|
+
const restricted = inputs.length - 1;
|
|
25
|
+
const repetitions = inputs[restricted];
|
|
26
|
+
|
|
27
|
+
if (repetitions < LOOP_MIN_COUNT)
|
|
28
|
+
throw new Error(`Incorrect repetitions count: ${repetitions}, expected: > 0`);
|
|
29
|
+
|
|
30
|
+
const preProcLines: string[] = [];
|
|
31
|
+
|
|
32
|
+
// Used math funcs
|
|
33
|
+
this.ivp.usedMathFuncs.forEach((idx) => {
|
|
34
|
+
if (idx !== POW_IDX)
|
|
35
|
+
preProcLines.push(`const ${MATH_FUNCS[idx]} = (x) => Math.${MATH_FUNCS[idx]}(x);`);
|
|
36
|
+
else
|
|
37
|
+
preProcLines.push(`const pow = (x, y) => Math.pow(x, y);`);
|
|
38
|
+
});
|
|
39
|
+
|
|
40
|
+
// Used math consts
|
|
41
|
+
this.ivp.usedMathConsts.forEach((idx) => {
|
|
42
|
+
preProcLines.push(`const ${MATH_CONSTS[idx]} = Math.${MATH_CONSTS[idx]};`);
|
|
43
|
+
});
|
|
44
|
+
|
|
45
|
+
// Model constants
|
|
46
|
+
if (this.ivp.consts !== null)
|
|
47
|
+
this.ivp.consts.forEach((input, name) => preProcLines.push(`const ${name} = ${input.value};`));
|
|
48
|
+
|
|
49
|
+
preProcLines.push(`const inputs = arguments[1].slice(0, ${restricted});`);
|
|
50
|
+
|
|
51
|
+
// Extract inputs
|
|
52
|
+
argName2IdxMap.forEach((idx, name) => preProcLines.push(`let ${name} = inputs[${idx}];`));
|
|
53
|
+
|
|
54
|
+
this.ivp.deqs.solutionNames.forEach((name, idx) => {
|
|
55
|
+
preProcLines.push(`let ${name} = inputs[${idx + argSize}];`);
|
|
56
|
+
});
|
|
57
|
+
|
|
58
|
+
if (this.ivp.params !== null) {
|
|
59
|
+
const shift = argSize + this.ivp.deqs.solutionNames.length;
|
|
60
|
+
let idx = 0;
|
|
61
|
+
|
|
62
|
+
this.ivp.params.forEach((_, name) => {
|
|
63
|
+
preProcLines.push(`let ${name} = inputs[${idx + shift}];`);
|
|
64
|
+
++idx;
|
|
65
|
+
});
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
// Updates
|
|
69
|
+
this.ivp.loop.updates.forEach((expr) => preProcLines.push(`${expr};`));
|
|
70
|
+
|
|
71
|
+
// Input vector update
|
|
72
|
+
argName2IdxMap.forEach((idx, name) => preProcLines.push(`inputs[${idx}] = ${name};`));
|
|
73
|
+
|
|
74
|
+
this.ivp.deqs.solutionNames.forEach((name, idx) => {
|
|
75
|
+
preProcLines.push(`inputs[${idx + argSize}] = ${name};`);
|
|
76
|
+
});
|
|
77
|
+
|
|
78
|
+
if (this.ivp.params !== null) {
|
|
79
|
+
const shift = argSize + this.ivp.deqs.solutionNames.length;
|
|
80
|
+
let idx = 0;
|
|
81
|
+
|
|
82
|
+
this.ivp.params.forEach((_, name) => {
|
|
83
|
+
preProcLines.push(`inputs[${idx + shift}] = ${name};`);
|
|
84
|
+
++idx;
|
|
85
|
+
});
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
preProcLines.push(`return inputs;`);
|
|
89
|
+
|
|
90
|
+
const postProcLines = [
|
|
91
|
+
'const solution = arguments[0];',
|
|
92
|
+
'const lastIdx = solution[0].length - 1;',
|
|
93
|
+
'const inputs = new Float64Array(arguments[1]);',
|
|
94
|
+
`const duration = inputs[${argName2IdxMap.get(ARG.FINISH)}] - inputs[${argName2IdxMap.get(ARG.START)}];`,
|
|
95
|
+
`inputs[${argName2IdxMap.get(ARG.START)}] = inputs[${argName2IdxMap.get(ARG.FINISH)}];`,
|
|
96
|
+
`inputs[${argName2IdxMap.get(ARG.FINISH)}] += duration;`,
|
|
97
|
+
];
|
|
98
|
+
|
|
99
|
+
this.ivp.deqs.solutionNames.forEach((_, idx) => {
|
|
100
|
+
postProcLines.push(`inputs[${idx + argSize}] = solution[${idx + 1}][lastIdx];`);
|
|
101
|
+
});
|
|
102
|
+
|
|
103
|
+
postProcLines.push('return inputs;');
|
|
104
|
+
|
|
105
|
+
const preCode = preProcLines.join('\n');
|
|
106
|
+
const postCode = postProcLines.join('\n');
|
|
107
|
+
|
|
108
|
+
const wrappers = new Array<Wrapper>(repetitions);
|
|
109
|
+
|
|
110
|
+
for (let i = 0; i < repetitions; ++i) {
|
|
111
|
+
wrappers[i] = {
|
|
112
|
+
preproc: preCode,
|
|
113
|
+
out: null,
|
|
114
|
+
postproc: postCode,
|
|
115
|
+
};
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
wrappers[repetitions - 1].postproc = this.getArgumentCorrectionCode();
|
|
119
|
+
|
|
120
|
+
return {
|
|
121
|
+
wrappers: wrappers,
|
|
122
|
+
out: getOutputCode(this.ivp),
|
|
123
|
+
};
|
|
124
|
+
} // getPipeline
|
|
125
|
+
|
|
126
|
+
/** Return code for correction of an argument */
|
|
127
|
+
private getArgumentCorrectionCode(): string {
|
|
128
|
+
return `const arg = arguments[0][${ARG_COL_IDX}];
|
|
129
|
+
const length = arg.length;
|
|
130
|
+
const step = arg[1] - arg[0];
|
|
131
|
+
const correction = Math.min(step * ${CORRECTION_FACTOR}, ${DEFAULT_CORRECTION});
|
|
132
|
+
for (let i = 0; i < length - 1; ++i) {
|
|
133
|
+
if (arg[i + 1] - arg[i] < step)
|
|
134
|
+
arg[i] -= correction;
|
|
135
|
+
}
|
|
136
|
+
return arguments[0];`;
|
|
137
|
+
} // getArgumentCorrectionCode
|
|
138
|
+
} // CyclicModelPipelineCreator
|
|
@@ -0,0 +1,146 @@
|
|
|
1
|
+
// Features for creating output code for a pipeline
|
|
2
|
+
import { MATH_CONSTS, POW_IDX, MATH_FUNCS } from '../scripting-tools/scripting-tools';
|
|
3
|
+
import { ARG_INP_COUNT } from './constants';
|
|
4
|
+
const SHIFT = 1;
|
|
5
|
+
/** Return output for the model WITHOUT expressions */
|
|
6
|
+
function getOutputNoExprs(ivp) {
|
|
7
|
+
const outputs = ivp.outputs;
|
|
8
|
+
if (outputs === null)
|
|
9
|
+
throw new Error('Grok Lib issue: no outputs in the initial value problem');
|
|
10
|
+
if (exprsInOutputs(ivp))
|
|
11
|
+
throw new Error('Grok Lib issue: no expressions are allowed');
|
|
12
|
+
const lines = ['const solution = [];'];
|
|
13
|
+
outputs.forEach((_, name) => {
|
|
14
|
+
if (name === ivp.arg.name)
|
|
15
|
+
lines.push('solution.push(arguments[0][0]);');
|
|
16
|
+
else {
|
|
17
|
+
const idx = ivp.deqs.solutionNames.indexOf(name);
|
|
18
|
+
if (idx > -1)
|
|
19
|
+
lines.push(`solution.push(arguments[0][${idx + 1}]);`);
|
|
20
|
+
}
|
|
21
|
+
});
|
|
22
|
+
lines.push('return solution;');
|
|
23
|
+
return lines.join('\n');
|
|
24
|
+
} // getOutputNoExprs
|
|
25
|
+
/** Return output for the model WITH expressions */
|
|
26
|
+
function getOutputWithExprs(ivp) {
|
|
27
|
+
const outputs = ivp.outputs;
|
|
28
|
+
if (outputs === null)
|
|
29
|
+
throw new Error('Grok Lib issue: no outputs in the initial value problem');
|
|
30
|
+
const exprs = ivp.exprs;
|
|
31
|
+
if (!exprsInOutputs(ivp) || (exprs === null))
|
|
32
|
+
throw new Error('Grok Lib issue: expressions must be given');
|
|
33
|
+
const argName = ivp.arg.name;
|
|
34
|
+
const lines = ['const solution = [];'];
|
|
35
|
+
// Used math funcs
|
|
36
|
+
ivp.usedMathFuncs.forEach((idx) => {
|
|
37
|
+
if (idx !== POW_IDX)
|
|
38
|
+
lines.push(`const ${MATH_FUNCS[idx]} = (x) => Math.${MATH_FUNCS[idx]}(x);`);
|
|
39
|
+
else
|
|
40
|
+
lines.push(`const pow = (x, y) => Math.pow(x, y);`);
|
|
41
|
+
});
|
|
42
|
+
// Used math consts
|
|
43
|
+
ivp.usedMathConsts.forEach((idx) => lines.push(`const ${MATH_CONSTS[idx]} = Math.${MATH_CONSTS[idx]};`));
|
|
44
|
+
// Model constants
|
|
45
|
+
if (ivp.consts !== null)
|
|
46
|
+
ivp.consts.forEach((input, name) => lines.push(`const ${name} = ${input.value};`));
|
|
47
|
+
// Model parameters
|
|
48
|
+
if (ivp.params !== null) {
|
|
49
|
+
let idx = ARG_INP_COUNT + ivp.deqs.solutionNames.length;
|
|
50
|
+
ivp.params.forEach((_, name) => {
|
|
51
|
+
lines.push(`const ${name} = arguments[1][${idx}];`);
|
|
52
|
+
++idx;
|
|
53
|
+
});
|
|
54
|
+
}
|
|
55
|
+
lines.push('');
|
|
56
|
+
lines.push('const length = arguments[0][0].length;');
|
|
57
|
+
const funcNames = ivp.deqs.solutionNames;
|
|
58
|
+
lines.push(`let ${argName} = 0;`);
|
|
59
|
+
funcNames.forEach((name) => lines.push(`let ${name} = 0;`));
|
|
60
|
+
lines.push('');
|
|
61
|
+
exprs.forEach((_, name) => {
|
|
62
|
+
lines.push(`let ${name} = 0;`);
|
|
63
|
+
if (outputs.has(name))
|
|
64
|
+
lines.push(`let ${name}Raw = new Float64Array(length);`);
|
|
65
|
+
});
|
|
66
|
+
lines.push('');
|
|
67
|
+
lines.push('for (let k = 0; k < length; ++k) {');
|
|
68
|
+
lines.push(` ${argName} = arguments[0][0][k];`);
|
|
69
|
+
funcNames.forEach((name, idx) => lines.push(` ${name} = arguments[0][${SHIFT + idx}][k];`));
|
|
70
|
+
lines.push('');
|
|
71
|
+
exprs.forEach((expr, name) => {
|
|
72
|
+
lines.push(` ${name} = ${expr};`);
|
|
73
|
+
if (outputs.has(name))
|
|
74
|
+
lines.push(` ${name}Raw[k] = ${name};`);
|
|
75
|
+
});
|
|
76
|
+
lines.push('}');
|
|
77
|
+
lines.push('');
|
|
78
|
+
outputs.forEach((_, name) => {
|
|
79
|
+
if (name === argName)
|
|
80
|
+
lines.push('solution.push(arguments[0][0]);');
|
|
81
|
+
else {
|
|
82
|
+
const idx = ivp.deqs.solutionNames.indexOf(name);
|
|
83
|
+
if (idx > -1)
|
|
84
|
+
lines.push(`solution.push(arguments[0][${idx + 1}]);`);
|
|
85
|
+
else if (exprs.has(name))
|
|
86
|
+
lines.push(`solution.push(${name}Raw);`);
|
|
87
|
+
}
|
|
88
|
+
});
|
|
89
|
+
lines.push('return solution;');
|
|
90
|
+
return lines.join('\n');
|
|
91
|
+
} // getOutputWithExprs
|
|
92
|
+
/** Return a code for output extraction */
|
|
93
|
+
export function getOutputCode(ivp) {
|
|
94
|
+
const outputs = ivp.outputs;
|
|
95
|
+
if (outputs === null)
|
|
96
|
+
return null;
|
|
97
|
+
checkApplicability(ivp);
|
|
98
|
+
if (exprsInOutputs(ivp))
|
|
99
|
+
return getOutputWithExprs(ivp);
|
|
100
|
+
else
|
|
101
|
+
return getOutputNoExprs(ivp);
|
|
102
|
+
} // getOutputCode
|
|
103
|
+
/** Check whether outputs have items from expressions */
|
|
104
|
+
function exprsInOutputs(ivp) {
|
|
105
|
+
const outputs = ivp.outputs;
|
|
106
|
+
if (outputs === null)
|
|
107
|
+
return false;
|
|
108
|
+
const exprs = ivp.exprs;
|
|
109
|
+
if (exprs === null)
|
|
110
|
+
return false;
|
|
111
|
+
let flag = false;
|
|
112
|
+
exprs.forEach((_, name) => flag || (flag = outputs.has(name)));
|
|
113
|
+
return flag;
|
|
114
|
+
}
|
|
115
|
+
/** Check applicability of model outputs */
|
|
116
|
+
function checkApplicability(ivp) {
|
|
117
|
+
const outputs = ivp.outputs;
|
|
118
|
+
if (outputs === null)
|
|
119
|
+
throw new Error('Model has no outputs');
|
|
120
|
+
const exprs = ivp.exprs;
|
|
121
|
+
if (exprs === null)
|
|
122
|
+
return;
|
|
123
|
+
if (ivp.loop !== null) {
|
|
124
|
+
if (exprsInOutputs(ivp))
|
|
125
|
+
throw new Error('Non-supported model: expressions in output & loops');
|
|
126
|
+
return;
|
|
127
|
+
}
|
|
128
|
+
if (ivp.updates !== null) {
|
|
129
|
+
if (exprsInOutputs(ivp))
|
|
130
|
+
throw new Error('Non-supported model: expressions in output and updates');
|
|
131
|
+
}
|
|
132
|
+
} // checkApplicability
|
|
133
|
+
/** Return a code for output extraction */
|
|
134
|
+
export function getOutputNames(ivp) {
|
|
135
|
+
const outputs = ivp.outputs;
|
|
136
|
+
if (outputs === null)
|
|
137
|
+
return [ivp.arg.name].concat(ivp.deqs.solutionNames);
|
|
138
|
+
const names = new Array(outputs.size);
|
|
139
|
+
let idx = 0;
|
|
140
|
+
outputs.forEach((output) => {
|
|
141
|
+
names[idx] = output.caption;
|
|
142
|
+
++idx;
|
|
143
|
+
});
|
|
144
|
+
return names;
|
|
145
|
+
} // getOutputNames
|
|
146
|
+
//# sourceMappingURL=output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AAC;AACH,CAAC,CAAC,qBAAqB;AAEvB,0CAA0C;AAC1C,MAAM,UAAU,cAAc,CAAC,GAAQ;IACrC,MAAM,OAAO,GAAG,GAAG,CAAC,OAAO,CAAC;IAC5B,IAAI,OAAO,KAAK,IAAI;QAClB,OAAO,CAAC,GAAG,CAAC,GAAG,CAAC,IAAI,CAAC,CAAC,MAAM,CAAC,GAAG,CAAC,IAAI,CAAC,aAAa,CAAC,CAAC;IAEvD,MAAM,KAAK,GAAG,IAAI,KAAK,CAAS,OAAO,CAAC,IAAI,CAAC,CAAC;IAE9C,IAAI,GAAG,GAAG,CAAC,CAAC;IACZ,OAAO,CAAC,OAAO,CAAC,CAAC,MAAM,EAAE,EAAE;QACzB,KAAK,CAAC,GAAG,CAAC,GAAG,MAAM,CAAC,OAAO,CAAC;QAC5B,EAAE,GAAG,CAAC;IACR,CAAC,CAAC,CAAC;IAEH,OAAO,KAAK,CAAC;AACf,CAAC,CAAC,iBAAiB"}
|
|
@@ -0,0 +1,196 @@
|
|
|
1
|
+
// Features for creating output code for a pipeline
|
|
2
|
+
|
|
3
|
+
import {IVP, MATH_CONSTS, POW_IDX, MATH_FUNCS} from '../scripting-tools/scripting-tools';
|
|
4
|
+
import {ARG_INP_COUNT} from './constants';
|
|
5
|
+
|
|
6
|
+
const SHIFT = 1;
|
|
7
|
+
|
|
8
|
+
/** Return output for the model WITHOUT expressions */
|
|
9
|
+
function getOutputNoExprs(ivp: IVP): string {
|
|
10
|
+
const outputs = ivp.outputs;
|
|
11
|
+
if (outputs === null)
|
|
12
|
+
throw new Error('Grok Lib issue: no outputs in the initial value problem');
|
|
13
|
+
|
|
14
|
+
if (exprsInOutputs(ivp))
|
|
15
|
+
throw new Error('Grok Lib issue: no expressions are allowed');
|
|
16
|
+
|
|
17
|
+
|
|
18
|
+
const lines: string[] = ['const solution = [];'];
|
|
19
|
+
|
|
20
|
+
outputs.forEach((_, name) => {
|
|
21
|
+
if (name === ivp.arg.name)
|
|
22
|
+
lines.push('solution.push(arguments[0][0]);');
|
|
23
|
+
else {
|
|
24
|
+
const idx = ivp.deqs.solutionNames.indexOf(name);
|
|
25
|
+
|
|
26
|
+
if (idx > -1)
|
|
27
|
+
lines.push(`solution.push(arguments[0][${idx + 1}]);`);
|
|
28
|
+
}
|
|
29
|
+
});
|
|
30
|
+
|
|
31
|
+
lines.push('return solution;');
|
|
32
|
+
|
|
33
|
+
return lines.join('\n');
|
|
34
|
+
} // getOutputNoExprs
|
|
35
|
+
|
|
36
|
+
/** Return output for the model WITH expressions */
|
|
37
|
+
function getOutputWithExprs(ivp: IVP): string {
|
|
38
|
+
const outputs = ivp.outputs;
|
|
39
|
+
if (outputs === null)
|
|
40
|
+
throw new Error('Grok Lib issue: no outputs in the initial value problem');
|
|
41
|
+
|
|
42
|
+
const exprs = ivp.exprs;
|
|
43
|
+
|
|
44
|
+
if (!exprsInOutputs(ivp) || (exprs === null))
|
|
45
|
+
throw new Error('Grok Lib issue: expressions must be given');
|
|
46
|
+
|
|
47
|
+
|
|
48
|
+
const argName = ivp.arg.name;
|
|
49
|
+
const lines: string[] = ['const solution = [];'];
|
|
50
|
+
|
|
51
|
+
// Used math funcs
|
|
52
|
+
ivp.usedMathFuncs.forEach((idx) => {
|
|
53
|
+
if (idx !== POW_IDX)
|
|
54
|
+
lines.push(`const ${MATH_FUNCS[idx]} = (x) => Math.${MATH_FUNCS[idx]}(x);`);
|
|
55
|
+
else
|
|
56
|
+
lines.push(`const pow = (x, y) => Math.pow(x, y);`);
|
|
57
|
+
});
|
|
58
|
+
|
|
59
|
+
// Used math consts
|
|
60
|
+
ivp.usedMathConsts.forEach((idx) => lines.push(`const ${MATH_CONSTS[idx]} = Math.${MATH_CONSTS[idx]};`));
|
|
61
|
+
|
|
62
|
+
// Model constants
|
|
63
|
+
if (ivp.consts !== null)
|
|
64
|
+
ivp.consts.forEach((input, name) => lines.push(`const ${name} = ${input.value};`));
|
|
65
|
+
|
|
66
|
+
// Model parameters
|
|
67
|
+
if (ivp.params !== null) {
|
|
68
|
+
let idx = ARG_INP_COUNT + ivp.deqs.solutionNames.length;
|
|
69
|
+
ivp.params.forEach((_, name) => {
|
|
70
|
+
lines.push(`const ${name} = arguments[1][${idx}];`);
|
|
71
|
+
++idx;
|
|
72
|
+
});
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
lines.push('');
|
|
76
|
+
|
|
77
|
+
lines.push('const length = arguments[0][0].length;');
|
|
78
|
+
const funcNames = ivp.deqs.solutionNames;
|
|
79
|
+
|
|
80
|
+
lines.push(`let ${argName} = 0;`);
|
|
81
|
+
funcNames.forEach((name) => lines.push(`let ${name} = 0;`));
|
|
82
|
+
|
|
83
|
+
lines.push('');
|
|
84
|
+
|
|
85
|
+
exprs.forEach((_, name) => {
|
|
86
|
+
lines.push(`let ${name} = 0;`);
|
|
87
|
+
|
|
88
|
+
if (outputs.has(name))
|
|
89
|
+
lines.push(`let ${name}Raw = new Float64Array(length);`);
|
|
90
|
+
});
|
|
91
|
+
|
|
92
|
+
lines.push('');
|
|
93
|
+
|
|
94
|
+
lines.push('for (let k = 0; k < length; ++k) {');
|
|
95
|
+
lines.push(` ${argName} = arguments[0][0][k];`);
|
|
96
|
+
funcNames.forEach((name, idx) => lines.push(` ${name} = arguments[0][${SHIFT + idx}][k];`));
|
|
97
|
+
lines.push('');
|
|
98
|
+
exprs.forEach((expr, name) => {
|
|
99
|
+
lines.push(` ${name} = ${expr};`);
|
|
100
|
+
|
|
101
|
+
if (outputs.has(name))
|
|
102
|
+
lines.push(` ${name}Raw[k] = ${name};`);
|
|
103
|
+
});
|
|
104
|
+
lines.push('}');
|
|
105
|
+
|
|
106
|
+
lines.push('');
|
|
107
|
+
|
|
108
|
+
outputs.forEach((_, name) => {
|
|
109
|
+
if (name === argName)
|
|
110
|
+
lines.push('solution.push(arguments[0][0]);');
|
|
111
|
+
else {
|
|
112
|
+
const idx = ivp.deqs.solutionNames.indexOf(name);
|
|
113
|
+
|
|
114
|
+
if (idx > -1)
|
|
115
|
+
lines.push(`solution.push(arguments[0][${idx + 1}]);`);
|
|
116
|
+
else if (exprs.has(name))
|
|
117
|
+
lines.push(`solution.push(${name}Raw);`);
|
|
118
|
+
}
|
|
119
|
+
});
|
|
120
|
+
|
|
121
|
+
lines.push('return solution;');
|
|
122
|
+
|
|
123
|
+
return lines.join('\n');
|
|
124
|
+
} // getOutputWithExprs
|
|
125
|
+
|
|
126
|
+
/** Return a code for output extraction */
|
|
127
|
+
export function getOutputCode(ivp: IVP): string | null {
|
|
128
|
+
const outputs = ivp.outputs;
|
|
129
|
+
if (outputs === null)
|
|
130
|
+
return null;
|
|
131
|
+
|
|
132
|
+
checkApplicability(ivp);
|
|
133
|
+
|
|
134
|
+
if (exprsInOutputs(ivp))
|
|
135
|
+
return getOutputWithExprs(ivp);
|
|
136
|
+
else
|
|
137
|
+
return getOutputNoExprs(ivp);
|
|
138
|
+
} // getOutputCode
|
|
139
|
+
|
|
140
|
+
/** Check whether outputs have items from expressions */
|
|
141
|
+
function exprsInOutputs(ivp: IVP): boolean {
|
|
142
|
+
const outputs = ivp.outputs;
|
|
143
|
+
if (outputs === null)
|
|
144
|
+
return false;
|
|
145
|
+
|
|
146
|
+
const exprs = ivp.exprs;
|
|
147
|
+
if (exprs === null)
|
|
148
|
+
return false;
|
|
149
|
+
|
|
150
|
+
let flag = false;
|
|
151
|
+
|
|
152
|
+
exprs.forEach((_, name) => flag ||= outputs.has(name));
|
|
153
|
+
|
|
154
|
+
return flag;
|
|
155
|
+
}
|
|
156
|
+
|
|
157
|
+
/** Check applicability of model outputs */
|
|
158
|
+
function checkApplicability(ivp: IVP): void {
|
|
159
|
+
const outputs = ivp.outputs;
|
|
160
|
+
|
|
161
|
+
if (outputs === null)
|
|
162
|
+
throw new Error('Model has no outputs');
|
|
163
|
+
|
|
164
|
+
const exprs = ivp.exprs;
|
|
165
|
+
if (exprs === null)
|
|
166
|
+
return;
|
|
167
|
+
|
|
168
|
+
if (ivp.loop !== null) {
|
|
169
|
+
if (exprsInOutputs(ivp))
|
|
170
|
+
throw new Error('Non-supported model: expressions in output & loops');
|
|
171
|
+
|
|
172
|
+
return;
|
|
173
|
+
}
|
|
174
|
+
|
|
175
|
+
if (ivp.updates !== null) {
|
|
176
|
+
if (exprsInOutputs(ivp))
|
|
177
|
+
throw new Error('Non-supported model: expressions in output and updates');
|
|
178
|
+
}
|
|
179
|
+
} // checkApplicability
|
|
180
|
+
|
|
181
|
+
/** Return a code for output extraction */
|
|
182
|
+
export function getOutputNames(ivp: IVP): string[] {
|
|
183
|
+
const outputs = ivp.outputs;
|
|
184
|
+
if (outputs === null)
|
|
185
|
+
return [ivp.arg.name].concat(ivp.deqs.solutionNames);
|
|
186
|
+
|
|
187
|
+
const names = new Array<string>(outputs.size);
|
|
188
|
+
|
|
189
|
+
let idx = 0;
|
|
190
|
+
outputs.forEach((output) => {
|
|
191
|
+
names[idx] = output.caption;
|
|
192
|
+
++idx;
|
|
193
|
+
});
|
|
194
|
+
|
|
195
|
+
return names;
|
|
196
|
+
} // getOutputNames
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { getOutputNames } from './output';
|
|
2
|
+
/** Creator of a pipeline for in-webworker computations */
|
|
3
|
+
export class PipelineCreator {
|
|
4
|
+
constructor(ivp) {
|
|
5
|
+
this.ivp = ivp;
|
|
6
|
+
this.outputNames = getOutputNames(ivp);
|
|
7
|
+
}
|
|
8
|
+
;
|
|
9
|
+
}
|
|
10
|
+
//# sourceMappingURL=pipeline-creator.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"pipeline-creator.js","sourceRoot":"","sources":["pipeline-creator.ts"],"names":[],"mappings":"AACA,OAAO,EAAC,cAAc,EAAC,MAAM,UAAU,CAAC;AAGxC,0DAA0D;AAC1D,MAAM,OAAgB,eAAe;IAInC,YAAY,GAAQ;QAClB,IAAI,CAAC,GAAG,GAAG,GAAG,CAAC;QACf,IAAI,CAAC,WAAW,GAAG,cAAc,CAAC,GAAG,CAAC,CAAC;IACzC,CAAC;IAAA,CAAC;CAGH"}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import {IVP} from '../scripting-tools';
|
|
2
|
+
import {getOutputNames} from './output';
|
|
3
|
+
import {Pipeline} from './pipeline';
|
|
4
|
+
|
|
5
|
+
/** Creator of a pipeline for in-webworker computations */
|
|
6
|
+
export abstract class PipelineCreator {
|
|
7
|
+
protected ivp: IVP;
|
|
8
|
+
protected outputNames: string[];
|
|
9
|
+
|
|
10
|
+
constructor(ivp: IVP) {
|
|
11
|
+
this.ivp = ivp;
|
|
12
|
+
this.outputNames = getOutputNames(ivp);
|
|
13
|
+
};
|
|
14
|
+
|
|
15
|
+
public abstract getPipeline(inputs: Float64Array): Pipeline;
|
|
16
|
+
}
|
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
import { solveIvp } from '../worker-tools';
|
|
2
|
+
import { BasicModelPipelineCreator } from './basic-pipeline-creator';
|
|
3
|
+
import { UpdatesModelPipelineCreator } from './updates-pipeline-creator';
|
|
4
|
+
import { CyclicModelPipelineCreator } from './loops-pipeline-creator';
|
|
5
|
+
/** Return concatenated arrays */
|
|
6
|
+
function concat(arr1, arr2) {
|
|
7
|
+
const result = new Float64Array(arr1.length + arr2.length);
|
|
8
|
+
result.set(arr1, 0);
|
|
9
|
+
result.set(arr2, arr1.length);
|
|
10
|
+
return result;
|
|
11
|
+
}
|
|
12
|
+
/** Apply pipeline to initial value problem with the source inputs, and return a solution */
|
|
13
|
+
export function applyPipeline(pipeline, ivp, sourceInputs) {
|
|
14
|
+
let solution = [];
|
|
15
|
+
let currentSolution;
|
|
16
|
+
let func;
|
|
17
|
+
let inputs = new Float64Array(sourceInputs);
|
|
18
|
+
const wrappers = pipeline.wrappers;
|
|
19
|
+
let step;
|
|
20
|
+
let isFirstSolverCall = true;
|
|
21
|
+
const stepsCount = wrappers.length;
|
|
22
|
+
if (stepsCount < 1)
|
|
23
|
+
throw new Error(`Incorrect solution pipeline: ${stepsCount} steps.`);
|
|
24
|
+
// Perform pipeline steps
|
|
25
|
+
for (let idx = 0; idx < stepsCount; ++idx) {
|
|
26
|
+
step = wrappers[idx];
|
|
27
|
+
// Pre-processing
|
|
28
|
+
if (step.preproc !== null) {
|
|
29
|
+
func = new Function(step.preproc);
|
|
30
|
+
inputs = func(solution, inputs);
|
|
31
|
+
//console.log('Pre');
|
|
32
|
+
}
|
|
33
|
+
//console.log(inputs);
|
|
34
|
+
// Solving a problem
|
|
35
|
+
currentSolution = solveIvp(ivp, inputs);
|
|
36
|
+
// Output from solution
|
|
37
|
+
if (step.out !== null) {
|
|
38
|
+
func = new Function(step.out);
|
|
39
|
+
currentSolution = func(currentSolution, inputs);
|
|
40
|
+
}
|
|
41
|
+
if (isFirstSolverCall) {
|
|
42
|
+
solution = currentSolution;
|
|
43
|
+
isFirstSolverCall = false;
|
|
44
|
+
}
|
|
45
|
+
else
|
|
46
|
+
currentSolution.forEach((arr, kdx) => solution[kdx] = concat(solution[kdx], arr));
|
|
47
|
+
// Post-processing
|
|
48
|
+
if (step.postproc !== null) {
|
|
49
|
+
func = new Function(step.postproc);
|
|
50
|
+
inputs = func(solution, inputs);
|
|
51
|
+
//console.log('Pro');
|
|
52
|
+
}
|
|
53
|
+
//console.log(inputs);
|
|
54
|
+
}
|
|
55
|
+
// Compute final output
|
|
56
|
+
const out = pipeline.out;
|
|
57
|
+
if (out !== null) {
|
|
58
|
+
func = new Function(out);
|
|
59
|
+
return func(solution, sourceInputs);
|
|
60
|
+
}
|
|
61
|
+
return solution;
|
|
62
|
+
} // performPipeline
|
|
63
|
+
/** Return pipeline creator specified by the initial value problem */
|
|
64
|
+
export function getPipelineCreator(ivp) {
|
|
65
|
+
if (ivp.updates !== null)
|
|
66
|
+
return new UpdatesModelPipelineCreator(ivp);
|
|
67
|
+
if (ivp.loop !== null)
|
|
68
|
+
return new CyclicModelPipelineCreator(ivp);
|
|
69
|
+
return new BasicModelPipelineCreator(ivp);
|
|
70
|
+
}
|
|
71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