PennyLane-Qiskit Plugin¶
- Release:
0.39.0-dev
The PennyLane-Qiskit plugin integrates the Qiskit quantum computing framework with PennyLane’s quantum machine learning capabilities.
PennyLane is a cross-platform Python library for quantum machine learning, automatic differentiation, and optimization of hybrid quantum-classical computations.
Qiskit is an open-source framework for quantum computing.
Once the PennyLane-Qiskit plugin is installed, the Qiskit devices can be accessed straightaway in PennyLane, without the need to import new packages.
Devices¶
The following devices are available:
For example, the 'qiskit.aer'
device with two wires is called like this:
import pennylane as qml
dev = qml.device('qiskit.aer', wires=2)
Backends¶
Qiskit devices have different backends, which define the actual simulator or hardware used by the device. A backend instance should be initalized and passed to the device.
Different simulator backends are optimized for different purposes. To change what backend is used, a simulator backend can be defined as follows:
from qiskit_aer import UnitarySimulator
dev = qml.device('qiskit.aer', wires=<num_qubits>, backend=UnitarySimulator())
Note
For 'qiskit.aer'
, PennyLane chooses the aer_simulator
as the default backend if no
backend is specified. For more details on the aer_simulator
, including available backend
options, see Qiskit Aer Simulator documentation.
To access a real device, we can use the 'qiskit.remote'
device. A real hardware backend can
be defined as follows:
from qiskit_ibm_runtime import QiskitRuntimeService
QiskitRuntimeService.save_account(channel="ibm_quantum", token="<IQP_TOKEN>")
# To access saved credentials for the IBM quantum channel and select an instance
service = QiskitRuntimeService(channel="ibm_quantum", instance="my_hub/my_group/my_project")
backend = service.least_busy(operational=True, simulator=False, min_num_qubits=<num_qubits>)
# passing a string in backend would result in an error
dev = qml.device('qiskit.remote', wires=<num_qubits>, backend=backend)
Tutorials¶
Check out these demos to see the PennyLane-Qiskit plugin in action:
You can also try it out using any of the qubit based demos from the PennyLane documentation, for example the tutorial on
qubit rotation.
Simply replace 'default.qubit'
with any of the available Qiskit devices,
such as 'qiskit.aer'
, or 'qiskit.remote'
if you have an API key for
hardware access.