backends
¶
Circuit execution backends for shot-based simulators.
AerCircuitBackend
¶
Run a program on Qiskit Aer and return shot counts.
The program is translated to a Qiskit circuit and transpiled for
AerSimulator. A set seed is passed as seed_simulator.
basis_gates is passed the same way when it is set. z_expectations
and x_expectations estimate Pauli expectations from those counts.
depth, width, gate_count, t_count, and toffoli_count
read that transpiled circuit. A unitary stays one instruction, so t
and ccx counts stay zero unless transpilation emits those names.
Attributes:
-
name–"aer". Stored on simulation result metadata. -
shots–Shot budget passed to each
run_countscall by a simulator. -
basis_gates–Gate names passed to
AerSimulator, orNonefor Aer's own basis. -
BASIS_GATE_NAMES–Gate names
basis_gatesmay contain.
Source code in shadowsim/backends/aer.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 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 | |
__init__
¶
Store the shot budget and optional compilation basis.
Parameters:
-
shots(int, default:10000) –Number of shots for each circuit. Must be a positive integer.
-
basis_gates(Sequence[str] | None, default:None) –Gate names
transpilemay use.Nonekeeps Aer's own basis. Names are stripped, lowercased, and de-duplicated. Each name must be inBASIS_GATE_NAMES.
Raises:
-
ValueError–shotsis not a positive integer,basis_gatesis not a sequence of gate names, the sequence is empty, or a name is not a gate Aer can compile into.
Source code in shadowsim/backends/aer.py
run_counts
¶
run_counts(
program: Program, *, shots: int, seed: int | None
) -> dict[str, int]
Translate program to Qiskit, transpile that for Aer, and return counts.
Parameters:
-
program(Program) –Program to execute.
-
shots(int) –Number of shots.
-
seed(int | None) –Passed as
seed_simulatorwhen set. Omitted whenNone.
Returns:
-
dict[str, int]–Mapping from bitstring to shot count.
Raises:
-
ValueError–programcannot be compiled intobasis_gates.
Source code in shadowsim/backends/aer.py
z_expectations
¶
z_expectations(
program: Program,
qubits: Sequence[int],
*,
shots: int,
seed: int | None,
) -> list[float]
Estimate ⟨Z⟩ on qubits from computational-basis shots.
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) –Number of shots.
-
seed(int | None) –Passed as
seed_simulatorwhen set. Omitted whenNone.
Returns:
-
list[float]–One estimate per entry of
qubits, each(n0 - n1) / shots.
Raises:
-
ValueError–An index is outside
program, orprogramcannot be compiled intobasis_gates.
Source code in shadowsim/backends/aer.py
x_expectations
¶
x_expectations(
program: Program,
qubits: Sequence[int],
*,
shots: int,
seed: int | None,
) -> list[float]
Estimate ⟨X⟩ on qubits by applying Hadamard and then measuring.
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) –Number of shots.
-
seed(int | None) –Passed as
seed_simulatorwhen set. Omitted whenNone.
Returns:
-
list[float]–One estimate per entry of
qubits, each(n0 - n1) / shots.
Raises:
-
ValueError–An index is outside
program, orprogramcannot be compiled intobasis_gates.
Source code in shadowsim/backends/aer.py
depth
¶
depth(program: Program) -> int
Return the depth of program after transpilation for Aer.
Parameters:
-
program(Program) –Program to measure. It is translated and transpiled for this basis.
Returns:
-
int–Length of the critical path on the transpiled circuit.
Raises:
-
ValueError–programcannot be compiled intobasis_gates.
Source code in shadowsim/backends/aer.py
width
¶
width(program: Program) -> int
Return the qubit count of program after transpilation for Aer.
Parameters:
-
program(Program) –Program to measure. It is translated and transpiled for this basis.
Returns:
-
int–Number of qubits on the transpiled circuit. Classical bits are not included.
Raises:
-
ValueError–programcannot be compiled intobasis_gates.
Source code in shadowsim/backends/aer.py
gate_count
¶
gate_count(program: Program) -> int
Return the instruction count of program after transpilation for Aer.
Parameters:
-
program(Program) –Program to measure. It is translated and transpiled for this basis.
Returns:
-
int–Total number of instructions on the transpiled circuit, including
-
int–measurements when
programcontains them.
Raises:
-
ValueError–programcannot be compiled intobasis_gates.
Source code in shadowsim/backends/aer.py
t_count
¶
t_count(program: Program) -> int
Return the number of t gates after transpilation for Aer.
tdg is not included. A multi-qubit unitary stays one instruction, so
a program built only from unitaries reports zero.
Parameters:
-
program(Program) –Program to measure. It is translated and transpiled for this basis.
Returns:
-
int–Count of instructions named
t.
Raises:
-
ValueError–programcannot be compiled intobasis_gates.
Source code in shadowsim/backends/aer.py
toffoli_count
¶
toffoli_count(program: Program) -> int
Return the number of ccx and ccz gates after transpilation for Aer.
A multi-qubit unitary stays one instruction, so a program built only from unitaries reports zero.
Parameters:
-
program(Program) –Program to measure. It is translated and transpiled for this basis.
Returns:
-
int–Sum of
ccxandcczinstructions.
Raises:
-
ValueError–programcannot be compiled intobasis_gates.
Source code in shadowsim/backends/aer.py
CircuitBackend
¶
Bases: Protocol
Execute one program and return shot counts or Pauli expectations.
Attributes:
-
name(str) –Identifier stored on simulation result metadata.
Source code in shadowsim/backends/circuit.py
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 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 | |
run_counts
¶
run_counts(
program: Program, *, shots: int, seed: int | None
) -> dict[str, int]
Run program for shots and return bitstring counts.
Parameters:
-
program(Program) –Program to execute. Implementations compile it for their target.
-
shots(int) –Number of shots.
-
seed(int | None) –Optional seed. Implementations use it only when the target accepts one.
Returns:
-
dict[str, int]–Mapping from bitstring to shot count.
Source code in shadowsim/backends/circuit.py
z_expectations
¶
z_expectations(
program: Program,
qubits: Sequence[int],
*,
shots: int,
seed: int | None,
) -> list[float]
Return ⟨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) –Number of shots used when the backend estimates from counts.
-
seed(int | None) –Optional seed. Implementations use it only when the target accepts one.
Returns:
-
list[float]–One expectation per entry of
qubits.
Raises:
-
ValueError–An index is outside
program.
Source code in shadowsim/backends/circuit.py
x_expectations
¶
x_expectations(
program: Program,
qubits: Sequence[int],
*,
shots: int,
seed: int | None,
) -> list[float]
Return ⟨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) –Number of shots used when the backend estimates from counts.
-
seed(int | None) –Optional seed. Implementations use it only when the target accepts one.
Returns:
-
list[float]–One expectation per entry of
qubits.
Raises:
-
ValueError–An index is outside
program.
Source code in shadowsim/backends/circuit.py
depth
¶
depth(program: Program) -> int
Return the depth of program after compilation for this backend.
Parameters:
-
program(Program) –Program to measure. Implementations compile it for their target.
Returns:
-
int–Length of the critical path on the compiled circuit.
Raises:
-
NotImplementedError–This backend does not expose gate counts.
Source code in shadowsim/backends/circuit.py
width
¶
width(program: Program) -> int
Return the number of qubits on program after compilation.
Parameters:
-
program(Program) –Program to measure. Implementations compile it for their target.
Returns:
-
int–Qubit count of the compiled circuit. Classical bits are not included.
Raises:
-
NotImplementedError–This backend does not expose gate counts.
Source code in shadowsim/backends/circuit.py
gate_count
¶
gate_count(program: Program) -> int
Return the instruction count of program after compilation.
Parameters:
-
program(Program) –Program to measure. Implementations compile it for their target.
Returns:
-
int–Total number of instructions on the compiled circuit, including
-
int–measurements when
programcontains them.
Raises:
-
NotImplementedError–This backend does not expose gate counts.
Source code in shadowsim/backends/circuit.py
t_count
¶
t_count(program: Program) -> int
Return the number of t gates on program after compilation.
tdg is not included.
Parameters:
-
program(Program) –Program to measure. Implementations compile it for their target.
Returns:
-
int–Count of instructions named
t.
Raises:
-
NotImplementedError–This backend does not expose gate counts.
Source code in shadowsim/backends/circuit.py
toffoli_count
¶
toffoli_count(program: Program) -> int
Return the number of Toffoli gates on program after compilation.
A Toffoli is ccx or ccz.
Parameters:
-
program(Program) –Program to measure. Implementations compile it for their target.
Returns:
-
int–Sum of
ccxandcczinstructions.
Raises:
-
NotImplementedError–This backend does not expose gate counts.
Source code in shadowsim/backends/circuit.py
CirqCircuitBackend
¶
Bases: _UnsupportedCircuitMetrics
Evolve one program with the Cirq 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–"cirq". Stored on simulation result metadata.
Source code in shadowsim/backends/cirq.py
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 | |
__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 Cirq 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
cirqextra is not installed.
Source code in shadowsim/backends/cirq.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
cirqextra is not installed.
Source code in shadowsim/backends/cirq.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
cirqextra is not installed.
Source code in shadowsim/backends/cirq.py
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>.
Source code in shadowsim/backends/numpy.py
PauliPropagationBackend
¶
Bases: _UnsupportedCircuitMetrics
Propagate one Pauli observable per requested qubit [@rudolph2025pauli].
The program is translated to Qiskit and written as OpenQASM 2 for
PauliPropagation.OpenQASMInterface.readqasm. z_expectations and
x_expectations return the expectation of Z or X on |0...0> after
that circuit. Shot counts are not available.
Attributes:
-
name–"pauli_propagation". Stored on simulation result metadata. -
max_weight–Largest Pauli weight kept during propagation.
infkeeps every weight. -
min_abs_coeff–Smallest coefficient magnitude kept during propagation.
Source code in shadowsim/backends/pauli_propagation.py
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 140 141 142 143 144 145 146 147 148 149 150 151 152 | |
__init__
¶
Record the PauliPropagation backend name and truncation settings.
Parameters:
-
max_weight(float, default:_MAX_WEIGHT) –Largest Pauli weight kept during propagation.
infkeeps every weight. -
min_abs_coeff(float, default:_MIN_ABS_COEFF) –Smallest coefficient magnitude kept during propagation.
Raises:
-
TypeError–A setting is not a real number.
-
ValueError–A setting is negative, or
min_abs_coeffis not finite.
Source code in shadowsim/backends/pauli_propagation.py
run_counts
¶
run_counts(
program: Program, *, shots: int, seed: int | None
) -> dict[str, int]
Reject a request for shot counts.
Parameters:
-
program(Program) –Unused. PauliPropagation does not sample a program.
-
shots(int) –Unused.
-
seed(int | None) –Unused.
Raises:
-
NotImplementedError–PauliPropagation does not support shot counts.
Source code in shadowsim/backends/pauli_propagation.py
z_expectations
¶
z_expectations(
program: Program,
qubits: Sequence[int],
*,
shots: int,
seed: int | None,
) -> list[float]
Return ⟨Z⟩ for each qubit in qubits.
Truncation uses max_weight and min_abs_coeff stored on this backend.
Parameters:
-
program(Program) –Program to propagate, without measurements or resets.
-
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, the Julia package is missing, or the program cannot be read. -
ImportError–The
pauli_propagationextra is not installed.
Source code in shadowsim/backends/pauli_propagation.py
x_expectations
¶
x_expectations(
program: Program,
qubits: Sequence[int],
*,
shots: int,
seed: int | None,
) -> list[float]
Return ⟨X⟩ for each qubit in qubits.
Truncation uses max_weight and min_abs_coeff stored on this backend.
Parameters:
-
program(Program) –Program to propagate, without measurements or resets.
-
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, the Julia package is missing, or the program cannot be read. -
ImportError–The
pauli_propagationextra is not installed.
Source code in shadowsim/backends/pauli_propagation.py
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.
Source code in shadowsim/backends/qulacs.py
ListedBackend
¶
Bases: TypedDict
Display record for one concrete circuit backend.
Source code in shadowsim/backends/catalog.py
from_qiskit
¶
from_qiskit(circuit: QuantumCircuit) -> Program
Record the instructions of circuit as a :class:Program.
Qubit indexes are positions in circuit.qubits. Initialize, Hadamard,
reset, barrier, and measure are recorded as those operations. Any other
instruction that provides a matrix, including rx and a custom unitary,
is recorded as that matrix on the instruction's qubits.
Parameters:
-
circuit(QuantumCircuit) –Circuit to record.
Returns:
-
Program–The operations on
circuit, in order.
Raises:
-
ImportError–Qiskit is not installed.
-
ValueError–An instruction has no matrix and is not initialize, reset, barrier, or measure.
Source code in shadowsim/backends/circuit.py
to_qiskit
¶
to_qiskit(program: Program) -> QuantumCircuit
Build a Qiskit circuit from program.
The circuit has one quantum register and, when program has classical
bits, one classical register. A measurement writes the same qubit onto the
same classical bit recorded in program.
Parameters:
-
program(Program) –Operations to append.
Returns:
-
QuantumCircuit–A circuit with those operations.
Raises:
-
ImportError–Qiskit is not installed.
Source code in shadowsim/backends/circuit.py
listed_backends
¶
listed_backends() -> list[ListedBackend]
Return the concrete circuit backends in export order.
Each exported backend module is imported on its own. A missing extra skips
that module. CircuitBackend is a protocol, so it is omitted. Each
record uses the class name and the first line of its docstring. Required
constructor arguments appear in setup. A shots parameter is written
as {shots} so the page can fill the shot budget. basis_gates, when
its default is None, is a gate list written as {basis_gates}. Its
choices are the class attribute BASIS_GATE_NAMES. Any other parameter
with a default is a numeric field the page can edit, written as {name}.
Returns:
-
list[ListedBackend]–Backends the builder page can offer.
Raises:
-
ImportError–No circuit backend module could be imported. The first failure is re-raised.
Source code in shadowsim/backends/catalog.py
__getattr__
¶
Import a circuit backend the first time it is accessed.