paulicirc.layers

Layers of Pauli gadgets.

Layer

final class Layer(num_qubits)[source]

Bases: object

A layer of Pauli gadgets with compatible legs.

static __new__(cls, num_qubits)[source]

Create an empty Pauli layer with the given number of qubits.

Parameters:

num_qubits (int)

Return type:

Self

add_gadget(gadget_or_legs, phase=None)[source]

Add a gadget to the layer.

Parameters:
Return type:

bool

commutes_with(legs, /)[source]

Check if the legs commute with the current layer.

Parameters:

legs (PauliArray | Gadget)

Return type:

bool

classmethod from_gadgets(gadgets, num_qubits=None)[source]

Constructs a layer from the given gadgets.

Parameters:
Return type:

Self

is_compatible_with(legs, /)[source]

Check if the legs are compatible with the current layer.

Parameters:

legs (PauliArray | Gadget)

Return type:

bool

property leg_paulistr

Paulistring representation of the layer’s legs.

Return type:

str

property legs

Legs of the Pauli layer.

Return type:

PauliArray

property num_qubits

Number of qubits for the Pauli layer.

Return type:

int

phase(legs)[source]

Get the phase of the given legs in the layer, or None if the legs are incompatible with the layer.

Parameters:

legs (PauliArray)

Return type:

Phase

static select_leg_subset(qubits, legs)[source]

Selects legs based on the given subset of qubits.

Parameters:
Return type:

PauliArray

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:
Return type:

Complex128Array1D

unitary(*, canonical_phase=True, _use_cupy=False)[source]

Returns the unitary matrix associated to this Pauli gadget circuit.

Parameters:
  • canonical_phase (bool; default = True)

  • _use_cupy (bool; default = False)

Return type:

Complex128Array2D

LayeredCircuit

final class LayeredCircuit(num_qubits)[source]

Bases: object

A quantum circuit, represented as a sequential composition of Pauli layers.

append(gadget)[source]

Appends a gadget to the layered circuit.

Parameters:

gadget (Gadget)

Return type:

None

circuit()[source]

Returns a circuit constructed from the current gadget layers, where the gadgets for each layer are listed in canonical order.

Return type:

Circuit

extend(gadgets)[source]

Appends a sequence of gadgets to the layered circuit.

Parameters:

gadgets (Iterable[Gadget])

Return type:

None

property layers

Layers of the circuit.

Return type:

Sequence[Layer]

property num_layers

Number of layers in the circuit.

Return type:

int

property num_qubits

Number of qubits in the circuit.

Return type:

int

random_circuit(*, rng)[source]

Returns a circuit constructed from the current gadget layers, where the gadgets for each layer are listed in random order.

Parameters:

rng (int | RNG | None)

Return type:

Circuit

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:
Return type:

Complex128Array1D

unitary(*, canonical_phase=True, _use_cupy=False)[source]

Returns the unitary matrix associated to this Pauli gadget circuit.

Parameters:
  • canonical_phase (bool; default = True)

  • _use_cupy (bool; default = False)

Return type:

Complex128Array2D