ParameterManager¶
from cascaqit import ParameterManager
ParameterManager ¶
ParameterManager(
schema: ParameterSchemaIR = ParameterSchemaIR(),
assignments: dict[str, ParameterScalar] = dict(),
assignment_units: dict[str, str | None] = dict(),
targets: tuple[ParameterTargetIR, ...] = (),
metadata: dict[str, Any] = dict(),
schema_version: str = CANONICAL_PARAMETER_SCHEMA_VERSION,
)
Keep a parameter schema, assigned values and mappings to program locations together. Start with ParameterManager() or HybridProgram.parameters. declare(), assign() and map_target() return a new manager; retain their return values. bind() returns a binding result. Do not mutate the exposed dictionaries to bypass binding validation.
Direct construction accepts schema, assignments, assignment_units, targets, metadata and schema_version. Schema and target types belong to cascaqit.parameters. Target mappings describe where a parameter is used; they do not themselves rewrite or execute a program.
from cascaqit import Parameter, ParameterManager
manager = ParameterManager().declare(Parameter("theta", unit="rad", lower_bound=0.0))
manager = manager.assign("theta", 0.5, unit="rad")
binding = manager.bind()
assert not binding.has_errors
assert binding.bind_set is not None
assert binding.bind_set.values["theta"] == 0.5
assert manager.bind({"theta": -0.1}).has_errors
See Hybrid parameters for usage in programs.
Add a Parameter declaration and return a new manager. Other input types raise TypeError; duplicate names raise ValueError.
assign ¶
assign(
name: str,
value: ParameterScalar,
*,
unit: str | None = None,
) -> ParameterManager
Store a value and optional unit for name, returning a new manager. Reassignment replaces the stored value. This checks basic shape; bind() checks declaration, dtype, bounds and unit compatibility.
Append ParameterTargetIR. Its target ID must be unique; wrong types raise TypeError and duplicate IDs raise ValueError.
bind ¶
bind(
values: Mapping[str, ParameterScalar] | None = None,
*,
units: Mapping[str, str | None] | None = None,
bind_id: str = "bind.default",
) -> ParameterBindingResult
Merge stored assignments with this call’s values, giving the new values precedence; units similarly overrides stored units. Resolve defaults and derived expressions and return ParameterBindingResult. Success provides a ParameterBindIR in bind_set. Failure sets has_errors=True and bind_set=None, with reasons in diagnostics. Derived parameters cannot be assigned directly, and cyclic dependencies fail. Any supplied non-None unit must exactly match the declaration; omitting a unit does not convert values.
bind_many ¶
bind_many(
value_sets: Sequence[Mapping[str, ParameterScalar]],
*,
units: Mapping[str, str | None] | None = None,
bind_id_prefix: str = "bind",
) -> tuple[ParameterBindingResult, ...]
Bind each mapping in input order and return a tuple of results. IDs are bind_id_prefix.0, .1, and so on; the prefix must be nonempty. One failed point does not discard other results; inspect each has_errors flag.
Restore ParameterManager from a dictionary. Restore the schema, assignments, units and target mappings. Restoration does not establish a successful binding. Missing required fields or invalid values can raise KeyError, TypeError or ValueError.
Parse a JSON object and call from_dict(), returning ParameterManager. 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.