Skip to content

ResultIR

from cascaqit import ResultIR

ResultIR

ResultIR(
    result_id: str,
    program_hash: str,
    target_id: str,
    shots: int,
    counts: dict[str, int],
    samples: tuple[str, ...],
    probabilities: dict[str, float] | None = None,
    measurement_results: tuple[
        MeasurementResultIR, ...
    ] = (),
    state_result: StateResultIR | None = None,
    observables: dict[str, Any] = dict(),
    observable_batch: ObservableBatchResultIR | None = None,
    bit_ordering: dict[str, Any] = (
        lambda: {
            "convention": UNSPECIFIED_BIT_ORDER_CONVENTION
        }
    )(),
    occupation_encoding: OccupationEncoding = OccupationEncoding(),
    diagnostics: tuple[DiagnosticsIR, ...] = (),
    schema_version: str = SCHEMA_VERSION,
    metadata: dict[str, Any] = dict(),
)

Store data returned by one program execution, usually obtained from Circuit.run(), AHSProgram.run() or a LocalBackend job.result(). For direct construction, result_id, program_hash and target_id identify the result and its source; shots, counts and samples hold sampling data. Callers supply those fields: constructing the object does not run or authenticate an experiment.

Probabilities is optional state-probability data and is None when unavailable or not requested; it is not counts/shots. observable_batch stores observables with estimator information, while observables contains other available scalars or metadata. bit_ordering and occupation_encoding describe bit order and occupancy. Diagnostics and metadata retain validation, execution and source records.

With one explicit measurement register, top-level counts, samples and probabilities match that register. With multiple registers, top-level counts and samples must be empty and probabilities None; read each register by key. state_result may separately retain full-state data. Partial measurement probabilities are not full-state probabilities.

from cascaqit import Circuit, ResultIR

result = Circuit(2).x(0).measure((1, 0), key="reordered").run(shots=16, seed=7)
assert result.measurement("reordered").counts == {"01": 16}
restored = ResultIR.from_json(result.to_json())
assert restored.stable_hash() == result.stable_hash()

See Digital execution records for a reading workflow. For noisy results, also distinguish the pre-readout state from recorded outcomes when interpreting probabilities, counts and observables.

measurement

measurement(key: str | None = None) -> MeasurementResultIR

Return MeasurementResultIR for key. Omit key only when exactly one explicit register exists. No registers, multiple registers without a key or an ambiguous key raise ValueError; an unknown key raises KeyError.

execution_config

execution_config() -> SimulationExecutionConfigIR | None

Return recorded SimulationExecutionConfigIR or None. This reads saved execution configuration without replanning on the current machine.

resource_usage

resource_usage() -> SimulationResourceUsageIR | None

Return SimulationResourceUsageIR when recorded, otherwise None. Distinguish estimates, state-array sizes and measurements according to their fields; they are not all peak process memory.

solver_evidence

solver_evidence() -> SimulationSolverEvidenceIR | None

Return recorded SimulationSolverEvidenceIR or None, exposing integrator, step and error-control information. Missing records do not imply zero error; this does not recompute a trajectory.

state_transitions

state_transitions() -> tuple[StateTransitionIR, ...]

Return saved StateTransitionIR records as a tuple, empty when absent. They describe recorded handoffs without reconstructing missing intermediate state arrays.

interaction_reports

interaction_reports() -> tuple[InteractionReportIR, ...]

Return InteractionReportIR records in Analog-block order, describing executed interaction configuration, geometry and pair summaries. Return an empty tuple when absent.

interaction_report

interaction_report() -> InteractionReportIR | None

Return None when absent or the single report when exactly one exists. Multiple Analog reports raise ValueError; use interaction_reports in that case.

artifact_refs

artifact_refs() -> tuple[ArtifactRefIR, ...]

Read artifact references from metadata and return a tuple of ArtifactRefIR. This does not read the referenced files.

with_artifact_refs

with_artifact_refs(
    artifacts: tuple[ArtifactRefIR, ...],
) -> ResultIR

Return a new ResultIR replacing the metadata artifact-reference list with artifacts, rather than appending. This stores references without writing artifact files or uploading data.

to_dict

to_dict() -> dict[str, Any]

Return a serialized dictionary. Empty measurement_results and absent state_result or observable_batch are omitted, preserving the absent-field convention. Other data comes from this result.

to_json

to_json(*, indent: int | None = None) -> str

Return a JSON string, using stable compact formatting when indent=None or formatted output when indent is supplied. No file is written.

stable_hash

stable_hash() -> str

Return the SHA-256 digest of serialized result data and metadata. It identifies content without proving experimental correctness; adding metadata may also change the hash.

from_dict

from_dict(data: dict[str, Any]) -> ResultIR

Restore ResultIR from a dictionary. Restore measurement, state, observable and diagnostic objects and check consistency of single/multiple-register fields. Missing required fields or invalid values can raise KeyError, TypeError or ValueError.

from_json

from_json(text: str) -> ResultIR

Parse a JSON object and call from_dict(), returning ResultIR. Invalid JSON raises a parsing error; a non-object root raises TypeError.