Identity¶
identity
¶
Versioned structural content identity for compiler artifacts.
Downstream forward and artifact provenance consume this manifest. It records compiler structure, not fitted values, solver settings, runtime versions or proof of numerical equivalence. It never changes Python object equality or hashing.
StructuralModelIdentity(schema_version, digest)
dataclass
¶
Validate a portable reference to a structural manifest.
Attributes:
| Name | Type | Description |
|---|---|---|
schema_version |
int
|
Canonical manifest and reference format, currently 1. |
digest |
str
|
SHA-256 of the exact canonical manifest's UTF-8 bytes. |
Examples:
>>> from op_system import compile_spec
>>> model = compile_spec({
... "kind": "expr",
... "state": ["x"],
... "equations": {"x": "-k*x"},
... })
>>> identity = StructuralModelIdentity.from_compiled(model)
>>> StructuralModelIdentity.from_json(identity.to_json()) == identity
True
>>> identity.digest.startswith("sha256:")
True
__post_init__()
¶
Refuse unknown formats and malformed content references.
Raises:
| Type | Description |
|---|---|
ValueError
|
Version or digest is missing, malformed or unsupported. |
Source code in src/op_system/identity.py
59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 | |
from_compiled(compiled)
classmethod
¶
Identify compiler structure without binding runtime parameters.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
compiled
|
CompiledRhs
|
An unmodified artifact produced by the compiler. |
required |
Returns:
| Type | Description |
|---|---|
StructuralModelIdentity
|
Reference to :func: |
Source code in src/op_system/identity.py
75 76 77 78 79 80 81 82 83 84 85 86 | |
from_json(payload)
classmethod
¶
Read a reference without treating it as an independently expected identity.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
payload
|
str
|
Exact two-field reference JSON. |
required |
Returns:
| Type | Description |
|---|---|
StructuralModelIdentity
|
Validated reference. Downstream guarded loaders must additionally |
StructuralModelIdentity
|
compare an independently supplied expected identity. |
Raises:
| Type | Description |
|---|---|
ValueError
|
The reference is malformed or uses an unknown schema. |
Source code in src/op_system/identity.py
96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 | |
to_json()
¶
Serialize the small reference, excluding the model manifest.
Returns:
| Type | Description |
|---|---|
str
|
Versioned reference JSON; this does not serialize a runnable model. |
Source code in src/op_system/identity.py
88 89 90 91 92 93 94 | |
structural_model_json(compiled)
¶
Serialize typed normalized IR and ordered compiler layouts as a canonical DAG.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
compiled
|
CompiledRhs
|
An unmodified compiler-produced artifact with retained source IR. |
required |
Returns:
| Type | Description |
|---|---|
str
|
Canonical schema-1 UTF-8/ASCII JSON text. Mapping keys are sorted; |
str
|
state, parameter, axis, coordinate, operation and observable sequences |
str
|
retain their semantic order. Scalars have explicit type tags and floats |
str
|
use exact hexadecimal strings. Shared typed trees are content-interned. |
str
|
The manifest includes normalized declarations/constants/operators and |
str
|
gauge/coordinate options, but never bound runtime values or closures. |
str
|
This is an identity manifest, not the external executable IR export. |
Raises:
| Type | Description |
|---|---|
ValueError
|
The artifact has no typed normalized source. |
Source code in src/op_system/identity.py
225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 | |