Skip to content

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.

required

required: bool

Return True when neither a default nor an expression exists, so binding must supply the parameter.

dependencies

dependencies: tuple[str, ...]

Return names referenced by a derived expression, or an empty tuple for an ordinary parameter. This does not return the parameter’s own name.

contains

contains(value: ParameterScalar) -> bool

Validate type and finiteness, then check inclusive bounds. A valid typed value outside the bounds returns False; invalid types or nonfinite values raise instead.

evaluate

evaluate(
    values: Mapping[str, ParameterScalar],
) -> ParameterScalar

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.

to_ir

to_ir() -> ParameterIR

Return ParameterIR retaining dtype, unit, bounds, default, expression and compilation impact.

from_ir

from_ir(parameter: ParameterIR) -> Parameter

Return a new Parameter from cascaqit.parameters.ParameterIR; other input types raise TypeError.

from_dict

from_dict(data: Mapping[str, Any]) -> Parameter

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.

from_json

from_json(text: str) -> Parameter

Parse a JSON object and call from_dict(), returning Parameter. Invalid JSON raises a parsing error; a non-object root raises TypeError.

to_dict

to_dict() -> dict[str, Any]

Return a JSON-compatible dictionary, serializing nested objects and converting tuples to arrays. This stores the declaration, not an execution result.

to_json

to_json(*, indent: int | None = None) -> str

Return a JSON string without writing a file. indent=None uses compact formatting; supply an indentation width for readable output.

stable_hash

stable_hash() -> str

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.