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