mixle.utils.serialization module¶
Safe JSON serialization helpers for mixle distribution and estimator objects.
The legacy load_models(eval_string) path reconstructed models by executing
their repr strings. This module instead serializes distribution state as a
small tagged JSON value graph and reconstructs only classes registered from
mixle’s own distribution modules.
- exception SerializationError[source]
Bases:
ValueErrorRaised when an object cannot be serialized or decoded safely.
- register_serializable_class(cls, type_id=None)[source]
Register a class that may be reconstructed from serialized state.
Deserialization never imports a class named in the payload. The class must already be present in this registry, which is populated from mixle package modules by
ensure_pysp_serialization_registry.
- register_serializable_callable(fn, callable_id=None)[source]
Register a callable that may appear inside a serialized distribution.
This is intentionally explicit. Arbitrary lambdas or local functions cannot be made safe by JSON alone; callers that need SelectDistribution-like routing should register a stable process-local callable id.
- serializable_class_ids()[source]
Return the registered class ids, primarily for diagnostics/tests.
- ensure_pysp_serialization_registry()[source]
Populate the closed registry of mixle classes that can be decoded.
- Return type:
None
- to_serializable(value)[source]
Convert a mixle model/value to a JSON-compatible tagged value.
- from_serializable(payload)[source]
Decode a value produced by
to_serializable.
- to_json(value, **kwargs)[source]
Serialize a mixle model/value to strict JSON.