Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Plugin cleanup and refactor #44

Merged
merged 8 commits into from
Aug 6, 2019
Merged
Show file tree
Hide file tree
Changes from 7 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 31 additions & 0 deletions .pylintrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
[MASTER]
# A comma-separated list of package or module names from where C extensions may
# be loaded. Extensions are loading into the active Python interpreter and may
quantshah marked this conversation as resolved.
Show resolved Hide resolved
# run arbitrary code
extension-pkg-whitelist=numpy,scipy,autograd,qiskit

[TYPECHECK]

# List of module names for which member attributes should not be checked
# (useful for modules/projects where namespaces are manipulated during runtime
# and thus existing member attributes cannot be deduced by static analysis. It
# supports qualified module names, as well as Unix pattern matching.
ignored-modules=numpy,scipy,autograd,qiskit

# List of classes names for which member attributes should not be checked
# (useful for classes with attributes dynamically set). This supports can work
quantshah marked this conversation as resolved.
Show resolved Hide resolved
# with qualified names.
ignored-classes=numpy,scipy,autograd,qiskit

[MESSAGES CONTROL]

# Enable the message, report, category or checker with the given id(s). You can
# either give multiple identifier separated by comma (,) or put this option
quantshah marked this conversation as resolved.
Show resolved Hide resolved
# multiple time.
quantshah marked this conversation as resolved.
Show resolved Hide resolved
#enable=

# Disable the message, report, category or checker with the given id(s). You
# can either give multiple identifier separated by comma (,) or put this option
quantshah marked this conversation as resolved.
Show resolved Hide resolved
# multiple time (only on the command line, not in the configuration file where
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

"multiple times"

# it should appear only once).
disable=line-too-long,invalid-name,too-many-lines,redefined-builtin,too-many-locals,duplicate-code,bad-continuation
117 changes: 72 additions & 45 deletions README.rst
Original file line number Diff line number Diff line change
@@ -1,27 +1,27 @@
PennyLane qiskit Plugin
#########################
PennyLane Qiskit Plugin
#######################

.. image:: https://img.shields.io/travis/com/XanaduAI/pennylane-qiskit/master.svg?style=for-the-badge
.. image:: https://img.shields.io/travis/com/XanaduAI/pennylane-qiskit/master.svg?style=popout-square
:alt: Travis
:target: https://travis-ci.com/XanaduAI/pennylane-qiskit

.. image:: https://img.shields.io/codecov/c/github/XanaduAI/pennylane-qiskit/master.svg?style=for-the-badge
.. image:: https://img.shields.io/codecov/c/github/XanaduAI/pennylane-qiskit/master.svg?style=popout-square
:alt: Codecov coverage
:target: https://codecov.io/gh/XanaduAI/pennylane-qiskit

.. image:: https://img.shields.io/codacy/grade/f4132f03ce224f82bd3e8ba436b52af3.svg?style=for-the-badge
.. image:: https://img.shields.io/codacy/grade/f4132f03ce224f82bd3e8ba436b52af3.svg?style=popout-square
:alt: Codacy grade
:target: https://www.codacy.com/app/XanaduAI/pennylane-qiskit?utm_source=github.com&utm_medium=referral&utm_content=carstenblank/pennylane-qiskit&utm_campaign=Badge_Grade
:target: https://www.codacy.com/app/XanaduAI/pennylane-qiskit

.. image:: https://img.shields.io/readthedocs/pennylane-qiskit.svg?style=for-the-badge
.. image:: https://img.shields.io/readthedocs/pennylane-qiskit.svg?style=popout-square
:alt: Read the Docs
:target: https://pennylane-qiskit.readthedocs.io

.. image:: https://img.shields.io/pypi/v/PennyLane-qiskit.svg?style=for-the-badge
.. image:: https://img.shields.io/pypi/v/PennyLane-qiskit.svg?style=popout-square
:alt: PyPI
:target: https://pypi.org/project/PennyLane-qiskit

.. image:: https://img.shields.io/pypi/pyversions/PennyLane-qiskit.svg?style=for-the-badge
.. image:: https://img.shields.io/pypi/pyversions/PennyLane-qiskit.svg?style=popout-square
:alt: PyPI - Python Version
:target: https://pypi.org/project/PennyLane-qiskit

Expand All @@ -30,51 +30,57 @@ PennyLane qiskit Plugin
`PennyLane <https://pennylane.readthedocs.io>`_ is a cross-platform Python library for quantum machine
learning, automatic differentiation, and optimization of hybrid quantum-classical computations.

