squlearn.util.pennylane.PennyLaneCircuit

class squlearn.util.pennylane.PennyLaneCircuit(circuit: QuantumCircuit, observable: None | SparsePauliOp | List[SparsePauliOp] | str | Observable | List[Observable] = None, executor: Executor = None)

Class for converting a Qiskit circuit to a PennyLane circuit.

Parameters:
  • circuit (QuantumCircuit) – Qiskit circuit to convert to PennyLane

  • observable (Union[None, SparsePauliOp, List[SparsePauliOp], str]) – Observable to be measured Can be also a string like "probs" or "state"

  • executor (Executor) – Executor object to handle the PennyLane circuit. Has to be initialized with a PennyLane device.

Attributes:

pennylane_circuit

PennyLane circuit that can be called with parameters

Type:

qml.qnode

circuit_parameter_names

List of circuit parameter names

Type:

list

observable_parameter_names

List of observable parameter names

Type:

list

circuit_parameter_dimensions

Dictionary with the dimension of each circuit parameter

Type:

dict

observable_parameter_dimension

Dictionary with the dimension of each observable parameter

Type:

dict

circuit_arguments

List of all circuit and observable parameters names

Type:

list

hash

Hashable object of the circuit and observable for caching

Type:

str

Methods:

build_circuit_instructions(circuit: QuantumCircuit) tuple

Function to build the instructions for the PennyLane circuit from the Qiskit circuit.

This functions converts the Qiskit gates and parameter expressions to PennyLane compatible gates and functions.

Parameters:

circuit (QuantumCircuit) – Qiskit circuit to convert to PennyLane

Returns:

Tuple with lists of PennyLane gates, PennyLane gate parameter functions, PennyLane gate wires, PennyLane gate parameters and PennyLane gate parameter dimensions

build_observable_instructions(observable: List[SparsePauliOp] | SparsePauliOp)

Function to build the instructions for the PennyLane observable from the Qiskit observable.

This functions converts the Qiskit SparsePauli and parameter expressions to PennyLane compatible Pauli words and functions.

Parameters:

observable (Union[List[SparsePauliOp], SparsePauliOp]) – Qiskit observable to convert to PennyLane

Returns:

Tuple with lists of PennyLane observable parameter functions, PennyLane Pauli words, PennyLane observable parameters and PennyLane observable parameter dimensions

build_pennylane_circuit(max_diff: int | None = None)

Function to build the PennyLane circuit from the Qiskit circuit and observable.

The functions returns a callable PennyLane circuit that can be called with parameters. The PennyLane circuit is built from the instructions previously generated from the Qiskit circuit and observable.

Returns:

Callable PennyLane circuit

draw(engine: str = 'pennylane', **kwargs)

Draw the circuit with the specified engine

Parameters:
  • engine (str) – Engine to draw the circuit. Can be either "pennylane" or "qiskit"

  • **kwargs – Additional arguments for the drawing engine (only for qiskit)

Returns:

matplotlib Figure object of the circuit visualization

get_pennylane_circuit() callable

Builds and returns the PennyLane circuit as callable function