qulacs
¶
Run a program on the Qulacs statevector simulator.
Qubit 0 is the least significant bit of a gate matrix and of each sample.
Hadamard uses the Qulacs kernel. Every Unitary is a dense matrix.
QulacsCircuitBackend
¶
Bases: _UnsupportedCircuitMetrics
Evolve one program with the Qulacs statevector simulator.
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 state preparation after
the register has left |0...0> are rejected. depth, width,
gate_count, t_count, and toffoli_count are not available.
Statevectors agree with the NumPy backend to an absolute tolerance of
1e-8. One local Hamiltonian makes the Trotter product exact: that
⟨Z⟩ curve matches cos(2t) to 1e-8. A seeded Hadamard of 4000
shots stays within 0.05 of the NumPy frequencies.
Attributes:
-
name–"qulacs". Stored on simulation result metadata.
Source code in shadowsim/backends/qulacs.py
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 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 | |
__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 Qulacs sampling.
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, measures a qubit and then applies a gate, or prepares a state after leaving|0...0>. -
ImportError–The
qulacsextra is not installed.
Source code in shadowsim/backends/qulacs.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>. -
ImportError–The
qulacsextra is not installed.
Source code in shadowsim/backends/qulacs.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>. -
ImportError–The
qulacsextra is not installed.