ObservableSet¶
from cascaqit import ObservableSet
ObservableSet ¶
ObservableSet(
observables: Iterable[Observable],
*,
schema_version: str = OBSERVABLE_SCHEMA_VERSION,
)
Store an ordered collection of Observable declarations. Construction snapshots an iterable into a tuple. Supply at least one observable with unique names. Wrong element types raise TypeError; empty collections or duplicate names raise ValueError.
Iteration, len(), integer indexing and slicing are supported. An integer index returns an Observable; a slice returns a tuple. These operations do not evaluate observables. schema_version identifies the serialized format.
from cascaqit import ObservableSet, PauliX, PauliZZ
requested = ObservableSet([PauliX("q0", name="X0"), PauliZZ("q0", "q1", name="ZZ")])
assert requested.names == ("X0", "ZZ")
assert requested[0].name == "X0"
assert len(requested[:1]) == 1
Pass it as observables= to LocalBackend.run() to read several observables from one evolution. This does not mean arbitrary noncommuting observables share one physical measurement. See Observable batches for execution and variance interpretation.
Return names in declaration order. A backend observable batch should retain this order.
Return a new dictionary mapping names to Observable declarations. It contains declarations, not expectation values.
Restore ObservableSet from a dictionary. Restore observables in input order and recheck name uniqueness. Missing required fields or invalid values can raise KeyError, TypeError or ValueError.
Parse a JSON object and call from_dict(), returning ObservableSet. 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.