@cognipilot/rumoca-core 0.9.4 → 0.9.5
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 +5 -5
- package/modelica_language.js +88 -0
- package/package.json +11 -1
- package/parse_worker.js +1 -2
- package/rumoca_bind_wasm.d.ts +96 -5
- package/rumoca_bind_wasm.js +480 -36
- package/rumoca_bind_wasm_bg.wasm +0 -0
- package/rumoca_diffsol.js +109 -0
- package/rumoca_gpu.js +139 -79
- package/rumoca_interactive.js +1098 -0
- package/rumoca_package_meta.json +1 -1
- package/rumoca_runtime.js +164 -0
- package/rumoca_worker.js +307 -87
package/rumoca_bind_wasm.js
CHANGED
|
@@ -143,37 +143,6 @@ export function compile_to_json(source, model_name) {
|
|
|
143
143
|
}
|
|
144
144
|
}
|
|
145
145
|
|
|
146
|
-
/**
|
|
147
|
-
* @param {string} source
|
|
148
|
-
* @param {string} model_name
|
|
149
|
-
* @param {string} project_sources_json
|
|
150
|
-
* @returns {string}
|
|
151
|
-
*/
|
|
152
|
-
export function compile_with_project_sources(source, model_name, project_sources_json) {
|
|
153
|
-
let deferred5_0;
|
|
154
|
-
let deferred5_1;
|
|
155
|
-
try {
|
|
156
|
-
const ptr0 = passStringToWasm0(source, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
|
|
157
|
-
const len0 = WASM_VECTOR_LEN;
|
|
158
|
-
const ptr1 = passStringToWasm0(model_name, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
|
|
159
|
-
const len1 = WASM_VECTOR_LEN;
|
|
160
|
-
const ptr2 = passStringToWasm0(project_sources_json, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
|
|
161
|
-
const len2 = WASM_VECTOR_LEN;
|
|
162
|
-
const ret = wasm.compile_with_project_sources(ptr0, len0, ptr1, len1, ptr2, len2);
|
|
163
|
-
var ptr4 = ret[0];
|
|
164
|
-
var len4 = ret[1];
|
|
165
|
-
if (ret[3]) {
|
|
166
|
-
ptr4 = 0; len4 = 0;
|
|
167
|
-
throw takeFromExternrefTable0(ret[2]);
|
|
168
|
-
}
|
|
169
|
-
deferred5_0 = ptr4;
|
|
170
|
-
deferred5_1 = len4;
|
|
171
|
-
return getStringFromWasm0(ptr4, len4);
|
|
172
|
-
} finally {
|
|
173
|
-
wasm.__wbindgen_free(deferred5_0, deferred5_1, 1);
|
|
174
|
-
}
|
|
175
|
-
}
|
|
176
|
-
|
|
177
146
|
/**
|
|
178
147
|
* @param {string} source
|
|
179
148
|
* @param {string} model_name
|
|
@@ -245,6 +214,37 @@ export function compile_with_source_roots_with_options(source, model_name, sourc
|
|
|
245
214
|
}
|
|
246
215
|
}
|
|
247
216
|
|
|
217
|
+
/**
|
|
218
|
+
* @param {string} source
|
|
219
|
+
* @param {string} model_name
|
|
220
|
+
* @param {string} workspace_sources_json
|
|
221
|
+
* @returns {string}
|
|
222
|
+
*/
|
|
223
|
+
export function compile_with_workspace_sources(source, model_name, workspace_sources_json) {
|
|
224
|
+
let deferred5_0;
|
|
225
|
+
let deferred5_1;
|
|
226
|
+
try {
|
|
227
|
+
const ptr0 = passStringToWasm0(source, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
|
|
228
|
+
const len0 = WASM_VECTOR_LEN;
|
|
229
|
+
const ptr1 = passStringToWasm0(model_name, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
|
|
230
|
+
const len1 = WASM_VECTOR_LEN;
|
|
231
|
+
const ptr2 = passStringToWasm0(workspace_sources_json, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
|
|
232
|
+
const len2 = WASM_VECTOR_LEN;
|
|
233
|
+
const ret = wasm.compile_with_workspace_sources(ptr0, len0, ptr1, len1, ptr2, len2);
|
|
234
|
+
var ptr4 = ret[0];
|
|
235
|
+
var len4 = ret[1];
|
|
236
|
+
if (ret[3]) {
|
|
237
|
+
ptr4 = 0; len4 = 0;
|
|
238
|
+
throw takeFromExternrefTable0(ret[2]);
|
|
239
|
+
}
|
|
240
|
+
deferred5_0 = ptr4;
|
|
241
|
+
deferred5_1 = len4;
|
|
242
|
+
return getStringFromWasm0(ptr4, len4);
|
|
243
|
+
} finally {
|
|
244
|
+
wasm.__wbindgen_free(deferred5_0, deferred5_1, 1);
|
|
245
|
+
}
|
|
246
|
+
}
|
|
247
|
+
|
|
248
248
|
/**
|
|
249
249
|
* @param {string} uris_json
|
|
250
250
|
* @returns {Uint8Array}
|
|
@@ -817,6 +817,17 @@ export function parse_source_root_file(source, filename) {
|
|
|
817
817
|
}
|
|
818
818
|
}
|
|
819
819
|
|
|
820
|
+
/**
|
|
821
|
+
* @returns {number}
|
|
822
|
+
*/
|
|
823
|
+
export function prime_source_root_completion_cache() {
|
|
824
|
+
const ret = wasm.prime_source_root_completion_cache();
|
|
825
|
+
if (ret[2]) {
|
|
826
|
+
throw takeFromExternrefTable0(ret[1]);
|
|
827
|
+
}
|
|
828
|
+
return ret[0] >>> 0;
|
|
829
|
+
}
|
|
830
|
+
|
|
820
831
|
/**
|
|
821
832
|
* @param {string} dae_json
|
|
822
833
|
* @param {string} model_name
|
|
@@ -844,16 +855,421 @@ export function render_target(dae_json, model_name, target, manifest_source, tem
|
|
|
844
855
|
}
|
|
845
856
|
|
|
846
857
|
/**
|
|
847
|
-
*
|
|
858
|
+
* Default colocated `rumoca-scenario.<model>.toml` (`{ ok, path, content }`)
|
|
859
|
+
* for a create-config action on a Modelica model.
|
|
860
|
+
* @param {string} workspace_sources_json
|
|
861
|
+
* @param {string} model
|
|
862
|
+
* @param {string} task
|
|
863
|
+
* @returns {string}
|
|
864
|
+
*/
|
|
865
|
+
export function scenario_default_scenario_config(workspace_sources_json, model, task) {
|
|
866
|
+
let deferred5_0;
|
|
867
|
+
let deferred5_1;
|
|
868
|
+
try {
|
|
869
|
+
const ptr0 = passStringToWasm0(workspace_sources_json, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
|
|
870
|
+
const len0 = WASM_VECTOR_LEN;
|
|
871
|
+
const ptr1 = passStringToWasm0(model, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
|
|
872
|
+
const len1 = WASM_VECTOR_LEN;
|
|
873
|
+
const ptr2 = passStringToWasm0(task, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
|
|
874
|
+
const len2 = WASM_VECTOR_LEN;
|
|
875
|
+
const ret = wasm.scenario_default_scenario_config(ptr0, len0, ptr1, len1, ptr2, len2);
|
|
876
|
+
var ptr4 = ret[0];
|
|
877
|
+
var len4 = ret[1];
|
|
878
|
+
if (ret[3]) {
|
|
879
|
+
ptr4 = 0; len4 = 0;
|
|
880
|
+
throw takeFromExternrefTable0(ret[2]);
|
|
881
|
+
}
|
|
882
|
+
deferred5_0 = ptr4;
|
|
883
|
+
deferred5_1 = len4;
|
|
884
|
+
return getStringFromWasm0(ptr4, len4);
|
|
885
|
+
} finally {
|
|
886
|
+
wasm.__wbindgen_free(deferred5_0, deferred5_1, 1);
|
|
887
|
+
}
|
|
888
|
+
}
|
|
889
|
+
|
|
890
|
+
/**
|
|
891
|
+
* Configured `[codegen]` target settings for a model (`{ target, outputDir }`).
|
|
892
|
+
* @param {string} workspace_sources_json
|
|
893
|
+
* @param {string} model
|
|
894
|
+
* @returns {string}
|
|
895
|
+
*/
|
|
896
|
+
export function scenario_get_codegen_config(workspace_sources_json, model) {
|
|
897
|
+
let deferred4_0;
|
|
898
|
+
let deferred4_1;
|
|
899
|
+
try {
|
|
900
|
+
const ptr0 = passStringToWasm0(workspace_sources_json, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
|
|
901
|
+
const len0 = WASM_VECTOR_LEN;
|
|
902
|
+
const ptr1 = passStringToWasm0(model, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
|
|
903
|
+
const len1 = WASM_VECTOR_LEN;
|
|
904
|
+
const ret = wasm.scenario_get_codegen_config(ptr0, len0, ptr1, len1);
|
|
905
|
+
var ptr3 = ret[0];
|
|
906
|
+
var len3 = ret[1];
|
|
907
|
+
if (ret[3]) {
|
|
908
|
+
ptr3 = 0; len3 = 0;
|
|
909
|
+
throw takeFromExternrefTable0(ret[2]);
|
|
910
|
+
}
|
|
911
|
+
deferred4_0 = ptr3;
|
|
912
|
+
deferred4_1 = len3;
|
|
913
|
+
return getStringFromWasm0(ptr3, len3);
|
|
914
|
+
} finally {
|
|
915
|
+
wasm.__wbindgen_free(deferred4_0, deferred4_1, 1);
|
|
916
|
+
}
|
|
917
|
+
}
|
|
918
|
+
|
|
919
|
+
/**
|
|
920
|
+
* Parse a single `rumoca-scenario.toml` scenario file (by workspace path) into the editor's
|
|
921
|
+
* scenario descriptor (`task`, `model`, `viewerMode`, interactive ports, ...).
|
|
922
|
+
* @param {string} workspace_sources_json
|
|
923
|
+
* @param {string} path
|
|
924
|
+
* @returns {string}
|
|
925
|
+
*/
|
|
926
|
+
export function scenario_get_scenario_config(workspace_sources_json, path) {
|
|
927
|
+
let deferred4_0;
|
|
928
|
+
let deferred4_1;
|
|
929
|
+
try {
|
|
930
|
+
const ptr0 = passStringToWasm0(workspace_sources_json, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
|
|
931
|
+
const len0 = WASM_VECTOR_LEN;
|
|
932
|
+
const ptr1 = passStringToWasm0(path, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
|
|
933
|
+
const len1 = WASM_VECTOR_LEN;
|
|
934
|
+
const ret = wasm.scenario_get_scenario_config(ptr0, len0, ptr1, len1);
|
|
935
|
+
var ptr3 = ret[0];
|
|
936
|
+
var len3 = ret[1];
|
|
937
|
+
if (ret[3]) {
|
|
938
|
+
ptr3 = 0; len3 = 0;
|
|
939
|
+
throw takeFromExternrefTable0(ret[2]);
|
|
940
|
+
}
|
|
941
|
+
deferred4_0 = ptr3;
|
|
942
|
+
deferred4_1 = len3;
|
|
943
|
+
return getStringFromWasm0(ptr3, len3);
|
|
944
|
+
} finally {
|
|
945
|
+
wasm.__wbindgen_free(deferred4_0, deferred4_1, 1);
|
|
946
|
+
}
|
|
947
|
+
}
|
|
948
|
+
|
|
949
|
+
/**
|
|
950
|
+
* Full `rumoca-scenario.toml` scenario as a JSON tree for the config GUI:
|
|
951
|
+
* `{ ok, config: <toml-as-json>, descriptor }`. The `config` tree round-trips
|
|
952
|
+
* every section (including nested interactive-IO) losslessly.
|
|
953
|
+
* @param {string} workspace_sources_json
|
|
954
|
+
* @param {string} path
|
|
955
|
+
* @returns {string}
|
|
956
|
+
*/
|
|
957
|
+
export function scenario_get_scenario_config_full(workspace_sources_json, path) {
|
|
958
|
+
let deferred4_0;
|
|
959
|
+
let deferred4_1;
|
|
960
|
+
try {
|
|
961
|
+
const ptr0 = passStringToWasm0(workspace_sources_json, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
|
|
962
|
+
const len0 = WASM_VECTOR_LEN;
|
|
963
|
+
const ptr1 = passStringToWasm0(path, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
|
|
964
|
+
const len1 = WASM_VECTOR_LEN;
|
|
965
|
+
const ret = wasm.scenario_get_scenario_config_full(ptr0, len0, ptr1, len1);
|
|
966
|
+
var ptr3 = ret[0];
|
|
967
|
+
var len3 = ret[1];
|
|
968
|
+
if (ret[3]) {
|
|
969
|
+
ptr3 = 0; len3 = 0;
|
|
970
|
+
throw takeFromExternrefTable0(ret[2]);
|
|
971
|
+
}
|
|
972
|
+
deferred4_0 = ptr3;
|
|
973
|
+
deferred4_1 = len3;
|
|
974
|
+
return getStringFromWasm0(ptr3, len3);
|
|
975
|
+
} finally {
|
|
976
|
+
wasm.__wbindgen_free(deferred4_0, deferred4_1, 1);
|
|
977
|
+
}
|
|
978
|
+
}
|
|
979
|
+
|
|
980
|
+
/**
|
|
981
|
+
* Effective + preset + default simulation settings for a model, given the
|
|
982
|
+
* workspace's `rumoca-scenario.toml` files and an optional editor `fallback` settings JSON.
|
|
983
|
+
* @param {string} workspace_sources_json
|
|
984
|
+
* @param {string} model
|
|
985
|
+
* @param {string} fallback_json
|
|
986
|
+
* @returns {string}
|
|
987
|
+
*/
|
|
988
|
+
export function scenario_get_simulation_config(workspace_sources_json, model, fallback_json) {
|
|
989
|
+
let deferred5_0;
|
|
990
|
+
let deferred5_1;
|
|
991
|
+
try {
|
|
992
|
+
const ptr0 = passStringToWasm0(workspace_sources_json, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
|
|
993
|
+
const len0 = WASM_VECTOR_LEN;
|
|
994
|
+
const ptr1 = passStringToWasm0(model, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
|
|
995
|
+
const len1 = WASM_VECTOR_LEN;
|
|
996
|
+
const ptr2 = passStringToWasm0(fallback_json, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
|
|
997
|
+
const len2 = WASM_VECTOR_LEN;
|
|
998
|
+
const ret = wasm.scenario_get_simulation_config(ptr0, len0, ptr1, len1, ptr2, len2);
|
|
999
|
+
var ptr4 = ret[0];
|
|
1000
|
+
var len4 = ret[1];
|
|
1001
|
+
if (ret[3]) {
|
|
1002
|
+
ptr4 = 0; len4 = 0;
|
|
1003
|
+
throw takeFromExternrefTable0(ret[2]);
|
|
1004
|
+
}
|
|
1005
|
+
deferred5_0 = ptr4;
|
|
1006
|
+
deferred5_1 = len4;
|
|
1007
|
+
return getStringFromWasm0(ptr4, len4);
|
|
1008
|
+
} finally {
|
|
1009
|
+
wasm.__wbindgen_free(deferred5_0, deferred5_1, 1);
|
|
1010
|
+
}
|
|
1011
|
+
}
|
|
1012
|
+
|
|
1013
|
+
/**
|
|
1014
|
+
* Scenario-local source roots configured for a model (`{ sourceRootPaths }`).
|
|
1015
|
+
* @param {string} workspace_sources_json
|
|
1016
|
+
* @param {string} model
|
|
1017
|
+
* @param {string} task
|
|
1018
|
+
* @returns {string}
|
|
1019
|
+
*/
|
|
1020
|
+
export function scenario_get_source_roots(workspace_sources_json, model, task) {
|
|
1021
|
+
let deferred5_0;
|
|
1022
|
+
let deferred5_1;
|
|
1023
|
+
try {
|
|
1024
|
+
const ptr0 = passStringToWasm0(workspace_sources_json, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
|
|
1025
|
+
const len0 = WASM_VECTOR_LEN;
|
|
1026
|
+
const ptr1 = passStringToWasm0(model, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
|
|
1027
|
+
const len1 = WASM_VECTOR_LEN;
|
|
1028
|
+
const ptr2 = passStringToWasm0(task, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
|
|
1029
|
+
const len2 = WASM_VECTOR_LEN;
|
|
1030
|
+
const ret = wasm.scenario_get_source_roots(ptr0, len0, ptr1, len1, ptr2, len2);
|
|
1031
|
+
var ptr4 = ret[0];
|
|
1032
|
+
var len4 = ret[1];
|
|
1033
|
+
if (ret[3]) {
|
|
1034
|
+
ptr4 = 0; len4 = 0;
|
|
1035
|
+
throw takeFromExternrefTable0(ret[2]);
|
|
1036
|
+
}
|
|
1037
|
+
deferred5_0 = ptr4;
|
|
1038
|
+
deferred5_1 = len4;
|
|
1039
|
+
return getStringFromWasm0(ptr4, len4);
|
|
1040
|
+
} finally {
|
|
1041
|
+
wasm.__wbindgen_free(deferred5_0, deferred5_1, 1);
|
|
1042
|
+
}
|
|
1043
|
+
}
|
|
1044
|
+
|
|
1045
|
+
/**
|
|
1046
|
+
* Configured plot/visualization views for a model (`{ views: [...] }`).
|
|
1047
|
+
* @param {string} workspace_sources_json
|
|
1048
|
+
* @param {string} model
|
|
1049
|
+
* @returns {string}
|
|
1050
|
+
*/
|
|
1051
|
+
export function scenario_get_visualization_config(workspace_sources_json, model) {
|
|
1052
|
+
let deferred4_0;
|
|
1053
|
+
let deferred4_1;
|
|
1054
|
+
try {
|
|
1055
|
+
const ptr0 = passStringToWasm0(workspace_sources_json, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
|
|
1056
|
+
const len0 = WASM_VECTOR_LEN;
|
|
1057
|
+
const ptr1 = passStringToWasm0(model, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
|
|
1058
|
+
const len1 = WASM_VECTOR_LEN;
|
|
1059
|
+
const ret = wasm.scenario_get_visualization_config(ptr0, len0, ptr1, len1);
|
|
1060
|
+
var ptr3 = ret[0];
|
|
1061
|
+
var len3 = ret[1];
|
|
1062
|
+
if (ret[3]) {
|
|
1063
|
+
ptr3 = 0; len3 = 0;
|
|
1064
|
+
throw takeFromExternrefTable0(ret[2]);
|
|
1065
|
+
}
|
|
1066
|
+
deferred4_0 = ptr3;
|
|
1067
|
+
deferred4_1 = len3;
|
|
1068
|
+
return getStringFromWasm0(ptr3, len3);
|
|
1069
|
+
} finally {
|
|
1070
|
+
wasm.__wbindgen_free(deferred4_0, deferred4_1, 1);
|
|
1071
|
+
}
|
|
1072
|
+
}
|
|
1073
|
+
|
|
1074
|
+
/**
|
|
1075
|
+
* Clear a model's simulation preset. Returns `{ writes, result }`.
|
|
1076
|
+
* @param {string} workspace_sources_json
|
|
1077
|
+
* @param {string} model
|
|
1078
|
+
* @returns {string}
|
|
1079
|
+
*/
|
|
1080
|
+
export function scenario_reset_simulation_preset(workspace_sources_json, model) {
|
|
1081
|
+
let deferred4_0;
|
|
1082
|
+
let deferred4_1;
|
|
1083
|
+
try {
|
|
1084
|
+
const ptr0 = passStringToWasm0(workspace_sources_json, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
|
|
1085
|
+
const len0 = WASM_VECTOR_LEN;
|
|
1086
|
+
const ptr1 = passStringToWasm0(model, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
|
|
1087
|
+
const len1 = WASM_VECTOR_LEN;
|
|
1088
|
+
const ret = wasm.scenario_reset_simulation_preset(ptr0, len0, ptr1, len1);
|
|
1089
|
+
var ptr3 = ret[0];
|
|
1090
|
+
var len3 = ret[1];
|
|
1091
|
+
if (ret[3]) {
|
|
1092
|
+
ptr3 = 0; len3 = 0;
|
|
1093
|
+
throw takeFromExternrefTable0(ret[2]);
|
|
1094
|
+
}
|
|
1095
|
+
deferred4_0 = ptr3;
|
|
1096
|
+
deferred4_1 = len3;
|
|
1097
|
+
return getStringFromWasm0(ptr3, len3);
|
|
1098
|
+
} finally {
|
|
1099
|
+
wasm.__wbindgen_free(deferred4_0, deferred4_1, 1);
|
|
1100
|
+
}
|
|
1101
|
+
}
|
|
1102
|
+
|
|
1103
|
+
/**
|
|
1104
|
+
* Write a model's `[codegen]` target settings. Returns `{ writes, result }`.
|
|
1105
|
+
* @param {string} workspace_sources_json
|
|
1106
|
+
* @param {string} model
|
|
1107
|
+
* @param {string} codegen_json
|
|
1108
|
+
* @returns {string}
|
|
1109
|
+
*/
|
|
1110
|
+
export function scenario_set_codegen_config(workspace_sources_json, model, codegen_json) {
|
|
1111
|
+
let deferred5_0;
|
|
1112
|
+
let deferred5_1;
|
|
1113
|
+
try {
|
|
1114
|
+
const ptr0 = passStringToWasm0(workspace_sources_json, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
|
|
1115
|
+
const len0 = WASM_VECTOR_LEN;
|
|
1116
|
+
const ptr1 = passStringToWasm0(model, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
|
|
1117
|
+
const len1 = WASM_VECTOR_LEN;
|
|
1118
|
+
const ptr2 = passStringToWasm0(codegen_json, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
|
|
1119
|
+
const len2 = WASM_VECTOR_LEN;
|
|
1120
|
+
const ret = wasm.scenario_set_codegen_config(ptr0, len0, ptr1, len1, ptr2, len2);
|
|
1121
|
+
var ptr4 = ret[0];
|
|
1122
|
+
var len4 = ret[1];
|
|
1123
|
+
if (ret[3]) {
|
|
1124
|
+
ptr4 = 0; len4 = 0;
|
|
1125
|
+
throw takeFromExternrefTable0(ret[2]);
|
|
1126
|
+
}
|
|
1127
|
+
deferred5_0 = ptr4;
|
|
1128
|
+
deferred5_1 = len4;
|
|
1129
|
+
return getStringFromWasm0(ptr4, len4);
|
|
1130
|
+
} finally {
|
|
1131
|
+
wasm.__wbindgen_free(deferred5_0, deferred5_1, 1);
|
|
1132
|
+
}
|
|
1133
|
+
}
|
|
1134
|
+
|
|
1135
|
+
/**
|
|
1136
|
+
* Render a `rumoca-scenario.toml` from the config GUI's JSON tree. Returns
|
|
1137
|
+
* `{ writes: [{path, content}], result }` for the editor to apply.
|
|
1138
|
+
* @param {string} path
|
|
1139
|
+
* @param {string} config_json
|
|
1140
|
+
* @returns {string}
|
|
1141
|
+
*/
|
|
1142
|
+
export function scenario_set_scenario_config(path, config_json) {
|
|
1143
|
+
let deferred4_0;
|
|
1144
|
+
let deferred4_1;
|
|
1145
|
+
try {
|
|
1146
|
+
const ptr0 = passStringToWasm0(path, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
|
|
1147
|
+
const len0 = WASM_VECTOR_LEN;
|
|
1148
|
+
const ptr1 = passStringToWasm0(config_json, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
|
|
1149
|
+
const len1 = WASM_VECTOR_LEN;
|
|
1150
|
+
const ret = wasm.scenario_set_scenario_config(ptr0, len0, ptr1, len1);
|
|
1151
|
+
var ptr3 = ret[0];
|
|
1152
|
+
var len3 = ret[1];
|
|
1153
|
+
if (ret[3]) {
|
|
1154
|
+
ptr3 = 0; len3 = 0;
|
|
1155
|
+
throw takeFromExternrefTable0(ret[2]);
|
|
1156
|
+
}
|
|
1157
|
+
deferred4_0 = ptr3;
|
|
1158
|
+
deferred4_1 = len3;
|
|
1159
|
+
return getStringFromWasm0(ptr3, len3);
|
|
1160
|
+
} finally {
|
|
1161
|
+
wasm.__wbindgen_free(deferred4_0, deferred4_1, 1);
|
|
1162
|
+
}
|
|
1163
|
+
}
|
|
1164
|
+
|
|
1165
|
+
/**
|
|
1166
|
+
* Write a model's simulation preset into its colocated `rum.<model>.toml`.
|
|
1167
|
+
* Returns `{ writes, result }` for the editor to apply to its workspace store.
|
|
1168
|
+
* @param {string} workspace_sources_json
|
|
1169
|
+
* @param {string} model
|
|
1170
|
+
* @param {string} preset_json
|
|
1171
|
+
* @returns {string}
|
|
1172
|
+
*/
|
|
1173
|
+
export function scenario_set_simulation_preset(workspace_sources_json, model, preset_json) {
|
|
1174
|
+
let deferred5_0;
|
|
1175
|
+
let deferred5_1;
|
|
1176
|
+
try {
|
|
1177
|
+
const ptr0 = passStringToWasm0(workspace_sources_json, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
|
|
1178
|
+
const len0 = WASM_VECTOR_LEN;
|
|
1179
|
+
const ptr1 = passStringToWasm0(model, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
|
|
1180
|
+
const len1 = WASM_VECTOR_LEN;
|
|
1181
|
+
const ptr2 = passStringToWasm0(preset_json, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
|
|
1182
|
+
const len2 = WASM_VECTOR_LEN;
|
|
1183
|
+
const ret = wasm.scenario_set_simulation_preset(ptr0, len0, ptr1, len1, ptr2, len2);
|
|
1184
|
+
var ptr4 = ret[0];
|
|
1185
|
+
var len4 = ret[1];
|
|
1186
|
+
if (ret[3]) {
|
|
1187
|
+
ptr4 = 0; len4 = 0;
|
|
1188
|
+
throw takeFromExternrefTable0(ret[2]);
|
|
1189
|
+
}
|
|
1190
|
+
deferred5_0 = ptr4;
|
|
1191
|
+
deferred5_1 = len4;
|
|
1192
|
+
return getStringFromWasm0(ptr4, len4);
|
|
1193
|
+
} finally {
|
|
1194
|
+
wasm.__wbindgen_free(deferred5_0, deferred5_1, 1);
|
|
1195
|
+
}
|
|
1196
|
+
}
|
|
1197
|
+
|
|
1198
|
+
/**
|
|
1199
|
+
* Write a model's scenario-local source roots. Returns `{ writes, result }`.
|
|
1200
|
+
* @param {string} workspace_sources_json
|
|
1201
|
+
* @param {string} model
|
|
1202
|
+
* @param {string} source_roots_json
|
|
848
1203
|
* @returns {string}
|
|
849
1204
|
*/
|
|
850
|
-
export function
|
|
1205
|
+
export function scenario_set_source_roots(workspace_sources_json, model, source_roots_json) {
|
|
1206
|
+
let deferred5_0;
|
|
1207
|
+
let deferred5_1;
|
|
1208
|
+
try {
|
|
1209
|
+
const ptr0 = passStringToWasm0(workspace_sources_json, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
|
|
1210
|
+
const len0 = WASM_VECTOR_LEN;
|
|
1211
|
+
const ptr1 = passStringToWasm0(model, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
|
|
1212
|
+
const len1 = WASM_VECTOR_LEN;
|
|
1213
|
+
const ptr2 = passStringToWasm0(source_roots_json, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
|
|
1214
|
+
const len2 = WASM_VECTOR_LEN;
|
|
1215
|
+
const ret = wasm.scenario_set_source_roots(ptr0, len0, ptr1, len1, ptr2, len2);
|
|
1216
|
+
var ptr4 = ret[0];
|
|
1217
|
+
var len4 = ret[1];
|
|
1218
|
+
if (ret[3]) {
|
|
1219
|
+
ptr4 = 0; len4 = 0;
|
|
1220
|
+
throw takeFromExternrefTable0(ret[2]);
|
|
1221
|
+
}
|
|
1222
|
+
deferred5_0 = ptr4;
|
|
1223
|
+
deferred5_1 = len4;
|
|
1224
|
+
return getStringFromWasm0(ptr4, len4);
|
|
1225
|
+
} finally {
|
|
1226
|
+
wasm.__wbindgen_free(deferred5_0, deferred5_1, 1);
|
|
1227
|
+
}
|
|
1228
|
+
}
|
|
1229
|
+
|
|
1230
|
+
/**
|
|
1231
|
+
* Write a model's plot/visualization views. Returns `{ writes, result }`.
|
|
1232
|
+
* @param {string} workspace_sources_json
|
|
1233
|
+
* @param {string} model
|
|
1234
|
+
* @param {string} views_json
|
|
1235
|
+
* @returns {string}
|
|
1236
|
+
*/
|
|
1237
|
+
export function scenario_set_visualization_config(workspace_sources_json, model, views_json) {
|
|
1238
|
+
let deferred5_0;
|
|
1239
|
+
let deferred5_1;
|
|
1240
|
+
try {
|
|
1241
|
+
const ptr0 = passStringToWasm0(workspace_sources_json, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
|
|
1242
|
+
const len0 = WASM_VECTOR_LEN;
|
|
1243
|
+
const ptr1 = passStringToWasm0(model, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
|
|
1244
|
+
const len1 = WASM_VECTOR_LEN;
|
|
1245
|
+
const ptr2 = passStringToWasm0(views_json, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
|
|
1246
|
+
const len2 = WASM_VECTOR_LEN;
|
|
1247
|
+
const ret = wasm.scenario_set_visualization_config(ptr0, len0, ptr1, len1, ptr2, len2);
|
|
1248
|
+
var ptr4 = ret[0];
|
|
1249
|
+
var len4 = ret[1];
|
|
1250
|
+
if (ret[3]) {
|
|
1251
|
+
ptr4 = 0; len4 = 0;
|
|
1252
|
+
throw takeFromExternrefTable0(ret[2]);
|
|
1253
|
+
}
|
|
1254
|
+
deferred5_0 = ptr4;
|
|
1255
|
+
deferred5_1 = len4;
|
|
1256
|
+
return getStringFromWasm0(ptr4, len4);
|
|
1257
|
+
} finally {
|
|
1258
|
+
wasm.__wbindgen_free(deferred5_0, deferred5_1, 1);
|
|
1259
|
+
}
|
|
1260
|
+
}
|
|
1261
|
+
|
|
1262
|
+
/**
|
|
1263
|
+
* @param {string} workspace_sources_json
|
|
1264
|
+
* @returns {string}
|
|
1265
|
+
*/
|
|
1266
|
+
export function sync_workspace_sources(workspace_sources_json) {
|
|
851
1267
|
let deferred3_0;
|
|
852
1268
|
let deferred3_1;
|
|
853
1269
|
try {
|
|
854
|
-
const ptr0 = passStringToWasm0(
|
|
1270
|
+
const ptr0 = passStringToWasm0(workspace_sources_json, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
|
|
855
1271
|
const len0 = WASM_VECTOR_LEN;
|
|
856
|
-
const ret = wasm.
|
|
1272
|
+
const ret = wasm.sync_workspace_sources(ptr0, len0);
|
|
857
1273
|
var ptr2 = ret[0];
|
|
858
1274
|
var len2 = ret[1];
|
|
859
1275
|
if (ret[3]) {
|
|
@@ -878,6 +1294,34 @@ export function wasm_init(_num_threads) {
|
|
|
878
1294
|
return ret !== 0;
|
|
879
1295
|
}
|
|
880
1296
|
|
|
1297
|
+
/**
|
|
1298
|
+
* @param {string} workspace_sources_json
|
|
1299
|
+
* @param {string} focus_path
|
|
1300
|
+
* @returns {string}
|
|
1301
|
+
*/
|
|
1302
|
+
export function workspace_effective_source_roots(workspace_sources_json, focus_path) {
|
|
1303
|
+
let deferred4_0;
|
|
1304
|
+
let deferred4_1;
|
|
1305
|
+
try {
|
|
1306
|
+
const ptr0 = passStringToWasm0(workspace_sources_json, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
|
|
1307
|
+
const len0 = WASM_VECTOR_LEN;
|
|
1308
|
+
const ptr1 = passStringToWasm0(focus_path, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
|
|
1309
|
+
const len1 = WASM_VECTOR_LEN;
|
|
1310
|
+
const ret = wasm.workspace_effective_source_roots(ptr0, len0, ptr1, len1);
|
|
1311
|
+
var ptr3 = ret[0];
|
|
1312
|
+
var len3 = ret[1];
|
|
1313
|
+
if (ret[3]) {
|
|
1314
|
+
ptr3 = 0; len3 = 0;
|
|
1315
|
+
throw takeFromExternrefTable0(ret[2]);
|
|
1316
|
+
}
|
|
1317
|
+
deferred4_0 = ptr3;
|
|
1318
|
+
deferred4_1 = len3;
|
|
1319
|
+
return getStringFromWasm0(ptr3, len3);
|
|
1320
|
+
} finally {
|
|
1321
|
+
wasm.__wbindgen_free(deferred4_0, deferred4_1, 1);
|
|
1322
|
+
}
|
|
1323
|
+
}
|
|
1324
|
+
|
|
881
1325
|
function __wbg_get_imports() {
|
|
882
1326
|
const import0 = {
|
|
883
1327
|
__proto__: null,
|
|
@@ -902,7 +1346,7 @@ function __wbg_get_imports() {
|
|
|
902
1346
|
wasm.__wbindgen_free(deferred0_0, deferred0_1, 1);
|
|
903
1347
|
}
|
|
904
1348
|
},
|
|
905
|
-
|
|
1349
|
+
__wbg_log_eb5eb4b225300419: function(arg0, arg1) {
|
|
906
1350
|
console.log(getStringFromWasm0(arg0, arg1));
|
|
907
1351
|
},
|
|
908
1352
|
__wbg_new_361308b2356cecd0: function() {
|
package/rumoca_bind_wasm_bg.wasm
CHANGED
|
Binary file
|
|
@@ -0,0 +1,109 @@
|
|
|
1
|
+
// Lazy diffsol (stiff/implicit) simulation driver for the @cognipilot/rumoca
|
|
2
|
+
// package.
|
|
3
|
+
//
|
|
4
|
+
// Why this exists: the main rumoca WASM module is SIMD-free and loads on every
|
|
5
|
+
// browser. The diffsol solver pulls relaxed-SIMD (via faer/pulp), and WASM
|
|
6
|
+
// validates a whole module at instantiation — so a single combined module
|
|
7
|
+
// would hard-fail the entire package on browsers without relaxed-SIMD. Instead
|
|
8
|
+
// the diffsol code ships as a *separate* tiny module (~0.4 MB gz,
|
|
9
|
+
// `rumoca_bind_wasm_diffsol.js`) that is loaded only when (a) the browser
|
|
10
|
+
// supports relaxed-SIMD and (b) the user actually runs a stiff solve.
|
|
11
|
+
//
|
|
12
|
+
// Usage (the main module is already initialized by the caller):
|
|
13
|
+
// import { diffsolAvailable, simulateWithDiffsol } from "@cognipilot/rumoca/diffsol";
|
|
14
|
+
// const ok = await diffsolAvailable(pkgBase); // grey out the UI if false
|
|
15
|
+
// const result = await simulateWithDiffsol(mainModule, pkgBase, src, model, tEnd, dt);
|
|
16
|
+
//
|
|
17
|
+
// `pkgBase` is the same base URL the main `rumoca_bind_wasm.js` was imported
|
|
18
|
+
// from (the addon wasm sits next to it).
|
|
19
|
+
|
|
20
|
+
// Minimal module that uses a 1-operand relaxed-SIMD op
|
|
21
|
+
// (`i32x4.relaxed_trunc_f32x4_s`, 0xFD 0x101). `WebAssembly.validate` returns
|
|
22
|
+
// false on engines without relaxed-SIMD. This is a cheap *hint* for greying out
|
|
23
|
+
// the UI; the authoritative check is whether the addon actually instantiates
|
|
24
|
+
// (see `diffsolAvailable`). NOTE: verify in a real browser as part of the
|
|
25
|
+
// editor smoke test.
|
|
26
|
+
const RELAXED_SIMD_PROBE = new Uint8Array([
|
|
27
|
+
0x00, 0x61, 0x73, 0x6d, 0x01, 0x00, 0x00, 0x00, // \0asm v1
|
|
28
|
+
0x01, 0x05, 0x01, 0x60, 0x00, 0x01, 0x7b, // type: () -> v128
|
|
29
|
+
0x03, 0x02, 0x01, 0x00, // func 0 : type 0
|
|
30
|
+
0x0a, 0x19, 0x01, 0x17, 0x00, // code: 1 body, size 23, 0 locals
|
|
31
|
+
0xfd, 0x0c, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, // v128.const 0
|
|
32
|
+
0xfd, 0x81, 0x02, // i32x4.relaxed_trunc_f32x4_s
|
|
33
|
+
0x0b, // end
|
|
34
|
+
]);
|
|
35
|
+
|
|
36
|
+
/** Quick, non-authoritative hint: does this engine validate relaxed-SIMD? */
|
|
37
|
+
export function relaxedSimdSupported() {
|
|
38
|
+
try {
|
|
39
|
+
return WebAssembly.validate(RELAXED_SIMD_PROBE);
|
|
40
|
+
} catch {
|
|
41
|
+
return false;
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
let addonPromise = null;
|
|
46
|
+
|
|
47
|
+
/**
|
|
48
|
+
* Lazily import + initialize the diffsol addon module from `pkgBase`. Resolves
|
|
49
|
+
* to the module's exports, or rejects (e.g. `CompileError` on a browser without
|
|
50
|
+
* relaxed-SIMD). Cached after the first call.
|
|
51
|
+
*/
|
|
52
|
+
export function loadDiffsolAddon(pkgBase) {
|
|
53
|
+
if (!addonPromise) {
|
|
54
|
+
addonPromise = (async () => {
|
|
55
|
+
const mod = await import(pkgBase + "rumoca_bind_wasm_diffsol.js");
|
|
56
|
+
await mod.default(); // run wasm-bindgen init (instantiates the wasm)
|
|
57
|
+
return mod;
|
|
58
|
+
})();
|
|
59
|
+
// Allow a retry if loading failed (e.g. transient network).
|
|
60
|
+
addonPromise.catch(() => {
|
|
61
|
+
addonPromise = null;
|
|
62
|
+
});
|
|
63
|
+
}
|
|
64
|
+
return addonPromise;
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
/**
|
|
68
|
+
* Authoritative check: true iff the diffsol addon actually instantiates in this
|
|
69
|
+
* browser. Downloads/compiles the addon once (cached). Use this to enable or
|
|
70
|
+
* grey out the stiff-solver options.
|
|
71
|
+
*/
|
|
72
|
+
export async function diffsolAvailable(pkgBase) {
|
|
73
|
+
try {
|
|
74
|
+
await loadDiffsolAddon(pkgBase);
|
|
75
|
+
return true;
|
|
76
|
+
} catch {
|
|
77
|
+
return false;
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
/**
|
|
82
|
+
* Run a stiff (diffsol) simulation: the main module lowers the model to a
|
|
83
|
+
* SolveModel JSON, the addon simulates it. Returns the parsed
|
|
84
|
+
* `{ payload, ... }` object (same shape as the main module's `simulate_model`).
|
|
85
|
+
* Throws a clear error if the addon can't load (old browser) — callers should
|
|
86
|
+
* fall back to rk45 / the GPU path or surface the message.
|
|
87
|
+
*/
|
|
88
|
+
export async function simulateWithDiffsol(mainModule, pkgBase, source, modelName, tEnd, dt, parameterOverridesJson = "{}") {
|
|
89
|
+
if (typeof mainModule.lower_model_to_solve_json !== "function") {
|
|
90
|
+
throw new Error(
|
|
91
|
+
"this rumoca build predates the diffsol addon; rebuild the package",
|
|
92
|
+
);
|
|
93
|
+
}
|
|
94
|
+
let addon;
|
|
95
|
+
try {
|
|
96
|
+
addon = await loadDiffsolAddon(pkgBase);
|
|
97
|
+
} catch (err) {
|
|
98
|
+
throw new Error(
|
|
99
|
+
"the stiff (diffsol) solver needs a browser with WebAssembly relaxed-SIMD " +
|
|
100
|
+
"(Chrome 114+, Firefox 120+, Safari 16.4+). Use the rk45 solver or the GPU " +
|
|
101
|
+
`path instead. (${err && err.message ? err.message : err})`,
|
|
102
|
+
);
|
|
103
|
+
}
|
|
104
|
+
// The payload carries the lowered model plus the resolved t_end/dt (so an
|
|
105
|
+
// annotation-driven duration is honored even when the caller passes 0).
|
|
106
|
+
const prepJson = mainModule.lower_model_to_solve_json(source, modelName, tEnd, dt, parameterOverridesJson);
|
|
107
|
+
const resultJson = addon.simulate_solve_model_diffsol(prepJson);
|
|
108
|
+
return JSON.parse(resultJson);
|
|
109
|
+
}
|