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

Add some explanation and example to circuit library documentation #7354

Merged
merged 56 commits into from
Apr 19, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
56 commits
Select commit Hold shift + click to select a range
6cba20b
Add some explanation and example to circuit library
1ucian0 Dec 6, 2021
b26898f
Merge branch 'main' of github.com:Qiskit/qiskit-terra into circuit_li…
1ucian0 Dec 9, 2021
da4d506
remove BooleanExpression
1ucian0 Dec 9, 2021
4c54f09
missing gates
1ucian0 Dec 9, 2021
ae35544
merge
1ucian0 Jan 8, 2022
46784f7
standard and directives
1ucian0 Jan 10, 2022
22954b9
Merge branch 'main' of github.com:Qiskit/qiskit-terra into circuit_li…
1ucian0 Jan 10, 2022
dd2afad
title mod
1ucian0 Jan 11, 2022
db327e3
generalized gates
1ucian0 Jan 14, 2022
a8e448e
boolean logic circuits
1ucian0 Jan 20, 2022
23963c9
Merge branch 'main' of github.com:Qiskit/qiskit-terra into circuit_li…
1ucian0 Jan 24, 2022
6b27c98
Basis Change Circuits and Arithmetic Circuits
1ucian0 Jan 24, 2022
7766026
section Amplitude Functions is duplicated. (maybe a bad merge in #5142?)
1ucian0 Jan 24, 2022
1a77edc
N-local and feature map
1ucian0 Jan 24, 2022
846b3fc
dup entry
1ucian0 Jan 24, 2022
c18e46d
Template circuits
1ucian0 Jan 24, 2022
aba5c45
Merge branch 'main' of github.com:Qiskit/qiskit-terra into circuit_li…
1ucian0 Jan 24, 2022
5346bf4
ups
1ucian0 Jan 24, 2022
54e1b8a
line too long
1ucian0 Jan 27, 2022
2411cf9
conflict solving
1ucian0 Feb 8, 2022
6c8ee83
address https:/Qiskit/qiskit-terra/pull/7354#discussion_r…
1ucian0 Feb 8, 2022
69ca4e9
addressing https:/Qiskit/qiskit-terra/pull/7354#discussio…
1ucian0 Feb 8, 2022
c45d0a3
addressing https:/Qiskit/qiskit-terra/pull/7354#discussio…
1ucian0 Feb 8, 2022
45b2bb1
Update qiskit/circuit/library/__init__.py
1ucian0 Feb 8, 2022
ecd955e
Merge branch 'circuit_library_docs' of github.com:1ucian0/qiskit-terr…
1ucian0 Feb 8, 2022
6d87bab
import to address https:/Qiskit/qiskit-terra/pull/7354#di…
1ucian0 Feb 8, 2022
923fcf1
Update qiskit/circuit/library/__init__.py
1ucian0 Feb 8, 2022
a0b96d4
Update qiskit/circuit/library/__init__.py
1ucian0 Feb 8, 2022
7a5292e
addressing https:/Qiskit/qiskit-terra/pull/7354#discussio…
1ucian0 Feb 8, 2022
8894ca9
Merge branch 'circuit_library_docs' of github.com:1ucian0/qiskit-terr…
1ucian0 Feb 8, 2022
1bcc567
conflict
1ucian0 Mar 22, 2022
7a8d5a2
Update qiskit/circuit/library/__init__.py
1ucian0 Mar 29, 2022
62f03b8
Update qiskit/circuit/library/__init__.py
1ucian0 Mar 29, 2022
f444508
Update qiskit/circuit/library/__init__.py
1ucian0 Mar 29, 2022
0a5e124
Update qiskit/circuit/library/__init__.py
1ucian0 Mar 29, 2022
c731eaf
Update qiskit/circuit/library/__init__.py
1ucian0 Mar 29, 2022
4c13265
Apply suggestions from code review
1ucian0 Mar 29, 2022
6121178
Merge branch 'main' of github.com:Qiskit/qiskit-terra into circuit_li…
1ucian0 Mar 29, 2022
c3c72d1
directives
1ucian0 Mar 29, 2022
e5c3d89
pretty colors
1ucian0 Mar 31, 2022
686ce5e
Merge branch 'main' of github.com:Qiskit/qiskit-terra into circuit_li…
1ucian0 Mar 31, 2022
5ca1e4a
undo changes in standard_gates/__init__.py
1ucian0 Mar 31, 2022
03935fc
operations
1ucian0 Mar 31, 2022
6f07f5a
Update qiskit/circuit/library/__init__.py
1ucian0 Mar 31, 2022
22b2fb6
Update qiskit/circuit/library/__init__.py
1ucian0 Mar 31, 2022
f54d3be
Apply suggestions from code review
1ucian0 Mar 31, 2022
704f6a7
Apply suggestions from code review
1ucian0 Mar 31, 2022
6e95c77
example
1ucian0 Mar 31, 2022
b19a524
Update qiskit/circuit/library/__init__.py
mtreinish Apr 11, 2022
1444edf
Merge branch 'main' into circuit_library_docs
mtreinish Apr 11, 2022
2ebc78d
Merge remote-tracking branch 'ibm/main' into circuit_library_docs
jakelishman Apr 18, 2022
7fe2b17
Fix Sphinx errors
jakelishman Apr 18, 2022
0e18d5a
Fix duplicate definitions and indentation
jakelishman Apr 18, 2022
024f810
Merge remote-tracking branch 'ibm/main' into circuit_library_docs
jakelishman Apr 18, 2022
6d468e8
Fix typo
mtreinish Apr 19, 2022
9ec4f03
Merge branch 'main' into circuit_library_docs
mergify[bot] Apr 19, 2022
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
3 changes: 0 additions & 3 deletions qiskit/circuit/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -187,9 +187,6 @@
Gate
ControlledGate
Delay
Barrier
Measure
Reset
Instruction
InstructionSet
EquivalenceLibrary
Expand Down
155 changes: 132 additions & 23 deletions qiskit/circuit/library/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,45 @@

.. currentmodule:: qiskit.circuit.library

Standard Gates
The circuit library is a collection of well-studied and valuable circuits, directives, and gates.
We call them valuable for different reasons, for instance they can serve as building blocks for
algorithms or they are circuits that we think are hard to simulate classically.

Each element can be plugged into a circuit using the :meth:`.QuantumCircuit.append`
method and so the circuit library allows users to program at higher levels of abstraction.
For example, to append a multi-controlled CNOT:

.. jupyter-execute::

from qiskit.circuit.library import MCXGate
gate = MCXGate(4)

from qiskit import QuantumCircuit
circuit = QuantumCircuit(5)
circuit.append(gate, [0, 1, 4, 2, 3])
circuit.draw('mpl')

The library is organized in several sections.

Standard gates
==============

These operations are reversible unitary gates and they all subclass
:class:`~qiskit.circuit.Gate`. As a consequence, they all have the methods
:meth:`~qiskit.circuit.Gate.to_matrix`, :meth:`~qiskit.circuit.Gate.power`,
and :meth:`~qiskit.circuit.Gate.control`, which we can generally only apply to unitary operations.

For example:

.. jupyter-execute::

from qiskit.circuit.library import XGate
gate = XGate()
print(gate.to_matrix()) # X gate
print(gate.power(1/2).to_matrix()) # √X gate
print(gate.control(1).to_matrix()) # CX (controlled X) gate
mtreinish marked this conversation as resolved.
Show resolved Hide resolved


.. autosummary::
:toctree: ../stubs/
:template: autosummary/class_no_inherited_members.rst
Expand All @@ -44,11 +80,7 @@
CZGate
HGate
IGate
MCPhaseGate
MCXGate
MCXGrayCode
MCXRecursive
MCXVChain
MSGate
PhaseGate
RCCXGate
RC3XGate
Expand Down Expand Up @@ -86,15 +118,44 @@
This summary table deliberately does not generate toctree entries; these directives are "owned"
by ``qiskit.circuit``.

Directives are operations to the quantum stack that are meant to be interpreted by the backend or
the transpiler. In general, the transpiler or backend might optionally ignore them if there is no
implementation for them.

.. autosummary::
:toctree: ../stubs/

Barrier

~qiskit.circuit.Barrier
~qiskit.circuit.Measure
~qiskit.circuit.Reset
Standard Operations
===================

Operations are non-reversible changes in the quantum state of the circuit.

.. autosummary::
:toctree: ../stubs/

Measure
Reset

Generalized Gates
=================

These "gates" (many are :class:`~qiskit.circuit.QuantumCircuit` subclasses) allow to
set the amount of qubits involved at instantiation time.


.. jupyter-execute::

from qiskit.circuit.library import Diagonal

diagonal = Diagonal([1, 1])
print(diagonal.num_qubits)

diagonal = Diagonal([1, 1, 1, 1])
print(diagonal.num_qubits)
mtreinish marked this conversation as resolved.
Show resolved Hide resolved


.. autosummary::
:toctree: ../stubs/
:template: autosummary/class_no_inherited_members.rst
Expand All @@ -104,18 +165,27 @@
MCMTVChain
Permutation
GMS
MSGate
GR
GRX
GRY
GRZ
MCPhaseGate
MCXGate
MCXGrayCode
MCXRecursive
MCXVChain
RVGate
PauliGate
LinearFunction

Boolean Logic Circuits
======================

These are :class:`~qiskit.circuit.QuantumCircuit` subclasses
that implement boolean logic operations, such as the logical
or of a set of qubit states.


.. autosummary::
:toctree: ../stubs/
:template: autosummary/class_no_inherited_members.rst
Expand All @@ -128,6 +198,10 @@
Basis Change Circuits
=====================

These circuits allow basis transformations of the qubit states. For example,
in the case of the Quantum Fourier Transform (QFT), it transforms between
the computational basis and the Fourier basis.

.. autosummary::
:toctree: ../stubs/
:template: autosummary/class_no_inherited_members.rst
Expand All @@ -137,6 +211,9 @@
Arithmetic Circuits
===================

These :class:`~qiskit.circuit.QuantumCircuit`\\ s perform classical arithmetic,
such as addition or multiplication.

Amplitude Functions
-------------------

Expand Down Expand Up @@ -209,15 +286,6 @@

ExactReciprocal

Amplitude Functions
===================

.. autosummary::
:toctree: ../stubs/
:template: autosummary/class_no_inherited_members.rst

LinearAmplitudeFunction

1ucian0 marked this conversation as resolved.
Show resolved Hide resolved
Particular Quantum Circuits
===========================

Expand All @@ -240,6 +308,10 @@
N-local circuits
================

These :class:`~qiskit.circuit.library.BlueprintCircuit` subclasses are used
as parameterized models (a.k.a. ansatzes or variational forms) in variational algorithms.
They are heavily used in near-term algorithms in e.g. Chemistry, Physics or Optimization.

.. autosummary::
:toctree: ../stubs/
:template: autosummary/class_no_inherited_members.rst
Expand All @@ -256,6 +328,9 @@
Data encoding circuits
======================

These :class:`~qiskit.circuit.library.BlueprintCircuit` encode classical
data in quantum states and are used as feature maps for classification.

.. autosummary::
:toctree: ../stubs/
:template: autosummary/class_no_inherited_members.rst
Expand All @@ -265,8 +340,38 @@
ZZFeatureMap
StatePreparation

Template circuits
=================

Templates are functions that return circuits that compute the identity. They are used at
circuit optimization where matching part of the template allows the compiler
to replace the match with the inverse of the remainder from the template.

In this example, the identity constant in a template is checked:

.. jupyter-execute::

from qiskit.circuit.library.templates import template_nct_4b_1
from qiskit.quantum_info import Operator
import numpy as np

template = template_nct_4b_1()

identity = np.identity(2 ** len(template.qubits), dtype=complex)
data = Operator(template).data
np.allclose(data, identity) # True, template_nct_4b_1 is the identity

NCT (Not-CNOT-Toffoli) template circuits
========================================
----------------------------------------

Template circuits for :class:`~qiskit.circuit.library.XGate`,
:class:`~qiskit.circuit.library.CXGate`,
and :class:`~qiskit.circuit.library.CCXGate` (Toffoli) gates.

**Reference:**
Maslov, D. and Dueck, G. W. and Miller, D. M.,
Techniques for the synthesis of reversible Toffoli networks, 2007
http://dx.doi.org/10.1145/1278349.1278355

.. autosummary::
:toctree: ../stubs/
Expand Down Expand Up @@ -295,7 +400,6 @@
templates.nct.template_nct_7c_1
templates.nct.template_nct_7d_1
templates.nct.template_nct_7e_1
templates.nct.template_nct_2a_1
templates.nct.template_nct_9a_1
templates.nct.template_nct_9c_1
templates.nct.template_nct_9c_2
Expand All @@ -321,7 +425,9 @@
templates.nct.template_nct_9d_10

Clifford template circuits
==========================
--------------------------

Template circuits over Clifford gates.

.. autosummary::
:toctree: ../stubs/
Expand All @@ -346,7 +452,9 @@
clifford_8_3

RZXGate template circuits
=========================
-------------------------

Template circuits with :class:`~qiskit.circuit.library.RZXGate`.

.. autosummary::
:toctree: ../stubs/
Expand All @@ -366,6 +474,7 @@
from ..measure import Measure
from ..reset import Reset


from .blueprintcircuit import BlueprintCircuit
from .generalized_gates import (
Diagonal,
Expand Down