circuit
¶
Circuit backend protocol and Qiskit program translation.
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
backend_samples
¶
Return whether backend stores a shot budget.
Parameters:
-
backend(object) –Circuit backend. Sampling backends store
shots.
Returns:
-
bool–True when
backendhas ashotsattribute.
Source code in shadowsim/backends/circuit.py
backend_shots
¶
Return the positive shot count stored on backend.
Parameters:
-
backend(object) –Sampling backend. It must store
shotsas a positive integer.
Returns:
-
int–That shot count.
Raises:
-
ValueError–shotsis missing or not a positive integer.
Source code in shadowsim/backends/circuit.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.