paulicirc.circuits
Circuits of Pauli gadgets.
Circuit
- final class Circuit(data, num_qubits=None)[source]
Bases:
objectA quantum circuit, represented as a sequential composition of Pauli gadgets.
- __bytes__()[source]
Serializes a circuit to bytes:
1B fixed to 0x01, to indicate a
Circuitencoding1B encoding the circuit phase dtype (currently, fixed to 0x04 for float64)
8B encoding the number of gadgets, encoded as unsigned big endian
8B encoding the number of qubits, encoded as unsigned big endian
the bytes of the underlying data array, using
numpy.ndarray.tobytes
- Return type:
- __getitem__(idx)[source]
Accesses the gadget at a given index, or selects/slices a sub-circuit.
- Parameters:
idx (
SupportsIndex|slice|list[SupportsIndex])- Return type:
- static __new__(cls, data, num_qubits=None)[source]
Constructs a gadget circuit from the given data.
- Parameters:
data (
CircuitData)
- Return type:
- __setitem__(idx, value)[source]
Writes a gadget at the given index of this circuit, or writes a sub-circuit onto the given selection/slice of this circuit.
- Parameters:
idx (
SupportsIndex|slice|list[SupportsIndex])
- Return type:
- commute(codes)[source]
Commutes adjacent gadget pairs in the circuit according to the given commutation codes.
See
Gadget.commute_pastfor a description of the commutation procedure and associated commutation code conventions.- Parameters:
codes (
Sequence[int] |CommutationCodeArray)- Return type:
- static from_bytes(bs)[source]
Deserializes a circuit from bytes. See
Circuit.__bytes__for discussion of the encoding.
- classmethod from_gadgets(gadgets, num_qubits=None)[source]
Constructs a circuit from the given gadgets.
- inverse()[source]
Returns the inverse of this graph, with both phases and gadget order inverted.
- Return type:
- property is_zero
Whether the circuit is all zero (legs set to
_, phases set to 0).- Return type:
- iter_gadgets(*, start=0, stop=None, fast=False)[source]
Iterates over the gadgets in the circuit.
If
fastis set toTrue, the gadgets yielded are ephemeral: they should not be stored, as the same object will be reused in each iteration.
- property legs
The 2D array of gadget legs for this circuit.
- Return type:
- property listing
Returns a listing of the circuit.
- Return type:
- property phases
Array of phases for the gadgets in the circuit.
- Return type:
- classmethod random(num_gadgets, num_qubits, *, rng=None)[source]
Constructs a circuit with the given number of gadgets and qubits, where all gadgets have random legs and random phase.
- statevec(input, canonical_phase=True, _use_cupy=False)[source]
Computes the statevector resulting from the application of this gadget circuit to the given input statevector.
- Parameters:
input (
ComplexArray1D|FloatArray1D)canonical_phase (
bool; default =True)_use_cupy (
bool; default =False)
- Return type:
CircuitData
CircuitListing
CommutationCodeArray
- CommutationCodeArray
A 1D array of commutation codes, used by
Circuit.commute.See
Gadget.commute_pastfor a description of the commutation procedure and associated commutation code conventions.
commute_circuit
- commute_circuit(circ, codes)[source]
Low-level function. Commutes subsequent gadget pairs in the circuit according to the given codes. Expects the number of codes to be
m//2, wheremis the number of gadgets.See
Gadget.commute_pastfor a description of the commutation procedure and associated commutation code conventions.- Parameters:
circ (
CircuitData)codes (
CommutationCodeArray)
- Return type:
get_circuit_legs
- get_circuit_legs = CPUDispatcher(<function get_circuit_legs>)[source]
Low-level function. Extract a 2D array of leg information from given circuit data. The returned array has values in
range(4), where the encoding is explained inGadgetData.
rand_circ
set_circuit_legs
- set_circuit_legs(circ, legs)[source]
Low-level function. Sets leg information in the given circuit data. The input array should have values in
range(4), where the encoding is explained inGadgetData.- Parameters:
circ (
CircuitData)legs (
PauliArray2D)
- Return type:
statevec_from_gadgets
- statevec_from_gadgets(self, input, canonical_phase=True, _use_cupy=False)[source]
Low-level function. Computes the statevector resulting from the application of the given gadgets to the given input statevector.
- Parameters:
input (
ComplexArray1D|FloatArray1D)canonical_phase (
bool; default =True)_use_cupy (
bool; default =False)
- Return type: