diff --git a/.github/workflows/deploy-docs.yml b/.github/workflows/deploy-docs.yml new file mode 100644 index 00000000..eba5c214 --- /dev/null +++ b/.github/workflows/deploy-docs.yml @@ -0,0 +1,56 @@ +# This code is part of a Qiskit project. +# +# (C) Copyright IBM 2023. +# +# This code is licensed under the Apache License, Version 2.0. You may +# obtain a copy of this license in the LICENSE.txt file in the root directory +# of this source tree or at http://www.apache.org/licenses/LICENSE-2.0. +# +# Any modifications or derivative works of this code must retain this +# copyright notice, and modified files need to carry a notice indicating +# that they have been altered from the originals. + +name: Deploy Docs + +on: + workflow_dispatch: + +concurrency: + group: ${{ github.repository }}-${{ github.ref }}-${{ github.head_ref }}-${{ github.workflow }} + cancel-in-progress: true + +jobs: + docs_publish: + if: ${{ startsWith(github.ref, 'refs/heads/stable') && contains('["mtreinish","Cryoris","ElePT","woodsp-ibm"]', github.actor) }} + runs-on: ${{ matrix.os }} + strategy: + matrix: + os: [ubuntu-latest] + python-version: [3.8] + steps: + - uses: actions/checkout@v3 + with: + fetch-depth: 0 + - uses: actions/setup-python@v4 + with: + python-version: ${{ matrix.python-version }} + - uses: ./.github/actions/install-optimization + with: + os: ${{ matrix.os }} + - name: Install Dependencies + run: | + pip install jupyter qiskit-terra[visualization] + sudo apt-get install -y pandoc graphviz + shell: bash + - name: Build and publish + env: + encrypted_rclone_key: ${{ secrets.encrypted_rclone_key }} + encrypted_rclone_iv: ${{ secrets.encrypted_rclone_iv }} + QISKIT_PARALLEL: False + QISKIT_DOCS_BUILD_TUTORIALS: 'always' + run: | + echo "earliest_version: 0.1.0" >> releasenotes/config.yaml + tools/ignore_untagged_notes.sh + make html + tools/deploy_documentation.sh + shell: bash diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index a578bcb0..c0e28d98 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -66,16 +66,38 @@ jobs: run: | sudo apt-get -y install pandoc graphviz python3-enchant hunspell-en-us pip install pyenchant - echo "earliest_version: 0.1.0" >> releasenotes/config.yaml shell: bash - run: pip check if: ${{ !cancelled() }} shell: bash + - name: Copyright Check + run: | + python tools/check_copyright.py -check + if: ${{ !cancelled() }} + shell: bash - name: Style Check run: | make style if: ${{ !cancelled() }} shell: bash + - name: Run make html + run: | + make clean_sphinx + make html + cd docs/_build/html + mkdir artifacts + tar -zcvf artifacts/documentation.tar.gz --exclude=./artifacts . + if: ${{ !cancelled() }} + shell: bash + - name: Run upload documentation + uses: actions/upload-artifact@v3 + with: + name: documentation + path: docs/_build/html/artifacts/documentation.tar.gz + if: ${{ !cancelled() }} + - run: make doctest + if: ${{ !cancelled() }} + shell: bash Algorithms: runs-on: ${{ matrix.os }} strategy: @@ -129,6 +151,54 @@ jobs: with: name: ${{ matrix.os }}-${{ matrix.python-version }} path: ./ci-artifact-data/* + Tutorials: + runs-on: ${{ matrix.os }} + strategy: + fail-fast: false + matrix: + os: [ ubuntu-latest ] + python-version: [ 3.8, 3.11 ] + steps: + - uses: actions/checkout@v3 + with: + fetch-depth: 0 + - uses: actions/setup-python@v4 + with: + python-version: ${{ matrix.python-version }} + cache: 'pip' + cache-dependency-path: | + setup.py + requirements.txt + requirements-dev.txt + - uses: ./.github/actions/install-main-dependencies + with: + os: ${{ matrix.os }} + python-version: ${{ matrix.python-version }} + if: ${{ !startsWith(github.ref, 'refs/heads/stable') && !startsWith(github.base_ref, 'stable/') }} + - uses: ./.github/actions/install-algorithms + with: + os: ${{ matrix.os }} + - name: Install Dependencies + run: | + pip install jupyter qiskit-terra[visualization] + sudo apt-get install -y pandoc graphviz + shell: bash + - name: Run Qiskit Algorithms Tutorials + env: + QISKIT_PARALLEL: False + QISKIT_DOCS_BUILD_TUTORIALS: 'always' + run: | + tools/ignore_untagged_notes.sh + make html + cd docs/_build/html + mkdir artifacts + tar -zcvf artifacts/tutorials.tar.gz --exclude=./artifacts . + shell: bash + - name: Run upload tutorials + uses: actions/upload-artifact@v3 + with: + name: tutorials${{ matrix.python-version }} + path: docs/_build/html/artifacts/tutorials.tar.gz Deprecation_Messages_and_Coverage: needs: [Checks, Algorithms] runs-on: ubuntu-latest diff --git a/Makefile b/Makefile index bcd230e5..06d21f82 100644 --- a/Makefile +++ b/Makefile @@ -35,9 +35,9 @@ endif # You can set this variable from the command line. SPHINXOPTS = -.PHONY: lint style black test test_ci spell copyright coverage clean +.PHONY: lint style black test test_ci spell copyright html doctest clean_sphinx coverage clean -all_check: spell style lint copyright +all_check: spell style lint copyright clean_sphinx html doctest lint: pylint -rn qiskit_algorithms test tools @@ -58,10 +58,20 @@ test_ci: spell: pylint -rn --disable=all --enable=spelling --spelling-dict=en_US --spelling-private-dict-file=.pylintdict qiskit_algorithms test tools + sphinx-build -M spelling docs docs/_build -W -T --keep-going $(SPHINXOPTS) copyright: python tools/check_copyright.py +html: + sphinx-build -M html docs docs/_build -W -T --keep-going $(SPHINXOPTS) + +doctest: + sphinx-build -M doctest docs docs/_build -W -T --keep-going $(SPHINXOPTS) + +clean_sphinx: + make -C docs clean + coverage: coverage3 run --source qiskit_algorithms -m unittest discover -s test -q coverage3 report diff --git a/docs/Makefile b/docs/Makefile new file mode 100644 index 00000000..e87c8596 --- /dev/null +++ b/docs/Makefile @@ -0,0 +1,28 @@ +# This code is part of Qiskit. +# +# (C) Copyright IBM 2018, 2023. +# +# This code is licensed under the Apache License, Version 2.0. You may +# obtain a copy of this license in the LICENSE.txt file in the root directory +# of this source tree or at http://www.apache.org/licenses/LICENSE-2.0. +# +# Any modifications or derivative works of this code must retain this +# copyright notice, and modified files need to carry a notice indicating +# that they have been altered from the originals. + +# You can set these variables from the command line. +SPHINXOPTS = +SPHINXBUILD = sphinx-build +SOURCEDIR = . +BUILDDIR = _build + +# Put it first so that "make" without argument is like "make help". +help: + @$(SPHINXBUILD) -M help "$(SOURCEDIR)" "$(BUILDDIR)" $(SPHINXOPTS) $(O) + +.PHONY: help Makefile + +# Catch-all target: route all unknown targets to Sphinx using the new +# "make mode" option. $(O) is meant as a shortcut for $(SPHINXOPTS). +%: Makefile + @$(SPHINXBUILD) -M $@ "$(SOURCEDIR)" "$(BUILDDIR)" $(SPHINXOPTS) $(O) diff --git a/docs/_static/nbsphinx-gallery.css b/docs/_static/nbsphinx-gallery.css new file mode 100644 index 00000000..f60c7b59 --- /dev/null +++ b/docs/_static/nbsphinx-gallery.css @@ -0,0 +1,31 @@ +.nbsphinx-gallery { + display: grid; + grid-template-columns: repeat(auto-fill, minmax(160px, 1fr)); + gap: 5px; + margin-top: 1em; + margin-bottom: 1em; +} + +.nbsphinx-gallery>a { + padding: 5px; + border: 1px dotted currentColor; + border-radius: 2px; + text-align: center; +} + +.nbsphinx-gallery>a:hover { + border-style: solid; +} + +.nbsphinx-gallery img { + max-width: 100%; + max-height: 100%; +} + +.nbsphinx-gallery>a>div:first-child { + display: flex; + align-items: start; + justify-content: center; + height: 120px; + margin-bottom: 5px; +} \ No newline at end of file diff --git a/docs/_templates/autosummary/class.rst b/docs/_templates/autosummary/class.rst new file mode 100644 index 00000000..daff18c1 --- /dev/null +++ b/docs/_templates/autosummary/class.rst @@ -0,0 +1,31 @@ +{# + We show all the class's methods and attributes on the same page. By default, we document + all methods, including those defined by parent classes. +-#} + +{{ objname | escape | underline }} + +.. currentmodule:: {{ module }} + +.. autoclass:: {{ objname }} + :no-members: + :show-inheritance: + +{% block attributes_summary %} + {% if attributes %} + .. rubric:: Attributes + {% for item in attributes %} + .. autoattribute:: {{ item }} + {%- endfor %} + {% endif %} +{% endblock -%} + +{% block methods_summary %} + {% set wanted_methods = (methods | reject('==', '__init__') | list) %} + {% if wanted_methods %} + .. rubric:: Methods + {% for item in wanted_methods %} + .. automethod:: {{ item }} + {%- endfor %} + {% endif %} +{% endblock %} diff --git a/docs/_templates/autosummary/class_no_inherited_members.rst b/docs/_templates/autosummary/class_no_inherited_members.rst new file mode 100644 index 00000000..269a89b7 --- /dev/null +++ b/docs/_templates/autosummary/class_no_inherited_members.rst @@ -0,0 +1,28 @@ +{# This is identical to class.rst, except for the filtering in `set wanted_methods`. -#} + +{{ objname | escape | underline }} + +.. currentmodule:: {{ module }} + +.. autoclass:: {{ objname }} + :no-members: + :show-inheritance: + +{% block attributes_summary %} + {% if attributes %} + .. rubric:: Attributes + {% for item in attributes %} + .. autoattribute:: {{ item }} + {%- endfor %} + {% endif %} +{% endblock -%} + +{% block methods_summary %} + {% set wanted_methods = (methods | reject('in', inherited_members) | reject('==', '__init__') | list) %} + {% if wanted_methods %} + .. rubric:: Methods + {% for item in wanted_methods %} + .. automethod:: {{ item }} + {%- endfor %} + {% endif %} +{% endblock %} diff --git a/docs/apidocs/algorithms.rst b/docs/apidocs/algorithms.rst new file mode 100644 index 00000000..ce2ad817 --- /dev/null +++ b/docs/apidocs/algorithms.rst @@ -0,0 +1,6 @@ +.. _qiskit-algorithms: + +.. automodule:: qiskit_algorithms + :no-members: + :no-inherited-members: + :no-special-members: diff --git a/docs/conf.py b/docs/conf.py new file mode 100644 index 00000000..88ce2f0f --- /dev/null +++ b/docs/conf.py @@ -0,0 +1,160 @@ +# This code is part of a Qiskit project. +# +# (C) Copyright IBM 2023. +# +# This code is licensed under the Apache License, Version 2.0. You may +# obtain a copy of this license in the LICENSE.txt file in the root directory +# of this source tree or at http://www.apache.org/licenses/LICENSE-2.0. +# +# Any modifications or derivative works of this code must retain this +# copyright notice, and modified files need to carry a notice indicating +# that they have been altered from the originals. + +# pylint: disable=invalid-name + +"""Sphinx documentation builder.""" + +# -- General configuration --------------------------------------------------- +import datetime +import doctest + +import os +import sys + +sys.path.insert(0, os.path.abspath("..")) +sys.path.append(os.path.abspath(".")) + +project = "Qiskit Algorithms" +copyright = f"2017-{datetime.date.today().year}, Qiskit Algorithms Development Team" # pylint: disable=redefined-builtin +author = "Qiskit Algorithms Development Team" + +# The short X.Y version +version = "0.1" +# The full version, including alpha/beta/rc tags +release = "0.1.0" + +# Manually add the gallery CSS file for now +# TODO: Figure out why the styling is not working by default +html_css_files = [ + "nbsphinx-gallery.css", +] + +extensions = [ + "sphinx.ext.napoleon", + "sphinx.ext.autodoc", + "sphinx.ext.autosummary", + "sphinx.ext.mathjax", + "sphinx.ext.viewcode", + "sphinx.ext.extlinks", + "sphinx.ext.intersphinx", + "sphinx.ext.doctest", + "reno.sphinxext", + "sphinx_design", + "matplotlib.sphinxext.plot_directive", + "sphinx.ext.doctest", + "qiskit_sphinx_theme", + "nbsphinx" +] + +rst_prolog = """ +.. raw:: html + +