`qiskit <https://qiskit.org/documentation/>`_ is an open-source compilation framework capable of targeting various
`Qiskit <https://qiskit.org/documentation/>`_ 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.
This PennyLane plugin allows to use both the software and hardware backends of Qiskit as devices for PennyLane.


Features
========

* Provides three devices to be used with PennyLane: ``qiskit.basicaer``, ``qiskit.aer`` and ``qiskit.ibmq``. These devices provide access to the various backends.
* 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.
* Combine Qiskit's high performance simulator and hardware backend support with PennyLane's automatic
differentiation and optimization.

.. header-end-inclusion-marker-do-not-remove
.. installation-start-inclusion-marker-do-not-remove

Installation
============

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:
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``:

.. code-block:: bash

$ python -m pip install pennylane_qiskit
pip install pennylane-qiskit

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

.. code-block:: bash

$ make test

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

.. note::

Tests on the `IBMQ device <https://pennylane-qiskit.readthedocs.io/en/latest/devices.html>`_ can
only be run if a :code:`ibmqx_token` for the `IBM Q experience <https://quantumexperience.ng.bluemix.net/qx/experience>`_ is
only be run if a ``ibmqx_token`` for the
`IBM Q experience <https://quantumexperience.ng.bluemix.net/qx/experience>`_ is
configured in the `PennyLane configuration file <https://pennylane.readthedocs.io/configuration.html>`_.
If this is the case, running :code:`make test` also executes tests on the :code:`ibmq` device. By default tests on
the :code:`ibmq` device run with :code:`ibmq_qasm_simulator` backend and those done by the :code:`basicaer` and
:code:`aer` device are run with the :code:`qasm_simulator` backend. At the time of writing this means that the test are "free".

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.

.. installation-end-inclusion-marker-do-not-remove
Expand All @@ -83,7 +89,10 @@ in the source folder. Tests restricted to a specific provider can be run by exec
Getting started
===============

You can instantiate a :code:`'qiskit.aer'` device for PennyLane with:
Once the PennyLane-Qiskit plugin is installed, the three provided Qiskit devices
can be accessed straight away in PennyLane.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

straightaway


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

.. code-block:: python

Expand Down Expand Up @@ -122,11 +131,16 @@ To get a current overview what backends are available you can query this by

dev.capabilities()['backend']

While the device :code:`'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 :code:`'qiskit.basicaer'`.
There is an important difference of the two: while :code:`'qiskit.aer'` supports a simulation with noise
:code:`'qiskit.basicaer'` does not.
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'``.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

"used"


Another important difference between the two is that while ``'qiskit.aer'``
supports a simulation with noise, ``'qiskit.basicaer'`` does not.

Noise models
============

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

Expand All @@ -145,20 +159,32 @@ You can instantiate a noise model and apply it to the device by calling

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 <https://qiskit.org/documentation/aer/device_noise_simulation.html>`_.
Please refer to the Qiskit documentation for more information on
`noise models <https://qiskit.org/documentation/aer/device_noise_simulation.html>`_.

IBM Q Experience
================

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 :code:`'qiskit.ibmq'` device by giving your IBM Quantum Experience token:
PennyLane-Qiskit supports running PennyLane on IBM Q hardware via the ``qistkit.ibmq`` device.
You can choose between different backends having either simulators or real hardware.
quantshah marked this conversation as resolved.
Show resolved Hide resolved

.. code-block:: python

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

In order to avoid accidentally publishing your token, you should better specify it via the
By default, the ``qiskit.ibmq`` device will attempt to use an already active or stored
IBM Q account. If none are available, you may also directly pass your IBM Q API token,
as well as an optional URL:

.. code-block:: python

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


In order to avoid accidentally publishing your token, it is best to store it using the
``qiskit.IBMQ.save_account()`` function. Alternatively, you can specify the token or URL via the
`PennyLane configuration file <https://pennylane.readthedocs.io/en/latest/code/configuration.html>`__ by
adding a section such as

Expand All @@ -168,20 +194,19 @@ adding a section such as

[qiskit.ibmq]
ibmqx_token = "XXX"
ibmqx_url = "XXX"

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

Per default the backend :code:`ibmq` uses the simulator backend :code:`ibmq_qasm_simulator`, but you can change that
to be any of the real backends as given by
Note that, by default, the ``qiskit.ibmq`` device uses the simulator backend
``ibmq_qasm_simulator``, but this may be changed to any of the real backends as given by

.. code-block:: python

dev.capabilities()['backend']

.. gettingstarted-end-inclusion-marker-do-not-remove

