quchip.utils.state_versioning

StateVersioned — shared mutation-tracking / cache-invalidation mixin.

The engine caches assembled Hamiltonians (and dressed-state analyses) keyed on a per-object state_version counter. After construction finishes, every tracked public mutation bumps the counter so stale caches invalidate deterministically. Both BaseDevice and BaseCoupling need exactly this machinery, so it lives here once instead of being copy-pasted into each base.

_finish_init() flips mutation tracking on and fires exactly once per instance. __init_subclass__() wraps each concrete subclass’s own __init__; the wrapper calls _finish_init() only when type(self).__init__ resolves to itself — the entry-point init for the instance’s actual type — so super().__init__ chains and explicit inner-init forwards never re-fire it.

Subclass-authored init machinery that synthesizes __init__ after the __init_subclass__ super-chain runs (the declarative DeviceModel) must call _wrap_init_for_finish() on the freshly-installed init itself; the helper is idempotent, so a repeat call is harmless.

The JAX pytree _unflatten path bypasses __init__ entirely — it builds via cls.__new__ and sets _tracking_enabled directly — and so bypasses the wrapper as well.

Classes

StateVersioned()

Mixin: monotone state_version bumped on tracked public mutations.

class quchip.utils.state_versioning.StateVersioned[source]

Bases: object

Mixin: monotone state_version bumped on tracked public mutations.

property state_version: int

Return the monotone counter bumped on every tracked public-parameter mutation.