+ +.. |version| replace:: {0} +""".format( + release +) + +nbsphinx_prolog = """ +{% set docname = env.doc2path(env.docname, base=None) %} +.. only:: html + + .. role:: raw-html(raw) + :format: html + + .. note:: + This page was generated from `docs/{{ docname }}`__. + + __""" + +vers = version.split(".") +link_str = f" https://github.com/qiskit-community/qiskit-algorithms/blob/stable/{vers[0]}.{vers[1]}/docs/" +nbsphinx_prolog += link_str + "{{ docname }}" + +nbsphinx_timeout = 360 +nbsphinx_execute = os.getenv("QISKIT_DOCS_BUILD_TUTORIALS", "never") +nbsphinx_widgets_path = "" +nbsphinx_thumbnails = { + "**": "_static/images/logo.png", +} + +templates_path = ["_templates"] + +# Number figures, tables and code-blocks if they have a caption. +numfig = True +# Available keys are 'figure', 'table', 'code-block' and 'section'. '%s' is the number. +numfig_format = {"table": "Table %s"} + +# The language for content autogenerated by Sphinx or the default for gettext content translation. +language = "en" + +# Relative to source directory, affects general discovery, and html_static_path and html_extra_path. +exclude_patterns = ["_build", "**.ipynb_checkpoints"] + +pygments_style = "colorful" + +# Whether module names are included in crossrefs of functions, classes, etc. +add_module_names = False + +# A list of prefixes that are ignored for sorting the Python module index +# (e.g., if this is set to ['foo.'], then foo.bar is shown under B, not F). +modindex_common_prefix = ["qiskit."] + +intersphinx_mapping = { + "python": ("https://docs.python.org/3", None), + "numpy": ("https://numpy.org/doc/stable", None), + "scipy": ("https://docs.scipy.org/doc/scipy", None), + "qiskit": ("https://qiskit.org/documentation/", None), +} + +# -- Options for HTML output ------------------------------------------------- + +html_theme = "qiskit-ecosystem" +html_last_updated_fmt = "%Y/%m/%d" +html_title = f"{project} {release}" + + +# -- Options for Autosummary and Autodoc ------------------------------------- + +# Note that setting autodoc defaults here may not have as much of an effect as you may expect; any +# documentation created by autosummary uses a template file (in autosummary in the templates path), +# which likely overrides the autodoc defaults. + +# Move type hints from signatures to the parameter descriptions (except in overload cases, where +# that's not possible). +autodoc_typehints = "description" +# Only add type hints from signature to description body if the parameter has documentation. The +# return type is always added to the description (if in the signature). +autodoc_typehints_description_target = "documented_params" + +autosummary_generate = True +autosummary_generate_overwrite = False +autoclass_content = "both" + + +# -- Options for Doctest -------------------------------------------------------- + +doctest_default_flags = ( + doctest.ELLIPSIS + | doctest.NORMALIZE_WHITESPACE + | doctest.IGNORE_EXCEPTION_DETAIL + | doctest.DONT_ACCEPT_TRUE_FOR_1 +) + +# Leaving this string empty disables testing of doctest blocks from docstrings. +# Doctest blocks are structures like this one: +# >> code +# output +doctest_test_doctest_blocks = "" + diff --git a/docs/getting_started.rst b/docs/getting_started.rst new file mode 100644 index 00000000..749588d5 --- /dev/null +++ b/docs/getting_started.rst @@ -0,0 +1,106 @@ +:orphan: + +############### +Getting started +############### + +Installation +============ + +Qiskit Algorithms depends on the main Qiskit package which has its own +`Qiskit Getting Started `__ detailing the +installation options for Qiskit and its supported environments/platforms. You should refer to +that first, before focusing on the additional installation instructions +specific to Qiskit Algorithms. + +Qiskit Algorithms has some functions that have been made optional where the dependent code and/or +support program(s) are not (or cannot be) installed by default. +See :ref:`optional_installs` for more information. + +.. tab-set:: + + .. tab-item:: Start locally + + The simplest way to get started is to use the pip package manager: + + .. code:: sh + + pip install qiskit-algorithms + + .. tab-item:: Install from source + + Installing Qiskit Algorithms from source allows you to access the most recently + updated version under development, instead of using the version in the Python Package + Index (PyPI) repository. + + Since Qiskit Algorithms depends on Qiskit, and its latest changes may require new or changed + features of Qiskit, you should first follow Qiskit's `"Install from source"` instructions + here `Qiskit Getting Started `__ + + .. raw:: html + +

Installing Qiskit Algorithms from Source

+ + Using the same development environment that you installed Qiskit in you are ready to install + Qiskit Algorithms. + + 1. Clone the Qiskit Algorithms repository. + + .. code:: sh + + git clone https://github.com/qiskit-community/qiskit-algorithms.git + + 2. Cloning the repository creates a local folder called ``qiskit-algorithms``. + + .. code:: sh + + cd qiskit-algorithms + + 3. If you want to run tests or linting checks, install the developer requirements. + + .. code:: sh + + pip install -r requirements-dev.txt + + 4. Install ``qiskit-algorithms``. + + .. code:: sh + + pip install . + + If you want to install it in editable mode, meaning that code changes to the + project don't require a reinstall to be applied, you can do this with: + + .. code:: sh + + pip install -e . + + +.. _optional_installs: + +Optional installs +================= + +Some optimization algorithms require specific libraries to be run: + +* **Scikit-quant**, may be installed using the command `pip install scikit-quant`. + +* **SnobFit**, may be installed using the command `pip install SQSnobFit`. + +* **NLOpt**, may be installed using the command `pip install nlopt`. + + +Ready to get going?... +====================== + +.. qiskit-call-to-action-grid:: + + .. qiskit-call-to-action-item:: + :description: Find out about Qiskit Algorithms. + :header: Dive into the tutorials + :button_link: ./tutorials/index.html + :button_text: Qiskit Algorithms tutorials + +.. Hiding - Indices and tables + :ref:`genindex` + :ref:`modindex` diff --git a/docs/index.rst b/docs/index.rst new file mode 100644 index 00000000..aad34a14 --- /dev/null +++ b/docs/index.rst @@ -0,0 +1,35 @@ +################################ +Qiskit Algorithms documentation +################################ + +Overview +======== + +Qiskit Algorithms is a library of quantum algorithms based on Qiskit, +suitable to run on near-term quantum devices with short-depth circuits. + + +Next Steps +=========== + +`Getting started `_ + +`Tutorials `_ + + +.. currentmodule:: qiskit_algorithms + +.. toctree:: + :hidden: + + Overview + Getting Started + API References + Tutorials + Release Notes + GitHub + +.. Hiding - Indices and tables + :ref:`genindex` + :ref:`modindex` + :ref:`search` diff --git a/docs/release_notes.rst b/docs/release_notes.rst new file mode 100644 index 00000000..ec77acc3 --- /dev/null +++ b/docs/release_notes.rst @@ -0,0 +1 @@ +.. release-notes:: Release Notes diff --git a/docs/tutorials/01_algorithms_introduction.ipynb b/docs/tutorials/01_algorithms_introduction.ipynb new file mode 100644 index 00000000..13baa14e --- /dev/null +++ b/docs/tutorials/01_algorithms_introduction.ipynb @@ -0,0 +1,338 @@ +{ + "cells": [ + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "# An Introduction to Algorithms in Qiskit\n", + "\n", + "This is an introduction to algorithms in Qiskit and provides a high-level overview to help understand the various aspects of the functionality to get started. Other tutorials will provide more in-depth material, on given algorithms, and ways to use them etc." + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## How is the algorithm library structured?\n", + "\n", + "Qiskit provides a number of [Algorithms](https://qiskit.org/documentation/apidoc/algorithms.html) and they are grouped by category according to the task they can perform. For instance `Minimum Eigensolvers` to find the smallest eigen value of an operator, for example ground state energy of a chemistry Hamiltonian or a solution to an optimization problem when expressed as an Ising Hamiltonian. There are `Time Evolvers` for the time evolution of quantum systems and `Amplitude Estimators` for value estimation that can be used say in financial applications. The full set of categories can be seen in the Algorithms documentation link above.\n", + "\n", + "Algorithms are configurable and often part of the configuration will be in the form of smaller building blocks, of which different instances of the building block type can be given. For instance with `VQE`, the Variational Quantum Eigensolver, it takes a trial wavefunction, in the form of a `QuantumCircuit` and a classical optimizer among other things.\n", + "\n", + "Let's take a look at an example to construct a VQE instance. Here `TwoLocal` is the variational form (trial wavefunction), a parameterized circuit which can be varied, and `SLSQP` a classical optimizer. These are created as separate instances and passed to VQE when it is constructed. Trying, for example, a different classical optimizer, or variational form is simply a case of creating an instance of the one you want and passing it into VQE." + ] + }, + { + "cell_type": "code", + "execution_count": 1, + "metadata": {}, + "outputs": [], + "source": [ + "from qiskit_algorithms.optimizers import SLSQP\n", + "from qiskit.circuit.library import TwoLocal\n", + "\n", + "num_qubits = 2\n", + "ansatz = TwoLocal(num_qubits, \"ry\", \"cz\")\n", + "optimizer = SLSQP(maxiter=1000)" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "Let's draw the ansatz so we can see it's a `QuantumCircuit` where θ\\[0\\] through θ\\[7\\] will be the parameters that are varied as VQE optimizer finds the minimum eigenvalue. We'll come back to the parameters later in a working example below." + ] + }, + { + "cell_type": "code", + "execution_count": 2, + "metadata": {}, + "outputs": [ + { + "data": { + "image/png": "iVBORw0KGgoAAAANSUhEUgAAAY0AAAB7CAYAAACIG9xhAAAAOXRFWHRTb2Z0d2FyZQBNYXRwbG90bGliIHZlcnNpb24zLjUuMiwgaHR0cHM6Ly9tYXRwbG90bGliLm9yZy8qNh9FAAAACXBIWXMAAAsTAAALEwEAmpwYAAAW2klEQVR4nO3deVzUBf7H8dcMN6Kh4pl3AioKHnmtGXmkqG2tWpqt5UrrgUbXWm25rRmbtupvyw4rM1Mr1lI7zJRSNNaz0EhFVDJRxAMVRRgOYZjv7w90lJDhK8f3+53p83w85vGQ73xr3rwfM/OZ7zFfTIqiKAghhBAqmPUOIIQQwnnI0BBCCKGaDA0hhBCqydAQQgihmgwNIYQQqsnQEEIIoZoMDSGEEKrJ0BBCCKGaDA0hhBCqydAQQgihmgwNIYQQqsnQEEIIoZoMDSGEEKrJ0BBCCKGaDA0hhBCqydAQQgihmgwNIYQQqsnQEEIIoZoMDSGEEKrJ0BBCCKGaDA0hhBCqydAQQgihmgwNIYQQqsnQEEIIoZoMDSGEEKrJ0BBCCKGau94BjO6HFz/kwoE0XR67QUhbesdM1OWx9SBda0e61o5eXddWzzI0KnHhQBqZO1P0jvG7IF1rR7rWjqt1LbunhBBCqCZDQwghhGoyNIQQQqgmQ0MIIYRqciC8hkSsmU2jHkHYrFaUEhuW9LPsXfg5x9ft1DuaS5GetSNda8eZupahUYP2vr6afa+vweRmpmPkMMIXPcEXyWnkHjujdzSXIj1rR7rWjrN0LbunaoFSYiP1402YPdxpENJG7zguS3rWjnStHaN3LUOjFpg93AmeMBSAnKOndU7juqRn7UjX2jF617J7qgaFPj6KzlPvxd3PG6W4hO1PL+LiweMA3LnoSY6t3U56XCIAAz98lpQl6zmzPVnPyOUU5xdizSvE85Y6uHl66B3nhlyhZ4BiSwHWgst4+fth9jDmS9FVui7KycNWZMWzvh9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G3bjORFX3Hi20Qd0zo3R103CGnD7f98GMWmcDnbwtboN3RO69wcdV2vXTP6vTYNa/5lco9n8vP8z3RO69wqew9pdkdnTm8zzh+3kqFRA36aE2v/d+sRfegSPZKctNNk7kwhYcp/yq0/aMXzFGRma5jQdTjqOm5U+SuFStdV56jrr4c8W2596brqHHV96vu9nPp+b5n19exahkYNO/7NLo5/s8vhOnJqYs2QrrUjXWvH6F3L0KhEg5C2v8vH1oN0rR3pWjt6/b619bgmRS7UJIQQQiU51UcIIYRqMjSEEEKoJkNDCCGEajI0hBBCqCZDQwghhGoyNIQQQqgmQ0MIIYRqMjSEEEKoJkNDCCGEajI0hBBCqCZDQwghhGoyNIQQQqgmQ0MIIYRqMjSEEEKoJkNDCCGEajI0hBBCqCZDQwghhGoyNIQQQqj2/y53nt/BUk9dAAAAAElFTkSuQmCC", + "text/plain": [ + "
" + ] + }, + "execution_count": 2, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "ansatz.decompose().draw(\"mpl\", style=\"iqx\")" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "But more is needed before we can run the algorithm so let's get to that next." + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## How to run an algorithm?\n", + "\n", + "Algorithms rely on the primitives to evaluate expectation values or sample circuits. The primitives can be based on a simulator or real device and can be used interchangeably in the algorithms, as they all implement the same interface.\n", + "\n", + "In the VQE, we have to evaluate expectation values, so for example we can use the `qiskit.primitives.Estimator` which is shipped with the default Qiskit Terra installation." + ] + }, + { + "cell_type": "code", + "execution_count": 3, + "metadata": {}, + "outputs": [], + "source": [ + "from qiskit.primitives import Estimator\n", + "\n", + "estimator = Estimator()" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "This estimator uses an exact, statevector simulation to evaluate the expectation values. We can also use a shot-based and noisy simulators or real backends instead. For more information of the simulators you can check out [Qiskit Aer](https://qiskit.org/documentation/apidoc/aer_primitives.html) and for the actual hardware [Qiskit IBM Runtime](https://qiskit.org/documentation/partners/qiskit_ibm_runtime/).\n", + "\n", + "With all the ingredients ready, we can now instantiate the VQE:" + ] + }, + { + "cell_type": "code", + "execution_count": 4, + "metadata": {}, + "outputs": [], + "source": [ + "from qiskit_algorithms.minimum_eigensolvers import VQE\n", + "\n", + "vqe = VQE(estimator, ansatz, optimizer)" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "Now we can call the [compute_mininum_eigenvalue()](https://qiskit.org/documentation/stubs/qiskit_algorithms.minimum_eigensolvers.VQE.compute_minimum_eigenvalue.html#qiskit_algorithms.minimum_eigensolvers.VQE.compute_minimum_eigenvalue) method. The latter is the interface of choice for the application modules, such as Nature and Optimization, in order that they can work interchangeably with any algorithm within the specific category." + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## A complete working example\n", + "\n", + "Let's put what we have learned from above together and create a complete working example. VQE will find the minimum eigenvalue, i.e. minimum energy value of a Hamiltonian operator and hence we need such an operator for VQE to work with. Such an operator is given below. This was originally created by the Nature application module as the Hamiltonian for an H2 molecule at 0.735A interatomic distance. It's a sum of Pauli terms as below, but for now I am not going to say anything further about it since the goal is to run the algorithm, but further information on operators can be found in other tutorials." + ] + }, + { + "cell_type": "code", + "execution_count": 5, + "metadata": {}, + "outputs": [], + "source": [ + "from qiskit.quantum_info import SparsePauliOp\n", + "\n", + "H2_op = SparsePauliOp.from_list([\n", + " (\"II\", -1.052373245772859),\n", + " (\"IZ\", 0.39793742484318045),\n", + " (\"ZI\", -0.39793742484318045),\n", + " (\"ZZ\", -0.01128010425623538),\n", + " (\"XX\", 0.18093119978423156)\n", + "])" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "So let's run VQE and print the result object it returns." + ] + }, + { + "cell_type": "code", + "execution_count": 6, + "metadata": { + "scrolled": true + }, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "{ 'aux_operators_evaluated': None,\n", + " 'cost_function_evals': 102,\n", + " 'eigenvalue': -1.857275020719397,\n", + " 'optimal_circuit': ,\n", + " 'optimal_parameters': { ParameterVectorElement(θ[0]): -2.403507257619715,\n", + " ParameterVectorElement(θ[5]): 1.7060524493254914,\n", + " ParameterVectorElement(θ[1]): 3.085467047665086,\n", + " ParameterVectorElement(θ[2]): -2.1949965223522487,\n", + " ParameterVectorElement(θ[3]): 4.276089268519914,\n", + " ParameterVectorElement(θ[4]): -3.098644972035885,\n", + " ParameterVectorElement(θ[6]): 0.032773583818940334,\n", + " ParameterVectorElement(θ[7]): 2.8861019033185396},\n", + " 'optimal_point': array([-2.40350726, 3.08546705, -2.19499652, 4.27608927, -3.09864497,\n", + " 1.70605245, 0.03277358, 2.8861019 ]),\n", + " 'optimal_value': -1.857275020719397,\n", + " 'optimizer_evals': None,\n", + " 'optimizer_result': ,\n", + " 'optimizer_time': 0.29071593284606934}\n" + ] + } + ], + "source": [ + "result = vqe.compute_minimum_eigenvalue(H2_op)\n", + "print(result)" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "From the above result we can see the number of cost function (=energy) evaluations the optimizer took until it found the minimum eigenvalue of $\\approx -1.85727$ which is the electronic ground state energy of the given H2 molecule. The optimal parameters of the ansatz can also be seen which are the values that were in the ansatz at the minimum value." + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## Updating the primitive inside VQE\n", + "\n", + "To close off let's also change the estimator primitive inside the a VQE. Maybe you're satisfied with the simulation results and now want to use a shot-based simulator, or run on hardware!\n", + "\n", + "In this example we're changing to a shot-based estimator, still using Qiskit Terra's reference primitive. However you could replace the primitive by e.g. Qiskit Aer's estimator (`qiskit_aer.primitives.Estimator`) or even a real backend (`qiskit_ibm_runtime.Estimator`).\n", + "\n", + "For noisy loss functions, the SPSA optimizer typically performs well, so we also update the optimizer. See also the [noisy VQE tutorial](https://qiskit.org/documentation/tutorials/algorithms/03_vqe_simulation_with_noise.html) for more details on shot-based and noisy simulations." + ] + }, + { + "cell_type": "code", + "execution_count": 7, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "{ 'aux_operators_evaluated': None,\n", + " 'cost_function_evals': 200,\n", + " 'eigenvalue': -1.8574503552440247,\n", + " 'optimal_circuit': ,\n", + " 'optimal_parameters': { ParameterVectorElement(θ[0]): -7.7940259581467375,\n", + " ParameterVectorElement(θ[5]): 0.28827257835035214,\n", + " ParameterVectorElement(θ[1]): -1.8091021117029589,\n", + " ParameterVectorElement(θ[2]): -2.460381278734678,\n", + " ParameterVectorElement(θ[3]): -7.725013961075425,\n", + " ParameterVectorElement(θ[4]): -1.3793338621798832,\n", + " ParameterVectorElement(θ[6]): -2.4148423942537587,\n", + " ParameterVectorElement(θ[7]): -1.8555574263247812},\n", + " 'optimal_point': array([-7.79402596, -1.80910211, -2.46038128, -7.72501396, -1.37933386,\n", + " 0.28827258, -2.41484239, -1.85555743]),\n", + " 'optimal_value': -1.8574503552440247,\n", + " 'optimizer_evals': None,\n", + " 'optimizer_result': ,\n", + " 'optimizer_time': 0.8142139911651611}\n" + ] + } + ], + "source": [ + "from qiskit_algorithms.optimizers import SPSA\n", + "\n", + "estimator = Estimator(options={\"shots\": 1000})\n", + "\n", + "vqe.estimator = estimator\n", + "vqe.optimizer = SPSA(maxiter=100)\n", + "result = vqe.compute_minimum_eigenvalue(operator=H2_op)\n", + "print(result)" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "Note: We do not fix the random seed in the simulators here, so re-running gives slightly varying results." + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "This concludes this introduction to algorithms in Qiskit. Please check out the other algorithm tutorials in this series for both broader as well as more in depth coverage of the algorithms." + ] + }, + { + "cell_type": "code", + "execution_count": 8, + "metadata": {}, + "outputs": [ + { + "data": { + "text/html": [ + "

Version Information

Qiskit SoftwareVersion
qiskit-terra0.23.0.dev0+f52bb33
qiskit-aer0.11.1
qiskit-ignis0.7.1
qiskit-ibmq-provider0.19.2
qiskit-nature0.5.0
qiskit-optimization0.5.0
qiskit-machine-learning0.6.0
System information
Python version3.10.4
Python compilerClang 12.0.0
Python buildmain, Mar 31 2022 03:38:35
OSDarwin
CPUs4
Memory (Gb)32.0
Wed Dec 07 11:02:26 2022 CET
" + ], + "text/plain": [ + "" + ] + }, + "metadata": {}, + "output_type": "display_data" + }, + { + "data": { + "text/html": [ + "

This code is a part of Qiskit

© Copyright IBM 2017, 2022.

This code is licensed under the Apache License, Version 2.0. You may
obtain a copy of this license in the LICENSE.txt file in the root directory
of this source tree or at http://www.apache.org/licenses/LICENSE-2.0.

Any modifications or derivative works of this code must retain this
copyright notice, and modified files need to carry a notice indicating
that they have been altered from the originals.

" + ], + "text/plain": [ + "" + ] + }, + "metadata": {}, + "output_type": "display_data" + } + ], + "source": [ + "import qiskit.tools.jupyter\n", + "%qiskit_version_table\n", + "%qiskit_copyright" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [] + } + ], + "metadata": { + "kernelspec": { + "display_name": "Python 3.10.6 ('venv': venv)", + "language": "python", + "name": "python3" + }, + "language_info": { + "codemirror_mode": { + "name": "ipython", + "version": 3 + }, + "file_extension": ".py", + "mimetype": "text/x-python", + "name": "python", + "nbconvert_exporter": "python", + "pygments_lexer": "ipython3", + "version": "3.10.6" + }, + "vscode": { + "interpreter": { + "hash": "f8729fd834348017bca17aea688b306f536a675180840f7307eb909fff39c285" + } + } + }, + "nbformat": 4, + "nbformat_minor": 2 +} \ No newline at end of file diff --git a/docs/tutorials/index.rst b/docs/tutorials/index.rst new file mode 100644 index 00000000..b08c5092 --- /dev/null +++ b/docs/tutorials/index.rst @@ -0,0 +1,16 @@ +###################### +Algorithms Tutorials +###################### + + +.. nbgallery:: + :glob: + + * + + +.. Hiding - Indices and tables + :ref:`genindex` + :ref:`modindex` + :ref:`search` + diff --git a/qiskit_algorithms/__init__.py b/qiskit_algorithms/__init__.py index c9949c82..091f23f6 100644 --- a/qiskit_algorithms/__init__.py +++ b/qiskit_algorithms/__init__.py @@ -23,13 +23,6 @@ a different implementation of the same component type in order to potentially alter the behavior and outcome of the algorithm. -Quantum algorithms are run via a :class:`~qiskit_algorithms.QuantumInstance` -which must be set with the -desired backend where the algorithm's circuits will be executed and be configured with a number of -compile and runtime parameters controlling circuit compilation and execution. It ultimately uses -`Terra `__ for the actual compilation and execution of the quantum -circuits created by the algorithm and its components. - .. currentmodule:: qiskit_algorithms Algorithms @@ -92,23 +85,6 @@ eigensolvers -Legacy Eigensolvers -+++++++++++++++++++ - -These algorithms, still based on the :class:`.QuantumInstance`, are superseded -by the primitive-based versions in the section above but are still supported for now. - -.. autosummary:: - :toctree: ../stubs/ - :nosignatures: - - Eigensolver - EigensolverResult - NumPyEigensolver - VQD - VQDResult - - Time Evolvers ------------- @@ -138,23 +114,6 @@ VarQITE VarQRTE -Legacy Time Evolvers -++++++++++++++++++++ - -These algorithms, still based on the :class:`.QuantumInstance`, are superseded -by the primitive-based versions in the section above but are still supported for now. - -.. autosummary:: - :toctree: ../stubs/ - :nosignatures: - - RealEvolver - ImaginaryEvolver - TrotterQRTE - EvolutionResult - EvolutionProblem - - Variational Quantum Time Evolution ++++++++++++++++++++++++++++++++++ @@ -209,23 +168,6 @@ minimum_eigensolvers -Legacy Minimum Eigensolvers -+++++++++++++++++++++++++++ - -These algorithms, still based on the :class:`.QuantumInstance`, are superseded -by the primitive-based versions in the section above but are still supported for now. - -.. autosummary:: - :toctree: ../stubs/ - :nosignatures: - - MinimumEigensolver - MinimumEigensolverResult - NumPyMinimumEigensolver - QAOA - VQE - - Optimizers ---------- @@ -274,18 +216,6 @@ AlgorithmError -Utility methods ---------------- - -Utility methods used by algorithms. - -.. autosummary:: - :toctree: ../stubs/ - - eval_observables - estimate_observables - - Utility classes --------------- diff --git a/qiskit_algorithms/optimizers/__init__.py b/qiskit_algorithms/optimizers/__init__.py index b40144c9..942de206 100644 --- a/qiskit_algorithms/optimizers/__init__.py +++ b/qiskit_algorithms/optimizers/__init__.py @@ -35,7 +35,6 @@ :nosignatures: OptimizerResult - OptimizerSupportLevel Optimizer Minimizer diff --git a/releasenotes/notes/migrate-algrithms-from-terra-6a8aa994d1206806.yaml b/releasenotes/notes/migrate-algrithms-from-terra-6a8aa994d1206806.yaml index 0cefe6b9..af4e214b 100644 --- a/releasenotes/notes/migrate-algrithms-from-terra-6a8aa994d1206806.yaml +++ b/releasenotes/notes/migrate-algrithms-from-terra-6a8aa994d1206806.yaml @@ -1,17 +1,23 @@ --- -prelude: - - | +prelude: | Qiskit's `qiskit.algorithms` module has been superseded by this new standalone library, ``qiskit_algorithms``. + As of Qiskit's 0.25 release, active development of new algorithm features has moved to this new package. + If you're relying on :mod:`qiskit.algorithms` you should update your requirements to also include ``qiskit-algorithms`` and update the imports - from ``qiskit.algorithms`` to ``qiskit_algorithms``. If you have not yet - migrated from ``QuantumInstance``-based to primitives-based algorithms, - you should follow the migration guidelines in https://qisk.it/algo_migration, - to complete the migration of your code, as this package does not include - any deprecated algorithm function. - The decision to migrate the :mod:`~.algorithms` module to a - separate package was made to clarify the purpose of Qiskit and + from ``qiskit.algorithms`` to ``qiskit_algorithms``. + + .. note:: + + If you have not yet + migrated from ``QuantumInstance``-based to primitives-based algorithms, + you should first follow the migration guidelines in https://qisk.it/algo_migration, + to complete the migration of your code, as this package does not include + any deprecated algorithm function. + + The decision to migrate the :mod:`qiskit.algorithms` module to a + separate package was made to clarify the purpose of `Qiskit `_ and make a distinction between the tools and libraries built on top of it. diff --git a/requirements-dev.txt b/requirements-dev.txt index 9271ef3a..f8c068a4 100644 --- a/requirements-dev.txt +++ b/requirements-dev.txt @@ -1,9 +1,17 @@ coverage>=4.4.0,<7.0 matplotlib>=3.3 -black~=22.0 +jupyter +black[jupyter]~=22.0 pylint>=2.15.0 stestr>=2.0.0 -ddt>=1.2.0,!=1.4.0 +pylatexenc>=1.4 +ddt>=1.2.0,!=1.4.0,!=1.4.3 reno>=3.4.0 +Sphinx>=5.0 +nbsphinx +qiskit-sphinx-theme~=1.14.0rc1 +sphinx-design>=0.2.0 +sphinxcontrib-spelling +jupyter-sphinx discover rustworkx>=0.13 diff --git a/tools/deploy_documentation.sh b/tools/deploy_documentation.sh new file mode 100755 index 00000000..d555c715 --- /dev/null +++ b/tools/deploy_documentation.sh @@ -0,0 +1,29 @@ +#!/bin/bash + +# This code is part of a Qiskit project. +# +# (C) Copyright IBM 2023. +# +# This code is licensed under the Apache License, Version 2.0. You may +# obtain a copy of this license in the LICENSE.txt file in the root directory +# of this source tree or at http://www.apache.org/licenses/LICENSE-2.0. +# +# Any modifications or derivative works of this code must retain this +# copyright notice, and modified files need to carry a notice indicating +# that they have been altered from the originals. + +# Script for pushing the documentation to qiskit.org/ecosystem. +set -e + +curl https://downloads.rclone.org/rclone-current-linux-amd64.deb -o rclone.deb +sudo apt-get install -y ./rclone.deb + +RCLONE_CONFIG_PATH=$(rclone config file | tail -1) + +echo "show current dir: " +pwd + +# Push to qiskit.org/ecosystem +openssl aes-256-cbc -K $encrypted_rclone_key -iv $encrypted_rclone_iv -in tools/rclone.conf.enc -out $RCLONE_CONFIG_PATH -d +echo "Pushing built docs to qiskit.org/ecosystem" +rclone sync --progress --exclude locale/** ./docs/_build/html IBMCOS:qiskit-org-web-resources/ecosystem/algorithms diff --git a/tox.ini b/tox.ini index 2c2f6408..e86634ce 100644 --- a/tox.ini +++ b/tox.ini @@ -43,3 +43,15 @@ commands = stestr run {posargs} coverage3 combine coverage3 report + +[testenv:docs] +basepython = python3 +commands = + sphinx-build -j auto -W -T --keep-going -b html {posargs} docs/ docs/_build/html + +[testenv:docs-clean] +skip_install = true +deps = +allowlist_externals = rm +commands = rm -rf {toxinidir}/docs/stubs/ {toxinidir}/docs/_build +