Please refer to the `documentation of the PennyLane qiskit Plugin <https://pennylane-qiskit.readthedocs.io/>`_ as
well as well as to the `documentation of PennyLane <https://pennylane.readthedocs.io/>`_ for further reference.
Please refer to the `plugin documentation <https://pennylane-qiskit.readthedocs.io/>`_ as
well as well as to the `PennyLane documentation <https://pennylane.readthedocs.io/>`_ for further reference.
quantshah marked this conversation as resolved.
Show resolved Hide resolved

.. howtocite-start-inclusion-marker-do-not-remove

Expand All @@ -190,7 +215,8 @@ How to cite

If you are doing research using PennyLane, please cite `our whitepaper <https://arxiv.org/abs/1811.04968>`_:

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

.. howtocite-end-inclusion-marker-do-not-remove

Expand All @@ -201,7 +227,8 @@ We welcome contributions - simply fork the repository of this plugin, and then m
`pull request <https://help.github.com/articles/about-pull-requests/>`_ 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.
We also encourage bug reports, suggestions for new features and enhancements, and even links to cool projects
or applications built on PennyLane.


Authors
Expand Down
4 changes: 4 additions & 0 deletions doc/code/aer.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
.. automodule:: pennylane_qiskit.aer
:members:
:private-members:
:special-members:
4 changes: 4 additions & 0 deletions doc/code/basic_aer.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
.. automodule:: pennylane_qiskit.basic_aer
:members:
:private-members:
:special-members:
4 changes: 4 additions & 0 deletions doc/code/gates.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
.. automodule:: pennylane_qiskit.gates
:members:
:private-members:
:special-members:
4 changes: 4 additions & 0 deletions doc/code/ibmq.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
.. automodule:: pennylane_qiskit.ibmq
:members:
:private-members:
:special-members:
4 changes: 4 additions & 0 deletions doc/code/operations.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
.. automodule:: pennylane_qiskit.ops
:members:
:private-members:
:special-members:
4 changes: 4 additions & 0 deletions doc/code/qiskit_device.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
.. automodule:: pennylane_qiskit.qiskit_device
:members:
:private-members:
:special-members:
65 changes: 3 additions & 62 deletions doc/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,8 +55,8 @@
master_doc = 'index'

# General information about the project.
project = 'PennyLane-qiskit'
copyright = "Copyright 2018, Carsten Blank"
project = 'PennyLane-Qiskit'
copyright = "Copyright 2019, Xanadu Quantum Technologies Inc."
author = 'Carsten Blank'

# The version info for the project you're documenting, acts as replacement for
Expand Down Expand Up @@ -252,68 +252,9 @@
# "projectlink": "http://myproject.url",
}

edit_on_github_project = 'carstenblank/pennylane-qiskit'
edit_on_github_project = 'XanaduAI/pennylane-qiskit'
edit_on_github_branch = 'master/doc'

# -- Options for HTMLHelp output ------------------------------------------

# Output file base name for HTML help builder.
htmlhelp_basename = 'PennyLaneQiskitdoc'


# -- Options for LaTeX output ---------------------------------------------

latex_elements = {
# The paper size ('letterpaper' or 'a4paper').
#
# 'papersize': 'letterpaper',

# The font size ('10pt', '11pt' or '12pt').
#
# 'pointsize': '10pt',

# Additional stuff for the LaTeX preamble.
#
# 'preamble': '',

# Latex figure (float) alignment
#
# 'figure_align': 'htbp',
}

latex_additional_files = ['macros.tex']

# Grouping the document tree into LaTeX files. List of tuples
# (source start file, target name, title,
# author, documentclass [howto, manual, or own class]).
latex_documents = [
(master_doc, 'PennyLane-qiskit.tex', 'PennyLane-qiskit Documentation',
'Carsten Blank', 'manual'),
]


# -- Options for manual page output ---------------------------------------

# One entry per manual page. List of tuples
# (source start file, name, description, authors, manual section).
man_pages = [
(master_doc, 'pennylane-qiskit', 'PennyLane-qiskit Documentation',
[author], 1)
]


# -- Options for Texinfo output -------------------------------------------

# Grouping the document tree into Texinfo files. List of tuples
# (source start file, target name, title, author,
# dir menu entry, description, category)
texinfo_documents = [
(master_doc, 'PennyLane-qiskit', 'PennyLane-qiskit Documentation',
author, 'PennyLane-qiskit', 'qiskit plugin for the PennyLane quantum machine learning library.',
'Miscellaneous'),
]


#============================================================

# the order in which autodoc lists the documented members
Expand Down
2 changes: 0 additions & 2 deletions doc/devices.rst

This file was deleted.

3 changes: 0 additions & 3 deletions doc/expectations.rst

This file was deleted.

Loading