numpy
¶
Run a program on a NumPy statevector.
NumpyCircuitBackend
¶
Bases: _UnsupportedCircuitMetrics
Evolve one program with a NumPy statevector.
This is the reference for small programs. Correctness and readability come
before performance. z_expectations and x_expectations are exact, so
shots and seed are accepted and ignored there. run_counts samples
the computational-basis distribution, and the same seed repeats those
counts. The backend stores no shots attribute, so Trotterization reads
the exact expectations.
Reset, a measurement followed by a gate, and Prepare after the
register has left |0...0> are rejected. depth, width,
gate_count, t_count, and toffoli_count are not available.
Checked programs agree with Aer statevector probabilities to an absolute
tolerance of 1e-8. One local Hamiltonian makes the Trotter product
exact: that ⟨Z⟩ curve matches cos(2t) to 1e-8 and QuTiP to
1e-6. A seeded Hadamard of 4000 shots stays within 0.05 of Aer and
of 1/2.
Attributes:
-
name–"numpy". Stored on simulation result metadata.
Source code in shadowsim/backends/numpy.py
13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 | |
__init__
¶
run_counts
¶
run_counts(
program: Program, *, shots: int, seed: int | None
) -> dict[str, int]
Sample program in the computational basis.
Parameters:
-
program(Program) –Program to execute.
-
shots(int) –Number of shots.
-
seed(int | None) –Seed for the NumPy generator.
Nonedraws without a fixed seed.
Returns:
-
dict[str, int]–Mapping from bitstring to shot count. The rightmost character is qubit 0.
Raises:
-
ValueError–shotsis not a positive integer, or the statevector probabilities do not sum to 1. -
TypeError–seedis not anintorNone. -
NotImplementedError–programresets a qubit, or measures a qubit and then applies a gate.
Source code in shadowsim/backends/numpy.py
z_expectations
¶
z_expectations(
program: Program,
qubits: Sequence[int],
*,
shots: int,
seed: int | None,
) -> list[float]
Return exact ⟨Z⟩ for each qubit in qubits.
Parameters:
-
program(Program) –Program to execute, before the computational-basis measurement.
-
qubits(Sequence[int]) –0-based indexes in
program. The result follows this order. -
shots(int) –Unused. The value is not estimated from shots.
-
seed(int | None) –Unused.
Returns:
-
list[float]–One expectation per entry of
qubits.
Raises:
-
ValueError–An index is outside
program. -
NotImplementedError–programresets a qubit, measures a qubit and then applies a gate, or prepares a state after leaving|0...0>.
Source code in shadowsim/backends/numpy.py
x_expectations
¶
x_expectations(
program: Program,
qubits: Sequence[int],
*,
shots: int,
seed: int | None,
) -> list[float]
Return exact ⟨X⟩ for each qubit in qubits.
Parameters:
-
program(Program) –Program to execute, before the X-basis measurement.
-
qubits(Sequence[int]) –0-based indexes in
program. The result follows this order. -
shots(int) –Unused. The value is not estimated from shots.
-
seed(int | None) –Unused.
Returns:
-
list[float]–One expectation per entry of
qubits.
Raises:
-
ValueError–An index is outside
program. -
NotImplementedError–programresets a qubit, measures a qubit and then applies a gate, or prepares a state after leaving|0...0>.