@casadi/casadi-reader 0.1.0 → 0.2.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.
package/CHANGELOG.md CHANGED
@@ -1,3 +1,14 @@
1
+ # 0.2.0
2
+
3
+ - Generate JavaScript, Python, C/C++, MATLAB and Julia readers from the compact serialization scheme, with language-specific runtime templates.
4
+ - Decode MX/SX expression vectors and their ordered dependencies, in ordinary and debug files.
5
+ - Refresh serializer layouts, including irregular nonzero assignments and finite differences.
6
+ - Preserve typed fields and shared references for generic Function property inspection.
7
+ - Remove structural `offset` and `byteLength` fields; keep `root` and `roots`. Lazy byte payload handles retain their I/O metadata.
8
+ - Use explicit layout calls instead of runtime inheritance resolution.
9
+
10
+ Breaking change: structural records no longer expose byte spans. npm publication remains JavaScript-only; the other language readers are available as source.
11
+
1
12
  # 0.1.0
2
13
 
3
14
  - Replace MX graph interpretation with a schema-driven structural reader.
package/NOTICE CHANGED
@@ -1,7 +1,7 @@
1
1
  casadi-reader's implementation is licensed under the MIT License (LICENSE).
2
2
 
3
- The vendored schemes/serialization_scheme.json contains serializer source
4
- excerpts from CasADi 3.8.1, https://github.com/casadi/casadi. Those excerpts
3
+ The vendored schemes/serialization_scheme.json contains decoding metadata derived
4
+ from CasADi 3.8.1, https://github.com/casadi/casadi. The upstream sources
5
5
  retain CasADi's LGPL-3.0-or-later license; they are not relicensed by this
6
6
  repository's MIT License. License texts are in LICENSES/.
7
7
 
@@ -11,7 +11,7 @@ Copyright (C) 2010-2023 Joel Andersson, Joris Gillis, Moritz Diehl,
11
11
  Copyright (C) 2011-2014 Greg Horn
12
12
  Additional source-file notices remain available in the referenced CasADi tree.
13
13
 
14
- The published reader runtime assets contain generated protocol metadata,
15
- not the scheme's serializer source excerpts. The full scheme is included in
14
+ The published reader runtime assets contain generated decoding metadata.
15
+ Neither these assets nor the vendored scheme contains serializer source bodies. The full scheme is included in
16
16
  this source repository and Python source distributions as a generation/test
17
17
  input; it is not needed by the installed readers.
package/README.md CHANGED
@@ -8,8 +8,9 @@ reconstruct entry mappings, or build visualization graphs. Those tasks belong
8
8
  in [casadi-viz](https://github.com/casadi/casadi-viz). An ONNX-backed function is
9
9
  read as serialized configuration and model bytes; the reader never runs ONNX.
10
10
 
11
- The current development and release focus is npm. Other language prototypes in
12
- this repository are deferred and still use the earlier MX-specific API.
11
+ JavaScript, Python, C, C++, MATLAB and Julia expose the same structural document
12
+ contract. C and C++ share a native engine; MATLAB and Julia bind that engine.
13
+ Only JavaScript packaging and publishing are currently enabled in CI.
13
14
 
14
15
  ## API
15
16
 
@@ -39,26 +40,23 @@ The output is ordinary JavaScript data:
39
40
  {
40
41
  type: 'Function',
41
42
  fields: [
42
- {name: 'Function::null', type: 'bool', value: false, offset: 19, byteLength: 1},
43
+ {name: 'Function::null', type: 'bool', value: false},
43
44
  // Serialized field order and duplicate field names are preserved.
44
45
  ],
45
- layouts: ['MXFunction::serialize_body', /* base layouts ... */],
46
- offset: 18,
47
- byteLength: 1234
46
+ layouts: ['MXFunction::serialize_body', /* base layouts ... */]
48
47
  }
49
48
  ]
50
49
  }
