Observable¶
from cascaqit import Observable
Observable ¶
Observable(
name: str,
terms: tuple[PauliTerm, ...],
schema_version: str = OBSERVABLE_SCHEMA_VERSION,
)
Declare a named Pauli product. terms contains PauliTerm factors on distinct logical targets, with bases I, X, Y or Z. Terms must be nonempty and targets unique. The name must be a nonempty string without leading or trailing whitespace.
An Observable is an operator product, not a weighted sum of terms; use PauliHamiltonian for a Hamiltonian sum. Usually construct simple observables with PauliX(), PauliZ() or PauliProduct. Direct construction uses PauliTerm from cascaqit.observables.
A declaration does not perform a measurement or append basis rotations to a circuit. Put declarations into an ObservableSet and pass it to a supporting backend. Interpret returned values with their estimator_kind: X/Y expectations computed from an exact state are not estimates from computational-basis counts. See Observable batches.
from cascaqit import Observable, PauliProduct
xx = PauliProduct((("q0", "X"), ("q1", "X")), name="XX")
assert xx.targets == ("q0", "q1")
assert Observable.from_json(xx.to_json()) == xx
Return target names in factor declaration order without sorting. The evaluator checks that targets exist in the evaluation state.
Return a tuple of PauliBasis enums in the same order, paired with targets.
Restore Observable from a dictionary. Rebuild PauliTerm factors and recheck nonempty terms, bases and distinct targets. Missing required fields or invalid values can raise KeyError, TypeError or ValueError.
Parse a JSON object and call from_dict(), returning Observable. 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.