neuralqx.experimental.utils.struct.registry module¶
Class-reference registry utilities for struct and pytree serialisation.
This module provides a stable mechanism for converting runtime classes into importable string references and resolving them back later.
Class references use the canonical format:
"module.path:QualifiedClassName"
Examples:
- "neuralqx.graph.core.graph_handler:GraphHandler"
- "my_pkg.subpkg.models:Outer.Inner"
Struct and pytree serialisation needs a process-independent way to identify types. Raw class objects are not portable across sessions, but importable class references are.
- The registry combines:
a fast in-memory cache for already-seen classes,
a lazy importer fallback for classes not yet loaded in the process.
- class_ref(cls)¶
Return canonical class reference string for
cls.- Parameters:
- Return type:
- Returns:
A deterministic
"module:qualname"reference suitable for manifests.
Notes
The returned value is purely structural and does not validate importability at call time. Import validation occurs during
resolve_class().
- register_class_ref(cls)¶
Register
clsin the process-local class cache.This improves resolution speed and avoids repeated import traversal for classes already encountered during struct/pytree processing.
- Return type:
- resolve_class(ref)¶
Resolve a class reference into a runtime class object.
- This functions resolves by:
Look up
refin the in-memory registry cache.If missing, import module + qualified name lazily.
Cache resolved result for future calls.
- Parameters:
ref (
str) – Class reference in"module:qualname"format.- Return type:
- Returns:
Imported and validated class object.
- Raises:
SerializationError – If the reference format is invalid, import fails, attribute traversal fails, or the resolved object is not a class.