Parameter¶
from cascaqit import Parameter
Parameter ¶
Parameter(
name: str,
dtype: ParameterDType = "float",
unit: str | None = None,
default: ParameterScalar | None = None,
lower_bound: int | float | None = None,
upper_bound: int | float | None = None,
expression: Expression | None = None,
compile_impact: CompileImpact = "bind_only",
source_span: SourceSpan | None = None,
metadata: Mapping[str, Any] = dict(),
schema_version: str = CANONICAL_PARAMETER_SCHEMA_VERSION,
)
Declare a parameter with a type, unit and optional bounds. name must be a Python identifier that is not a keyword. Supported dtypes are float, int and bool: float accepts integers or floats, int rejects floats, and booleans are accepted only for bool parameters. Numeric values must be finite, bounds are inclusive, and bool parameters cannot have numeric bounds.
default supplies an omitted binding. expression defines a derived value and is mutually exclusive with default; its dtype and unit must match. unit is a label, with no implicit conversion. compile_impact is bind_only or recompile, allowing binding and compilation layers to distinguish changes. source_span, metadata and schema_version retain origin and format information.
Arithmetic operators +, -, *, /, ** and unary signs return an Expression, subject to type and unit rules. Wrong types raise TypeError; invalid names, units, ranges or nonfinite values generally raise ValueError. In a circuit or analog program, prefer Circuit.parameter() or AHSProgram.parameter() so that the program owns the declaration.
from cascaqit import Parameter
angle = Parameter("theta", unit="rad", default=0.25, lower_bound=0.0)
assert angle.evaluate({}) == 0.25
assert angle.contains(0.0)
assert Parameter.from_json(angle.to_json()) == angle
See Digital parameter binding and Shared parameters for complete workflows.
Return True when neither a default nor an expression exists, so binding must supply the parameter.
Return names referenced by a derived expression, or an empty tuple for an ordinary parameter. This does not return the parameter’s own name.
Validate type and finiteness, then check inclusive bounds. A valid typed value outside the bounds returns False; invalid types or nonfinite values raise instead.
Return the resolved scalar. Derived parameters always evaluate their expression; ordinary parameters prefer values[name] and then their default. Missing values, expression failures or out-of-range results raise. This does not resolve an entire dependency graph; use ParameterManager.bind() for interdependent declarations.
Return ParameterIR retaining dtype, unit, bounds, default, expression and compilation impact.
Return a new Parameter from cascaqit.parameters.ParameterIR; other input types raise TypeError.
Restore Parameter from a dictionary. Nested expression and source_span values are restored to their types and constructor validation runs again. Missing required fields or invalid values can raise KeyError, TypeError or ValueError.
Parse a JSON object and call from_dict(), returning Parameter. Invalid JSON raises a parsing error; a non-object root raises TypeError.
Return a JSON-compatible dictionary, serializing nested objects and converting tuples to arrays. This stores the declaration, not an execution result.
Return a JSON string without writing a file. indent=None uses compact formatting; supply an indentation width for readable output.
Return the SHA-256 hex digest of canonical JSON. Fields, identifiers and metadata can affect it. Use it to compare saved content, not to decide physical equivalence.