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 examples to Squeezing and Displacement Embeddings #1920

Merged
merged 14 commits into from
Nov 22, 2021
Merged
Show file tree
Hide file tree
Changes from 3 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
3 changes: 2 additions & 1 deletion doc/releases/changelog-dev.md
Original file line number Diff line number Diff line change
Expand Up @@ -290,10 +290,11 @@
* Improves the Developer's Guide Testing document.
[(#1896)](https://github.com/PennyLaneAI/pennylane/pull/1896)

* Add documentation example for AngleEmbedding, BasisEmbedding and StronglyEntanglingLayers.
* Add documentation example for AngleEmbedding, BasisEmbedding, StronglyEntanglingLayers, SqueezingEmbedding and DisplacementEmbedding.
[(#1910)](https://github.com/PennyLaneAI/pennylane/pull/1910)
[(#1908)](https://github.com/PennyLaneAI/pennylane/pull/1908)
[(#1912)](https://github.com/PennyLaneAI/pennylane/pull/1912)
[(#1920)](https://github.com/PennyLaneAI/pennylane/pull/1920)

<h3>Contributors</h3>

Expand Down
52 changes: 52 additions & 0 deletions pennylane/templates/embeddings/displacement.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,58 @@ class DisplacementEmbedding(Operation):
c (float): value of the phase of all displacement gates if ``execution='amplitude'``, or
the amplitude of all displacement gates if ``execution='phase'``

Example:
antalszava marked this conversation as resolved.
Show resolved Hide resolved
antalszava marked this conversation as resolved.
Show resolved Hide resolved

Depending on the ``method`` argument, the feature vector will be encoded in the phase or the amplitude.
The argument ``c`` will define the value of the other quantity.
The default values are :math:`0.1` for ``c`` and amplitude for ``method``.
antalszava marked this conversation as resolved.
Show resolved Hide resolved

.. code-block:: python

dev = qml.device('default.gaussian', wires=3)

@qml.qnode(dev)
def circuit(feature_vector):
qml.DisplacementEmbedding(features=feature_vector, wires=range(3))
qml.QuadraticPhase(0.1, wires=1)
return qml.expval(qml.NumberOperator(wires=1))

X = [1, 2, 3]

>>> print(circuit(X))
4.1215690638748494

And, the resulting circuit is:

>>> print(qml.draw(circuit)(X))
0: ──D(1, 0.1)──────────┤
1: ──D(2, 0.1)──P(0.1)──┤ ⟨n⟩
2: ──D(3, 0.1)──────────┤

Using different parameters:

.. code-block:: python

dev = qml.device('default.gaussian', wires=3)

@qml.qnode(dev)
def circuit(feature_vector):
qml.DisplacementEmbedding(features=feature_vector, wires=range(3), method='phase', c=0.5)
qml.QuadraticPhase(0.1, wires=1)
return qml.expval(qml.NumberOperator(wires=1))

X = [1, 2, 3]

>>> print(circuit(X)
antalszava marked this conversation as resolved.
Show resolved Hide resolved
0.23401288309122226

And, the resulting circuit is:

>>> print(qml.draw(circuit)(X))
0: ──D(0.5, 1)──────────┤
1: ──D(0.5, 2)──P(0.1)──┤ ⟨n⟩
2: ──D(0.5, 3)──────────┤

Raises:
ValueError: if inputs do not have the correct format
antalszava marked this conversation as resolved.
Show resolved Hide resolved
"""
Expand Down
52 changes: 52 additions & 0 deletions pennylane/templates/embeddings/squeezing.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,58 @@ class SqueezingEmbedding(Operation):
c (float): value of the phase of all squeezing gates if ``execution='amplitude'``, or the
amplitude of all squeezing gates if ``execution='phase'``

Example:
antalszava marked this conversation as resolved.
Show resolved Hide resolved

Depending on the ``method`` argument, the feature vector will be encoded in the phase or the amplitude.
The argument ``c`` will define the value of the other quantity.
The default values are :math:`0.1` for ``c`` and amplitude for ``method``.
antalszava marked this conversation as resolved.
Show resolved Hide resolved

.. code-block:: python

dev = qml.device('default.gaussian', wires=3)

@qml.qnode(dev)
def circuit(feature_vector):
qml.SqueezingEmbedding(features=feature_vector, wires=range(3))
qml.QuadraticPhase(0.1, wires=1)
return qml.expval(qml.NumberOperator(wires=1))

X = [1, 2, 3]

>>> print(circuit(X))
13.018280763205285

And, the resulting circuit is:

>>> print(qml.draw(circuit)(X))
0: ──S(1, 0.1)──────────┤
1: ──S(2, 0.1)──P(0.1)──┤ ⟨n⟩
2: ──S(3, 0.1)──────────┤

Using different parameters:

.. code-block:: python

dev = qml.device('default.gaussian', wires=3)

@qml.qnode(dev)
def circuit(feature_vector):
qml.SqueezingEmbedding(features=feature_vector, wires=range(3), method='phase', c=0.5)
qml.QuadraticPhase(0.1, wires=1)
return qml.expval(qml.NumberOperator(wires=1))

X = [1, 2, 3]

>>> print(circuit(X)
antalszava marked this conversation as resolved.
Show resolved Hide resolved
0.22319028857312428

And, the resulting circuit is:

>>> print(qml.draw(circuit)(X))
0: ──S(0.5, 1)──────────┤
1: ──S(0.5, 2)──P(0.1)──┤ ⟨n⟩
2: ──S(0.5, 3)──────────┤

Raises:
ValueError: if inputs do not have the correct format
antalszava marked this conversation as resolved.
Show resolved Hide resolved
"""
Expand Down