Trace a result through a view and a report¶
Inspect the result of a Hadamard circuit, then derive a result view and a standard Digital report from the same record. Complete Backend and Job and reading results. Use the installed environment.
Before running, predict equal probabilities for 0 and 1. The script requests 16 shots and also asks for state probabilities, so you can distinguish a state property from its finite sample.
Keep the original result with its diagnostics¶
"""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()
python3 examples/user/tracks/sdk_platform_engineer/02_foundation_result_diagnostics_en.py
ResultIR contains the execution result. build_result_view(result) copies its public facts into a view. visualize(result, profile='digital') organizes saved facts into report sections. Neither operation calls the Backend to generate a replacement result.
{
"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"
}
Check view_source_matches, view_counts_match and source_unchanged. The first two compare the source identity and counts; the third compares the result hash before and after building the view and report. The reported probabilities should remain one half each.
metadata_only describes how the view is produced: it reads public result data without interpreting external artifact bytes or executing a program. It does not mean that the view has no counts or probabilities. view_backend_called should be false.
Diagnostics are not all failures. Read severity together with code, stage, object path and any suggestion. This successful Digital run includes informational completion and result-alignment codes. An integration that treats every nonempty diagnostic list as an error would reject valid runs. Conversely, an attractive report does not erase a warning or a mismatched physical prediction.
Follow a discrepancy back to its source¶
- Print
result.countsandview.counts. Is an uneven split a view error? - Set
return_probabilities=False. Which data remain usable, and what should your application display for probabilities? - Save the report with
visualize(result, output='artifacts/result-check.html', profile='digital', language='en'). Reopen it without rerunning the circuit and compare its measurements with the saved counts.
The counts should match exactly between source and view, even when they differ from 8/8. Omitting probabilities still leaves counts and diagnostics; missing probabilities should be presented as unavailable, not replaced with zeros. A saved HTML report is a presentation of that run and is useful for review, but keep the structured result and source when you need reproducibility.
A source ID locates a record; a source hash helps detect a changed record. Neither alone establishes that the circuit, units or decoding are scientifically correct. See result diagnostics and visualization for the interfaces, then inspect scan outcomes where one aggregate contains several results.