51
50
  ```
52
51
 
53
- The example's indices and byte counts are illustrative. `$ref` values are
52
+ The example's indices are illustrative. `$ref` values are
54
53
  zero-based indices into `objects`. Shared definitions appear once, even when
55
54
  referenced by several functions. Inline structures have their own `type` and
56
55
  `fields`. Vectors are arrays, pairs are two-element arrays, and maps are
57
56
  `{$map: [[key, value], ...]}` so arbitrary key types and field order survive.
58
57
  Repeated serializer fields remain repeated entries, not overwritten properties.
59
58
  64-bit integers outside JavaScript's exact range use `{$integer: "..."}`;
60
- nonfinite floating-point values use `{$float: "..."}`. Byte offsets count decoded
61
- wire bytes from the stream start, not characters in its a–p encoding.
59
+ nonfinite floating-point values use `{$float: "..."}`. Records and fields contain no source byte ranges.
62
60
 
63
61
  A file can contain several roots; `roots` retains them in order. `root` is a
64
62
  convenience index for a single shared-object root, otherwise null.
@@ -110,13 +108,20 @@ Python 3.9+ and the development dependencies in package-lock.json.
110
108
  ## Scheme and coverage
111
109
 
112
110
  CasADi's `misc/generate_serialization_scheme.py` produces the vendored
113
- `schemes/serialization_scheme.json`, including lowered reader layouts.
114
- `npm run generate` compiles that data into reader assets. The JavaScript engine
115
- executes field, base-layout, repetition, condition and discriminator instructions;
116
- it contains no SX/MX-specific decoding methods.
111
+ `schemes/serialization_scheme.json`: decoding rules and validation metadata,
112
+ without source bodies, pack expressions, source locations or extraction offsets.
113
+ Field bindings are retained only when decoding expressions can reference them.
114
+ `npm run generate` generates all six readers. The generic engines
115
+ execute field, base-layout, repetition, condition and discriminator instructions;
116
+ they contain no SX/MX-specific decoding methods. A small `Generator` base class
117
+ and language subclasses in `scripts/reader_generators.py` emit scheme data and
118
+ copy runtime templates from `scripts/templates`. Edit templates, then regenerate.
119
+ Use `--scheme PATH --output-root DIR` with `scripts/generate-reader-assets.py`
120
+ to generate readers for another extracted scheme without changing this checkout.
117
121
 
118
122
  The extractor includes inline serializers, inheritance and tensor metadata
119
- helpers. It derives operation dispatch families from CasADi's native dispatcher
123
+ helpers. Inherited serializers and template aliases are explicit layouts with
124
+ call instructions; readers perform no C++ inheritance lookup. It derives operation dispatch families from CasADi's native dispatcher
120
125
  and plugin registrations from the source. No mathematical evaluation occurs.
121
126
 
122
127
  Coverage is still experimental. Native plain/debug fixture pairs validate MX,
@@ -145,6 +150,34 @@ extracted npm tarball over HTTP and verify one JavaScript request with no scheme
145
150
  JSON or CasADi runtime request. Native CasADi is used only when regenerating the
146
151
  fixtures, via `scripts/generate-fixtures.py` and the Resource fixture generator.
147
152
 
153
+ ## Other languages
154
+
155
+ Python is dependency-free: `PYTHONPATH=python python3 -m casadi_reader model.casadi`.
156
+ `casadi_reader.read_casadi(path)` returns the same typed records as JavaScript;
157
+ `to_json(document)` makes them portable to the viewer. Use `lazy=True` for byte
158
+ handles and keep their source open while reading them.
159
+
160
+ Build the standalone native library and CLI using the root `CMakeLists.txt`.
161
+ C uses `cr_open_type` for files or `cr_decode` for copied encoded input;
162
+ `cr_json` exposes the structural JSON, valid until `cr_close`.
163
+ C++ wraps this lifetime in `casadi_reader::Document`. Both accept an optional
164
+ raw root type, such as `Resource`. Lazy byte access checks ranges and requires
165
+ an open document. The native engine limits collection/eager byte counts to one
166
+ million, nesting to 256, and input size to 1 GiB; larger opaque payloads can use
167
+ lazy mode within the file limit.
168
+
169
+ MATLAB uses `casadi_reader.read(path)` or a `casadi_reader.Document` for lazy
170
+ bytes; compile `matlab/casadi_reader_mex.cpp` with the native engine.
171
+ Julia uses `CasadiReader.read_casadi(path)` or `Document(path; lazy=true)` and
172
+ loads the native library through `CASADI_READER_LIBRARY`.
173
+
174
+ `python/tests/test_reader.py` compares every field against JavaScript
175
+ on all plain/debug fixtures, and also checks the native CLI when
176
+ `CASADI_READER_NATIVE` points to it. `scripts/test-bindings.py` runs the same
177
+ fixture comparisons in MATLAB/Julia; see its `--help` for local paths. Native
178
+ `native/tests/api.c` exercises the C ABI, copied input and lazy payload bounds.
179
+ These local language tests do not add language packaging to CI.
180
+
148
181
  ## Publishing
149
182
 
150
183
  `publish.yml` publishes on a published GitHub release, after tests. The release
@@ -156,5 +189,5 @@ repository `casadi-reader`, workflow `publish.yml`, with no environment name and
156
189
  with direct `npm publish` allowed. Publishing uses OIDC and provenance, with no
157
190
  npm token secret. See [npm's documentation](https://docs.npmjs.com/trusted-publishers/).
158
191
 
159
- The reader implementation is MIT licensed. Source excerpts in the vendored
160
- scheme retain CasADi's original license; see NOTICE.
192
+ The reader implementation is MIT licensed. The vendored scheme is derived from
193
+ CasADi; upstream attribution and license texts are retained in NOTICE and LICENSES.