Skip to content

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.

names

names: tuple[str, ...]

Return names in declaration order. A backend observable batch should retain this order.

by_name

by_name() -> dict[str, Observable]

Return a new dictionary mapping names to Observable declarations. It contains declarations, not expectation values.

from_dict

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

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.

from_json

from_json(text: str) -> ObservableSet

Parse a JSON object and call from_dict(), returning ObservableSet. 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.