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:
ExecutorBaseQuantum circuit executor backed by PennyLane.
The backend parameter accepts either a string (device name) or a ready-made
Deviceinstance.- 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 astr). 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 astr). Typical keys areconfigandcustom_decomps.
Note
If shots is set and a PennyLane
configobject containing ashotsvalue is passed via**kwargs, theconfigvalue takes precedence and aUserWarningis 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.
Native abstraction¶
Circuit¶
- class qc_executor.pennylane.PennyLaneCircuit(circuit)[source]¶
Bases:
objectPennyLane 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:
- 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:
objectConvert 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:
- 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