保存并核对实际运行记录¶
运行一条双量子比特 Bell 线路,把提交的程序、本地任务和返回结果对应起来。检查执行方法、seed、位序和轨迹记录,再判断另一位研究者复现实验还需要哪些材料。先完成Bell 课和结果与报告。
两个文件的 counts 相同,仍可能来自不同线路或配置。计数描述采样结果,周围的记录说明结果怎样产生。哈希可以标识记录的内容,但不能代替保存内容本身。
运行并检查¶
"""通过 Result reference 和执行配置检查 Digital 执行记录。
除了 counts,本例还读取 program hash、bit order、模拟方法、seed 语义和诊断信息,
并明确检查独立 Digital 路径当前是否提供完整 RunTrace。
"""
from __future__ import annotations
import json
from cascaqit import Circuit, LocalBackend
def main() -> None:
"""运行一个 Digital Job,并校验跨对象引用。"""
circuit = Circuit(2, program_id="lesson.digital.evidence")
circuit.h(0).cx(0, 1).measure_all(key="readout")
job = LocalBackend(seed=205).run(circuit, shots=32)
result = job.result()
config = result.metadata["simulation_execution_config"]
payload = {
"track": "digital_developer",
"level": "expert",
"lesson": "execution_evidence",
"facts": {
"job_state": job.status().state,
"program_hash_matches": result.program_hash
== circuit.to_ir().stable_hash(),
"trace_available": "run_trace" in result.metadata,
"reference_program_hash_matches": (
result.metadata["references"]["program_hash"] == result.program_hash
),
"method": config["method"],
"seed": config["seed"],
"bit_order": result.metadata["bitstring_ordering"]["qubit_order"],
"diagnostic_codes": result.metadata["diagnostics_summary"]["codes"],
},
"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/digital_developer/05_expert_execution_evidence_zh.py
{
"boundaries": {
"cloud_execution": false,
"credentials_loaded": false,
"hardware_execution": false,
"network_accessed": false
},
"facts": {
"bit_order": [
"q0",
"q1"
],
"diagnostic_codes": [
"DIGITAL_SIMULATION_COMPLETED",
"DIGITAL_RESULT_ALIGNMENT_VALID"
],
"job_state": "completed",
"method": "state_vector",
"program_hash_matches": true,
"reference_program_hash_matches": true,
"seed": 205,
"trace_available": true
},
"lesson": "execution_evidence",
"level": "expert",
"track": "digital_developer"
}
| 检查项 | 在本次运行中说明什么 |
|---|---|
job_state |
本地任务已完成 |
program_hash_matches |
结果标识的数值程序与提交线路一致 |
reference_program_hash_matches |
结果引用记录与程序标识一致 |
method、seed |
记录的配置采用态向量执行,seed 为 205 |
bit_order |
显示位串按 [q0, q1] 顺序读取 |
diagnostic_codes |
本地路径报告执行完成、结果对应关系有效 |
trace_available |
结果是否包含运行轨迹;当前示例返回 true |
在副本中查看 result.metadata["run_trace"] 和 result.state_transitions()。本次独立 Digital 运行记录一个 Digital 状态转换及末端采样,不会逐门保存每一步的状态。逻辑时间戳和 integrator_selected="not_applicable" 不能当成门耗时测量或 Analog 积分记录。与本次运行无关的编译或硬件字段可能缺失或为空。
保存足够的复现材料¶
用 result.to_dict() 保存结构化结果,同时保留脚本、已绑定参数、SDK 源码版本和依赖版本。HTML 报告是结果的一种视图,原始数据也要保存。实验记录模板列出了截图通常无法保留的信息。
分别做以下修改:
- 不改门,把 seed 从 205 改成 206。哪项引用应保持相同,哪些数据可能变化?
- 去掉 CX 后重跑,对比程序引用和概率。
- 保持门不变,只修改测量寄存器名。解释为什么“理想状态相同”与“完整程序记录相同”是不同的判断。
核对思路
修改 seed 改变采样配置,不改变提交的门程序或理想概率。计数可能变化,也可能偶然相同。去掉 CX 会改变线路和理想分布。测量寄存器名称属于完整程序描述,修改它可能改变程序标识,却不改变准备的量子态。仅有程序标识一致,还不能确认 seed、依赖版本或数值选项保持相同。
完成诊断不能证明实验回答了原本的科学问题。像 Rabi 项目那样,把运行记录与物理预测或独立参考结合起来。要混合量子门和脉冲演化,可以继续学习 D-A-D 实验。