可视化、接口与并行

适用版本 · ArcQML 0.1.0

本页目录

12.1 Unicode 文本电路图

Rust 顶层接口中的 draw 只把 Circuit 渲染为 Unicode 字符串:q0 位于最上方,单量子比特门显示为边框,受控门显示为控制点和连接线,参数化门以 p<index> 或固定数值显示。

rust
let mut circuit = Circuit::new(3)?;
circuit.h(0usize)?.cnot(0usize, 1usize)?.rz(0.3, 2usize)?;
println!("depth = {}", circuit.depth());
println!("{}", draw(&circuit));

12.2 Python API 的稳定可用面

Python 对象/函数 对应 Rust 概念 注意事项
Tensor / tensor / no_grad arcqml::Tensor 与梯度模式 numpy()item() 是显式离开 Tensor 表示的边界。
Circuit arcqml::Circuit 只绑定常用门集;参数名值与梯度以 dict 返回。
StateVectorSimulator 单态 simulator from_amplitudes 要 C 连续 complex128 一维 NumPy 数组。
BatchStateVectorSimulator batch simulator from_amplitudes 要 C 连续 complex128 二维行主序数组。
PauliSum SparsePauliOp 用于 run 的 observable。
mse_loss / BCE logits Rust 损失函数接口的子集 Python 当前未导出 L1、binary_nll 和多分类 CE。
Adam arcqml::Adam 默认 beta1=0.9、beta2=0.999、epsilon=1e-8、weight_decay=0。

Python 的 simulator.run 不修改当前态,apply_circuit 会修改当前态;这与 Rust 语义一致。Python BatchStateVectorSimulator 同样暂未支持 sample_counts。Python Circuit.gradients() 在任一参数尚未产生梯度时会按绑定层实现报告错误,故训练中应先 backward 再读取。

12.3 Rayon 线程池

Rust 顶层接口提供 init_rayon(num_threads)rayon_num_threads(),Python 同样导出这两个函数。初始化全局 Rayon 工作线程池必须发生在首次并行计算之前;批量路径在样本层进行任务调度,因此线程数、batch 大小、状态维度和内存带宽都会影响实际性能。线程池只能初始化一次,应用应在首次模拟之前完成配置。