pub fn sample(
circuit: &Circuit,
shots: usize,
seed: Option<u64>,
simulator: Simulator,
qubits: Option<&[Qubit]>,
) -> Result<ExecutionResult, QisError>Expand description
Samples a circuit from the all-zero initial state without changing it.
An explicit qubits list selects the final Z-basis outputs in bit order,
with the first qubit displayed at the right of each result string. Otherwise,
terminal measurement declarations select the outputs in first-occurrence
order, with duplicates removed. Without declarations, all circuit qubits
are sampled in circuit order, including idle qubits.
The circuit must have bound parameters and only terminal measurements.
Classical control flow is unsupported. Barrier and Delay are no-ops; Store
does not affect the returned quantum measurement counts. Reset requires
Simulator::DensityMatrix. A seed makes counts reproducible for the same
simulator and library version. shots and the selected output width must
both be positive.
use cqlib_core::circuit::{Circuit, Qubit};
use cqlib_core::qis::{sample, Simulator};
let mut circuit = Circuit::new(2);
circuit.h(Qubit::new(0)).unwrap();
circuit.cx(Qubit::new(0), Qubit::new(1)).unwrap();
let result = sample(&circuit, 1000, Some(42), Simulator::default(), None).unwrap();
assert_eq!(result.counts().values().sum::<usize>(), 1000);