Expand description
Self-contained dense state-vector simulator for QML circuits.
The quantum-ML algorithms in this crate (VQE, QAOA, QNNs, gradient
estimators, trainers) operate on ParameterizedQuantumCircuit values
and need real measurement statistics / expectation values to drive their
optimisation loops. Historically the execute_circuit_helper methods in
those modules returned a hard-coded 50/50 split of |0…0⟩ and |1…1⟩
counts, which silently fed fabricated data into every gradient and training
computation.
This module provides a small, exact, in-crate state-vector engine so those
helpers can produce genuine results. It is intentionally self-contained:
quantrs2-device must not depend on quantrs2-sim (that crate is a
sibling consumer, and adding it here would create a cross-dependency), so we
implement the few gates that QuantumGate can express directly.
For paths that genuinely require execution on remote hardware (with
credentials / network access), callers should return an honest
DeviceError instead of using this local simulator.
Functions§
- expected_
hamming_ weight - Compute the exact expectation value of the total-spin (number-of-ones)
observable
Σ_q (1 - Z_q)/2 = Σ_q n_q, i.e. the expected Hamming weight of a measurement outcome, directly from the state vector. - outcome_
probabilities - Compute the exact probability of each computational-basis outcome.
- simulate_
and_ sample - Simulate
circuitand sampleshotsmeasurement outcomes from the exact output distribution, returning aCircuitResultwith real counts. - simulate_
statevector - Simulate a
ParameterizedQuantumCircuitfrom the all-zero state and return the resulting amplitude vector of length2^num_qubits.