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

Top level import of templates #1779

Merged
merged 33 commits into from
Oct 22, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
33 commits
Select commit Hold shift + click to select a range
c3d59e4
remove newlines in docstring (#1647)
thisac Sep 13, 2021
ed6082a
Merge branch 'v0.18.0-rc0' of https://github.com/PennyLaneAI/pennylane
rmoyard Sep 13, 2021
e80b914
Merge branch 'master' of https://github.com/PennyLaneAI/pennylane
rmoyard Sep 14, 2021
101fb1d
Merge branch 'master' of https://github.com/PennyLaneAI/pennylane
rmoyard Sep 17, 2021
1cc5e1e
Merge branch 'master' of https://github.com/PennyLaneAI/pennylane
rmoyard Sep 21, 2021
03f3d6b
Merge branch 'master' of https://github.com/PennyLaneAI/pennylane
rmoyard Sep 22, 2021
10a26c8
Merge branch 'master' of https://github.com/PennyLaneAI/pennylane
rmoyard Sep 27, 2021
b5d5c0b
Merge branch 'master' of https://github.com/PennyLaneAI/pennylane
rmoyard Sep 28, 2021
0f6395f
Merge branch 'master' of https://github.com/PennyLaneAI/pennylane
rmoyard Oct 5, 2021
75a735f
Merge branch 'master' of https://github.com/PennyLaneAI/pennylane
rmoyard Oct 7, 2021
66576c8
Merge branch 'master' of https://github.com/PennyLaneAI/pennylane
rmoyard Oct 8, 2021
0c8b99d
Merge branch 'master' of https://github.com/PennyLaneAI/pennylane
rmoyard Oct 8, 2021
fb2056f
Merge branch 'master' of https://github.com/PennyLaneAI/pennylane
rmoyard Oct 12, 2021
5569f57
Merge branch 'master' of https://github.com/PennyLaneAI/pennylane
rmoyard Oct 13, 2021
ad68cbf
Merge branch 'master' of https://github.com/PennyLaneAI/pennylane
rmoyard Oct 14, 2021
3a6b9dd
Merge branch 'master' of https://github.com/PennyLaneAI/pennylane
rmoyard Oct 20, 2021
180c5f3
Template top level.
rmoyard Oct 20, 2021
66cba63
Changelog.
rmoyard Oct 20, 2021
fca8cd3
QFT in defautl qubit and default mixed
rmoyard Oct 20, 2021
b58bc45
Black and qaoaembedding
rmoyard Oct 20, 2021
baffc93
Typos layers.
rmoyard Oct 20, 2021
a34c0a0
Update documentation template.
rmoyard Oct 20, 2021
ba50f7b
Typo.
rmoyard Oct 20, 2021
4e72681
Update index.rst
rmoyard Oct 20, 2021
7130696
Change references for templates.
rmoyard Oct 20, 2021
196416d
Typo rst.
rmoyard Oct 20, 2021
2c464db
Template doc.
rmoyard Oct 20, 2021
3f31ab4
Move templates.
rmoyard Oct 20, 2021
ecf4e12
Typo
rmoyard Oct 20, 2021
a977bf7
Typo.
rmoyard Oct 20, 2021
fa3ee24
Change documentation from review.
rmoyard Oct 21, 2021
99903de
Update from pull.
rmoyard Oct 21, 2021
79f306b
Merge branch 'master' into templates_toplvl
antalszava Oct 22, 2021
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
6 changes: 0 additions & 6 deletions doc/code/pennylane.templates.template.rst

This file was deleted.

81 changes: 0 additions & 81 deletions doc/code/qml_templates.rst

This file was deleted.

2 changes: 1 addition & 1 deletion doc/directives.py
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ def run(self):
if 'link' in self.options:
link = self.options['link']
else:
link = "code/qml_templates"
link = "introduction/templates"

except FileNotFoundError as e:
print(e)
Expand Down
1 change: 0 additions & 1 deletion doc/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -214,7 +214,6 @@ PennyLane is **free** and **open source**, released under the Apache License, Ve
code/qml_qchem
code/qml_qnn
code/qml_tape
code/qml_templates
code/qml_transforms
code/qml_circuit_drawer
code/qml_utils
Expand Down
2 changes: 1 addition & 1 deletion doc/introduction/interfaces/numpy.rst
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,7 @@ and two non-differentiable arguments ``data`` and ``wires``:

@qml.qnode(dev)
def circuit(weights, data, wires):
qml.templates.AmplitudeEmbedding(data, wires=wires, normalize=True)
qml.AmplitudeEmbedding(data, wires=wires, normalize=True)
qml.RX(weights[0], wires=wires[0])
qml.RY(weights[1], wires=wires[1])
qml.RZ(weights[2], wires=wires[2])
Expand Down
2 changes: 1 addition & 1 deletion doc/introduction/interfaces/tf.rst
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@ To include non-differentiable data arguments, simply use ``tf.constant``:

@qml.qnode(dev, interface='tf')
def circuit3(weights, data):
qml.templates.AmplitudeEmbedding(data, normalize=True, wires=[0, 1])
qml.AmplitudeEmbedding(data, normalize=True, wires=[0, 1])
qml.RX(weights[0], wires=0)
qml.RY(weights[1], wires=1)
qml.CNOT(wires=[0, 1])
Expand Down
6 changes: 3 additions & 3 deletions doc/introduction/interfaces/torch.rst
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ To include non-differentiable data arguments, simply set ``requires_grad=False``

@qml.qnode(dev, interface='torch')
def circuit3(weights, data):
qml.templates.AmplitudeEmbedding(data, normalize=True, wires=[0, 1])
qml.AmplitudeEmbedding(data, normalize=True, wires=[0, 1])
qml.RX(weights[0], wires=0)
qml.RY(weights[1], wires=1)
qml.CNOT(wires=[0, 1])
Expand Down Expand Up @@ -238,12 +238,12 @@ the GPU will dominate performance; for less than 15 wires, the GPU will probably

dev = qml.device('default.qubit', wires=n_wires)

params_shape = qml.templates.StronglyEntanglingLayers.shape(n_layers=n_layers, n_wires=n_wires)
params_shape = qml.StronglyEntanglingLayers.shape(n_layers=n_layers, n_wires=n_wires)
params = torch.rand(params_shape)

@qml.qnode(dev, interface='torch', diff_method="backprop")
def circuit_cuda(params):
qml.templates.StronglyEntanglingLayers(params, wires=range(n_wires))
qml.StronglyEntanglingLayers(params, wires=range(n_wires))
return qml.expval(qml.PauliZ(0))

>>> import timeit
Expand Down
76 changes: 43 additions & 33 deletions doc/introduction/templates.rst
Original file line number Diff line number Diff line change
Expand Up @@ -25,37 +25,37 @@ Hence, they usually take a data sample such as a feature vector as an argument.
trainable parameters, and they may be constructed from repeated layers.

.. customgalleryitem::
:link: ../code/api/pennylane.templates.embeddings.AmplitudeEmbedding.html
:link: ../code/api/pennylane.AmplitudeEmbedding.html
rmoyard marked this conversation as resolved.
Show resolved Hide resolved
:description: AmplitudeEmbedding
:figure: ../_static/templates/embeddings/amplitude.png

.. customgalleryitem::
:link: ../code/api/pennylane.templates.embeddings.AngleEmbedding.html
:link: ../code/api/pennylane.AngleEmbedding.html
:description: AngleEmbedding
:figure: ../_static/templates/embeddings/angle.png

.. customgalleryitem::
:link: ../code/api/pennylane.templates.embeddings.BasisEmbedding.html
:link: ../code/api/pennylane.BasisEmbedding.html
:description: BasisEmbedding
:figure: ../_static/templates/embeddings/basis.png

.. customgalleryitem::
:link: ../code/api/pennylane.templates.embeddings.DisplacementEmbedding.html
:link: ../code/api/pennylane.DisplacementEmbedding.html
:description: DisplacementEmbedding
:figure: ../_static/templates/embeddings/displacement.png

.. customgalleryitem::
:link: ../code/api/pennylane.templates.embeddings.IQPEmbedding.html
:link: ../code/api/pennylane.IQPEmbedding.html
:description: IQPEmbedding
:figure: ../_static/templates/embeddings/iqp.png

.. customgalleryitem::
:link: ../code/api/pennylane.templates.embeddings.QAOAEmbedding.html
:link: ../code/api/pennylane.QAOAEmbedding.html
:description: QAOAEmbedding
:figure: ../_static/templates/embeddings/qaoa.png

.. customgalleryitem::
:link: ../code/api/pennylane.templates.embeddings.SqueezingEmbedding.html
:link: ../code/api/pennylane.SqueezingEmbedding.html
:description: SqueezingEmbedding
:figure: ../_static/templates/embeddings/squeezing.png

Expand All @@ -68,49 +68,47 @@ trainable parameters, and they may be constructed from repeated layers.
Layer templates
---------------

.. currentmodule:: pennylane.templates.layers

Layer architectures define sequences of trainable gates that are repeated like the layers in a
neural network. Note that arbitrary templates or operations can also be repeated using the
:func:`~pennylane.layer` function.

.. customgalleryitem::
:link: ../code/api/pennylane.templates.layers.CVNeuralNetLayers.html
:link: ../code/api/pennylane.CVNeuralNetLayers.html
:description: CVNeuralNetLayers
:figure: ../_static/templates/layers/cvqnn.png

.. customgalleryitem::
:link: ../code/api/pennylane.templates.layers.RandomLayers.html
:link: ../code/api/pennylane.RandomLayers.html
:description: RandomLayers
:figure: ../_static/templates/layers/random.png

.. customgalleryitem::
:link: ../code/api/pennylane.templates.layers.StronglyEntanglingLayers.html
:link: ../code/api/pennylane.StronglyEntanglingLayers.html
:description: StronglyEntanglingLayers
:figure: ../_static/templates/layers/strongly_entangling.png

.. customgalleryitem::
:link: ../code/api/pennylane.templates.layers.SimplifiedTwoDesign.html
:link: ../code/api/pennylane.SimplifiedTwoDesign.html
:description: SimplifiedTwoDesign
:figure: ../_static/templates/layers/simplified_two_design.png

.. customgalleryitem::
:link: ../code/api/pennylane.templates.layers.BasicEntanglerLayers.html
:link: ../code/api/pennylane.BasicEntanglerLayers.html
:description: BasicEntanglerLayers
:figure: ../_static/templates/layers/basic_entangler.png

.. customgalleryitem::
:link: ../code/api/pennylane.templates.layers.ParticleConservingU2.html
:link: ../code/api/pennylane.ParticleConservingU2.html
:description: ParticleConservingU2
:figure: ../_static/templates/layers/particle_conserving_u2.png

.. customgalleryitem::
:link: ../code/api/pennylane.templates.layers.ParticleConservingU1.html
:link: ../code/api/pennylane.ParticleConservingU1.html
:description: ParticleConservingU1
:figure: ../_static/templates/layers/particle_conserving_u1_thumbnail.png

.. customgalleryitem::
:link: ../code/api/pennylane.templates.layers.GateFabric.html
:link: ../code/api/pennylane.GateFabric.html
:description: GateFabric
:figure: ../_static/templates/layers/gate_fabric_layer.png

Expand All @@ -128,17 +126,17 @@ state. In contrast to embeddings that can in principle be used anywhere in a cir
state preparation is typically used as the first operation.

.. customgalleryitem::
:link: ../code/api/pennylane.templates.state_preparations.BasisStatePreparation.html
:link: ../code/api/pennylane.BasisStatePreparation.html
:description: BasisStatePreparation
:figure: ../_static/templates/state_preparations/basis.png

.. customgalleryitem::
:link: ../code/api/pennylane.templates.state_preparations.MottonenStatePreparation.html
:link: ../code/api/pennylane.MottonenStatePreparation.html
:description: MottonnenStatePrep
:figure: ../_static/templates/state_preparations/mottonen.png

.. customgalleryitem::
:link: ../code/api/pennylane.templates.state_preparations.ArbitraryStatePreparation.html
:link: ../code/api/pennylane.ArbitraryStatePreparation.html
:description: ArbitraryStatePreparation
:figure: ../_static/templates/subroutines/arbitrarystateprep.png

Expand All @@ -154,67 +152,67 @@ Other subroutines
Other useful templates which do not belong to the previous categories can be found here.

.. customgalleryitem::
:link: ../code/api/pennylane.templates.subroutines.GroverOperator.html
:link: ../code/api/pennylane.GroverOperator.html
:description: Grover Diffusion Operator
:figure: ../_static/templates/subroutines/grover.svg

.. customgalleryitem::
:link: ../code/api/pennylane.templates.subroutines.Interferometer.html
:link: ../code/api/pennylane.Interferometer.html
:description: Interferometer
:figure: ../_static/templates/subroutines/interferometer.png

.. customgalleryitem::
:link: ../code/api/pennylane.templates.subroutines.SingleExcitationUnitary.html
:link: ../code/api/pennylane.SingleExcitationUnitary.html
:description: SingleExcitationUnitary
:figure: ../_static/templates/subroutines/single_excitation_unitary.png

.. customgalleryitem::
:link: ../code/api/pennylane.templates.subroutines.DoubleExcitationUnitary.html
:link: ../code/api/pennylane.DoubleExcitationUnitary.html
:description: DoubleExcitationUnitary
:figure: ../_static/templates/subroutines/double_excitation_unitary.png

.. customgalleryitem::
:link: ../code/api/pennylane.templates.subroutines.UCCSD.html
:link: ../code/api/pennylane.UCCSD.html
:description: UCCSD
:figure: ../_static/templates/subroutines/uccsd.png

.. customgalleryitem::
:link: ../code/api/pennylane.templates.subroutines.kUpCCGSD.html
:link: ../code/api/pennylane.kUpCCGSD.html
:description: k-UpCCGSD
:figure: ../_static/templates/subroutines/kupccgsd.png

.. customgalleryitem::
:link: ../code/api/pennylane.templates.subroutines.ArbitraryUnitary.html
:link: ../code/api/pennylane.ArbitraryUnitary.html
:description: ArbitraryUnitary
:figure: ../_static/templates/subroutines/arbitraryunitary.png

.. customgalleryitem::
:link: ../code/api/pennylane.templates.subroutines.ApproxTimeEvolution.html
:link: ../code/api/pennylane.ApproxTimeEvolution.html
:description: ApproxTimeEvolution
:figure: ../_static/templates/subroutines/approx_time_evolution.png

.. customgalleryitem::
:link: ../code/api/pennylane.templates.subroutines.Permute.html
:link: ../code/api/pennylane.Permute.html
:description: Permute
:figure: ../_static/templates/subroutines/permute.png

.. customgalleryitem::
:link: ../code/api/pennylane.templates.subroutines.QuantumPhaseEstimation.html
:link: ../code/api/pennylane.QuantumPhaseEstimation.html
:description: QuantumPhaseEstimation
:figure: ../_static/templates/subroutines/qpe.svg

.. customgalleryitem::
:link: ../code/api/pennylane.templates.subroutines.QuantumMonteCarlo.html
:link: ../code/api/pennylane.QuantumMonteCarlo.html
:description: QuantumMonteCarlo
:figure: ../_static/templates/subroutines/qmc.svg

.. customgalleryitem::
:link: ../code/api/pennylane.templates.subroutines.AllSinglesDoubles.html
:link: ../code/api/pennylane.AllSinglesDoubles.html
:description: AllSinglesDoubles
:figure: ../_static/templates/subroutines/all_singles_doubles.png

.. customgalleryitem::
:link: ../code/api/pennylane.templates.subroutines.QFT.html
:link: ../code/api/pennylane.QFT.html
:description: QuantumFourierTransform
:figure: ../_static/templates/subroutines/qft.svg

Expand Down Expand Up @@ -346,3 +344,15 @@ As suggested by the camel-case naming, built-in templates in PennyLane are class
data structures than functions, since they can define properties and methods of templates (such as gradient
recipes or matrix representations). Consult the :ref:`Contributing templates<contributing_templates>`
page to learn how to code up your own template class, and how to add it to the PennyLane template library.

Layering Function
-----------------

The layer function creates a new template by repeatedly applying a sequence of quantum
gates to a set of wires. You can import this function both via
``qml.layer`` and ``qml.templates.layer``.

.. autosummary::

pennylane.layer

3 changes: 3 additions & 0 deletions doc/releases/changelog-dev.md
Original file line number Diff line number Diff line change
Expand Up @@ -387,6 +387,9 @@

<h3>Improvements</h3>

* Templates are now top level imported and can be used directly e.g. `qml.QFT(wires=0)`.
[(#1779)](https://github.com/PennyLaneAI/pennylane/pull/1779)

* Operators now have a `label` method to determine how they are drawn. This will
eventually override the `RepresentationResolver` class.
[(#1678)](https://github.com/PennyLaneAI/pennylane/pull/1678)
Expand Down
6 changes: 5 additions & 1 deletion pennylane/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,10 +42,14 @@
from pennylane.io import *
from pennylane.measure import density_matrix, expval, probs, sample, state, var
from pennylane.ops import *
from pennylane.templates import broadcast, layer, template
from pennylane.templates.embeddings import *
from pennylane.templates.layers import *
from pennylane.templates.state_preparations import *
from pennylane.templates.subroutines import *
from pennylane.optimize import *
from pennylane import qaoa
from pennylane.qnode import QNode, qnode
from pennylane.templates import broadcast, layer, template
from pennylane.transforms import (
adjoint,
batch_params,
Expand Down
Loading