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 override to_dict(), call super().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 by data["type"] and delegates to its from_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-less cls(). Subclasses needing real reconstruction either override from_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

Registrable()

Mixin owning a subclass registry and the shared (de)serialization contract.

class quchip.utils.registry.Registrable[source]

Bases: object

Mixin owning a subclass registry and the shared (de)serialization contract.

to_dict()[source]

Serialize the type tag; subclasses extend with their own fields.

Return type:

dict[str, Any]

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.

Parameters:
Return type:

Any