HamiltonianTerm¶
from cascaqit import HamiltonianTerm
HamiltonianTerm ¶
HamiltonianTerm(
term_id: str,
coefficient: float,
observable: Observable,
schema_version: str = ALGORITHM_SCHEMA_VERSION,
)
A finite, nonzero real coefficient multiplying an Observable, for use in PauliHamiltonian. term_id identifies the weighted term while observable.name identifies the observable; they serve different result references. Negative coefficients are allowed. Remove zero terms before construction and put a constant energy shift in PauliHamiltonian.constant.
from cascaqit import HamiltonianTerm, PauliZ
term = HamiltonianTerm("weighted_z", -0.7, PauliZ("q0"))
assert term.coefficient == -0.7
assert HamiltonianTerm.from_dict(term.to_dict()) == term
This is a declaration. Obtain expectation values through VQE or an observable execution path.
Restore a weighted term and its nested Observable from a dictionary, checking term_id, coefficient and object type. There is no from_json(); decode JSON text with json.loads() first.
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.