@sdeverywhere/check-core 0.1.0

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.
@@ -0,0 +1,907 @@
1
+ declare type SourceName = string;
2
+ declare type VarId = string;
3
+ declare type ScenarioKey = string;
4
+ declare type ScenarioGroupKey = string;
5
+ declare type DatasetKey = string;
6
+ declare type Dataset = Map<number, number>;
7
+ declare type DatasetMap = Map<DatasetKey, Dataset>;
8
+
9
+ declare type InputPosition = 'at-default' | 'at-minimum' | 'at-maximum';
10
+ interface PositionSetting {
11
+ kind: 'position';
12
+ inputVarId: VarId;
13
+ position: InputPosition;
14
+ }
15
+ interface ValueSetting {
16
+ kind: 'value';
17
+ inputVarId: VarId;
18
+ value: number;
19
+ }
20
+ declare type InputSetting = PositionSetting | ValueSetting;
21
+ interface SettingsScenario {
22
+ kind: 'settings';
23
+ key: ScenarioKey;
24
+ groupKey: ScenarioGroupKey;
25
+ settings: InputSetting[];
26
+ }
27
+ interface AllInputsScenario {
28
+ kind: 'all-inputs';
29
+ key: ScenarioKey;
30
+ groupKey: ScenarioGroupKey;
31
+ position: InputPosition;
32
+ }
33
+ declare type Scenario = SettingsScenario | AllInputsScenario;
34
+ declare function positionSetting(inputVarId: VarId, position: InputPosition): InputSetting;
35
+ declare function valueSetting(inputVarId: VarId, value: number): InputSetting;
36
+ declare function settingsScenario(key: ScenarioKey, groupKey: ScenarioGroupKey, settings: InputSetting[]): Scenario;
37
+ declare function inputAtPositionScenario(inputVarId: VarId, groupKey: ScenarioGroupKey, position: InputPosition): Scenario;
38
+ declare function inputAtValueScenario(inputVarId: VarId, groupKey: ScenarioGroupKey, value: number): Scenario;
39
+ declare function allInputsAtPositionScenario(position: InputPosition): Scenario;
40
+ /**
41
+ * Return an array of scenarios that can be used to run the model
42
+ * with a matrix of output/input scenarios.
43
+ *
44
+ * For each output variable, run the model:
45
+ * - once with all inputs at their default
46
+ * - once with all inputs at their minimum
47
+ * - once with all inputs at their maximum
48
+ * - twice for each input
49
+ * - once with single input at its minimum
50
+ * - once with single input at its maximum
51
+ */
52
+ declare function matrixScenarios(inputVarIds: VarId[]): Scenario[];
53
+
54
+ interface DatasetsResult {
55
+ /**
56
+ * The map of datasets for the scenario.
57
+ */
58
+ datasetMap: DatasetMap;
59
+ /**
60
+ * The number of milliseconds that elapsed when running the model, or undefined if the model
61
+ * wasn't run for this scenario.
62
+ */
63
+ modelRunTime?: number;
64
+ }
65
+ interface DataSource {
66
+ /** Return the datasets that result from running the given scenario. */
67
+ getDatasetsForScenario(scenario: Scenario, datasetKeys: DatasetKey[]): Promise<DatasetsResult>;
68
+ }
69
+
70
+ /**
71
+ * Holds information about an item related to a variable used in the model.
72
+ * For example, this can be used to attach information about a graph that
73
+ * an output variable is used in, or a slider that controls an input variable.
74
+ */
75
+ interface RelatedItem {
76
+ id: string;
77
+ locationPath: string[];
78
+ }
79
+ /**
80
+ * Holds information about an input variable used in the model.
81
+ */
82
+ interface InputVar {
83
+ varId: VarId;
84
+ varName: string;
85
+ defaultValue: number;
86
+ minValue: number;
87
+ maxValue: number;
88
+ relatedItem?: RelatedItem;
89
+ }
90
+ /**
91
+ * Holds information about an output variable used in the model.
92
+ */
93
+ interface OutputVar {
94
+ sourceName?: SourceName;
95
+ varId: VarId;
96
+ varName: string;
97
+ relatedItems?: RelatedItem[];
98
+ }
99
+ /**
100
+ * Holds information about a subscript used in the model.
101
+ */
102
+ interface Subscript {
103
+ /** The subscript identifier, as used in SDE. */
104
+ id: string;
105
+ /** The subscript name, as used in Vensim. */
106
+ name: string;
107
+ }
108
+ /**
109
+ * Holds information about a dimension (subscript family) used in the model.
110
+ */
111
+ interface Dimension {
112
+ /** The dimension identifier, as used in SDE. */
113
+ id: string;
114
+ /** The dimension name, as used in Vensim. */
115
+ name: string;
116
+ /** The set of subscripts in this dimension. */
117
+ subscripts: Subscript[];
118
+ }
119
+ /**
120
+ * Holds information about a variable used in the model implementation.
121
+ */
122
+ interface ImplVar {
123
+ /** The variable identifier, as used in SDE. */
124
+ varId: VarId;
125
+ /** The variable name, as used in Vensim. */
126
+ varName: string;
127
+ /** The variable index, used by SDE to reference the value in the generated model. */
128
+ varIndex: number;
129
+ /** The set of dimensions for this variable. */
130
+ dimensions: Dimension[];
131
+ /** The variable type (e.g. 'level', 'const'). */
132
+ varType: string;
133
+ }
134
+
135
+ /**
136
+ * Includes the properties needed to display a legend item in the UI.
137
+ */
138
+ interface LegendItem {
139
+ /** The item text. */
140
+ label: string;
141
+ /** The color of the item (in CSS/hex format). */
142
+ color: string;
143
+ }
144
+ /**
145
+ * Includes the properties needed to display a link item in the UI.
146
+ */
147
+ interface LinkItem {
148
+ /** Whether content is a URL or text to be copied to the clipboard. */
149
+ kind: 'url' | 'copy';
150
+ /** The link text that appears in the UI. */
151
+ text: string;
152
+ /** The link content (a URL or text). */
153
+ content: string;
154
+ }
155
+ declare type BundleGraphId = string;
156
+ /**
157
+ * Describes a dataset in a bundle-specific graph.
158
+ */
159
+ interface BundleGraphDatasetSpec {
160
+ /** The dataset key. */
161
+ datasetKey: DatasetKey;
162
+ /** The dataset or variable name. */
163
+ varName: string;
164
+ /** The source name. */
165
+ sourceName?: string;
166
+ /** The label string (as it appears in the graph legend). */
167
+ label?: string;
168
+ /** The color of the plot (in CSS/hex format). */
169
+ color: string;
170
+ }
171
+ /**
172
+ * Describes a bundle-specific graph.
173
+ */
174
+ interface BundleGraphSpec {
175
+ /** The graph identifier. */
176
+ id: BundleGraphId;
177
+ /** The graph title. */
178
+ title: string;
179
+ /** The legend items for the graph. */
180
+ legendItems: LegendItem[];
181
+ /** The datasets displayed in this graph. */
182
+ datasets: BundleGraphDatasetSpec[];
183
+ /** Metadata for the graph that can be used to diff to another graph. */
184
+ metadata: Map<string, string>;
185
+ }
186
+ /**
187
+ * Allows for displaying a bundle-specific graph.
188
+ */
189
+ interface BundleGraphView {
190
+ /** Destroy the underlying graph view and any associated resources. */
191
+ destroy(): void;
192
+ }
193
+ /**
194
+ * Wrapper around data that can be used to initialize a graph view.
195
+ */
196
+ interface BundleGraphData {
197
+ /** Return a graph view that can be attached to the given canvas element. */
198
+ createGraphView(canvas: HTMLCanvasElement): BundleGraphView;
199
+ }
200
+ /**
201
+ * Describes the model that is contained in this bundle.
202
+ */
203
+ interface ModelSpec {
204
+ /** The size of the model binary, in bytes. */
205
+ modelSizeInBytes: number;
206
+ /** The size of the static data, in bytes. */
207
+ dataSizeInBytes: number;
208
+ /** The map of all input variables in this version of the model. */
209
+ inputVars: Map<VarId, InputVar>;
210
+ /** The map of all output (and static data) variables in this version of the model. */
211
+ outputVars: Map<DatasetKey, OutputVar>;
212
+ /** The map of all variables (both internal and exported) in this version of the model. */
213
+ implVars: Map<DatasetKey, ImplVar>;
214
+ /** The custom input variable groups defined for this model. */
215
+ inputGroups: Map<string, InputVar[]>;
216
+ /** The custom dataset (output variable) groups defined for this model. */
217
+ datasetGroups: Map<string, DatasetKey[]>;
218
+ /** The start time (year) for the model. */
219
+ startTime?: number;
220
+ /** The end time (year) for the model. */
221
+ endTime?: number;
222
+ /** The specs for the bundled graphs. */
223
+ graphSpecs?: BundleGraphSpec[];
224
+ }
225
+ /**
226
+ * An interface that allows for running the bundled model under different input scenarios
227
+ * and capturing the resulting output data.
228
+ */
229
+ interface BundleModel extends DataSource {
230
+ /** The spec for the bundled model. */
231
+ modelSpec: ModelSpec;
232
+ /**
233
+ * Return the set of context graphs to be displayed for the given dataset. If left
234
+ * undefined, the set of graphs will be determined using the advertised graph specs.
235
+ */
236
+ getGraphsForDataset?(datasetKey: DatasetKey): BundleGraphId[];
237
+ /**
238
+ * Load the data used to display the graph by running the model with inputs
239
+ * configured for the given scenario.
240
+ */
241
+ getGraphDataForScenario(scenario: Scenario, graphId: BundleGraphId): Promise<BundleGraphData>;
242
+ /** Return the links to be displayed for the graph in the given scenario. */
243
+ getGraphLinksForScenario(scenario: Scenario, graphId: BundleGraphId): LinkItem[];
244
+ }
245
+ /**
246
+ * Provides access to the model that is contained in this bundle for use in
247
+ * model-check packages.
248
+ */
249
+ interface Bundle {
250
+ /**
251
+ * The version of the bundle. This should be incremented when there is an
252
+ * incompatible change to the bundle format. The model-check tools can use
253
+ * this value to skip tests if two bundles have different version numbers.
254
+ */
255
+ version: number;
256
+ /** The spec for the bundled model. */
257
+ modelSpec: ModelSpec;
258
+ /** Asynchronously initialize the underlying model. */
259
+ initModel(): Promise<BundleModel>;
260
+ }
261
+ /**
262
+ * Associates a name with a `Bundle`.
263
+ */
264
+ interface NamedBundle {
265
+ /** The name of the bundle, for example, "Current" or "Baseline". */
266
+ name: string;
267
+ /** The associated bundle. */
268
+ bundle: Bundle;
269
+ }
270
+ /**
271
+ * Represents a bundle that has had its model initialized.
272
+ */
273
+ interface LoadedBundle {
274
+ /** The name of the bundle, for example, "Current" or "Baseline". */
275
+ name: string;
276
+ /** The version of the bundle. */
277
+ version: number;
278
+ /** The initialized model. */
279
+ model: BundleModel;
280
+ }
281
+
282
+ declare type CheckDataRequestKey = string;
283
+ /**
284
+ * Coordinates on-demand loading of data used to display a graph representation
285
+ * of a check/predicate.
286
+ */
287
+ declare class CheckDataCoordinator {
288
+ readonly bundleModel: BundleModel;
289
+ private readonly taskQueue;
290
+ constructor(bundleModel: BundleModel);
291
+ requestDataset(requestKey: CheckDataRequestKey, scenario: Scenario, datasetKey: DatasetKey, onResponse: (dataset: Dataset) => void): void;
292
+ cancelRequest(key: CheckDataRequestKey): void;
293
+ }
294
+
295
+ declare type CheckPredicateOp = 'gt' | 'gte' | 'lt' | 'lte' | 'eq' | 'approx';
296
+
297
+ declare type CheckPredicateTimeSingle = number;
298
+ declare type CheckPredicateTimeRange = [number, number];
299
+ interface CheckPredicateTimeOptions {
300
+ after_excl?: number;
301
+ after_incl?: number;
302
+ before_excl?: number;
303
+ before_incl?: number;
304
+ }
305
+ declare type CheckPredicateTimeSpec = CheckPredicateTimeSingle | CheckPredicateTimeRange | CheckPredicateTimeOptions;
306
+
307
+ interface CheckResultErrorInfo {
308
+ kind: 'unknown-dataset' | 'unknown-input' | 'unknown-input-group' | 'empty-input-group';
309
+ name: string;
310
+ }
311
+ interface CheckResult {
312
+ status: 'passed' | 'failed' | 'error';
313
+ message?: string;
314
+ failValue?: number;
315
+ failOp?: CheckPredicateOp;
316
+ failRefValue?: number;
317
+ failTime?: number;
318
+ errorInfo?: CheckResultErrorInfo;
319
+ }
320
+
321
+ declare type CheckDatasetError = 'no-matches-for-dataset' | 'no-matches-for-group' | 'no-matches-for-type';
322
+ interface CheckDataset {
323
+ /** The key for the matched dataset; can be undefined if no dataset matched. */
324
+ datasetKey?: DatasetKey;
325
+ /** The name of the matched dataset, or the name associated with the error, if defined. */
326
+ name: string;
327
+ /** The error info if the dataset query failed to match. */
328
+ error?: CheckDatasetError;
329
+ }
330
+
331
+ interface CheckScenarioError {
332
+ kind: 'unknown-input-group' | 'empty-input-group';
333
+ /** The name of the input group that failed to match. */
334
+ name: string;
335
+ }
336
+ interface CheckScenarioInputDesc {
337
+ /** The name of the input. */
338
+ name: string;
339
+ /** The matched input variable; can be undefined if no input matched. */
340
+ inputVar?: InputVar;
341
+ /** The position of the input, if this is a position scenario. */
342
+ position?: InputPosition;
343
+ /** The value of the input, for the given position or explicit value. */
344
+ value?: number;
345
+ }
346
+ interface CheckScenario {
347
+ /** The scenario for the matched input(s); can be undefined if input(s) failed to match. */
348
+ scenario?: Scenario;
349
+ /** The name of the associated input group, if any. */
350
+ inputGroupName?: string;
351
+ /** The descriptions of the inputs; if empty, it is an "all inputs" scenario. */
352
+ inputDescs: CheckScenarioInputDesc[];
353
+ /** The error info if the scenario/input query failed to match. */
354
+ error?: CheckScenarioError;
355
+ }
356
+
357
+ /**
358
+ * The key type for data references (in the form `<ScenarioKey::DatasetKey>`).
359
+ */
360
+ declare type CheckDataRefKey = string;
361
+ /**
362
+ * The scenario and dataset referenced by a particular predicate (for cases
363
+ * where the check is against another dataset rather than a constant value).
364
+ */
365
+ interface CheckDataRef {
366
+ /** The key for the reference; can be undefined if inputs or datasets failed to match. */
367
+ key?: CheckDataRefKey;
368
+ /** The scenario used to generate the referenced dataset. */
369
+ scenario: CheckScenario;
370
+ /** The referenced dataset. */
371
+ dataset: CheckDataset;
372
+ }
373
+
374
+ declare type CheckKey = number;
375
+
376
+ declare type CheckStatus = 'passed' | 'failed' | 'error';
377
+ interface CheckPredicateOpConstantRef {
378
+ kind: 'constant';
379
+ value: number;
380
+ }
381
+ interface CheckPredicateOpDataRef {
382
+ kind: 'data';
383
+ dataRef: CheckDataRef;
384
+ }
385
+ declare type CheckPredicateOpRef = CheckPredicateOpConstantRef | CheckPredicateOpDataRef;
386
+ interface CheckPredicateReport {
387
+ checkKey: CheckKey;
388
+ result: CheckResult;
389
+ opRefs: Map<CheckPredicateOp, CheckPredicateOpRef>;
390
+ opValues: string[];
391
+ time?: CheckPredicateTimeSpec;
392
+ tolerance?: number;
393
+ }
394
+ interface CheckDatasetReport {
395
+ checkDataset: CheckDataset;
396
+ status: CheckStatus;
397
+ predicates: CheckPredicateReport[];
398
+ }
399
+ interface CheckScenarioReport {
400
+ checkScenario: CheckScenario;
401
+ status: CheckStatus;
402
+ datasets: CheckDatasetReport[];
403
+ }
404
+ interface CheckTestReport {
405
+ name: string;
406
+ status: CheckStatus;
407
+ scenarios: CheckScenarioReport[];
408
+ }
409
+ interface CheckGroupReport {
410
+ name: string;
411
+ tests: CheckTestReport[];
412
+ }
413
+ interface CheckReport {
414
+ groups: CheckGroupReport[];
415
+ }
416
+ declare type StyleFunc = (s: string) => string;
417
+ /**
418
+ * Return a string representation of the given scenario.
419
+ *
420
+ * @param scenario The scenario report.
421
+ * @param bold A function that applies bold styling to a string.
422
+ */
423
+ declare function scenarioMessage(scenario: CheckScenarioReport, bold: StyleFunc): string;
424
+ /**
425
+ * Return a string representation of the given dataset.
426
+ *
427
+ * @param dataset The dataset report.
428
+ * @param bold A function that applies bold styling to a string.
429
+ */
430
+ declare function datasetMessage(dataset: CheckDatasetReport, bold: StyleFunc): string;
431
+ /**
432
+ * Return a string representation of the given predicate.
433
+ *
434
+ * @param predicate The predicate report.
435
+ * @param bold A function that applies bold styling to a string.
436
+ */
437
+ declare function predicateMessage(predicate: CheckPredicateReport, bold: StyleFunc): string;
438
+
439
+ interface CheckOptions {
440
+ /** The strings containing check tests in YAML format. */
441
+ tests: string[];
442
+ }
443
+ interface CheckConfig {
444
+ /** The loaded bundle being checked. */
445
+ bundle: LoadedBundle;
446
+ /** The strings containing check tests in YAML format. */
447
+ tests: string[];
448
+ }
449
+
450
+ /**
451
+ * A simplified/terse version of `CheckPredicateReport` that matches the
452
+ * format of the JSON objects emitted by the CLI in terse mode.
453
+ */
454
+ interface CheckPredicateSummary {
455
+ checkKey: CheckKey;
456
+ result: CheckResult;
457
+ }
458
+ /**
459
+ * A simplified/terse version of `CheckReport` that matches the
460
+ * format of the JSON objects emitted by the CLI in terse mode.
461
+ * This only contains predicate summaries for checks that have a status
462
+ * of 'failed' or 'error'.
463
+ */
464
+ interface CheckSummary {
465
+ predicateSummaries: CheckPredicateSummary[];
466
+ }
467
+ /**
468
+ * Convert a full `CheckReport` to a simplified `CheckSummary` that only includes
469
+ * failed/errored checks.
470
+ *
471
+ * @param checkReport The full check report.
472
+ * @return The converted check summary.
473
+ */
474
+ declare function checkSummaryFromReport(checkReport: CheckReport): CheckSummary;
475
+ /**
476
+ * Convert a simplified `CheckSummary` to a full `CheckReport` that restores the
477
+ * structure of the tests from the given configuration.
478
+ *
479
+ * @param checkConfig The config used to reconstruct the check test structure.
480
+ * @param checkSummary The simplified check summary.
481
+ * @param simplifyScenarios If true, reduce the number of scenarios generated for a `matrix`.
482
+ * @return The converted check report.
483
+ */
484
+ declare function checkReportFromSummary(checkConfig: CheckConfig, checkSummary: CheckSummary, simplifyScenarios: boolean): CheckReport | undefined;
485
+
486
+ /**
487
+ * Describes a scenario/dataset comparison.
488
+ */
489
+ interface CompareItem {
490
+ /** The item title. */
491
+ title: string;
492
+ /** The item subtitle. */
493
+ subtitle?: string;
494
+ /** The scenario used for comparison. */
495
+ scenario: Scenario;
496
+ /** The key for the datasets being compared. */
497
+ datasetKey: DatasetKey;
498
+ }
499
+ /**
500
+ * The title and subtitle info for a group of comparisons.
501
+ */
502
+ interface CompareGroupInfo {
503
+ /** The group title. */
504
+ title: string;
505
+ /** The group subtitle. */
506
+ subtitle?: string;
507
+ /** The related items (e.g. graphs or sliders) for the group. */
508
+ relatedItems: RelatedItem[];
509
+ }
510
+ /**
511
+ * Describes a group of comparisons. The results can be grouped either
512
+ * by dataset or by scenario.
513
+ */
514
+ interface CompareGroup {
515
+ /** The group title/subtitle info. */
516
+ info: CompareGroupInfo;
517
+ /** The items in the group. */
518
+ items: CompareItem[];
519
+ }
520
+
521
+ /**
522
+ * The variable/source name info associated with a dataset.
523
+ */
524
+ interface DatasetInfo {
525
+ /** The variable name. */
526
+ varName: string;
527
+ /** The new variable name, if it was renamed. */
528
+ newVarName?: string;
529
+ /** The source name. */
530
+ sourceName?: string;
531
+ /** The new source name, if it was renamed. */
532
+ newSourceName?: string;
533
+ /** The related items (e.g. graphs) for the dataset. */
534
+ relatedItems: RelatedItem[];
535
+ }
536
+ /**
537
+ * The human-readable title and subtitle for a scenario.
538
+ */
539
+ interface ScenarioInfo {
540
+ /** The scenario title. */
541
+ title: string;
542
+ /** The scenario subtitle. */
543
+ subtitle?: string;
544
+ /**
545
+ * The position of the scenario when displayed in a row. Typically, 0 means
546
+ * "left", 1 means "middle", and so on.
547
+ */
548
+ position: number;
549
+ }
550
+
551
+ /**
552
+ * Provides access to the set of scenarios that are used when comparing the two models.
553
+ */
554
+ interface CompareScenarios {
555
+ /**
556
+ * Return an array containing all configured scenarios.
557
+ */
558
+ getScenarios(): Scenario[];
559
+ /**
560
+ * Return the scenario for the given key.
561
+ *
562
+ * @param scenarioKey The key for the scenario.
563
+ */
564
+ getScenario(scenarioKey: ScenarioKey): Scenario | undefined;
565
+ /**
566
+ * Return the group info for the given group key.
567
+ *
568
+ * @param groupKey The scenario group key.
569
+ */
570
+ getScenarioGroupInfo(groupKey: ScenarioGroupKey): CompareGroupInfo | undefined;
571
+ /**
572
+ * Return the title/subtitle info for the given scenario.
573
+ *
574
+ * Note that the given `groupKey` could be different than `scenario.groupKey`. This
575
+ * will be the case for the "all inputs at default" item that is included in each
576
+ * row in the detail view for reference purposes. The provided `groupKey` will be
577
+ * used to customize the title and subtitle for that item (for example, it will show
578
+ * the default value of the input associated with the row).
579
+ *
580
+ * @param scenario The scenario to be displayed.
581
+ * @param groupKey The key for the group in which the scenario will be displayed.
582
+ */
583
+ getScenarioInfo(scenario: Scenario, groupKey: ScenarioGroupKey): ScenarioInfo | undefined;
584
+ }
585
+ /**
586
+ * Provides access to the set of datasets that are configured for comparison.
587
+ */
588
+ interface CompareDatasets {
589
+ /** The mapping of renamed dataset keys. */
590
+ renamedDatasetKeys?: Map<DatasetKey, DatasetKey>;
591
+ /**
592
+ * Return the keys for the datasets that should be compared for the given scenario.
593
+ *
594
+ * @param scenario The scenario.
595
+ */
596
+ getDatasetKeysForScenario(scenario: Scenario): DatasetKey[];
597
+ /**
598
+ * Return the dataset info for the given key.
599
+ */
600
+ getDatasetInfo(datasetKey: DatasetKey): DatasetInfo | undefined;
601
+ }
602
+ interface CompareOptions {
603
+ baseline: NamedBundle;
604
+ thresholds: number[];
605
+ scenarios: CompareScenarios;
606
+ datasets: CompareDatasets;
607
+ }
608
+ interface CompareConfig {
609
+ bundleL: LoadedBundle;
610
+ bundleR: LoadedBundle;
611
+ thresholds: number[];
612
+ scenarios: CompareScenarios;
613
+ datasets: CompareDatasets;
614
+ }
615
+
616
+ declare type CompareDataRequestKey = string;
617
+ /**
618
+ * Coordinates loading of data in parallel from two models.
619
+ */
620
+ declare class CompareDataCoordinator {
621
+ readonly bundleModelL: BundleModel;
622
+ readonly bundleModelR: BundleModel;
623
+ private readonly taskQueue;
624
+ constructor(bundleModelL: BundleModel, bundleModelR: BundleModel);
625
+ requestDatasetMaps(requestKey: CompareDataRequestKey, scenario: Scenario, datasetKeys: DatasetKey[], onResponse: (datasetMapL: DatasetMap, datasetMapR: DatasetMap) => void): void;
626
+ requestGraphData(requestKey: CompareDataRequestKey, bundle: 'left' | 'right', scenario: Scenario, graphId: BundleGraphId, onResponse: (graphData: BundleGraphData) => void): void;
627
+ cancelRequest(key: CompareDataRequestKey): void;
628
+ }
629
+
630
+ interface PerfReport {
631
+ readonly minTime: number;
632
+ readonly maxTime: number;
633
+ readonly avgTime: number;
634
+ readonly allTimes: number[];
635
+ }
636
+ declare class PerfStats {
637
+ private readonly times;
638
+ addRun(timeInMillis: number): void;
639
+ toReport(): PerfReport;
640
+ }
641
+
642
+ interface CompareDatasetReport {
643
+ scenarioKey: ScenarioKey;
644
+ datasetKey: DatasetKey;
645
+ diffReport: DiffReport;
646
+ }
647
+ interface CompareReport {
648
+ datasetReports: CompareDatasetReport[];
649
+ perfReportL: PerfReport;
650
+ perfReportR: PerfReport;
651
+ }
652
+
653
+ interface DiffPoint {
654
+ time: number;
655
+ valueL: number;
656
+ valueR: number;
657
+ }
658
+ declare type DiffValidity = 'neither' | 'left-only' | 'right-only' | 'both';
659
+ interface DiffReport {
660
+ validity: DiffValidity;
661
+ minValue: number;
662
+ maxValue: number;
663
+ avgDiff: number;
664
+ minDiff: number;
665
+ maxDiff: number;
666
+ maxDiffPoint: DiffPoint;
667
+ }
668
+ declare function diffDatasets(datasetL: Dataset | undefined, datasetR: Dataset | undefined): DiffReport;
669
+ declare function compareDatasets(scenarioKey: ScenarioKey, datasetKey: DatasetKey, datasetMapL: DatasetMap, datasetMapR: DatasetMap): CompareDatasetReport;
670
+
671
+ /**
672
+ * A simplified/terse version of `CompareDatasetReport` that matches the
673
+ * format of the JSON objects emitted by the CLI in terse mode.
674
+ * The object keys are terse and it only includes the minimum set of fields
675
+ * to keep the file smaller when there are many reported differences.
676
+ */
677
+ interface CompareDatasetSummary {
678
+ /** Short for `scenarioKey`. */
679
+ s: ScenarioKey;
680
+ /** Short for `datasetKey`. */
681
+ d: DatasetKey;
682
+ /** Short for `maxDiff`. */
683
+ md: number;
684
+ }
685
+ /**
686
+ * A simplified/terse version of `CompareReport` that matches the
687
+ * format of the JSON objects emitted by the CLI in terse mode.
688
+ */
689
+ interface CompareSummary {
690
+ datasetSummaries: CompareDatasetSummary[];
691
+ perfReportL: PerfReport;
692
+ perfReportR: PerfReport;
693
+ }
694
+ /**
695
+ * Convert a full `CompareReport` to a simplified `CompareSummary` that includes
696
+ * the minimum set of fields needed to keep the file smaller when there are many
697
+ * reported differences.
698
+ *
699
+ * @param compareReport The full compare report.
700
+ * @return The converted compare summary.
701
+ */
702
+ declare function compareSummaryFromReport(compareReport: CompareReport): CompareSummary;
703
+
704
+ declare type GraphInclusion = 'neither' | 'left-only' | 'right-only' | 'both';
705
+ interface GraphMetadataReport {
706
+ /** The key for the metadata field. */
707
+ key: string;
708
+ /** The value of the metadata field in the left bundle. */
709
+ valueL?: string;
710
+ /** The value of the metadata field in the right bundle. */
711
+ valueR?: string;
712
+ }
713
+ interface GraphDatasetReport {
714
+ /** The dataset key. */
715
+ datasetKey: DatasetKey;
716
+ /** The max diff for this dataset. */
717
+ maxDiff?: number;
718
+ }
719
+ interface GraphReport {
720
+ /** Indicates which bundles the graph is defined in. */
721
+ inclusion: GraphInclusion;
722
+ /** The metadata fields with differences. */
723
+ metadataReports: GraphMetadataReport[];
724
+ /** The datasets with differences. */
725
+ datasetReports: GraphDatasetReport[];
726
+ }
727
+ /**
728
+ * Compare the metadata and datasets for the given graphs.
729
+ *
730
+ * @param graphL The graph defined in the left bundle.
731
+ * @param graphR The graph defined in the right bundle.
732
+ * @param scenarioKey The scenario used for comparing datasets.
733
+ * @param datasetSummaries The set of summaries from a previous comparison run.
734
+ */
735
+ declare function diffGraphs(graphL: BundleGraphSpec | undefined, graphR: BundleGraphSpec | undefined, scenarioKey: ScenarioKey, datasetSummaries: CompareDatasetSummary[]): GraphReport;
736
+
737
+ interface ConfigOptions {
738
+ /**
739
+ * The bundle being checked. This bundle will also be compared against the
740
+ * "baseline" bundle, if `compare` is defined.
741
+ */
742
+ current: NamedBundle;
743
+ /**
744
+ * The model check options.
745
+ */
746
+ check: CheckOptions;
747
+ /**
748
+ * The model comparison options.
749
+ */
750
+ compare?: CompareOptions;
751
+ }
752
+ interface Config {
753
+ check: CheckConfig;
754
+ compare?: CompareConfig;
755
+ }
756
+
757
+ declare function createConfig(options: ConfigOptions): Promise<Config>;
758
+
759
+ /**
760
+ * Manages a set of dataset keys (corresponding to the available model outputs
761
+ * in the given bundles) that can be used to compare two versions of the model.
762
+ *
763
+ * This class computes the union of the available dataset keys and handles
764
+ * renames so that if any variables were renamed in the "right" bundle, the
765
+ * old key will be used so that the variable can still be compared.
766
+ *
767
+ * This is intended to be a simple, general purpose way to create a set of
768
+ * dataset keys, but every model is different, so you can replace this with
769
+ * a different set of dataset keys that is better suited for the model you
770
+ * are testing.
771
+ */
772
+ declare class DatasetManager implements CompareDatasets {
773
+ private readonly bundleL;
774
+ private readonly bundleR;
775
+ readonly renamedDatasetKeys?: Map<DatasetKey, DatasetKey>;
776
+ readonly allOutputVarKeys: DatasetKey[];
777
+ readonly modelOutputVarKeys: DatasetKey[];
778
+ /**
779
+ * @param bundleL The "left" bundle being compared.
780
+ * @param bundleR The "right" bundle being compared.
781
+ * @param renamedDatasetKeys The mapping of renamed dataset keys.
782
+ */
783
+ constructor(bundleL: Bundle, bundleR: Bundle, renamedDatasetKeys?: Map<DatasetKey, DatasetKey>);
784
+ getDatasetKeysForScenario(scenario: Scenario): DatasetKey[];
785
+ getDatasetInfo(datasetKey: DatasetKey): DatasetInfo | undefined;
786
+ }
787
+
788
+ /**
789
+ * Manages a set of scenarios (corresponding to the available model inputs
790
+ * in the given bundles) that can be used to compare two versions of the model.
791
+ */
792
+ declare class ScenarioManager implements CompareScenarios {
793
+ private readonly bundleL;
794
+ private readonly bundleR;
795
+ private readonly scenarios;
796
+ private readonly scenarioInfo;
797
+ private readonly defaultInfoForGroup;
798
+ private readonly groupInfo;
799
+ /**
800
+ * @param bundleL The "left" bundle being compared.
801
+ * @param bundleR The "right" bundle being compared.
802
+ */
803
+ constructor(bundleL: Bundle, bundleR: Bundle);
804
+ getScenarios(): Scenario[];
805
+ getScenario(scenarioKey: ScenarioKey): Scenario | undefined;
806
+ getScenarioGroupInfo(groupKey: ScenarioGroupKey): CompareGroupInfo | undefined;
807
+ getScenarioInfo(scenario: Scenario, groupKey: ScenarioGroupKey): ScenarioInfo | undefined;
808
+ /**
809
+ * Override the title and subtitle that are displayed when the "all inputs at default"
810
+ * scenario is included for a particular group. This can be used to customize the
811
+ * text instead of showing the default message ("...at default").
812
+ *
813
+ * @param groupKey The scenario group key.
814
+ * @param scenarioInfo The custom info to be displayed.
815
+ */
816
+ setDefaultScenarioInfoForGroup(groupKey: ScenarioGroupKey, scenarioInfo: ScenarioInfo): void;
817
+ /**
818
+ * Add a scenario to the set.
819
+ *
820
+ * @param scenario The scenario to be added.
821
+ * @param scenarioInfo The custom title/subtitle for the scenario. If left undefined, the
822
+ * default (possibly generic) info will be used.
823
+ * @param groupInfo The custom title/subtitle for the group. If left undefined, the
824
+ * default (possibly generic) info will be used.
825
+ */
826
+ addScenario(scenario: Scenario, scenarioInfo?: ScenarioInfo, groupInfo?: CompareGroupInfo): void;
827
+ /**
828
+ * Adds a set of scenarios that can be used to compare the two versions of
829
+ * the given model.
830
+ *
831
+ * This function computes a matrix of input scenarios using the input variables
832
+ * advertised by the given bundles. It will generate scenarios such that for
833
+ * any output variable, the model will be run:
834
+ * - once with all inputs at their default
835
+ * - once with all inputs at their minimum
836
+ * - once with all inputs at their maximum
837
+ * - twice for each input
838
+ * - once with single input at its minimum
839
+ * - once with single input at its maximum
840
+ *
841
+ * This is intended to be a simple, general purpose way to create a set of
842
+ * scenarios, but every model is different, so you can replace this with a
843
+ * function to generate a different set of scenarios that is better suited
844
+ * for the model you are testing.
845
+ */
846
+ addScenarioMatrix(): void;
847
+ private getGroupInfoForScenario;
848
+ private getInfoForScenario;
849
+ private getInfoForPositionSetting;
850
+ private getRelatedItemsForSettings;
851
+ private getInputVarForSetting;
852
+ }
853
+
854
+ declare class PerfRunner {
855
+ readonly bundleModelL: BundleModel;
856
+ readonly bundleModelR: BundleModel;
857
+ private readonly mode;
858
+ private readonly taskQueue;
859
+ onComplete?: (reportL: PerfReport, reportR: PerfReport) => void;
860
+ onError?: (error: Error) => void;
861
+ constructor(bundleModelL: BundleModel, bundleModelR: BundleModel, mode?: 'serial' | 'parallel');
862
+ start(): void;
863
+ }
864
+
865
+ interface SuiteReport {
866
+ checkReport: CheckReport;
867
+ compareReport?: CompareReport;
868
+ }
869
+
870
+ declare type CancelRunSuite = () => void;
871
+ interface RunSuiteCallbacks {
872
+ onProgress?: (pct: number) => void;
873
+ onComplete?: (suiteReport: SuiteReport) => void;
874
+ onError?: (error: Error) => void;
875
+ }
876
+ interface RunSuiteOptions {
877
+ /** Set to true to reduce the number of scenarios generated for a `matrix`. */
878
+ simplifyScenarios?: boolean;
879
+ }
880
+ /**
881
+ * Run the full suite of checks and comparisons defined in the given configuration.
882
+ *
883
+ * @param config The test suite configuration.
884
+ * @param callbacks The callbacks that will be notified.
885
+ * @param options Options to control how the tests are run.
886
+ * @return A function that will cancel the process when invoked.
887
+ */
888
+ declare function runSuite(config: Config, callbacks: RunSuiteCallbacks, options?: RunSuiteOptions): CancelRunSuite;
889
+
890
+ /**
891
+ * A simplified/terse version of `SuiteReport` that matches the
892
+ * format of the JSON objects emitted by the CLI in terse mode.
893
+ */
894
+ interface SuiteSummary {
895
+ checkSummary: CheckSummary;
896
+ compareSummary?: CompareSummary;
897
+ }
898
+ /**
899
+ * Convert a full `SuiteReport` to a simplified `SuiteSummary` that only includes
900
+ * failed/errored checks or comparisons with differences.
901
+ *
902
+ * @param suiteReport The full suite report.
903
+ * @return The converted suite summary.
904
+ */
905
+ declare function suiteSummaryFromReport(suiteReport: SuiteReport): SuiteSummary;
906
+
907
+ export { AllInputsScenario, Bundle, BundleGraphData, BundleGraphDatasetSpec, BundleGraphId, BundleGraphSpec, BundleGraphView, BundleModel, CheckDataCoordinator, CheckDataRequestKey, CheckDatasetReport, CheckGroupReport, CheckKey, CheckPredicateOp, CheckPredicateOpConstantRef, CheckPredicateOpDataRef, CheckPredicateOpRef, CheckPredicateReport, CheckPredicateSummary, CheckPredicateTimeOptions, CheckPredicateTimeRange, CheckPredicateTimeSingle, CheckPredicateTimeSpec, CheckReport, CheckResult, CheckResultErrorInfo, CheckScenarioReport, CheckStatus, CheckSummary, CheckTestReport, CompareConfig, CompareDataCoordinator, CompareDataRequestKey, CompareDatasetReport, CompareDatasetSummary, CompareDatasets, CompareGroup, CompareGroupInfo, CompareItem, CompareOptions, CompareReport, CompareScenarios, CompareSummary, Config, ConfigOptions, DataSource, Dataset, DatasetInfo, DatasetKey, DatasetManager, DatasetMap, DatasetsResult, DiffPoint, DiffReport, DiffValidity, Dimension, GraphDatasetReport, GraphInclusion, GraphMetadataReport, GraphReport, ImplVar, InputPosition, InputSetting, InputVar, LegendItem, LinkItem, LoadedBundle, ModelSpec, NamedBundle, OutputVar, PerfReport, PerfRunner, PerfStats, PositionSetting, RelatedItem, RunSuiteCallbacks, RunSuiteOptions, Scenario, ScenarioGroupKey, ScenarioInfo, ScenarioKey, ScenarioManager, SettingsScenario, SourceName, Subscript, SuiteReport, SuiteSummary, ValueSetting, VarId, allInputsAtPositionScenario, checkReportFromSummary, checkSummaryFromReport, compareDatasets, compareSummaryFromReport, createConfig, datasetMessage, diffDatasets, diffGraphs, inputAtPositionScenario, inputAtValueScenario, matrixScenarios, positionSetting, predicateMessage, runSuite, scenarioMessage, settingsScenario, suiteSummaryFromReport, valueSetting };