quchip.declarative.parameters¶
Declared-parameter metadata, synthesized __init__ signatures, and validation.
Concrete DeviceModel,
CouplingModel, and
Envelope subclasses use parameter() to
declare fields. This module resolves those declarations into synthesized
constructors and enforces their sign constraints at construction and on later
writes.
Functions
|
Declared numerical and structural values used for copying and cache keys. |
|
Build a synthesized |
|
Track authored buffer edits and ordinary versioned assignments. |
|
Describe a synthesized constructor argument to static type checkers. |
|
Give a derived component independent writable authored values. |
|
Declare a traceable numerical parameter on a model class. |
|
Resolve declarative parameter fields for cls through 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, but keep tracers. |
|
Declare serialized structural configuration on a model class. |
|
Resolve structural setting fields for cls through the MRO. |
Validate cross-cutting constraints on a class's declared fields. |
|
|
Enforce declared sign constraints on concrete scalars. |
Classes
|
Expose synthesized declarative constructors without runtime fields. |
|
Expose keyword-only synthesized constructors for control declarations. |
|
Metadata for a declared parameter's validation and serialization. |
|
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 declared parameter’s validation and serialization.
Sign constraints apply to concrete scalars. Traced values pass unchecked.
- Parameters:
default (Any, default
UNBOUND) – Constructor default.UNBOUNDmakes the field required.positive (bool, default False) – Reject concrete values outside the selected sign constraint.
nonnegative (bool, default False) – Reject concrete values outside the selected sign constraint.
serialize (bool, default True) – Include the field in serialized model data.
unit (str or None) – Display metadata for units and mathematical notation.
symbol (str or None) – Display metadata for units and mathematical notation.
noise (bool) – Mark noise fields, force keyword-only construction, or require a value.
kw_only (bool) – Mark noise fields, force keyword-only construction, or require a value.
required (bool) – Mark noise fields, force keyword-only construction, or require a value.
- class quchip.declarative.parameters.Setting(default=unbound, serialize=True, kw_only=True)[source]¶
Bases:
objectMetadata for a serialized, non-traceable structural model choice.
- Parameters:
- 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. If omitted, the constructor argument is required. Use
default=UNBOUNDto defer its value 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 (for example
"GHz").symbol (str or None, optional) – Mathematical symbol for displaying authored physics. If omitted, the display uses the field name.
noise (bool, optional) – If set,
Chip.set_noise()can configure this field while its current value is unset.kw_only (bool, optional) – Place the declared field after the
*in synthesized constructors.
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.KeywordOnlyDeclarativeMeta(name, bases, namespace, **kwargs)[source]¶
Bases:
DeclarativeMetaExpose keyword-only synthesized constructors for control declarations.
- quchip.declarative.parameters.serializable_value(value)[source]¶
Prefer a concrete scalar for serialization, but keep tracers.
- quchip.declarative.parameters.validate_sign(name, spec, value)[source]¶
Enforce declared sign constraints on concrete scalars.
Tracers and
None(unset) pass unchecked.
- 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, it 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 for each 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 through the MRO.
A field is included if and only if 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 (for examplefreq: Scalar = 5.0) silently drops the field. By design, this lets subclasses remove a parent’s parameter when they want a concrete override.
- quchip.declarative.parameters.setting_fields(cls)[source]¶
Resolve structural setting fields for cls through the MRO.
- quchip.declarative.parameters.authored_component_values(component)[source]¶
Declared numerical and structural values used for copying and cache keys.
- quchip.declarative.parameters.copy_authored_fields(source, target)[source]¶
Give a derived component independent writable authored values.
- quchip.declarative.parameters.component_fingerprint(component, *, traced=False)[source]¶
Track authored buffer edits and ordinary versioned assignments.
traced=Truekeys traced values by identity. Seescoped_entry().