Skip to content
This is a plugin to the PennyLane library to connect it to qiskit-terra.
Branch: master
Clone or download
Type Name Latest commit message Commit time
Failed to load latest commit information.
.github/ISSUE_TEMPLATE Update issue templates Nov 30, 2018
doc Complete refactoring regarding ibmq device. Jun 8, 2019
tests Pennylane 0.4 update and refactoring tests (#34) Jul 1, 2019
.coveragerc The code coverage configuration added. Nov 30, 2018
.editorconfig add .editorconfig Feb 15, 2019
.gitignore Adjustments not done yet! Nov 30, 2018
.readthedocs.yml YAML for the read the docs integration. Nov 30, 2018
.travis.yml Pennylane 0.4 update and refactoring tests (#34) Jul 1, 2019
CHANGELOG.rst Updated changelog for new release (#35) Jul 3, 2019
LICENSE Setup script, license and gitignore to start with. Nov 30, 2018 Fixing the MANIFEST file. Dec 23, 2018
Makefile Added the Makefile for easy to build mechanism. Nov 30, 2018
README.rst Update README.rst Jun 28, 2019
requirements.txt Adding numpy as required package. Jun 8, 2019 Renaming the device to correctly reflect it. Jun 8, 2019


PennyLane qiskit Plugin

Travis Codecov coverage Codacy grade Read the Docs PyPI PyPI - Python Version

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 compilation framework capable of targeting various types of hardware and a high-performance quantum computer simulator with emulation capabilities, and various compiler plug-ins.

This PennyLane plugin allows to use both the software and hardware backends of qiskit as devices for PennyLane.


  • Provides three devices to be used with PennyLane: qiskit.basicaer, qiskit.aer and qiskit.ibmq. These devices provide access to the various backends.
  • Supports a wide range of PennyLane operations and expectation values across the providers.
  • Combine qiskit high performance simulator and hardware backend support with PennyLane's automatic differentiation and optimization.


This plugin requires Python version 3.5 and above, as well as PennyLane and qiskit. Installation of this plugin, as well as all dependencies, can be done using pip:

$ python -m pip install pennylane_qiskit

To test that the PennyLane qiskit plugin is working correctly you can run

$ make test

in the source folder. Tests restricted to a specific provider can be run by executing make test-basicaer, make test-aer or make test-ibmq.


Tests on the IBMQ device can only be run if a ibmqx_token for the IBM Q experience is configured in the PennyLane configuration file. If this is the case, running make test also executes tests on the ibmq device. By default tests on the ibmq device run with ibmq_qasm_simulator backend and those done by the basicaer and aer device are run with the qasm_simulator backend. At the time of writing this means that the test are "free". Please verify that this is also the case for your account.

Getting started

You can instantiate a 'qiskit.aer' device for PennyLane with:

import pennylane as qml
dev = qml.device('qiskit.aer', wires=2)

This device can then be used just like other devices for the definition and evaluation of QNodes within PennyLane. A simple quantum function that returns the expectation value of a measurement and depends on three classical input parameters would look like:

def circuit(x, y, z):
    qml.RZ(z, wires=[0])
    qml.RY(y, wires=[0])
    qml.RX(x, wires=[0])
    qml.CNOT(wires=[0, 1])
    return qml.expval.PauliZ(wires=1)

You can then execute the circuit like any other function to get the quantum mechanical expectation value.

circuit(0.2, 0.1, 0.3)

You can also change the default device's backend with

dev = qml.device('qiskit.aer', wires=2, backend='unitary_simulator')

To get a current overview what backends are available you can query this by


While the device 'qiskit.aer' is the standard go-to simulator that is provided along the qiskit main package installation, there exists a natively included python simulator that is slower but will work usually without the need to check out other dependencies (gcc, blas and so on) which can be sed by 'qiskit.basicaer'. There is an important difference of the two: while 'qiskit.aer' supports a simulation with noise 'qiskit.basicaer' does not.

You can instantiate a noise model and apply it to the device by calling

import pennylane as qml

import qiskit
from qiskit.providers.aer.noise.device import basic_device_noise_model

ibmqx4 = qiskit.IBMQ.get_backend('ibmqx4')
device_properties =

noise_model = basic_device_noise_model(device_properties)

dev = qml.device('qiskit.aer', wires=2, noise_model=noise_model)

Then all simulations are done with noise. The basic noise model is explained a little at qiskit's documentation.

Finally one of the more interesting functionality is running your code through the IBM Quantum Experience API. You can choose between different backends having either simulators or real hardware depending on your agreement with IBM. To use this device you would instantiate a 'qiskit.ibmq' device by giving your IBM Quantum Experience token:

import pennylane as qml
dev = qml.device('qiskit.ibmq', wires=2, ibmqx_token="XXX")

In order to avoid accidentally publishing your token, you should better specify it via the PennyLane configuration file by adding a section such as


  ibmqx_token = "XXX"

It is also possible to define an environment variable IBMQX_TOKEN, from which the token will be taken if not provided in another way.

Per default the backend ibmq uses the simulator backend ibmq_qasm_simulator, but you can change that to be any of the real backends as given by


Please refer to the documentation of the PennyLane qiskit Plugin as well as well as to the documentation of PennyLane for further reference.

How to cite

If you are doing research using PennyLane, please cite our whitepaper:

Ville Bergholm, Josh Izaac, Maria Schuld, Christian Gogolin, Carsten Blank, Keri McKiernan and Nathan Killoran. PennyLane. arXiv, 2018. arXiv:1811.04968


We welcome contributions - simply fork the repository of this plugin, and then make a pull request containing your contribution. All contributers to this plugin will be listed as authors on the releases.

We also encourage bug reports, suggestions for new features and enhancements, and even links to cool projects or applications built on PennyLane.


Carsten Blank, Sebastian Boerakker, Christian Gogolin, Josh Izaac


If you are having issues, please let us know by posting the issue on our Github issue tracker.


The PennyLane qiskit plugin is free and open source, released under the Apache License, Version 2.0.

You can’t perform that action at this time.