quchip.utils.registry¶
Shared subclass-registry mixin for serializable quchip components.
A Registrable subtree maintains a single registry mapping each
concrete subclass’s fully-qualified name to the class object, populated
automatically at subclass-definition time. The mixin owns the shared
serialization contract — the {"type": ...} stamp and the registry-root
from_dict dispatch — so devices, couplings, drives, envelopes, and
signal transforms share one registration and dispatch rule instead of each
component family hand-rolling its own registry dict, __init_subclass__
registration, and base-vs-leaf dispatch.
Declaring a registry root¶
A registry root is declared with the registry_root=True class
keyword:
class BaseThing(Registrable, registry_root=True):
...
The root owns a fresh registry dict and is itself excluded from
registration. Every concrete subclass below it is registered under
f"{cls.__module__}.{cls.__qualname__}". Abstract subclasses — those
that still carry unimplemented abstract methods — are skipped as well:
they can never be instantiated, hence never serialized, so registering
them would only add dead entries.
Serialization contract¶
to_dict()stamps{"type": cls._type_key()}. Subclasses that carry extra payload overrideto_dict(), callsuper().to_dict(), and add their own fields — preserving each type’s payload exactly.from_dict(), when invoked on the registry root, looks the concrete class up bydata["type"]and delegates to itsfrom_dict, forwarding any extra positional / keyword arguments (a coupling’s two endpoints, a drive’s target, …). On a concrete subclass it reconstructs via_from_dict_payload(), whose default is the parameter-lesscls(). Subclasses needing real reconstruction either overridefrom_dict(devices, couplings, envelopes — payload-carrying) or override_from_dict_payload(drives — shared target/label/rwa reconstruction). The parameter-less default covers the signal transforms that take no constructor arguments.
Classes
Mixin owning a subclass registry and the shared (de)serialization contract. |
- class quchip.utils.registry.Registrable[source]¶
Bases:
objectMixin owning a subclass registry and the shared (de)serialization contract.
- classmethod from_dict(data, *args, **kwargs)[source]¶
Reconstruct from
to_dict()output.On the registry root, dispatch to the concrete subclass named by
data["type"](forwarding*args/**kwargs). On a concrete subclass, defer to_from_dict_payload(). Concrete subclasses that carry payload override this method directly.