quchip.declarative.parameters¶
Declared-parameter metadata, synthesized __init__ signatures, and validation.
parameter() is the field-declaration surface concrete
DeviceModel,
CouplingModel, and
Envelope 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 |
|
Describe a synthesized constructor argument to static type checkers. |
|
Declare a traceable numerical parameter on a model class. |
|
Resolve declarative parameter fields for cls, walking the MRO. |
|
Resolve declared parameters into a {name: value} dict. |
|
Pop declared structural settings from values and apply defaults. |
|
Prefer a concrete scalar for serialization while preserving tracers. |
|
Declare serialized structural configuration on a model class. |
|
Resolve structural setting fields for cls, walking the MRO. |
Validate cross-cutting constraints on a class's declared fields. |
|
|
Enforce a field's declared sign constraint on concrete scalars only. |
Classes
|
Expose synthesized declarative constructors without runtime fields. |
|
Expose drive parameters as keyword-only synthesized arguments. |
|
Metadata for a declarative model parameter field. |
|
Metadata for a serialized, non-traceable structural model choice. |
- class quchip.declarative.parameters.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.parameters.Setting(default=unbound, serialize=True, kw_only=True)[source]¶
Bases:
objectMetadata for a serialized, non-traceable structural model choice.
- quchip.declarative.parameters.constructor_field(*, default=unbound, kw_only=False, runtime=unbound)[source]¶
Describe a synthesized constructor argument to static type checkers.
- quchip.declarative.parameters.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.parameters.setting(*, default=unbound, serialize=True, kw_only=True)[source]¶
Declare serialized structural configuration on a model class.
- class quchip.declarative.parameters.DeclarativeMeta(name, bases, namespace, **kwargs)[source]¶
Bases:
ABCMetaExpose synthesized declarative constructors without runtime fields.
- class quchip.declarative.parameters.DriveDeclarativeMeta(name, bases, namespace, **kwargs)[source]¶
Bases:
DeclarativeMetaExpose drive parameters as keyword-only synthesized arguments.
- 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=())[source]¶
Build a synthesized
__init__signature from declared param fields.Declared parameters become optional positional-or-keyword arguments in declaration order. trailing appends structural keyword-only parameters such as
levelsandlabel.
- quchip.declarative.parameters.resolve_declared_params(cls, params, *, fields=None)[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.resolve_declared_settings(cls, values)[source]¶
Pop declared structural settings from values and apply defaults.
- 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.