Skip to content

Extract data and diagnostics from a result

Retain ResultIR before deriving tables or reports. A plot presents a result; editing the plot neither reruns the experiment nor changes its samples.

What you need What to check
Measurement statistics Read counts, sum them, then interpret strings using the recorded bit order
State probabilities Read optional probabilities; it can be None when not requested or unsuitable for the outcome space
Expectation values Read the relevant observable results; sample frequencies are not arbitrary observable expectations
Bit order Read this result’s ordering record rather than inferring it from symmetric Bell counts
Warnings and errors Use diagnostic severity, code, object_path and suggestion
Numerical settings and costs Inspect applied execution settings, solver records and resource use, not only requested values

Connect the result, view and report

The example retains a source digest, builds a metadata view and creates a report object. It checks that the source is unchanged and the view preserves counts and result identity.

"""Inspect Result, Diagnostics, ResultView, and a standard report together.

``ResultIR`` remains the source record. Result views and visualization reports
are derived consumers: they may summarize facts, but they do not execute a Job
or become a second authoritative result store.
"""

from __future__ import annotations

import json

from cascaqit import Circuit, build_result_view, visualize


def main() -> None:
    """Create one result and inspect its source and derived representations."""
    result = (
        Circuit(1, program_id="lesson.platform.result")
        .h(0)
        .measure_all()
        .run(shots=16, seed=402, return_probabilities=True)
    )
    source_hash = result.stable_hash()
    view = build_result_view(result)
    report = visualize(result, profile="digital")

    payload = {
        "track": "sdk_platform_engineer",
        "level": "foundation",
        "lesson": "result_diagnostics",
        "facts": {
            "result_id": result.result_id,
            "source_unchanged": source_hash == result.stable_hash(),
            "view_counts_match": view.counts == result.counts,
            "view_backend_called": view.backend_called,
            "probabilities": result.probabilities,
            "diagnostic_severities": [item.severity for item in result.diagnostics],
            "diagnostic_codes": [item.code for item in result.diagnostics],
            "view_metadata_only": view.metadata_only,
            "view_source_matches": view.result_id == result.result_id,
            "report_profile": report.profile,
            "report_sections": [section.section_id for section in report.sections],
        },
        "boundaries": {
            "hardware_execution": False,
            "cloud_execution": False,
            "network_accessed": False,
            "credentials_loaded": False,
        },
    }
    print(json.dumps(payload, sort_keys=True))


if __name__ == "__main__":
    main()

Download the full script

python examples/user/tracks/sdk_platform_engineer/02_foundation_result_diagnostics_en.py
{
  "boundaries": {
    "cloud_execution": false,
    "credentials_loaded": false,
    "hardware_execution": false,
    "network_accessed": false
  },
  "facts": {
    "diagnostic_codes": [
      "DIGITAL_SIMULATION_COMPLETED",
      "DIGITAL_RESULT_ALIGNMENT_VALID"
    ],
    "diagnostic_severities": [
      "info",
      "info"
    ],
    "probabilities": {
      "0": 0.5,
      "1": 0.5
    },
    "report_profile": "digital",
    "report_sections": [
      "experiment.design",
      "experiment.validate",
      "experiment.plan",
      "experiment.execute",
      "experiment.state",
      "experiment.measure",
      "experiment.analyze"
    ],
    "result_id": "result.lesson.platform.result",
    "source_unchanged": true,
    "view_backend_called": false,
    "view_counts_match": true,
    "view_metadata_only": true,
    "view_source_matches": true
  },
  "lesson": "result_diagnostics",
  "level": "foundation",
  "track": "sdk_platform_engineer"
}

Expect source_unchanged, view_counts_match and view_source_matches to be true, and view_backend_called false. An info diagnostic is not a failure. Conversely, absence of an error does not establish that an experimental hypothesis is correct.

Save and inspect the record

result.to_json() returns JSON text without writing a file. Retain the program, bindings, seed, SDK commit, method and sampling budget with the result. For plots, give visualize an HTML output path and keep the original result as well.

For a missing field, first check whether the request and backend provide it. Atom-loss outcomes can include erasures, for which an ordinary binary probability distribution may not apply. For a scan, inspect each point’s status before reading its ResultIR.

See ResultIR for fields, experiment reports for graphical output, and reading your first result for an introduction.

中文版

SDK 1.0.8a · `8b227bff`