@sdeverywhere/runtime 0.2.10 → 0.2.11
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/dist/index.d.ts +888 -864
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +2152 -2344
- package/dist/index.js.map +1 -1
- package/package.json +3 -5
- package/dist/index.cjs +0 -2490
- package/dist/index.cjs.map +0 -1
- package/dist/index.d.cts +0 -1224
package/dist/index.d.ts
CHANGED
|
@@ -1,81 +1,82 @@
|
|
|
1
|
-
import { Result } from
|
|
2
|
-
|
|
1
|
+
import { Result } from "neverthrow";
|
|
2
|
+
//#region src/_shared/types.d.ts
|
|
3
3
|
/** The name of a data source for external/static datasets, e.g., 'Ref', 'Constants'. */
|
|
4
|
-
type SourceName = string;
|
|
4
|
+
export type SourceName = string;
|
|
5
5
|
/** A variable name, as used in the modeling tool. */
|
|
6
|
-
type VarName = string;
|
|
6
|
+
export type VarName = string;
|
|
7
7
|
/** A variable identifier, as used in model code generated by SDEverywhere. */
|
|
8
|
-
type VarId = string;
|
|
8
|
+
export type VarId = string;
|
|
9
9
|
/** An input variable identifier, as used in model code generated by SDEverywhere. */
|
|
10
|
-
type InputVarId = string;
|
|
10
|
+
export type InputVarId = string;
|
|
11
11
|
/** An output variable identifier, as used in model code generated by SDEverywhere. */
|
|
12
|
-
type OutputVarId = string;
|
|
12
|
+
export type OutputVarId = string;
|
|
13
13
|
/**
|
|
14
14
|
* The variable index metadata that is used to identify a specific instance of a
|
|
15
15
|
* variable in a generated model.
|
|
16
16
|
*
|
|
17
17
|
* @hidden This is not yet part of the public API.
|
|
18
18
|
*/
|
|
19
|
-
interface VarSpec {
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
19
|
+
export interface VarSpec {
|
|
20
|
+
/** The variable index as used in the generated C/JS code. */
|
|
21
|
+
varIndex: number;
|
|
22
|
+
/** The subscript index values as used in the generated C/JS code. */
|
|
23
|
+
subscriptIndices?: number[] | Int32Array;
|
|
24
24
|
}
|
|
25
25
|
/**
|
|
26
26
|
* A reference to a variable in the generated model. A variable can be identified
|
|
27
27
|
* using either a `VarName` (the variable name, as used in the modeling tool) or a
|
|
28
28
|
* `VarId` (the variable identifier, as used in model code generated by SDEverywhere).
|
|
29
29
|
*/
|
|
30
|
-
interface VarRef {
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
30
|
+
export interface VarRef {
|
|
31
|
+
/**
|
|
32
|
+
* The name of the variable, as used in the modeling tool. If defined, the implementation
|
|
33
|
+
* will use this to identify the variable, and will ignore the `varId` property.
|
|
34
|
+
*/
|
|
35
|
+
varName?: VarName;
|
|
36
|
+
/**
|
|
37
|
+
* The identifier of the variable, as used in model code generated by SDEverywhere. If
|
|
38
|
+
* defined, the implementation will use this to identify the variable, and will ignore
|
|
39
|
+
* the `varName` property.
|
|
40
|
+
*/
|
|
41
|
+
varId?: VarId;
|
|
42
|
+
/**
|
|
43
|
+
* The low-level spec for the variable to be modified. If defined, the implementation
|
|
44
|
+
* will use this identify the variable. If it is undefined, the implementation will
|
|
45
|
+
* use the `varId` or `varName` to identify the variable, and may use this property
|
|
46
|
+
* to cache the resulting `VarSpec` in this property for performance reasons.
|
|
47
|
+
*
|
|
48
|
+
* @hidden This is not yet part of the public API.
|
|
49
|
+
*/
|
|
50
|
+
varSpec?: VarSpec;
|
|
51
51
|
}
|
|
52
52
|
/** A data point. */
|
|
53
|
-
interface Point {
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
53
|
+
export interface Point {
|
|
54
|
+
/** The x value (typically a time value). */
|
|
55
|
+
x: number;
|
|
56
|
+
/** The y value. */
|
|
57
|
+
y: number;
|
|
58
58
|
}
|
|
59
|
-
|
|
59
|
+
//#endregion
|
|
60
|
+
//#region src/_shared/inputs.d.ts
|
|
60
61
|
/** Callback functions that are called when the input value is changed. */
|
|
61
|
-
interface InputCallbacks {
|
|
62
|
-
|
|
63
|
-
|
|
62
|
+
export interface InputCallbacks {
|
|
63
|
+
/** Called after a new value is set. */
|
|
64
|
+
onSet?: () => void;
|
|
64
65
|
}
|
|
65
66
|
/**
|
|
66
67
|
* Represents a writable model input.
|
|
67
68
|
*/
|
|
68
|
-
interface InputValue {
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
69
|
+
export interface InputValue {
|
|
70
|
+
/** The ID of the associated input variable, as used in SDEverywhere. */
|
|
71
|
+
varId: InputVarId;
|
|
72
|
+
/** Get the current value of the input. */
|
|
73
|
+
get: () => number;
|
|
74
|
+
/** Set the input to the given value. */
|
|
75
|
+
set: (value: number) => void;
|
|
76
|
+
/** Reset the input to its default value. */
|
|
77
|
+
reset: () => void;
|
|
78
|
+
/** Callback functions that are called when the input value is changed. */
|
|
79
|
+
callbacks: InputCallbacks;
|
|
79
80
|
}
|
|
80
81
|
/**
|
|
81
82
|
* Create a basic `InputValue` instance that notifies when a new value is set.
|
|
@@ -84,110 +85,112 @@ interface InputValue {
|
|
|
84
85
|
* @param defaultValue The default value of the input.
|
|
85
86
|
* @param initialValue The inital value of the input; if undefined, will use `defaultValue`.
|
|
86
87
|
*/
|
|
87
|
-
declare function createInputValue(varId: InputVarId, defaultValue: number, initialValue?: number): InputValue;
|
|
88
|
-
|
|
88
|
+
export declare function createInputValue(varId: InputVarId, defaultValue: number, initialValue?: number): InputValue;
|
|
89
|
+
//#endregion
|
|
90
|
+
//#region src/_shared/outputs.d.ts
|
|
89
91
|
/** Indicates the type of error encountered when parsing an outputs buffer. */
|
|
90
|
-
type ParseError = 'invalid-point-count';
|
|
92
|
+
export type ParseError = 'invalid-point-count';
|
|
91
93
|
/** Type alias for a map that holds a `Series` instance for each output (or static) variable ID. */
|
|
92
|
-
type SeriesMap = Map<OutputVarId, Series>;
|
|
94
|
+
export type SeriesMap = Map<OutputVarId, Series>;
|
|
93
95
|
/** Type alias for a map that holds data for a given source name. */
|
|
94
|
-
type DataMap = Map<SourceName, SeriesMap>;
|
|
96
|
+
export type DataMap = Map<SourceName, SeriesMap>;
|
|
95
97
|
/**
|
|
96
98
|
* A time series of data points for an output variable.
|
|
97
99
|
*/
|
|
98
|
-
declare class Series {
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
100
|
+
export declare class Series {
|
|
101
|
+
readonly varId: OutputVarId;
|
|
102
|
+
readonly points: Point[];
|
|
103
|
+
/**
|
|
104
|
+
* @param varId The ID for the output variable (as used by SDEverywhere).
|
|
105
|
+
* @param points The data points for the variable, one point per time increment.
|
|
106
|
+
*/
|
|
107
|
+
constructor(varId: OutputVarId, points: Point[]);
|
|
108
|
+
/**
|
|
109
|
+
* Return the Y value at the given time. Note that this does not attempt to interpolate
|
|
110
|
+
* if there is no data point defined for the given time and will return undefined in
|
|
111
|
+
* that case.
|
|
112
|
+
*
|
|
113
|
+
* @param time The x (time) value.
|
|
114
|
+
* @return The y value for the given time, or undefined if there is no data point defined
|
|
115
|
+
* for the given time.
|
|
116
|
+
*/
|
|
117
|
+
getValueAtTime(time: number): number | undefined;
|
|
118
|
+
/**
|
|
119
|
+
* Create a new `Series` instance that is a copy of this one.
|
|
120
|
+
*/
|
|
121
|
+
copy(): Series;
|
|
120
122
|
}
|
|
121
123
|
/** Represents the outputs from a model run. */
|
|
122
|
-
declare class Outputs {
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
124
|
+
export declare class Outputs {
|
|
125
|
+
readonly varIds: OutputVarId[];
|
|
126
|
+
readonly startTime: number;
|
|
127
|
+
readonly endTime: number;
|
|
128
|
+
readonly saveFreq: number;
|
|
129
|
+
/** The number of data points in each series. */
|
|
130
|
+
readonly seriesLength: number;
|
|
131
|
+
/** The array of series, one for each output variable. */
|
|
132
|
+
readonly varSeries: Series[];
|
|
133
|
+
/**
|
|
134
|
+
* The latest model run time, in milliseconds.
|
|
135
|
+
* @hidden This is not yet part of the public API; it is exposed here for use
|
|
136
|
+
* in performance testing tools.
|
|
137
|
+
*/
|
|
138
|
+
runTimeInMillis: number;
|
|
139
|
+
/**
|
|
140
|
+
* The optional set of specs that dictate which variables from the model will be
|
|
141
|
+
* stored in this `Outputs` instance. If undefined, the default set of outputs
|
|
142
|
+
* will be stored (as configured in `varIds`).
|
|
143
|
+
* @hidden This is not yet part of the public API; it is exposed here for use
|
|
144
|
+
* in experimental testing tools.
|
|
145
|
+
*/
|
|
146
|
+
varSpecs?: VarSpec[];
|
|
147
|
+
/**
|
|
148
|
+
* @param varIds The output variable identifiers.
|
|
149
|
+
* @param startTime The start time for the model.
|
|
150
|
+
* @param endTime The end time for the model.
|
|
151
|
+
* @param saveFreq The frequency with which output values are saved (aka `SAVEPER`).
|
|
152
|
+
*/
|
|
153
|
+
constructor(varIds: OutputVarId[], startTime: number, endTime: number, saveFreq?: number);
|
|
154
|
+
/**
|
|
155
|
+
* The optional set of specs that dictate which variables from the model will be
|
|
156
|
+
* stored in this `Outputs` instance. If undefined, the default set of outputs
|
|
157
|
+
* will be stored (as configured in `varIds`).
|
|
158
|
+
* @hidden This is not yet part of the public API; it is exposed here for use
|
|
159
|
+
* in experimental testing tools.
|
|
160
|
+
*/
|
|
161
|
+
setVarSpecs(varSpecs: VarSpec[]): void;
|
|
162
|
+
/**
|
|
163
|
+
* Parse the given raw float buffer (produced by the model) and store the values
|
|
164
|
+
* into this `Outputs` instance.
|
|
165
|
+
*
|
|
166
|
+
* Note that the length of `outputsBuffer` must be greater than or equal to
|
|
167
|
+
* the capacity of this `Outputs` instance. The `Outputs` instance is allowed
|
|
168
|
+
* to be smaller to support the case where you want to extract a subset of
|
|
169
|
+
* the time range in the buffer produced by the model.
|
|
170
|
+
*
|
|
171
|
+
* @param outputsBuffer The raw outputs buffer produced by the model.
|
|
172
|
+
* @param rowLength The number of elements per row (one element per save point).
|
|
173
|
+
* @return An `ok` result if the buffer is valid, otherwise an `err` result.
|
|
174
|
+
*/
|
|
175
|
+
updateFromBuffer(outputsBuffer: Float64Array, rowLength: number): Result<void, ParseError>;
|
|
176
|
+
/**
|
|
177
|
+
* Return the series for the given output variable.
|
|
178
|
+
*
|
|
179
|
+
* @param varId The ID of the output variable (as used by SDEverywhere).
|
|
180
|
+
*/
|
|
181
|
+
getSeriesForVar(varId: OutputVarId): Series | undefined;
|
|
180
182
|
}
|
|
181
|
-
|
|
183
|
+
//#endregion
|
|
184
|
+
//#region src/_shared/constant-def.d.ts
|
|
182
185
|
/**
|
|
183
186
|
* Specifies the constant value that will be used to override a constant in a
|
|
184
187
|
* generated model.
|
|
185
188
|
*/
|
|
186
|
-
interface ConstantDef {
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
189
|
+
export interface ConstantDef {
|
|
190
|
+
/** The reference that identifies the constant variable to be modified. */
|
|
191
|
+
varRef: VarRef;
|
|
192
|
+
/** The new constant value. */
|
|
193
|
+
value: number;
|
|
191
194
|
}
|
|
192
195
|
/**
|
|
193
196
|
* Create a `ConstantDef` instance.
|
|
@@ -195,16 +198,17 @@ interface ConstantDef {
|
|
|
195
198
|
* @param varRef The reference to the constant variable to be modified.
|
|
196
199
|
* @param value The new constant value.
|
|
197
200
|
*/
|
|
198
|
-
declare function createConstantDef(varRef: VarRef, value: number): ConstantDef;
|
|
199
|
-
|
|
201
|
+
export declare function createConstantDef(varRef: VarRef, value: number): ConstantDef;
|
|
202
|
+
//#endregion
|
|
203
|
+
//#region src/_shared/lookup-def.d.ts
|
|
200
204
|
/**
|
|
201
205
|
* Specifies the data that will be used to set or override a lookup definition.
|
|
202
206
|
*/
|
|
203
|
-
interface LookupDef {
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
207
|
+
export interface LookupDef {
|
|
208
|
+
/** The reference that identifies the lookup or data variable to be modified. */
|
|
209
|
+
varRef: VarRef;
|
|
210
|
+
/** The lookup data as a flat array of (x,y) pairs. */
|
|
211
|
+
points?: Float64Array;
|
|
208
212
|
}
|
|
209
213
|
/**
|
|
210
214
|
* Create a `LookupDef` instance from the given array of `Point` objects.
|
|
@@ -213,8 +217,9 @@ interface LookupDef {
|
|
|
213
217
|
* @param points The lookup data as an array of `Point` objects. This can be
|
|
214
218
|
* undefined, in which case the lookup data will be reset to the original data.
|
|
215
219
|
*/
|
|
216
|
-
declare function createLookupDef(varRef: VarRef, points: Point[] | undefined): LookupDef;
|
|
217
|
-
|
|
220
|
+
export declare function createLookupDef(varRef: VarRef, points: Point[] | undefined): LookupDef;
|
|
221
|
+
//#endregion
|
|
222
|
+
//#region src/_shared/var-indices.d.ts
|
|
218
223
|
/**
|
|
219
224
|
* Return the length of the array that is required to store the variable
|
|
220
225
|
* indices for the given `VarSpec` instances.
|
|
@@ -224,7 +229,7 @@ declare function createLookupDef(varRef: VarRef, points: Point[] | undefined): L
|
|
|
224
229
|
*
|
|
225
230
|
* @param varSpecs The `VarSpec` instances to encode.
|
|
226
231
|
*/
|
|
227
|
-
declare function getEncodedVarIndicesLength(varSpecs: VarSpec[]): number;
|
|
232
|
+
export declare function getEncodedVarIndicesLength(varSpecs: VarSpec[]): number;
|
|
228
233
|
/**
|
|
229
234
|
* Encode variable indices to the given array.
|
|
230
235
|
*
|
|
@@ -233,7 +238,7 @@ declare function getEncodedVarIndicesLength(varSpecs: VarSpec[]): number;
|
|
|
233
238
|
*
|
|
234
239
|
* @param varSpecs The `VarSpec` instances to encode.
|
|
235
240
|
*/
|
|
236
|
-
declare function encodeVarIndices(varSpecs: VarSpec[], indicesArray: Int32Array): void;
|
|
241
|
+
export declare function encodeVarIndices(varSpecs: VarSpec[], indicesArray: Int32Array): void;
|
|
237
242
|
/**
|
|
238
243
|
* Return the lengths of the arrays that are required to store the constant values
|
|
239
244
|
* and indices for the given `ConstantDef` instances.
|
|
@@ -243,9 +248,9 @@ declare function encodeVarIndices(varSpecs: VarSpec[], indicesArray: Int32Array)
|
|
|
243
248
|
*
|
|
244
249
|
* @param constantDefs The `ConstantDef` instances to encode.
|
|
245
250
|
*/
|
|
246
|
-
declare function getEncodedConstantBufferLengths(constantDefs: ConstantDef[]): {
|
|
247
|
-
|
|
248
|
-
|
|
251
|
+
export declare function getEncodedConstantBufferLengths(constantDefs: ConstantDef[]): {
|
|
252
|
+
constantIndicesLength: number;
|
|
253
|
+
constantsLength: number;
|
|
249
254
|
};
|
|
250
255
|
/**
|
|
251
256
|
* Encode constant values and indices to the given arrays.
|
|
@@ -257,7 +262,7 @@ declare function getEncodedConstantBufferLengths(constantDefs: ConstantDef[]): {
|
|
|
257
262
|
* @param constantIndicesArray The view on the constant indices buffer.
|
|
258
263
|
* @param constantsArray The view on the constant values buffer.
|
|
259
264
|
*/
|
|
260
|
-
declare function encodeConstants(constantDefs: ConstantDef[], constantIndicesArray: Int32Array, constantsArray: Float64Array): void;
|
|
265
|
+
export declare function encodeConstants(constantDefs: ConstantDef[], constantIndicesArray: Int32Array, constantsArray: Float64Array): void;
|
|
261
266
|
/**
|
|
262
267
|
* Decode constant values and indices from the given buffer views and return the
|
|
263
268
|
* reconstructed `ConstantDef` instances.
|
|
@@ -268,7 +273,7 @@ declare function encodeConstants(constantDefs: ConstantDef[], constantIndicesArr
|
|
|
268
273
|
* @param constantIndicesArray The view on the constant indices buffer.
|
|
269
274
|
* @param constantsArray The view on the constant values buffer.
|
|
270
275
|
*/
|
|
271
|
-
declare function decodeConstants(constantIndicesArray: Int32Array, constantsArray: Float64Array): ConstantDef[];
|
|
276
|
+
export declare function decodeConstants(constantIndicesArray: Int32Array, constantsArray: Float64Array): ConstantDef[];
|
|
272
277
|
/**
|
|
273
278
|
* Return the lengths of the arrays that are required to store the lookup data
|
|
274
279
|
* and indices for the given `LookupDef` instances.
|
|
@@ -278,9 +283,9 @@ declare function decodeConstants(constantIndicesArray: Int32Array, constantsArra
|
|
|
278
283
|
*
|
|
279
284
|
* @param lookupDefs The `LookupDef` instances to encode.
|
|
280
285
|
*/
|
|
281
|
-
declare function getEncodedLookupBufferLengths(lookupDefs: LookupDef[]): {
|
|
282
|
-
|
|
283
|
-
|
|
286
|
+
export declare function getEncodedLookupBufferLengths(lookupDefs: LookupDef[]): {
|
|
287
|
+
lookupIndicesLength: number;
|
|
288
|
+
lookupsLength: number;
|
|
284
289
|
};
|
|
285
290
|
/**
|
|
286
291
|
* Encode lookup data and indices to the given arrays.
|
|
@@ -293,7 +298,7 @@ declare function getEncodedLookupBufferLengths(lookupDefs: LookupDef[]): {
|
|
|
293
298
|
* @param lookupsArray The view on the lookup data buffer. This can be undefined in
|
|
294
299
|
* the case where the data for the lookup(s) is empty.
|
|
295
300
|
*/
|
|
296
|
-
declare function encodeLookups(lookupDefs: LookupDef[], lookupIndicesArray: Int32Array, lookupsArray: Float64Array | undefined): void;
|
|
301
|
+
export declare function encodeLookups(lookupDefs: LookupDef[], lookupIndicesArray: Int32Array, lookupsArray: Float64Array | undefined): void;
|
|
297
302
|
/**
|
|
298
303
|
* Decode lookup data and indices from the given buffer views and return the
|
|
299
304
|
* reconstructed `LookupDef` instances.
|
|
@@ -305,8 +310,9 @@ declare function encodeLookups(lookupDefs: LookupDef[], lookupIndicesArray: Int3
|
|
|
305
310
|
* @param lookupsArray The view on the lookup data buffer. This can be undefined in
|
|
306
311
|
* the case where the data for the lookup(s) is empty.
|
|
307
312
|
*/
|
|
308
|
-
declare function decodeLookups(lookupIndicesArray: Int32Array, lookupsArray: Float64Array | undefined): LookupDef[];
|
|
309
|
-
|
|
313
|
+
export declare function decodeLookups(lookupIndicesArray: Int32Array, lookupsArray: Float64Array | undefined): LookupDef[];
|
|
314
|
+
//#endregion
|
|
315
|
+
//#region src/model-listing/model-listing.d.ts
|
|
310
316
|
type SubscriptId = string;
|
|
311
317
|
type DimensionId = string;
|
|
312
318
|
/**
|
|
@@ -316,159 +322,162 @@ type DimensionId = string;
|
|
|
316
322
|
* @hidden This is not yet part of the public API; it is exposed here for
|
|
317
323
|
* internal use only.
|
|
318
324
|
*/
|
|
319
|
-
interface ModelListingSpecs {
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
325
|
+
export interface ModelListingSpecs {
|
|
326
|
+
dimensions: {
|
|
327
|
+
id: DimensionId;
|
|
328
|
+
subIds: SubscriptId[];
|
|
329
|
+
}[];
|
|
330
|
+
variables: {
|
|
331
|
+
id: VarId;
|
|
332
|
+
index: number;
|
|
333
|
+
dimIds?: DimensionId[];
|
|
334
|
+
}[];
|
|
329
335
|
}
|
|
330
336
|
/**
|
|
331
337
|
* @hidden This is not yet part of the public API; it is exposed here for use
|
|
332
338
|
* in experimental testing tools.
|
|
333
339
|
*/
|
|
334
|
-
declare class ModelListing {
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
340
|
+
export declare class ModelListing {
|
|
341
|
+
readonly varSpecs: Map<VarId, VarSpec>;
|
|
342
|
+
constructor(listingObj: ModelListingSpecs);
|
|
343
|
+
/**
|
|
344
|
+
* Return the `VarSpec` for the given variable ID, or undefined if there is no spec defined
|
|
345
|
+
* in the listing for that variable.
|
|
346
|
+
*/
|
|
347
|
+
getSpecForVarId(varId: VarId): VarSpec | undefined;
|
|
348
|
+
/**
|
|
349
|
+
* Return the `VarSpec` for the given variable name, or undefined if there is no spec defined
|
|
350
|
+
* in the listing for that variable.
|
|
351
|
+
*/
|
|
352
|
+
getSpecForVarName(varName: VarName): VarSpec | undefined;
|
|
353
|
+
/**
|
|
354
|
+
* Create a new `Outputs` instance that uses the same start/end years as the given "normal"
|
|
355
|
+
* `Outputs` instance but is prepared for reading the specified internal variables from the model.
|
|
356
|
+
*
|
|
357
|
+
* @param normalOutputs The `Outputs` that is used to access normal output variables from the model.
|
|
358
|
+
* @param varIds The variable IDs to include with the new `Outputs` instance.
|
|
359
|
+
*/
|
|
360
|
+
deriveOutputs(normalOutputs: Outputs, varIds: OutputVarId[]): Outputs;
|
|
355
361
|
}
|
|
356
|
-
|
|
362
|
+
//#endregion
|
|
363
|
+
//#region src/runnable-model/run-model-options.d.ts
|
|
357
364
|
/**
|
|
358
365
|
* Additional options that can be passed to a `runModel` call to influence the model run.
|
|
359
366
|
*/
|
|
360
|
-
interface RunModelOptions {
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
|
|
367
|
+
export interface RunModelOptions {
|
|
368
|
+
/**
|
|
369
|
+
* If defined, override the values for the specified constant variables.
|
|
370
|
+
*
|
|
371
|
+
* Note that constant overrides do not persist after the `runModel` call. Because
|
|
372
|
+
* `initConstants` is called at the beginning of each `runModel` call, all constants
|
|
373
|
+
* are reset to their default values before each model run. If you want to override
|
|
374
|
+
* constants, you must provide them in the options for each `runModel` call. To
|
|
375
|
+
* reset constants to their original values, simply stop passing them in the options
|
|
376
|
+
* (or pass an empty array).
|
|
377
|
+
*/
|
|
378
|
+
constants?: ConstantDef[];
|
|
379
|
+
/**
|
|
380
|
+
* If defined, override the data for the specified lookups and/or data variables.
|
|
381
|
+
*
|
|
382
|
+
* If data was already defined in the generated model, the data provided in a
|
|
383
|
+
* `LookupDef` here will override the default data in the generated model.
|
|
384
|
+
*
|
|
385
|
+
* Note that unlike the `inputs` parameter for `runModel` (which must be provided
|
|
386
|
+
* with each call), the data overrides provided here persist after the `runModel`
|
|
387
|
+
* call. If you pass `lookups` in your Nth `runModel` call, that lookup data will
|
|
388
|
+
* still be in effect for the (N+1)th call. In other words, if your lookup data
|
|
389
|
+
* is not changing, you do not need to supply it with every `runModel` call.
|
|
390
|
+
*/
|
|
391
|
+
lookups?: LookupDef[];
|
|
385
392
|
}
|
|
386
|
-
|
|
393
|
+
//#endregion
|
|
394
|
+
//#region src/runnable-model/run-model-params.d.ts
|
|
387
395
|
/**
|
|
388
396
|
* Encapsulates the parameters that are passed to a `runModel` call.
|
|
389
397
|
*
|
|
390
398
|
* @hidden This is not yet exposed in the public API; it is currently only used by
|
|
391
399
|
* the implementations of the `RunnableModel` interface.
|
|
392
400
|
*/
|
|
393
|
-
interface RunModelParams {
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
|
|
404
|
-
|
|
405
|
-
|
|
406
|
-
|
|
407
|
-
|
|
408
|
-
|
|
409
|
-
|
|
410
|
-
|
|
411
|
-
|
|
412
|
-
|
|
413
|
-
|
|
414
|
-
|
|
415
|
-
|
|
416
|
-
|
|
417
|
-
|
|
418
|
-
|
|
419
|
-
|
|
420
|
-
|
|
421
|
-
|
|
422
|
-
|
|
423
|
-
|
|
424
|
-
|
|
425
|
-
|
|
426
|
-
|
|
427
|
-
|
|
428
|
-
|
|
429
|
-
|
|
430
|
-
|
|
431
|
-
|
|
432
|
-
|
|
433
|
-
|
|
434
|
-
|
|
435
|
-
|
|
436
|
-
|
|
437
|
-
|
|
438
|
-
|
|
439
|
-
|
|
440
|
-
|
|
441
|
-
|
|
442
|
-
|
|
443
|
-
|
|
444
|
-
|
|
445
|
-
|
|
446
|
-
|
|
447
|
-
|
|
448
|
-
|
|
449
|
-
|
|
450
|
-
|
|
451
|
-
|
|
452
|
-
|
|
453
|
-
|
|
454
|
-
|
|
455
|
-
|
|
456
|
-
|
|
457
|
-
|
|
458
|
-
|
|
459
|
-
|
|
460
|
-
|
|
461
|
-
|
|
462
|
-
|
|
463
|
-
|
|
464
|
-
|
|
465
|
-
|
|
466
|
-
|
|
467
|
-
|
|
468
|
-
|
|
469
|
-
|
|
401
|
+
export interface RunModelParams {
|
|
402
|
+
/**
|
|
403
|
+
* Return the array containing the inputs, or undefined if the implementation does not
|
|
404
|
+
* have the inputs readily available in an array. If this returns undefined, use
|
|
405
|
+
* `copyInputs` to copy the inputs into a provided array.
|
|
406
|
+
*/
|
|
407
|
+
getInputs(): Float64Array | undefined;
|
|
408
|
+
/**
|
|
409
|
+
* Copy the input values into an array.
|
|
410
|
+
*
|
|
411
|
+
* @param array An existing array, or undefined. If `array` is undefined, or it is
|
|
412
|
+
* not large enough to hold the input values, the `create` function will be called
|
|
413
|
+
* to allocate a new array.
|
|
414
|
+
* @param create A function that allocates a new `Float64Array` with the given length.
|
|
415
|
+
*/
|
|
416
|
+
copyInputs(array: Float64Array | undefined, create: (numElements: number) => Float64Array): void;
|
|
417
|
+
/**
|
|
418
|
+
* Return the length (in elements) of the output indices array, or 0 if the indices are
|
|
419
|
+
* not active (i.e., if they were not included in the latest `runModel` call).
|
|
420
|
+
*/
|
|
421
|
+
getOutputIndicesLength(): number;
|
|
422
|
+
/**
|
|
423
|
+
* Return the array containing the output indices, or undefined if the implementation does not
|
|
424
|
+
* have the output indices readily available in an array. If this returns undefined, use
|
|
425
|
+
* `copyOutputIndices` to copy the output indices into a provided array.
|
|
426
|
+
*/
|
|
427
|
+
getOutputIndices(): Int32Array | undefined;
|
|
428
|
+
/**
|
|
429
|
+
* Copy the output indices into an array.
|
|
430
|
+
*
|
|
431
|
+
* @param array An existing array, or undefined. If `array` is undefined, or it is
|
|
432
|
+
* not large enough to hold the input values, the `create` function will be called
|
|
433
|
+
* to allocate a new array.
|
|
434
|
+
* @param create A function that allocates a new `Int32Array` with the given length.
|
|
435
|
+
*/
|
|
436
|
+
copyOutputIndices(array: Int32Array | undefined, create: (numElements: number) => Int32Array): void;
|
|
437
|
+
/**
|
|
438
|
+
* Return the length (in elements) of the array that will receive the outputs.
|
|
439
|
+
*/
|
|
440
|
+
getOutputsLength(): number;
|
|
441
|
+
/**
|
|
442
|
+
* Return the array containing the outputs, or undefined if the implementation does not
|
|
443
|
+
* have an array available for writing the outputs.
|
|
444
|
+
*/
|
|
445
|
+
getOutputs(): Float64Array | undefined;
|
|
446
|
+
/**
|
|
447
|
+
* Return the `Outputs` object, or undefined if the implementation does not keep a reference
|
|
448
|
+
* to the `Outputs` object that was passed to `runModel`.
|
|
449
|
+
*/
|
|
450
|
+
getOutputsObject(): Outputs | undefined;
|
|
451
|
+
/**
|
|
452
|
+
* Store the output values that were written by the model. This will be used to populate
|
|
453
|
+
* the `Outputs` object that was passed to the latest `runModel` call.
|
|
454
|
+
*
|
|
455
|
+
* @param array The array that contains the output values.
|
|
456
|
+
*/
|
|
457
|
+
storeOutputs(array: Float64Array): void;
|
|
458
|
+
/**
|
|
459
|
+
* Return an array containing constant overrides, or undefined if no constants were passed
|
|
460
|
+
* to the latest `runModel` call.
|
|
461
|
+
*/
|
|
462
|
+
getConstants(): ConstantDef[] | undefined;
|
|
463
|
+
/**
|
|
464
|
+
* Return an array containing lookup overrides, or undefined if no lookups were passed to
|
|
465
|
+
* the latest `runModel` call.
|
|
466
|
+
*/
|
|
467
|
+
getLookups(): LookupDef[] | undefined;
|
|
468
|
+
/**
|
|
469
|
+
* Return the elapsed time (in milliseconds) of the model run.
|
|
470
|
+
*/
|
|
471
|
+
getElapsedTime(): number;
|
|
472
|
+
/**
|
|
473
|
+
* Store the elapsed time of the model run.
|
|
474
|
+
*
|
|
475
|
+
* @param elapsed The model run time, in milliseconds.
|
|
476
|
+
*/
|
|
477
|
+
storeElapsedTime(elapsed: number): void;
|
|
470
478
|
}
|
|
471
|
-
|
|
479
|
+
//#endregion
|
|
480
|
+
//#region src/runnable-model/buffered-run-model-params.d.ts
|
|
472
481
|
/**
|
|
473
482
|
* An implementation of `RunModelParams` that copies the input and output arrays into a single,
|
|
474
483
|
* combined buffer. This implementation is designed to work with an asynchronous `ModelRunner`
|
|
@@ -478,91 +487,92 @@ interface RunModelParams {
|
|
|
478
487
|
* @hidden This is not yet exposed in the public API; it is currently only used by
|
|
479
488
|
* the implementations of the `RunnableModel` interface.
|
|
480
489
|
*/
|
|
481
|
-
declare class BufferedRunModelParams implements RunModelParams {
|
|
482
|
-
|
|
483
|
-
|
|
484
|
-
|
|
485
|
-
|
|
486
|
-
|
|
487
|
-
|
|
488
|
-
|
|
489
|
-
|
|
490
|
-
|
|
491
|
-
|
|
492
|
-
|
|
493
|
-
|
|
494
|
-
|
|
495
|
-
|
|
496
|
-
|
|
497
|
-
|
|
498
|
-
|
|
499
|
-
|
|
500
|
-
|
|
501
|
-
|
|
502
|
-
|
|
503
|
-
|
|
504
|
-
|
|
505
|
-
|
|
506
|
-
|
|
507
|
-
|
|
508
|
-
|
|
509
|
-
|
|
510
|
-
|
|
511
|
-
|
|
512
|
-
|
|
513
|
-
|
|
514
|
-
|
|
515
|
-
|
|
516
|
-
|
|
517
|
-
|
|
518
|
-
|
|
519
|
-
|
|
520
|
-
|
|
521
|
-
|
|
522
|
-
|
|
523
|
-
|
|
524
|
-
|
|
525
|
-
|
|
526
|
-
|
|
527
|
-
|
|
528
|
-
|
|
529
|
-
|
|
530
|
-
|
|
531
|
-
|
|
532
|
-
|
|
533
|
-
|
|
534
|
-
|
|
535
|
-
|
|
536
|
-
|
|
537
|
-
|
|
538
|
-
|
|
539
|
-
|
|
540
|
-
|
|
541
|
-
|
|
542
|
-
|
|
543
|
-
|
|
544
|
-
|
|
545
|
-
|
|
546
|
-
|
|
547
|
-
|
|
548
|
-
|
|
549
|
-
|
|
550
|
-
|
|
551
|
-
|
|
552
|
-
|
|
553
|
-
|
|
554
|
-
|
|
555
|
-
|
|
556
|
-
|
|
557
|
-
|
|
558
|
-
|
|
559
|
-
|
|
560
|
-
|
|
561
|
-
|
|
562
|
-
|
|
563
|
-
|
|
490
|
+
export declare class BufferedRunModelParams implements RunModelParams {
|
|
491
|
+
private readonly listing?;
|
|
492
|
+
/**
|
|
493
|
+
* The array that holds all input and output values. This is grown as needed. The memory
|
|
494
|
+
* layout of the buffer is as follows:
|
|
495
|
+
* header
|
|
496
|
+
* extras (holds elapsed time, etc)
|
|
497
|
+
* inputs
|
|
498
|
+
* outputs
|
|
499
|
+
* outputIndices
|
|
500
|
+
* constants (values)
|
|
501
|
+
* constantIndices
|
|
502
|
+
* lookups (data)
|
|
503
|
+
* lookupIndices
|
|
504
|
+
*/
|
|
505
|
+
private encoded;
|
|
506
|
+
/**
|
|
507
|
+
* The header section of the `encoded` buffer. The header declares the byte offset and length
|
|
508
|
+
* (in elements) of each section of the buffer.
|
|
509
|
+
*/
|
|
510
|
+
private readonly header;
|
|
511
|
+
/** The extras section of the `encoded` buffer (holds elapsed time, etc). */
|
|
512
|
+
private readonly extras;
|
|
513
|
+
/** The inputs section of the `encoded` buffer. */
|
|
514
|
+
private readonly inputs;
|
|
515
|
+
/** The outputs section of the `encoded` buffer. */
|
|
516
|
+
private readonly outputs;
|
|
517
|
+
/** The output indices section of the `encoded` buffer. */
|
|
518
|
+
private readonly outputIndices;
|
|
519
|
+
/** The constant values section of the `encoded` buffer. */
|
|
520
|
+
private readonly constants;
|
|
521
|
+
/** The constant indices section of the `encoded` buffer. */
|
|
522
|
+
private readonly constantIndices;
|
|
523
|
+
/** The lookup data section of the `encoded` buffer. */
|
|
524
|
+
private readonly lookups;
|
|
525
|
+
/** The lookup indices section of the `encoded` buffer. */
|
|
526
|
+
private readonly lookupIndices;
|
|
527
|
+
/**
|
|
528
|
+
* @param listing The model listing that is used to locate a variable that is referenced by
|
|
529
|
+
* name or identifier. If undefined, variables cannot be referenced by name or identifier,
|
|
530
|
+
* and can only be referenced using a valid `VarSpec`.
|
|
531
|
+
*/
|
|
532
|
+
constructor(listing?: ModelListing);
|
|
533
|
+
/**
|
|
534
|
+
* Return the encoded buffer from this instance, which can be passed to `updateFromEncodedBuffer`.
|
|
535
|
+
*/
|
|
536
|
+
getEncodedBuffer(): ArrayBuffer;
|
|
537
|
+
getInputs(): Float64Array | undefined;
|
|
538
|
+
copyInputs(array: Float64Array | undefined, create: (numElements: number) => Float64Array): void;
|
|
539
|
+
getOutputIndicesLength(): number;
|
|
540
|
+
getOutputIndices(): Int32Array | undefined;
|
|
541
|
+
copyOutputIndices(array: Int32Array | undefined, create: (numElements: number) => Int32Array): void;
|
|
542
|
+
getOutputsLength(): number;
|
|
543
|
+
getOutputs(): Float64Array | undefined;
|
|
544
|
+
getOutputsObject(): Outputs | undefined;
|
|
545
|
+
storeOutputs(array: Float64Array): void;
|
|
546
|
+
getConstants(): ConstantDef[] | undefined;
|
|
547
|
+
getLookups(): LookupDef[] | undefined;
|
|
548
|
+
getElapsedTime(): number;
|
|
549
|
+
storeElapsedTime(elapsed: number): void;
|
|
550
|
+
/**
|
|
551
|
+
* Copy the outputs buffer to the given `Outputs` instance. This should be called
|
|
552
|
+
* after the `runModel` call has completed so that the output values are copied from
|
|
553
|
+
* the internal buffer to the `Outputs` instance that was passed to `runModel`.
|
|
554
|
+
*
|
|
555
|
+
* @param outputs The `Outputs` instance into which the output values will be copied.
|
|
556
|
+
*/
|
|
557
|
+
finalizeOutputs(outputs: Outputs): void;
|
|
558
|
+
/**
|
|
559
|
+
* Update this instance using the parameters that are passed to a `runModel` call.
|
|
560
|
+
*
|
|
561
|
+
* @param inputs The model input values (must be in the same order as in the spec file).
|
|
562
|
+
* @param outputs The structure into which the model outputs will be stored.
|
|
563
|
+
* @param options Additional options that influence the model run.
|
|
564
|
+
*/
|
|
565
|
+
updateFromParams(inputs: number[] | InputValue[], outputs: Outputs, options?: RunModelOptions): void;
|
|
566
|
+
/**
|
|
567
|
+
* Update this instance using the values contained in the encoded buffer from another
|
|
568
|
+
* `BufferedRunModelParams` instance.
|
|
569
|
+
*
|
|
570
|
+
* @param buffer An encoded buffer returned by `getEncodedBuffer`.
|
|
571
|
+
*/
|
|
572
|
+
updateFromEncodedBuffer(buffer: ArrayBuffer): void;
|
|
564
573
|
}
|
|
565
|
-
|
|
574
|
+
//#endregion
|
|
575
|
+
//#region src/runnable-model/referenced-run-model-params.d.ts
|
|
566
576
|
/**
|
|
567
577
|
* An implementation of `RunModelParams` that keeps references to the `inputs` and
|
|
568
578
|
* `outputs` parameters that are passed to the `runModel` function. This implementation
|
|
@@ -571,43 +581,44 @@ declare class BufferedRunModelParams implements RunModelParams {
|
|
|
571
581
|
* @hidden This is not yet exposed in the public API; it is currently only used by
|
|
572
582
|
* the implementations of the `RunnableModel` interface.
|
|
573
583
|
*/
|
|
574
|
-
declare class ReferencedRunModelParams implements RunModelParams {
|
|
575
|
-
|
|
576
|
-
|
|
577
|
-
|
|
578
|
-
|
|
579
|
-
|
|
580
|
-
|
|
581
|
-
|
|
582
|
-
|
|
583
|
-
|
|
584
|
-
|
|
585
|
-
|
|
586
|
-
|
|
587
|
-
|
|
588
|
-
|
|
589
|
-
|
|
590
|
-
|
|
591
|
-
|
|
592
|
-
|
|
593
|
-
|
|
594
|
-
|
|
595
|
-
|
|
596
|
-
|
|
597
|
-
|
|
598
|
-
|
|
599
|
-
|
|
600
|
-
|
|
601
|
-
|
|
602
|
-
|
|
603
|
-
|
|
604
|
-
|
|
605
|
-
|
|
606
|
-
|
|
607
|
-
|
|
608
|
-
|
|
584
|
+
export declare class ReferencedRunModelParams implements RunModelParams {
|
|
585
|
+
private readonly listing?;
|
|
586
|
+
private inputs;
|
|
587
|
+
private outputs;
|
|
588
|
+
private outputsLengthInElements;
|
|
589
|
+
private outputIndicesLengthInElements;
|
|
590
|
+
private constants;
|
|
591
|
+
private lookups;
|
|
592
|
+
/**
|
|
593
|
+
* @param listing The model listing that is used to locate a variable that is referenced by
|
|
594
|
+
* name or identifier. If undefined, variables cannot be referenced by name or identifier,
|
|
595
|
+
* and can only be referenced using a valid `VarSpec`.
|
|
596
|
+
*/
|
|
597
|
+
constructor(listing?: ModelListing);
|
|
598
|
+
getInputs(): Float64Array | undefined;
|
|
599
|
+
copyInputs(array: Float64Array | undefined, create: (numElements: number) => Float64Array): void;
|
|
600
|
+
getOutputIndicesLength(): number;
|
|
601
|
+
getOutputIndices(): Int32Array | undefined;
|
|
602
|
+
copyOutputIndices(array: Int32Array | undefined, create: (numElements: number) => Int32Array): void;
|
|
603
|
+
getOutputsLength(): number;
|
|
604
|
+
getOutputs(): Float64Array | undefined;
|
|
605
|
+
getOutputsObject(): Outputs | undefined;
|
|
606
|
+
storeOutputs(array: Float64Array): void;
|
|
607
|
+
getConstants(): ConstantDef[] | undefined;
|
|
608
|
+
getLookups(): LookupDef[] | undefined;
|
|
609
|
+
getElapsedTime(): number;
|
|
610
|
+
storeElapsedTime(elapsed: number): void;
|
|
611
|
+
/**
|
|
612
|
+
* Update this instance using the parameters that are passed to a `runModel` call.
|
|
613
|
+
*
|
|
614
|
+
* @param inputs The model input values (must be in the same order as in the spec file).
|
|
615
|
+
* @param outputs The structure into which the model outputs will be stored.
|
|
616
|
+
* @param options Additional options that influence the model run.
|
|
617
|
+
*/
|
|
618
|
+
updateFromParams(inputs: number[] | InputValue[], outputs: Outputs, options?: RunModelOptions): void;
|
|
609
619
|
}
|
|
610
|
-
|
|
620
|
+
//#endregion
|
|
621
|
+
//#region src/runnable-model/runnable-model.d.ts
|
|
611
622
|
/**
|
|
612
623
|
* This interface exposes the properties and functions that allow a `ModelRunner`
|
|
613
624
|
* implementation to run a model that was generated by the SDEverywhere transpiler.
|
|
@@ -617,131 +628,133 @@ declare class ReferencedRunModelParams implements RunModelParams {
|
|
|
617
628
|
* @hidden This is not yet exposed in the public API; it is currently only used by
|
|
618
629
|
* the internal implementations of this interface, and from the runtime-async package.
|
|
619
630
|
*/
|
|
620
|
-
interface RunnableModel {
|
|
621
|
-
|
|
622
|
-
|
|
623
|
-
|
|
624
|
-
|
|
625
|
-
|
|
626
|
-
|
|
627
|
-
|
|
628
|
-
|
|
629
|
-
|
|
630
|
-
|
|
631
|
-
|
|
632
|
-
|
|
633
|
-
|
|
634
|
-
|
|
635
|
-
|
|
636
|
-
|
|
637
|
-
|
|
638
|
-
|
|
639
|
-
|
|
640
|
-
|
|
641
|
-
|
|
642
|
-
|
|
643
|
-
|
|
644
|
-
|
|
645
|
-
|
|
646
|
-
|
|
647
|
-
|
|
631
|
+
export interface RunnableModel {
|
|
632
|
+
/** The start time for the model (aka `INITIAL TIME`). */
|
|
633
|
+
readonly startTime: number;
|
|
634
|
+
/** The end time for the model (aka `FINAL TIME`). */
|
|
635
|
+
readonly endTime: number;
|
|
636
|
+
/** The frequency with which output values are saved (aka `SAVEPER`). */
|
|
637
|
+
readonly saveFreq: number;
|
|
638
|
+
/** The number of save points for each output. */
|
|
639
|
+
readonly numSavePoints: number;
|
|
640
|
+
/** The output variable IDs for this model. */
|
|
641
|
+
readonly outputVarIds: OutputVarId[];
|
|
642
|
+
/**
|
|
643
|
+
* The model listing that is used to resolve variables. This can be undefined,
|
|
644
|
+
* in which case variables cannot be referenced by name or identifier, and can only
|
|
645
|
+
* be referenced using a valid `VarSpec`.
|
|
646
|
+
*/
|
|
647
|
+
readonly modelListing?: any;
|
|
648
|
+
/**
|
|
649
|
+
* Run the model synchronously on the current thread.
|
|
650
|
+
*
|
|
651
|
+
* @param params The parameters that control the model run.
|
|
652
|
+
*/
|
|
653
|
+
runModel(params: RunModelParams): void;
|
|
654
|
+
/**
|
|
655
|
+
* Terminate the runner by releasing underlying resources (e.g., the worker thread or
|
|
656
|
+
* Wasm module/buffers).
|
|
657
|
+
*/
|
|
658
|
+
terminate(): void;
|
|
648
659
|
}
|
|
649
|
-
|
|
660
|
+
//#endregion
|
|
661
|
+
//#region src/js-model/js-model-lookup.d.ts
|
|
650
662
|
type JsModelLookupMode = 'interpolate' | 'forward' | 'backward';
|
|
651
663
|
/**
|
|
652
664
|
* @hidden This is not yet part of the public API; for internal use only.
|
|
653
665
|
*/
|
|
654
666
|
declare class JsModelLookup {
|
|
655
|
-
|
|
656
|
-
|
|
657
|
-
|
|
658
|
-
|
|
659
|
-
|
|
660
|
-
|
|
661
|
-
|
|
662
|
-
|
|
663
|
-
|
|
664
|
-
|
|
665
|
-
|
|
666
|
-
|
|
667
|
-
|
|
668
|
-
|
|
669
|
-
|
|
670
|
-
|
|
671
|
-
|
|
672
|
-
|
|
673
|
-
|
|
674
|
-
|
|
675
|
-
|
|
676
|
-
|
|
677
|
-
|
|
678
|
-
|
|
679
|
-
|
|
680
|
-
|
|
681
|
-
|
|
682
|
-
|
|
683
|
-
|
|
684
|
-
|
|
685
|
-
|
|
686
|
-
|
|
687
|
-
|
|
688
|
-
|
|
689
|
-
|
|
690
|
-
|
|
691
|
-
|
|
692
|
-
|
|
693
|
-
|
|
694
|
-
|
|
695
|
-
|
|
696
|
-
|
|
697
|
-
|
|
698
|
-
|
|
699
|
-
|
|
700
|
-
|
|
701
|
-
|
|
702
|
-
|
|
703
|
-
|
|
704
|
-
|
|
705
|
-
|
|
706
|
-
|
|
707
|
-
|
|
708
|
-
|
|
709
|
-
|
|
710
|
-
|
|
711
|
-
|
|
712
|
-
|
|
713
|
-
|
|
714
|
-
|
|
715
|
-
|
|
716
|
-
|
|
717
|
-
|
|
718
|
-
|
|
719
|
-
|
|
720
|
-
|
|
721
|
-
|
|
722
|
-
|
|
723
|
-
|
|
724
|
-
|
|
725
|
-
|
|
726
|
-
|
|
727
|
-
|
|
728
|
-
|
|
729
|
-
|
|
730
|
-
|
|
731
|
-
|
|
732
|
-
|
|
733
|
-
|
|
734
|
-
|
|
735
|
-
|
|
736
|
-
|
|
737
|
-
|
|
738
|
-
|
|
739
|
-
|
|
740
|
-
|
|
741
|
-
|
|
742
|
-
|
|
667
|
+
/** The original data passed to the constructor. */
|
|
668
|
+
private readonly originalData;
|
|
669
|
+
/** The size (i.e., number of pairs) of the original data. */
|
|
670
|
+
private readonly originalSize;
|
|
671
|
+
/**
|
|
672
|
+
* The dynamic data array. This will be undefined initially, and the array
|
|
673
|
+
* will be allocated (or grown) by `setData`.
|
|
674
|
+
*/
|
|
675
|
+
private dynamicData;
|
|
676
|
+
/** The size (i.e., number of pairs) of the dynamic data. */
|
|
677
|
+
private dynamicSize;
|
|
678
|
+
/**
|
|
679
|
+
* The active data array. This will be the same as either `originalData`
|
|
680
|
+
* or `dynamicData`, depending on whether the lookup data is overridden
|
|
681
|
+
* at runtime using `setData`.
|
|
682
|
+
*/
|
|
683
|
+
private activeData;
|
|
684
|
+
/** The size (i.e., number of pairs) of the active data. */
|
|
685
|
+
private activeSize;
|
|
686
|
+
/**
|
|
687
|
+
* The inverted version of the active data array. This is allocated on demand
|
|
688
|
+
* only in the case of `LOOKUP INVERT` function calls.
|
|
689
|
+
*/
|
|
690
|
+
private invertedData?;
|
|
691
|
+
/**
|
|
692
|
+
* The input value for the last hit. This is cached for performance so that we
|
|
693
|
+
* can reduce the amount of linear searching in the common case where `LOOKUP`
|
|
694
|
+
* input values are monotonically increasing.
|
|
695
|
+
*/
|
|
696
|
+
private lastInput;
|
|
697
|
+
/** The index for the last hit (see `lastInput`). */
|
|
698
|
+
private lastHitIndex;
|
|
699
|
+
/**
|
|
700
|
+
* @param size The number of (x,y) pairs in the lookup.
|
|
701
|
+
* @param data The lookup data, as (x,y) pairs. The length of the array must be
|
|
702
|
+
* >= 2*n. Note that the data will be stored by reference, so if there is a chance
|
|
703
|
+
* that the array will be reused or modified by other code, be sure to pass in a
|
|
704
|
+
* copy of the array.
|
|
705
|
+
*/
|
|
706
|
+
constructor(size: number, data: number[] | Float64Array | undefined);
|
|
707
|
+
/**
|
|
708
|
+
* Set new data for this lookup instance, or restore the original data.
|
|
709
|
+
*
|
|
710
|
+
* If `data` is undefined, the original data that was supplied to the constructor will
|
|
711
|
+
* be restored as the "active" data. Otherwise, `data` will be copied to an internal
|
|
712
|
+
* data buffer, which will be the "active" data. If `size` is greater than the size
|
|
713
|
+
* passed to previous calls, the internal data buffer will be grown as needed.
|
|
714
|
+
*
|
|
715
|
+
* @param size The number of (x,y) pairs in the lookup.
|
|
716
|
+
* @param data The lookup data, as (x,y) pairs. The length of the array must be
|
|
717
|
+
* >= 2*n. Note that the data will be copied into an internal data buffer, so it
|
|
718
|
+
* is not necessary to defensively copy data before calling this method.
|
|
719
|
+
*/
|
|
720
|
+
setData(size: number, data: Float64Array | undefined): void;
|
|
721
|
+
getValueForX(x: number, mode: JsModelLookupMode): number;
|
|
722
|
+
getValueForY(y: number): number;
|
|
723
|
+
/**
|
|
724
|
+
* Interpolate the y value from the array of (x,y) pairs.
|
|
725
|
+
* NOTE: The x values are assumed to be monotonically increasing.
|
|
726
|
+
*/
|
|
727
|
+
private getValue;
|
|
728
|
+
/**
|
|
729
|
+
* Return the most appropriate y value from the array of (x,y) pairs when
|
|
730
|
+
* this instance is used to provide inputs for the `GAME` function.
|
|
731
|
+
*
|
|
732
|
+
* NOTE: The x values are assumed to be monotonically increasing.
|
|
733
|
+
*
|
|
734
|
+
* This method is similar to `getValueForX` in concept, except that this one
|
|
735
|
+
* returns the provided `defaultValue` if the `time` parameter is earlier than
|
|
736
|
+
* the first data point in the lookup. Also, this method always uses the
|
|
737
|
+
* `backward` interpolation mode, meaning that it holds the "current" value
|
|
738
|
+
* constant instead of interpolating.
|
|
739
|
+
*
|
|
740
|
+
* @param time The time that is used to select the data point that has an
|
|
741
|
+
* `x` value less than or equal to the provided time.
|
|
742
|
+
* @param defaultValue The value that is returned if this lookup is empty (has
|
|
743
|
+
* no points) or if the provided time is earlier than the first data point.
|
|
744
|
+
*/
|
|
745
|
+
getValueForGameTime(time: number, defaultValue: number): number;
|
|
746
|
+
/**
|
|
747
|
+
* Interpolate the y value from the array of (x,y) pairs.
|
|
748
|
+
* NOTE: The x values are assumed to be monotonically increasing.
|
|
749
|
+
*
|
|
750
|
+
* This method is similar to `getValue` in concept, but Vensim produces results for
|
|
751
|
+
* the `GET DATA BETWEEN TIMES` function that differ in unexpected ways from normal
|
|
752
|
+
* lookup behavior, so we implement it as a separate method here.
|
|
753
|
+
*/
|
|
754
|
+
getValueBetweenTimes(input: number, mode: JsModelLookupMode): number;
|
|
743
755
|
}
|
|
744
|
-
|
|
756
|
+
//#endregion
|
|
757
|
+
//#region src/js-model/js-model-functions.d.ts
|
|
745
758
|
/**
|
|
746
759
|
* Provides access to the minimal set of control parameters that are used in the
|
|
747
760
|
* implementation of certain model functions.
|
|
@@ -749,9 +762,9 @@ declare class JsModelLookup {
|
|
|
749
762
|
* @hidden This is not yet part of the public API; for internal use by generated
|
|
750
763
|
* `JsModel` implementations.
|
|
751
764
|
*/
|
|
752
|
-
interface JsModelFunctionContext {
|
|
753
|
-
|
|
754
|
-
|
|
765
|
+
export interface JsModelFunctionContext {
|
|
766
|
+
timeStep: number;
|
|
767
|
+
currentTime: number;
|
|
755
768
|
}
|
|
756
769
|
/**
|
|
757
770
|
* Exposes all the model function implementations that are called by a `JsModel` at runtime.
|
|
@@ -759,42 +772,42 @@ interface JsModelFunctionContext {
|
|
|
759
772
|
* @hidden This is not yet part of the public API; for internal use by generated
|
|
760
773
|
* `JsModel` implementations.
|
|
761
774
|
*/
|
|
762
|
-
interface JsModelFunctions {
|
|
763
|
-
|
|
764
|
-
|
|
765
|
-
|
|
766
|
-
|
|
767
|
-
|
|
768
|
-
|
|
769
|
-
|
|
770
|
-
|
|
771
|
-
|
|
772
|
-
|
|
773
|
-
|
|
774
|
-
|
|
775
|
-
|
|
776
|
-
|
|
777
|
-
|
|
778
|
-
|
|
779
|
-
|
|
780
|
-
|
|
781
|
-
|
|
782
|
-
|
|
783
|
-
|
|
784
|
-
|
|
785
|
-
|
|
786
|
-
|
|
787
|
-
|
|
788
|
-
|
|
789
|
-
|
|
790
|
-
|
|
791
|
-
|
|
792
|
-
|
|
793
|
-
|
|
794
|
-
|
|
795
|
-
|
|
796
|
-
|
|
797
|
-
|
|
775
|
+
export interface JsModelFunctions {
|
|
776
|
+
setContext(context: JsModelFunctionContext): void;
|
|
777
|
+
ABS(x: number): number;
|
|
778
|
+
ARCCOS(x: number): number;
|
|
779
|
+
ARCSIN(x: number): number;
|
|
780
|
+
ARCTAN(x: number): number;
|
|
781
|
+
COS(x: number): number;
|
|
782
|
+
EXP(x: number): number;
|
|
783
|
+
GAME(inputs: JsModelLookup, x: number): number;
|
|
784
|
+
INTEG(value: number, rate: number): number;
|
|
785
|
+
INTEGER(x: number): number;
|
|
786
|
+
INVERT_MATRIX(matrix: number[][], n: number): number[][];
|
|
787
|
+
LN(x: number): number;
|
|
788
|
+
MAX(x: number, y: number): number;
|
|
789
|
+
MIN(x: number, y: number): number;
|
|
790
|
+
MODULO(x: number, y: number): number;
|
|
791
|
+
POW(x: number, y: number): number;
|
|
792
|
+
POWER(x: number, y: number): number;
|
|
793
|
+
PULSE(start: number, width: number): number;
|
|
794
|
+
PULSE_TRAIN(start: number, width: number, interval: number, end: number): number;
|
|
795
|
+
QUANTUM(x: number, y: number): number;
|
|
796
|
+
RAMP(slope: number, startTime: number, endTime: number): number;
|
|
797
|
+
SIN(x: number): number;
|
|
798
|
+
SQRT(x: number): number;
|
|
799
|
+
STEP(height: number, stepTime: number): number;
|
|
800
|
+
TAN(x: number): number;
|
|
801
|
+
VECTOR_SORT_ORDER(vector: number[], size: number, direction: number): number[];
|
|
802
|
+
XIDZ(a: number, b: number, x: number): number;
|
|
803
|
+
ZIDZ(a: number, b: number): number;
|
|
804
|
+
createLookup(size: number, data: number[] | Float64Array): JsModelLookup;
|
|
805
|
+
LOOKUP(lookup: JsModelLookup, x: number): number;
|
|
806
|
+
LOOKUP_FORWARD(lookup: JsModelLookup, x: number): number;
|
|
807
|
+
LOOKUP_BACKWARD(lookup: JsModelLookup, x: number): number;
|
|
808
|
+
LOOKUP_INVERT(lookup: JsModelLookup, y: number): number;
|
|
809
|
+
WITH_LOOKUP(x: number, lookup: JsModelLookup): number;
|
|
810
|
+
GET_DATA_BETWEEN_TIMES(lookup: JsModelLookup, x: number, mode: number): number;
|
|
798
811
|
}
|
|
799
812
|
/**
|
|
800
813
|
* Returns a default implementation of the `JsModelFunctions` interface. If needed,
|
|
@@ -804,8 +817,9 @@ interface JsModelFunctions {
|
|
|
804
817
|
* @hidden This is not yet part of the public API; for internal use by generated
|
|
805
818
|
* `JsModel` implementations.
|
|
806
819
|
*/
|
|
807
|
-
declare function getJsModelFunctions(): JsModelFunctions;
|
|
808
|
-
|
|
820
|
+
export declare function getJsModelFunctions(): JsModelFunctions;
|
|
821
|
+
//#endregion
|
|
822
|
+
//#region src/js-model/js-model.d.ts
|
|
809
823
|
/**
|
|
810
824
|
* An interface that exposes the functions of a JavaScript model generated by the
|
|
811
825
|
* SDEverywhere transpiler. This allows for running the model with a given set of
|
|
@@ -821,43 +835,43 @@ declare function getJsModelFunctions(): JsModelFunctions;
|
|
|
821
835
|
* internal use only, and are subject to change in coordination with the code
|
|
822
836
|
* generated by the `@sdeverywhere/compile` package.
|
|
823
837
|
*/
|
|
824
|
-
interface JsModel {
|
|
825
|
-
|
|
826
|
-
|
|
827
|
-
|
|
828
|
-
|
|
829
|
-
|
|
830
|
-
|
|
831
|
-
|
|
832
|
-
|
|
833
|
-
|
|
834
|
-
|
|
835
|
-
|
|
836
|
-
|
|
837
|
-
|
|
838
|
-
|
|
839
|
-
|
|
840
|
-
|
|
841
|
-
|
|
842
|
-
|
|
843
|
-
|
|
844
|
-
|
|
845
|
-
|
|
846
|
-
|
|
847
|
-
|
|
848
|
-
|
|
849
|
-
|
|
850
|
-
|
|
851
|
-
|
|
852
|
-
|
|
853
|
-
|
|
854
|
-
|
|
855
|
-
|
|
856
|
-
|
|
857
|
-
|
|
858
|
-
|
|
859
|
-
|
|
860
|
-
|
|
838
|
+
export interface JsModel {
|
|
839
|
+
readonly kind: 'js';
|
|
840
|
+
readonly outputVarIds: string[];
|
|
841
|
+
readonly outputVarNames: string[];
|
|
842
|
+
readonly modelListing?: any;
|
|
843
|
+
/** @hidden */
|
|
844
|
+
getInitialTime(): number;
|
|
845
|
+
/** @hidden */
|
|
846
|
+
getFinalTime(): number;
|
|
847
|
+
/** @hidden */
|
|
848
|
+
getTimeStep(): number;
|
|
849
|
+
/** @hidden */
|
|
850
|
+
getSaveFreq(): number;
|
|
851
|
+
/** @hidden */
|
|
852
|
+
getModelFunctions(): JsModelFunctions;
|
|
853
|
+
/** @hidden */
|
|
854
|
+
setModelFunctions(functions: JsModelFunctions): void;
|
|
855
|
+
/** @hidden */
|
|
856
|
+
setTime(time: number): void;
|
|
857
|
+
/** @hidden */
|
|
858
|
+
setInputs(inputValue: (index: number) => number): void;
|
|
859
|
+
/** @hidden */
|
|
860
|
+
setConstant(varSpec: VarSpec, value: number): void;
|
|
861
|
+
/** @hidden */
|
|
862
|
+
setLookup(varSpec: VarSpec, points: Float64Array | undefined): void;
|
|
863
|
+
/** @hidden */
|
|
864
|
+
storeOutputs(storeValue: (value: number) => void): void;
|
|
865
|
+
/** @hidden */
|
|
866
|
+
storeOutput(varSpec: VarSpec, storeValue: (value: number) => void): void;
|
|
867
|
+
/** @hidden */
|
|
868
|
+
initConstants(): void;
|
|
869
|
+
/** @hidden */
|
|
870
|
+
initLevels(): void;
|
|
871
|
+
/** @hidden */
|
|
872
|
+
evalAux(): void;
|
|
873
|
+
/** @hidden */
|
|
874
|
+
evalLevels(): void;
|
|
861
875
|
}
|
|
862
876
|
/**
|
|
863
877
|
* Create a `RunnableModel` from a given `JsModel` that was generated by the
|
|
@@ -866,8 +880,9 @@ interface JsModel {
|
|
|
866
880
|
* @hidden This is not part of the public API; only the top-level `createRunnableModel`
|
|
867
881
|
* function is exposed in the public API.
|
|
868
882
|
*/
|
|
869
|
-
declare function initJsModel(model: JsModel): RunnableModel;
|
|
870
|
-
|
|
883
|
+
export declare function initJsModel(model: JsModel): RunnableModel;
|
|
884
|
+
//#endregion
|
|
885
|
+
//#region src/js-model/exec-js-model.d.ts
|
|
871
886
|
/**
|
|
872
887
|
* Run the given model synchronously and log the output values to the console in
|
|
873
888
|
* TSV (tab-separated values) format.
|
|
@@ -877,77 +892,80 @@ declare function initJsModel(model: JsModel): RunnableModel;
|
|
|
877
892
|
*
|
|
878
893
|
* @param jsModel A `JsModel` instance.
|
|
879
894
|
*/
|
|
880
|
-
declare function execJsModel(jsModel: JsModel): void;
|
|
881
|
-
|
|
895
|
+
export declare function execJsModel(jsModel: JsModel): void;
|
|
896
|
+
//#endregion
|
|
897
|
+
//#region src/js-model/_mocks/mock-js-model.d.ts
|
|
882
898
|
/**
|
|
883
899
|
* @hidden This type is not part of the public API; it is exposed only for use in
|
|
884
900
|
* tests in the runtime-async package.
|
|
885
901
|
*/
|
|
886
|
-
type OnEvalAux = (vars: Map<VarId, number>, constants: Map<VarId, number> | undefined, lookups: Map<VarId, JsModelLookup>) => void;
|
|
902
|
+
export type OnEvalAux = (vars: Map<VarId, number>, constants: Map<VarId, number> | undefined, lookups: Map<VarId, JsModelLookup>) => void;
|
|
887
903
|
/**
|
|
888
904
|
* @hidden This type is not part of the public API; it is exposed only for use in
|
|
889
905
|
* tests in the runtime-async package.
|
|
890
906
|
*/
|
|
891
|
-
declare class MockJsModel implements JsModel {
|
|
892
|
-
|
|
893
|
-
|
|
894
|
-
|
|
895
|
-
|
|
896
|
-
|
|
897
|
-
|
|
898
|
-
|
|
899
|
-
|
|
900
|
-
|
|
901
|
-
|
|
902
|
-
|
|
903
|
-
|
|
904
|
-
|
|
905
|
-
|
|
906
|
-
|
|
907
|
-
|
|
908
|
-
|
|
909
|
-
|
|
910
|
-
|
|
911
|
-
|
|
912
|
-
|
|
913
|
-
|
|
914
|
-
|
|
915
|
-
|
|
916
|
-
|
|
917
|
-
|
|
918
|
-
|
|
919
|
-
|
|
920
|
-
|
|
921
|
-
|
|
922
|
-
|
|
923
|
-
|
|
924
|
-
|
|
925
|
-
|
|
926
|
-
|
|
927
|
-
|
|
907
|
+
export declare class MockJsModel implements JsModel {
|
|
908
|
+
readonly kind = "js";
|
|
909
|
+
readonly outputVarIds: OutputVarId[];
|
|
910
|
+
readonly outputVarNames: OutputVarId[];
|
|
911
|
+
readonly modelListing?: any;
|
|
912
|
+
private readonly internalListing?;
|
|
913
|
+
private readonly initialTime;
|
|
914
|
+
private readonly finalTime;
|
|
915
|
+
private readonly vars;
|
|
916
|
+
private readonly constants;
|
|
917
|
+
private readonly lookups;
|
|
918
|
+
private fns;
|
|
919
|
+
readonly onEvalAux: OnEvalAux;
|
|
920
|
+
constructor(options: {
|
|
921
|
+
initialTime: number;
|
|
922
|
+
finalTime: number;
|
|
923
|
+
outputVarIds: OutputVarId[];
|
|
924
|
+
listingJson?: string;
|
|
925
|
+
onEvalAux: OnEvalAux;
|
|
926
|
+
});
|
|
927
|
+
varIdForSpec(varSpec: VarSpec): VarId;
|
|
928
|
+
getInitialTime(): number;
|
|
929
|
+
getFinalTime(): number;
|
|
930
|
+
getTimeStep(): number;
|
|
931
|
+
getSaveFreq(): number;
|
|
932
|
+
getModelFunctions(): JsModelFunctions;
|
|
933
|
+
setModelFunctions(fns: JsModelFunctions): void;
|
|
934
|
+
setTime(time: number): void;
|
|
935
|
+
setInputs(): void;
|
|
936
|
+
setConstant(varSpec: VarSpec, value: number): void;
|
|
937
|
+
setLookup(varSpec: VarSpec, points: Float64Array | undefined): void;
|
|
938
|
+
storeOutputs(storeValue: (value: number) => void): void;
|
|
939
|
+
storeOutput(varSpec: VarSpec, storeValue: (value: number) => void): void;
|
|
940
|
+
initConstants(): void;
|
|
941
|
+
initLevels(): void;
|
|
942
|
+
evalAux(): void;
|
|
943
|
+
evalLevels(): void;
|
|
928
944
|
}
|
|
929
|
-
|
|
945
|
+
//#endregion
|
|
946
|
+
//#region src/wasm-model/wasm-module.d.ts
|
|
930
947
|
/**
|
|
931
948
|
* Type declaration for a WebAssembly module wrapper produced
|
|
932
949
|
* by the Emscripten compiler. This only declares the minimal
|
|
933
950
|
* set of fields needed by the SDEverywhere runtime.
|
|
934
951
|
*/
|
|
935
|
-
interface WasmModule {
|
|
936
|
-
|
|
937
|
-
|
|
938
|
-
|
|
939
|
-
|
|
940
|
-
|
|
941
|
-
|
|
942
|
-
|
|
943
|
-
|
|
944
|
-
|
|
945
|
-
|
|
946
|
-
|
|
947
|
-
|
|
948
|
-
|
|
952
|
+
export interface WasmModule {
|
|
953
|
+
readonly kind: 'wasm';
|
|
954
|
+
readonly outputVarIds: OutputVarId[];
|
|
955
|
+
readonly modelListing?: any;
|
|
956
|
+
/** @hidden */
|
|
957
|
+
cwrap: (fname: string, rettype: string, argtypes: string[]) => any;
|
|
958
|
+
/** @hidden */
|
|
959
|
+
_malloc: (numBytes: number) => number;
|
|
960
|
+
/** @hidden */
|
|
961
|
+
_free: (byteOffset: number) => void;
|
|
962
|
+
/** @hidden */
|
|
963
|
+
HEAP32: Int32Array;
|
|
964
|
+
/** @hidden */
|
|
965
|
+
HEAPF64: Float64Array;
|
|
949
966
|
}
|
|
950
|
-
|
|
967
|
+
//#endregion
|
|
968
|
+
//#region src/wasm-model/wasm-model.d.ts
|
|
951
969
|
/**
|
|
952
970
|
* Initialize the wasm model.
|
|
953
971
|
*
|
|
@@ -957,88 +975,91 @@ interface WasmModule {
|
|
|
957
975
|
* @param wasmModule The `WasmModule` that wraps the `wasm` binary.
|
|
958
976
|
* @return The initialized `WasmModel` instance.
|
|
959
977
|
*/
|
|
960
|
-
declare function initWasmModel(wasmModule: WasmModule): RunnableModel;
|
|
961
|
-
|
|
978
|
+
export declare function initWasmModel(wasmModule: WasmModule): RunnableModel;
|
|
979
|
+
//#endregion
|
|
980
|
+
//#region src/wasm-model/_mocks/mock-wasm-module.d.ts
|
|
962
981
|
/**
|
|
963
982
|
* @hidden This type is not part of the public API; it is exposed only for use in
|
|
964
983
|
* tests in the runtime-async package.
|
|
965
984
|
*/
|
|
966
|
-
type OnRunModel = (inputs: Float64Array, outputs: Float64Array, constants: Map<VarId, number> | undefined, lookups: Map<VarId, JsModelLookup>, outputIndices?: Int32Array) => void;
|
|
985
|
+
export type OnRunModel = (inputs: Float64Array, outputs: Float64Array, constants: Map<VarId, number> | undefined, lookups: Map<VarId, JsModelLookup>, outputIndices?: Int32Array) => void;
|
|
967
986
|
/**
|
|
968
987
|
* @hidden This type is not part of the public API; it is exposed only for use in
|
|
969
988
|
* tests in the runtime-async package.
|
|
970
989
|
*/
|
|
971
|
-
declare class MockWasmModule implements WasmModule {
|
|
972
|
-
|
|
973
|
-
|
|
974
|
-
|
|
975
|
-
|
|
976
|
-
|
|
977
|
-
|
|
978
|
-
|
|
979
|
-
|
|
980
|
-
|
|
981
|
-
|
|
982
|
-
|
|
983
|
-
|
|
984
|
-
|
|
985
|
-
|
|
986
|
-
|
|
987
|
-
|
|
988
|
-
|
|
989
|
-
|
|
990
|
-
|
|
991
|
-
|
|
992
|
-
|
|
993
|
-
|
|
994
|
-
|
|
995
|
-
|
|
996
|
-
|
|
997
|
-
|
|
990
|
+
export declare class MockWasmModule implements WasmModule {
|
|
991
|
+
readonly kind = "wasm";
|
|
992
|
+
readonly outputVarIds: OutputVarId[];
|
|
993
|
+
readonly modelListing?: any;
|
|
994
|
+
private readonly internalListing?;
|
|
995
|
+
private readonly initialTime;
|
|
996
|
+
private readonly finalTime;
|
|
997
|
+
private readonly heap;
|
|
998
|
+
readonly HEAP32: Int32Array;
|
|
999
|
+
readonly HEAPF64: Float64Array;
|
|
1000
|
+
private mallocOffset;
|
|
1001
|
+
private readonly allocs;
|
|
1002
|
+
private readonly lookups;
|
|
1003
|
+
private readonly constants;
|
|
1004
|
+
readonly onRunModel: OnRunModel;
|
|
1005
|
+
constructor(options: {
|
|
1006
|
+
initialTime: number;
|
|
1007
|
+
finalTime: number;
|
|
1008
|
+
outputVarIds: string[];
|
|
1009
|
+
listingJson?: string;
|
|
1010
|
+
onRunModel: OnRunModel;
|
|
1011
|
+
});
|
|
1012
|
+
varIdForSpec(varSpec: VarSpec): VarId;
|
|
1013
|
+
cwrap(fname: string): (inputsAddress: number, _inputIndicesAddress: number, outputsAddress: number, outputIndicesAddress: number, constantValuesAddress: number, constantIndicesAddress: number) => void;
|
|
1014
|
+
_malloc(lengthInBytes: number): number;
|
|
1015
|
+
_free(): void;
|
|
1016
|
+
private getHeapView;
|
|
998
1017
|
}
|
|
999
|
-
|
|
1018
|
+
//#endregion
|
|
1019
|
+
//#region src/model-runner/model-runner.d.ts
|
|
1000
1020
|
/**
|
|
1001
1021
|
* Abstraction that allows for running a generated model on the JS thread
|
|
1002
1022
|
* or asynchronously (e.g. in a Web Worker), depending on the implementation.
|
|
1003
1023
|
*/
|
|
1004
|
-
interface ModelRunner {
|
|
1005
|
-
|
|
1006
|
-
|
|
1007
|
-
|
|
1008
|
-
|
|
1009
|
-
|
|
1010
|
-
|
|
1011
|
-
|
|
1012
|
-
|
|
1013
|
-
|
|
1014
|
-
|
|
1015
|
-
|
|
1016
|
-
|
|
1017
|
-
|
|
1018
|
-
|
|
1019
|
-
|
|
1020
|
-
|
|
1021
|
-
|
|
1022
|
-
|
|
1023
|
-
|
|
1024
|
-
|
|
1025
|
-
|
|
1026
|
-
|
|
1027
|
-
|
|
1028
|
-
|
|
1029
|
-
|
|
1030
|
-
|
|
1031
|
-
|
|
1032
|
-
|
|
1033
|
-
|
|
1034
|
-
|
|
1035
|
-
|
|
1036
|
-
|
|
1037
|
-
|
|
1024
|
+
export interface ModelRunner {
|
|
1025
|
+
/**
|
|
1026
|
+
* Create an `Outputs` instance that is sized to accommodate the output variable
|
|
1027
|
+
* data stored by the model.
|
|
1028
|
+
*
|
|
1029
|
+
* @return A new `Outputs` instance.
|
|
1030
|
+
*/
|
|
1031
|
+
createOutputs(): Outputs;
|
|
1032
|
+
/**
|
|
1033
|
+
* Run the model.
|
|
1034
|
+
*
|
|
1035
|
+
* @param inputs The model input values (must be in the same order as in the spec file).
|
|
1036
|
+
* @param outputs The structure into which the model outputs will be stored.
|
|
1037
|
+
* @param options Additional options that influence the model run.
|
|
1038
|
+
* @return A promise that resolves with the outputs when the model run is complete.
|
|
1039
|
+
*/
|
|
1040
|
+
runModel(inputs: number[] | InputValue[], outputs: Outputs, options?: RunModelOptions): Promise<Outputs>;
|
|
1041
|
+
/**
|
|
1042
|
+
* Run the model synchronously.
|
|
1043
|
+
*
|
|
1044
|
+
* @param inputs The model input values (must be in the same order as in the spec file).
|
|
1045
|
+
* @param outputs The structure into which the model outputs will be stored.
|
|
1046
|
+
* @param options Additional options that influence the model run.
|
|
1047
|
+
* @return The outputs of the run.
|
|
1048
|
+
*
|
|
1049
|
+
* @hidden This is only intended for internal use; some implementations may not support
|
|
1050
|
+
* running the model synchronously, in which case this will be undefined.
|
|
1051
|
+
*/
|
|
1052
|
+
runModelSync?(inputs: number[] | InputValue[], outputs: Outputs, options?: RunModelOptions): Outputs;
|
|
1053
|
+
/**
|
|
1054
|
+
* Terminate the runner by releasing underlying resources (e.g., the worker thread or
|
|
1055
|
+
* Wasm module/buffers).
|
|
1056
|
+
*/
|
|
1057
|
+
terminate(): Promise<void>;
|
|
1038
1058
|
}
|
|
1039
|
-
|
|
1059
|
+
//#endregion
|
|
1060
|
+
//#region src/model-runner/synchronous-model-runner.d.ts
|
|
1040
1061
|
/** Union of model types that are generated by the SDEverywhere transpiler/builder. */
|
|
1041
|
-
type GeneratedModel = JsModel | WasmModule;
|
|
1062
|
+
export type GeneratedModel = JsModel | WasmModule;
|
|
1042
1063
|
/**
|
|
1043
1064
|
* Create a `RunnableModel` from a given `JsModel` or `WasmModule` that was generated by the
|
|
1044
1065
|
* SDEverywhere transpiler/builder.
|
|
@@ -1046,14 +1067,15 @@ type GeneratedModel = JsModel | WasmModule;
|
|
|
1046
1067
|
* @hidden This is not yet part of the public API; it is only exposed for use by
|
|
1047
1068
|
* the runtime-async package.
|
|
1048
1069
|
*/
|
|
1049
|
-
declare function createRunnableModel(generatedModel: GeneratedModel): RunnableModel;
|
|
1070
|
+
export declare function createRunnableModel(generatedModel: GeneratedModel): RunnableModel;
|
|
1050
1071
|
/**
|
|
1051
1072
|
* Create a `ModelRunner` that runs a generated model on the JS thread.
|
|
1052
1073
|
*
|
|
1053
1074
|
* @param generatedModel A `JsModel` or `WasmModule` generated by the SDEverywhere transpiler.
|
|
1054
1075
|
*/
|
|
1055
|
-
declare function createSynchronousModelRunner(generatedModel: GeneratedModel): ModelRunner;
|
|
1056
|
-
|
|
1076
|
+
export declare function createSynchronousModelRunner(generatedModel: GeneratedModel): ModelRunner;
|
|
1077
|
+
//#endregion
|
|
1078
|
+
//#region src/model-scheduler/model-scheduler.d.ts
|
|
1057
1079
|
/**
|
|
1058
1080
|
* A high-level interface that schedules the underlying `ModelRunner`.
|
|
1059
1081
|
*
|
|
@@ -1065,55 +1087,56 @@ declare function createSynchronousModelRunner(generatedModel: GeneratedModel): M
|
|
|
1065
1087
|
* (on the main JavaScript thread) or asynchronously (in a Web Worker or Node.js
|
|
1066
1088
|
* worker thread).
|
|
1067
1089
|
*/
|
|
1068
|
-
declare class ModelScheduler {
|
|
1069
|
-
|
|
1070
|
-
|
|
1071
|
-
|
|
1072
|
-
|
|
1073
|
-
|
|
1074
|
-
|
|
1075
|
-
|
|
1076
|
-
|
|
1077
|
-
|
|
1078
|
-
|
|
1079
|
-
|
|
1080
|
-
|
|
1081
|
-
|
|
1082
|
-
|
|
1083
|
-
|
|
1084
|
-
|
|
1085
|
-
|
|
1086
|
-
|
|
1087
|
-
|
|
1088
|
-
|
|
1089
|
-
|
|
1090
|
-
|
|
1091
|
-
|
|
1092
|
-
|
|
1093
|
-
|
|
1094
|
-
|
|
1090
|
+
export declare class ModelScheduler {
|
|
1091
|
+
private readonly runner;
|
|
1092
|
+
private readonly userInputs;
|
|
1093
|
+
private outputs;
|
|
1094
|
+
/** The second array that holds a stable copy of the user inputs. */
|
|
1095
|
+
private readonly currentInputs;
|
|
1096
|
+
/** Whether a model run has been scheduled. */
|
|
1097
|
+
private runNeeded;
|
|
1098
|
+
/** Whether a model run is in progress. */
|
|
1099
|
+
private runInProgress;
|
|
1100
|
+
/** Called when `outputs` has been updated after a model run. */
|
|
1101
|
+
onOutputsChanged?: (outputs: Outputs) => void;
|
|
1102
|
+
/**
|
|
1103
|
+
* @param runner The model runner.
|
|
1104
|
+
* @param userInputs The input values, in the same order as in the spec file passed to `sde`.
|
|
1105
|
+
* @param outputs The structure into which the model outputs will be stored.
|
|
1106
|
+
*/
|
|
1107
|
+
constructor(runner: ModelRunner, userInputs: InputValue[], outputs: Outputs);
|
|
1108
|
+
/**
|
|
1109
|
+
* Schedule a model run (if not already pending). When the run is
|
|
1110
|
+
* complete, save the outputs and call the `onOutputsChanged` callback.
|
|
1111
|
+
*/
|
|
1112
|
+
private runModelIfNeeded;
|
|
1113
|
+
/**
|
|
1114
|
+
* Run the model asynchronously using the current set of input values.
|
|
1115
|
+
*/
|
|
1116
|
+
private runModelNow;
|
|
1095
1117
|
}
|
|
1096
|
-
|
|
1118
|
+
//#endregion
|
|
1119
|
+
//#region src/model-scheduler/multi-context-model-scheduler.d.ts
|
|
1097
1120
|
/**
|
|
1098
1121
|
* Defines a context that holds a distinct set of model inputs and outputs.
|
|
1099
1122
|
* These inputs and outputs are kept separate from those in other contexts,
|
|
1100
1123
|
* which allows an application to use the same underlying model instance
|
|
1101
1124
|
* with multiple sets of inputs and outputs.
|
|
1102
1125
|
*/
|
|
1103
|
-
interface ModelContext {
|
|
1104
|
-
|
|
1105
|
-
|
|
1106
|
-
|
|
1107
|
-
|
|
1108
|
-
|
|
1109
|
-
|
|
1110
|
-
|
|
1111
|
-
|
|
1112
|
-
|
|
1113
|
-
|
|
1114
|
-
|
|
1115
|
-
|
|
1116
|
-
|
|
1126
|
+
export interface ModelContext {
|
|
1127
|
+
/**
|
|
1128
|
+
* Called when the outputs have been updated after a model run.
|
|
1129
|
+
*/
|
|
1130
|
+
onOutputsChanged?: () => void;
|
|
1131
|
+
/**
|
|
1132
|
+
* Return the series data for the given model output variable or external
|
|
1133
|
+
* dataset.
|
|
1134
|
+
*
|
|
1135
|
+
* @param varId The ID of the output variable associated with the data.
|
|
1136
|
+
* @param sourceName The external data source name (e.g. "Ref"), or
|
|
1137
|
+
* undefined to use the latest model output data from this context.
|
|
1138
|
+
*/
|
|
1139
|
+
getSeriesForVar(varId: OutputVarId, sourceName?: SourceName): Series | undefined;
|
|
1117
1140
|
}
|
|
1118
1141
|
/**
|
|
1119
1142
|
* A high-level interface that schedules running of the underlying `ModelRunner`.
|
|
@@ -1134,91 +1157,92 @@ interface ModelContext {
|
|
|
1134
1157
|
* (on the main JavaScript thread) or asynchronously (in a Web Worker or Node.js
|
|
1135
1158
|
* worker thread).
|
|
1136
1159
|
*/
|
|
1137
|
-
declare class MultiContextModelScheduler {
|
|
1138
|
-
|
|
1139
|
-
|
|
1140
|
-
|
|
1141
|
-
|
|
1142
|
-
|
|
1143
|
-
|
|
1144
|
-
|
|
1145
|
-
|
|
1146
|
-
|
|
1147
|
-
|
|
1148
|
-
|
|
1149
|
-
|
|
1150
|
-
|
|
1151
|
-
|
|
1152
|
-
|
|
1153
|
-
|
|
1154
|
-
|
|
1155
|
-
|
|
1156
|
-
|
|
1157
|
-
|
|
1158
|
-
|
|
1159
|
-
|
|
1160
|
-
|
|
1161
|
-
|
|
1162
|
-
|
|
1163
|
-
|
|
1164
|
-
|
|
1165
|
-
|
|
1166
|
-
|
|
1167
|
-
|
|
1168
|
-
|
|
1169
|
-
|
|
1170
|
-
|
|
1171
|
-
|
|
1172
|
-
|
|
1173
|
-
|
|
1174
|
-
|
|
1175
|
-
|
|
1176
|
-
|
|
1177
|
-
|
|
1178
|
-
|
|
1179
|
-
|
|
1180
|
-
|
|
1181
|
-
|
|
1182
|
-
|
|
1183
|
-
|
|
1184
|
-
|
|
1185
|
-
|
|
1186
|
-
|
|
1187
|
-
|
|
1188
|
-
|
|
1189
|
-
|
|
1190
|
-
|
|
1191
|
-
|
|
1192
|
-
|
|
1193
|
-
|
|
1194
|
-
|
|
1195
|
-
|
|
1196
|
-
|
|
1197
|
-
|
|
1198
|
-
|
|
1199
|
-
|
|
1200
|
-
|
|
1201
|
-
|
|
1202
|
-
|
|
1203
|
-
|
|
1204
|
-
|
|
1205
|
-
|
|
1206
|
-
|
|
1207
|
-
|
|
1160
|
+
export declare class MultiContextModelScheduler {
|
|
1161
|
+
private readonly runner;
|
|
1162
|
+
/**
|
|
1163
|
+
* An optional `Outputs` instance that will be reused for the initial context. This will
|
|
1164
|
+
* be set to undefined after it is used for the first context.
|
|
1165
|
+
*/
|
|
1166
|
+
private initialOutputs?;
|
|
1167
|
+
/** The second array that holds a stable copy of the user inputs. */
|
|
1168
|
+
private currentInputs;
|
|
1169
|
+
/** The contexts that hold distinct sets of inputs and outputs. */
|
|
1170
|
+
private readonly contexts;
|
|
1171
|
+
/** Whether a model run has been scheduled. */
|
|
1172
|
+
private runNeeded;
|
|
1173
|
+
/** Whether a model run is in progress. */
|
|
1174
|
+
private runInProgress;
|
|
1175
|
+
/**
|
|
1176
|
+
* @param runner The model runner.
|
|
1177
|
+
* @param options Additional options for the scheduler.
|
|
1178
|
+
* @param options.initialOutputs An optional `Outputs` instance that will be reused
|
|
1179
|
+
* for the initial context. This is useful for saving memory when an `Outputs`
|
|
1180
|
+
* instance was already created for, e.g., a initial baseline/reference run.
|
|
1181
|
+
*/
|
|
1182
|
+
constructor(runner: ModelRunner, options?: {
|
|
1183
|
+
initialOutputs?: Outputs;
|
|
1184
|
+
});
|
|
1185
|
+
/**
|
|
1186
|
+
* Return true if the scheduler has started any model runs.
|
|
1187
|
+
*/
|
|
1188
|
+
isStarted(): boolean;
|
|
1189
|
+
/**
|
|
1190
|
+
* Add a new context that holds a distinct set of model inputs and outputs.
|
|
1191
|
+
* These inputs and outputs are kept separate from those in other contexts,
|
|
1192
|
+
* which allows an application to use the same underlying model to run with
|
|
1193
|
+
* multiple I/O contexts.
|
|
1194
|
+
*
|
|
1195
|
+
* Note that the contexts created before the first scheduled model run
|
|
1196
|
+
* will inherit the data from `initialOutputs` passed to the constructor,
|
|
1197
|
+
* but contexts created after that will initially have output values set
|
|
1198
|
+
* to zero.
|
|
1199
|
+
*
|
|
1200
|
+
* @param inputs The input values, in the same order as in the spec file passed to `sde`.
|
|
1201
|
+
* @param options Additional options for the context.
|
|
1202
|
+
* @param options.externalData Additional data that is external to the model outputs.
|
|
1203
|
+
* For example, this can contain data that was captured from an initial reference
|
|
1204
|
+
* run, or other static data that is displayed in graphs alongside the model
|
|
1205
|
+
* output data in graphs.
|
|
1206
|
+
*/
|
|
1207
|
+
addContext(inputs: InputValue[], options?: {
|
|
1208
|
+
externalData?: DataMap;
|
|
1209
|
+
}): ModelContext;
|
|
1210
|
+
/**
|
|
1211
|
+
* Remove the given context from the set of contexts managed by the scheduler.
|
|
1212
|
+
*
|
|
1213
|
+
* @param context The context to remove.
|
|
1214
|
+
*/
|
|
1215
|
+
removeContext(context: ModelContext): void;
|
|
1216
|
+
/**
|
|
1217
|
+
* Schedule a model run (if not already pending). When the run is
|
|
1218
|
+
* complete, save the outputs and call the `onOutputsChanged` callback.
|
|
1219
|
+
*/
|
|
1220
|
+
private runModelIfNeeded;
|
|
1221
|
+
/**
|
|
1222
|
+
* Run the model asynchronously for all relevant contexts.
|
|
1223
|
+
*/
|
|
1224
|
+
private runModelNow;
|
|
1225
|
+
/**
|
|
1226
|
+
* Run the model asynchronously using the current set of input values in the given context.
|
|
1227
|
+
*
|
|
1228
|
+
* @param context The context to use for the model run.
|
|
1229
|
+
*/
|
|
1230
|
+
private runModelNowForContext;
|
|
1208
1231
|
}
|
|
1209
|
-
|
|
1232
|
+
//#endregion
|
|
1233
|
+
//#region src/perf/perf.d.ts
|
|
1210
1234
|
/**
|
|
1211
1235
|
* Return a timestamp that can be passed to `perfElapsed` for calculating the elapsed
|
|
1212
1236
|
* time of an operation.
|
|
1213
1237
|
*
|
|
1214
1238
|
* @hidden This is not part of the public API; exposed only for use in performance testing.
|
|
1215
1239
|
*/
|
|
1216
|
-
declare function perfNow(): unknown;
|
|
1240
|
+
export declare function perfNow(): unknown;
|
|
1217
1241
|
/**
|
|
1218
1242
|
* Return the elapsed time between the given timestamp (created by `perfNow`) and now.
|
|
1219
1243
|
*
|
|
1220
1244
|
* @hidden This is not part of the public API; exposed only for use in performance testing.
|
|
1221
1245
|
*/
|
|
1222
|
-
declare function perfElapsed(t0: unknown): number;
|
|
1223
|
-
|
|
1224
|
-
|
|
1246
|
+
export declare function perfElapsed(t0: unknown): number;
|
|
1247
|
+
//#endregion
|
|
1248
|
+
//# sourceMappingURL=index.d.ts.map
|