pennylane

Dependencies

Install with pip install qc-executor[pennylane]. Requires:

  • pennylane>=0.34.0

Executor

class qc_executor.pennylane.PennyLaneExecutor(backend='default.qubit', *args, shots=None, seed=None, log_file=None, log_level='WARNING', caching=None, cache_dir='cache', max_cache_size=None, **kwargs)[source]

Bases: ExecutorBase

Quantum circuit executor backed by PennyLane.

The backend parameter accepts either a string (device name) or a ready-made Device instance.

Parameters:
  • backend (str or qml.devices.Device) – PennyLane device name or an already-instantiated device. Defaults to "default.qubit".

  • *args – Positional arguments forwarded to pennylane.device() (only when backend is a str). The most common positional argument is wires.

  • shots (int, optional) – Number of shots for sampling. Defaults to None.

  • seed (int, optional) – Random seed for reproducibility. Defaults to None.

  • log_file (str, optional) – Path to the log file. Defaults to None.

  • log_level (str) – Logging level ("DEBUG" / "INFO" / "WARNING" / "ERROR"). Defaults to "WARNING".

  • caching (bool, optional) – Whether to use caching. Defaults to None.

  • cache_dir (str) – Directory for caching. Defaults to "cache".

  • max_cache_size (int, optional) – Maximum cache entries. Defaults to None.

  • **kwargs – Keyword arguments forwarded to pennylane.device() (only when backend is a str). Typical keys are config and custom_decomps.

Note

If shots is set and a PennyLane config object containing a shots value is passed via **kwargs, the config value takes precedence and a UserWarning is emitted.

Devices are created once during initialization and are never recreated dynamically. The configured device must therefore provide enough wires for every executed circuit.

property shots: int | None

Return the number of shots.

property remote: bool

Return True if the execution access a remote backend.

property device_name: str

Return the name of the PennyLane device.

classmethod get_accepted_backend_types()[source]

Return all types accepted as the backend argument.

Covers: * PennyLane device instances (pennylane.devices.Device)

Returns:

List of accepted backend types.

Return type:

List[type]

classmethod get_accepted_backend_aliases()[source]

Return all currently available PennyLane device strings.

The list is discovered from PennyLane’s plugin registry so external PennyLane device plugins become available automatically.

Return type:

List[str]

Native abstraction

Circuit

class qc_executor.pennylane.PennyLaneCircuit(circuit)[source]

Bases: object

PennyLane circuit representation converted from a generic QuantumCircuit.

Parameters:

circuit (QuantumCircuit)

classmethod from_quantum_circuit(circuit)[source]

Create a PennyLane native circuit from a generic circuit.

Return type:

PennyLaneCircuit

Parameters:

circuit (QuantumCircuit)

property num_qubits: int

Number of qubits in the circuit

property pennylane_circuit: Callable | None

PennyLane circuit that can be called with parameters

property parameter_names: list

List of circuit parameter names

property parameter_dimensions: dict

Dictionary with the dimension of each circuit parameter

property hash: int

Hashable object of the circuit and observable for caching

build_pennylane_circuit()[source]

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

Operator

class qc_executor.pennylane.PennyLaneOperator(operator)[source]

Bases: object

Convert generic quantum operators to PennyLane-native operators.

Parameters:

operator (QuantumOperatorBase | list[QuantumOperatorBase]) – Operator definition(s) to convert.

classmethod from_quantum_operator(operator)[source]

Create a PennyLane native operator from a generic operator.

Return type:

PennyLaneOperator

Parameters:

operator (QuantumOperatorBase)

property parameter_names: list

List of operator parameter names

property parameter_dimensions: dict

Dictionary with the dimension of each operator parameter

property hash: int

Hashable object of the circuit and operator for caching

build_operator_instructions(operator)[source]

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

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

Parameters:

operator (List[SparsePauliOp] | SparsePauliOp) – Qiskit operator to convert to PennyLane

Returns:

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

build_pennylane_observable()[source]

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