quchip.declarative¶
Declarative physics model API.
- class quchip.declarative.CouplingModel(device_a, device_b, *, label=None, **params)[source]¶
Bases:
BaseCouplingDeclarative two-body coupling base.
Subclasses declare physics parameters via
parameter()and implementinteraction()(returning aPhysicsExprover the two endpoint operators). The chip’s approximation strategy is applied structurally by the engine after the authored interaction is assembled. Optional overrides:time_terms()— time-dependent Hamiltonian terms, each pairing a local operator with a public time coefficient.
coupling_strengthdefaults to the first declared parameter field (suited for the common case of oneg-like scalar). Override the property in subclasses with a different convention.Note
Coupling instances are not registered as JAX pytrees and cannot be passed as dynamic
jax.jit/jax.vmap/jax.gradarguments. Coupling parameters remain differentiable when the coupling (and the devices or chip it couples) is constructed from traced arguments inside the transformed function.Examples
>>> from quchip.declarative import CouplingModel, parameter, Scalar >>> class ExchangeCoupling(CouplingModel): ... g: Scalar = parameter(unit="GHz") ... def interaction(self, a, b, p): ... return p.g * (a.a * b.adag + a.adag * b.a) >>> c = ExchangeCoupling("q0", "q1", g=0.01) >>> c.coupling_strength 0.01
- Parameters:
device_a (BaseDevice | str)
device_b (BaseDevice | str)
label (Any)
params (Any)
- device_a: BaseDevice | str¶
- device_b: BaseDevice | str¶
- property coupling_strength: Any¶
Primary scalar coupling strength, defaulting to the first parameter.
- property coupling_strength_name: str¶
Display name of
coupling_strength, defaulting to the first parameter field.
- interaction(a, b, p)[source]¶
Return the full two-body interaction expression.
- Parameters:
a (EndpointOps) – Operator namespaces for the two coupled endpoints. Same-endpoint operators compose with
@; cross-endpoint operators combine with*(tensor product).b (EndpointOps) – Operator namespaces for the two coupled endpoints. Same-endpoint operators compose with
@; cross-endpoint operators combine with*(tensor product).p (Any)
- Returns:
The interaction Hamiltonian expression, in ordinary-frequency units (GHz).
- Return type:
- time_terms(a, b, p)[source]¶
Return time-dependent interaction terms.
- Parameters:
a (EndpointOps) – Operator namespaces for the two coupled endpoints.
b (EndpointOps) – Operator namespaces for the two coupled endpoints.
p (Any)
- Returns:
Local operators and their scalar time coefficients. The empty tuple denotes a purely static coupling.
- Return type:
- parametric_interaction(a, b, p)[source]¶
Return the parametric interaction structure, or
Nonewhen this coupling is not modulable.The coupling-side mirror of the device drive-dispatch protocols: a
ParametricDriveaccepts any coupling whose hook returns aPhysicsExpr.
- dissipation(a, b, p)[source]¶
Return authored two-endpoint Lindblad channels.
- Parameters:
- Return type:
tuple[CollapseChannel, …]
- interaction_hamiltonian()[source]¶
Return the authored symbolic interaction Hamiltonian.
- Return type:
- collapse_channels()[source]¶
Return normalized coupling collapse channels.
- Return type:
tuple[CollapseChannel, …]
- class quchip.declarative.CollapseChannel(operator, rate, name)[source]¶
Bases:
objectOne unscaled Lindblad operator and its rate in inverse nanoseconds.
- class quchip.declarative.CosineCoefficient(amplitude=unbound, frequency=unbound, phase=0.0)[source]¶
Bases:
TimeCoefficientCosine coefficient with amplitude in GHz and frequency in GHz.
- amplitude: Any = Parameter(default=unbound, positive=False, nonnegative=False, serialize=True, unit='GHz', symbol=None, noise=False, kw_only=False, required=False)¶
- frequency: Any = Parameter(default=unbound, positive=True, nonnegative=False, serialize=True, unit='GHz', symbol=None, noise=False, kw_only=False, required=False)¶
- class quchip.declarative.DeviceModel(*, levels=2, label=None, **params)[source]¶
Bases:
BaseDeviceDeclarative base for physics device models.
Subclasses declare their parameters as annotated class attributes using
parameter()(e.g.freq: Scalar = parameter(positive=True)) and implementlocal_hamiltonian(). The declared parameters become positional-or-keyword__init__arguments and JAX pytree leaves so the full instance is traceable / differentiable / sweepable end-to-end.The
hamiltonian()adapter compiles the declarative expression returned bylocal_hamiltonian()into an operator for the active default backend.Examples
>>> from quchip.declarative import DeviceModel, parameter, Scalar >>> class DuffingOscillator(DeviceModel): ... freq: Scalar = parameter(positive=True, unit="GHz") ... anharmonicity: Scalar = parameter(unit="GHz") ... def local_hamiltonian(self, op, p): ... return p.freq * op.n + 0.5 * p.anharmonicity * op.n @ (op.n - op.I) >>> device = DuffingOscillator(freq=5.0, anharmonicity=-0.3, levels=4) >>> device.freq 5.0
- label: Any¶
- T1: Any = Parameter(default=None, positive=True, nonnegative=False, serialize=True, unit='ns', symbol=None, noise=True, kw_only=True, required=False)¶
- T2: Any = Parameter(default=None, positive=True, nonnegative=False, serialize=True, unit='ns', symbol=None, noise=True, kw_only=True, required=False)¶
- thermal_population: Any = Parameter(default=None, positive=False, nonnegative=True, serialize=True, unit=None, symbol=None, noise=True, kw_only=True, required=False)¶
- approximation: ClassVar[str | None] = None¶
Declared approximation-regime statement surfaced by
physics_notes()— the mechanism that keeps a model’s stated validity range attached to the class rather than buried in a docstring a caller may not read.
- computational: ClassVar[bool] = False¶
Whether this device represents a computational qubit, as opposed to e.g. a bus resonator or a coupler element.
- validate()[source]¶
Cross-field validation hook, run at the end of construction.
Default is a no-op. Subclasses override to enforce constraints that span multiple declared parameters (e.g.
2 * edge <= duration). Checks must be gated on concrete scalars viaquchip.utils.jax_utils.maybe_concrete_scalar()so traced parameters never force concretization.- Return type:
None
- local_hamiltonian(op, p)[source]¶
Return this device’s local Hamiltonian as a declarative expression.
- Parameters:
op (LocalOps) – Operator namespace for this device’s endpoint, exposing
a,adag,n,Iand the Pauli handles as composablePhysicsExprnodes.p (ParameterNamespace) – Symbolic leaves for the parameters declared on this model.
- Returns:
The local Hamiltonian expression, in ordinary-frequency units (GHz).
- Return type:
- time_terms(op, p)[source]¶
Return local time-dependent Hamiltonian terms beyond the static model.
- Parameters:
- Return type:
- dissipation(op, p)[source]¶
Return device-local Lindblad channels.
The base channels implement T1, T2, and thermal occupation. Subclasses may append channels with
super().dissipation(op, p).- Parameters:
- Return type:
tuple[CollapseChannel, …]
- class quchip.declarative.LocalOps(label, space, device=None)[source]¶
Bases:
objectDeclarative operator namespace for one local Hilbert space endpoint.
Passed as
optoDeviceModel.local_hamiltonian()and as the two endpointsa,btoCouplingModel.interaction(). Each property returns aPhysicsExprthat composes with+,-,@(same endpoint),*(scalar or tensor product).Examples
>>> from quchip.declarative import LocalOps >>> from quchip.devices.spaces import FockSpace >>> op = LocalOps(label="q", space=FockSpace(3)) >>> H = 5.0 * op.n + 0.5 * (op.adag @ op.adag @ op.a @ op.a) >>> H.kind 'add'
- Parameters:
label (str)
space (LocalSpace)
device (Any)
- space: LocalSpace¶
- property a: PhysicsExpr¶
Lowering operator for this endpoint.
- property adag: PhysicsExpr¶
Raising operator for this endpoint.
- property n: PhysicsExpr¶
Number operator for this endpoint.
- property level: PhysicsExpr¶
Energy-level index operator in the authored local basis.
- property n2: PhysicsExpr¶
Squared charge operator in a compatible authored local space.
- property phi: PhysicsExpr¶
Phase operator in a compatible authored local space.
- property cos_phi: PhysicsExpr¶
Cosine of phase in a compatible authored local space.
- property sin_phi: PhysicsExpr¶
Sine of phase in a compatible authored local space.
- property I: PhysicsExpr¶
Identity operator for this endpoint.
- property x: PhysicsExpr¶
Unnormalized quadrature
x = a + a†(no 1/sqrt(2) factor).
- property charge: PhysicsExpr¶
Physical charge-like drive operator for this local representation.
- property sigma_x: PhysicsExpr¶
|0><1| + |1><0|on the computational|0>, |1>subspace of the truncated space.
- property sigma_y: PhysicsExpr¶
-i|0><1| + i|1><0|on the computational|0>, |1>subspace.
- property sigma_z: PhysicsExpr¶
|0><0| - |1><1|on the computational|0>, |1>subspace.
- property sigma_plus: PhysicsExpr¶
Raising operator
|1><0|on the computational subspace.
- property sigma_minus: PhysicsExpr¶
Lowering operator
|0><1|on the computational subspace.
- class quchip.declarative.Parameter(default=unbound, positive=False, nonnegative=False, serialize=True, unit=None, symbol=None, noise=False, kw_only=False, required=False)[source]¶
Bases:
objectMetadata for a declarative model parameter field.
The metadata is intentionally lightweight: it records validation and serialization intent while leaving the runtime value fully traceable. Sign constraints (
positive/nonnegative) are enforced only on concrete scalars, so traced values flow through unchecked.- Parameters:
- class quchip.declarative.PhysicsExpr(kind, args=(), labels=(), _bindings=<factory>)[source]¶
Bases:
objectAuthored scalar and operator algebra, independent of numerical values.
- Parameters:
- classmethod parameter(*, scope, name, symbol=None, unit=None)[source]¶
Create a symbolic declared-parameter leaf.
- Parameters:
- Return type:
- classmethod literal(value)[source]¶
Create a literal scalar leaf.
- Parameters:
value (Any)
- Return type:
- classmethod from_matrix(value, *, labels, dims, name=None)[source]¶
Create a named backend-neutral matrix contribution.
- classmethod from_function(function, *arguments, labels, dims, name=None)[source]¶
Create an opaque matrix-valued contribution from a pure function.
The function runs only during numerical materialization. Display keeps its declared name and arguments, such as
X(a, b), without exposing the implementation as symbolic algebra.
- classmethod from_state(value, *, labels, dims, name)[source]¶
Create a named authored ket contribution.
- classmethod from_state_function(function, *arguments, labels, dims, name)[source]¶
Create an opaque callable ket contribution.
- classmethod from_signal(signal, *, name='f')[source]¶
Create a scalar time-function leaf backed by an engine signal.
- Parameters:
- Return type:
- embed(labels, dims)[source]¶
Embed this local contribution into an ordered composite Hilbert space.
- Parameters:
- Return type:
- with_bindings(bindings)[source]¶
Attach default values used only by direct numerical inspection.
- Parameters:
- Return type:
- class quchip.declarative.TimeDependentTerm(operator, coefficient)[source]¶
Bases:
objectAn authored local operator and its time coefficient.
- Parameters:
operator (Any)
coefficient (TimeCoefficient)
- coefficient: TimeCoefficient¶
- class quchip.declarative.Setting(default=unbound, serialize=True, kw_only=True)[source]¶
Bases:
objectMetadata for a serialized, non-traceable structural model choice.
- class quchip.declarative.TimeCoefficient[source]¶
Bases:
Registrable,ABCScalar coefficient of a component’s time-dependent Hamiltonian term.
Time is measured in ns. Implementations use
quchip.qnpso values remain JAX-traceable without receiving an array namespace argument.
- quchip.declarative.as_operator_expr(value, *, labels, dims, name, arguments=(), owner=None, scope=None, allowed=None)[source]¶
Normalize symbolic, matrix, or opaque callable operator authorship.
- quchip.declarative.as_scalar_expr(value, *, name, arguments=(), owner=None, scope=None, allowed=None)[source]¶
Normalize symbolic, numeric, or opaque callable scalar authorship.
- quchip.declarative.as_state_expr(value, *, labels, dims, name, arguments=(), owner=None, scope=None, allowed=None)[source]¶
Normalize an authored ket array or opaque callable without evaluating it.
- quchip.declarative.parameter(*, default=<object object>, positive=False, nonnegative=False, serialize=True, unit=None, symbol=None, noise=False, kw_only=False)[source]¶
Declare a traceable numerical parameter on a model class.
unitis display metadata for human-readable surfaces such asChip.describe()— the package-wide units contract (GHz, ns, mK) still governs the value itself.Nonemeans dimensionless or unknown. Returns aParameterfield descriptor thatparameter_fields()collects at class-definition time.- Parameters:
default (Any, optional) – Declared default value. When omitted the parameter remains unbound until numerical materialization.
positive (bool, optional) – Reject concrete values
<= 0. Traced values pass unchecked.nonnegative (bool, optional) – Reject concrete values
< 0. Traced values pass unchecked.serialize (bool, optional) – Include the field in
to_dict()output.unit (str or None, optional) – Display-only unit label (e.g.
"GHz").symbol (str or None, optional) – Mathematical symbol used when displaying authored physics. The field name is used when omitted.
noise (bool, optional) – Whether
Chip.set_noise()may configure this field while its current value is unset.kw_only (bool)
- Return type:
Examples
>>> from quchip.declarative import DeviceModel, parameter, Scalar >>> class Oscillator(DeviceModel): ... freq: Scalar = parameter(positive=True, unit="GHz") ... def local_hamiltonian(self, op, p): ... return p.freq * op.n >>> Oscillator(freq=5.0, levels=3).freq 5.0
- quchip.declarative.setting(*, default=unbound, serialize=True, kw_only=True)[source]¶
Declare serialized structural configuration on a model class.
Modules
Authored Lindblad dissipation values. |
|
Public records for component-owned time-dependent Hamiltonian terms. |
|
One backend-neutral expression tree for authored scalar and operator physics. |
|
Declarative base classes for device and coupling physics models. |
|
Declarative operator-handle namespaces for the physics DSL. |
|
Declared-parameter metadata, synthesized |
|
Trace-safe numeric namespace for declarative model authors. |