quchip.declarative.parameters¶
Declared-parameter metadata, synthesized __init__ signatures, and validation.
parameter() is the field-declaration surface concrete
DeviceModel,
CouplingModel, and
EnvelopeShape subclasses use;
this module resolves those declarations into synthesized constructors and
runs their sign constraints, both at construction and on post-construction
writes.
Functions
|
Build a synthesized |
|
Declare a traceable scalar or modulation parameter on a model class. |
|
Resolve declarative parameter fields for cls, walking the MRO. |
|
Resolve declared parameters into a {name: value} dict. |
|
Prefer a concrete scalar for serialization while preserving tracers. |
|
Enforce a field's declared sign constraint on concrete scalars only. |
Classes
|
Metadata for a declarative model parameter field. |
- class quchip.declarative.parameters.Parameter(default=<object object>, positive=False, nonnegative=False, serialize=True, unit=None)[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.
- quchip.declarative.parameters.parameter(*, default=<object object>, positive=False, nonnegative=False, serialize=True, unit=None)[source]¶
Declare a traceable scalar or modulation 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 field is required in the synthesized
__init__.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").
- 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): ... return self.freq * op.n >>> Oscillator(freq=5.0, levels=3).freq 5.0
- quchip.declarative.parameters.serializable_value(value)[source]¶
Prefer a concrete scalar for serialization while preserving tracers.
- quchip.declarative.parameters.validate_sign(name, spec, value)[source]¶
Enforce a field’s declared sign constraint on concrete scalars only.
Shared by construction (
resolve_declared_params()) and post-construction writes (DeviceModel._validate_param_write) so the two paths cannot drift. Traced values flow through unchecked;Nonemeans “unset” and always passes.
- quchip.declarative.parameters.build_declared_signature(param_fields, trailing=(), *, owner=None)[source]¶
Build a synthesized
__init__signature from declared param fields.Declared parameters become positional-or-keyword arguments in declaration order, carrying their declared defaults. trailing appends extra (typically keyword-only) structural parameters — e.g.
levels,labeland the noise kwargs for aDeviceModel. owner names the class whose declarations are being synthesized, for the ordering error raised by_check_declaration_order().
- quchip.declarative.parameters.resolve_declared_params(cls, params)[source]¶
Resolve declared parameters into a {name: value} dict.
Walks
parameter_fields(cls): for each declared field, pops the matching kwarg from params (or uses its default), runs the concrete-only positivity check, and collects the result. Returns a dict of validated parameter values, one entry per declared field. RaisesTypeErrorif a required field is missing or if params still contains unrecognized keys after the loop.
- quchip.declarative.parameters.parameter_fields(cls)[source]¶
Resolve declarative parameter fields for cls, walking the MRO.
A field is included iff some class in the MRO annotates the name and the resolved class attribute (
getattr(cls, name)) is aParameterinstance. A subclass that shadows an inheritedParameterwith a concrete value (e.g.freq: Scalar = 5.0) silently drops the field — by design, so subclasses can elide a parent’s parameter when they want a concrete override.