Interfaces and parallelism

Applicable version · ArcQML 0.1.0

On this page

Text and SVG circuit diagrams

The top-level Rust draw interface only renders a Circuit as a Unicode string: q0 appears at the top, single-qubit gates as boxes, and controlled gates as control points and connecting lines. Parameterized gates show p<index> or a fixed value.

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

arcqml::visualization::draw_svg(&circuit) returns an SVG string. write_svg(&circuit, path) writes a file and returns Result; callers should handle write errors:

rust
arcqml::visualization::write_svg(&circuit, "circuit.svg")?;

Current Python exports

Python object / function Rust counterpart Notes
Tensor / tensor / no_grad arcqml::core::Tensor and gradient mode numpy() and item() explicitly leave the Tensor representation.
Circuit arcqml::circuit::Circuit Only common gates are bound; parameter names, values, and gradients are returned as a dict.
StateVectorSimulator Single-state simulator from_amplitudes requires a C-contiguous one-dimensional complex128 NumPy array.
BatchStateVectorSimulator Batch simulator from_amplitudes requires a C-contiguous two-dimensional row-major complex128 array.
PauliSum SparsePauliOp observable supplied to run.
mse_loss / BCE logits Subset of Rust loss interfaces Python does not currently export L1, binary_nll, or multiclass CE.
Adam arcqml::optim::Adam Defaults: beta1=0.9, beta2=0.999, epsilon=1e-8, weight_decay=0.

Python simulator.run leaves the current state unchanged; apply_circuit changes it, matching Rust semantics. Python BatchStateVectorSimulator also lacks sample_counts. Python Circuit.gradients() reports an error according to the binding implementation if any parameter has no gradient yet, so call backward before reading gradients during training.

Rayon thread pool

With the default parallel feature enabled, the top-level Rust API provides init_rayon(num_threads) and rayon_num_threads(), and Python exports both as well. Initialize the global Rayon worker pool before the first parallel computation. Batch execution schedules work by sample, so thread count, batch size, state dimension, and memory bandwidth all affect performance. The pool can be initialized only once; configure it before the first simulation.