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

FlipSign doc #3219

Merged
merged 16 commits into from
Oct 31, 2022
Merged
Show file tree
Hide file tree
Changes from all 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: 3 additions & 0 deletions doc/releases/changelog-dev.md
Original file line number Diff line number Diff line change
Expand Up @@ -335,6 +335,9 @@ Users can specify the control wires as well as the values to control the operati
* The code block in the usage details of the UCCSD template is updated.
[(#3140)](https://github.com/PennyLaneAI/pennylane/pull/3140)

* The example of the `FlipSign` template is updated.
[(#3219)](https://github.com/PennyLaneAI/pennylane/pull/3219)

<h3>Bug fixes</h3>

* Users no longer see unintuitive errors when inputing sequences to `qml.Hermitian`.
Expand Down
49 changes: 24 additions & 25 deletions pennylane/templates/subroutines/flip_sign.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,50 +20,49 @@


class FlipSign(Operation):
r"""FlipSign operator flips the sign for a given basic state.
r"""Flips the sign of a given basis state.

In a nutshell, this class perform the following operation:
This template performs the following operation:

FlipSign(n) :math:`|m\rangle = -|m\rangle` if :math:`m = n`

FlipSign(n) :math:`|m\rangle = |m\rangle` if :math:`m \not = n`,

where n is the basic state to flip and m is the input.
where n is the basis state to flip and m is the input.

Args:
n (array[int] or int): binary array or integer value representing the state to flip the sign
wires (array[int]): number of wires that the operator acts on
n (array[int] or int): binary array or integer value representing the state on which to
flip the sign
wires (array[int]): wires that the template acts on


.. details::
:title: Usage Details
**Example**

The template is used inside a qnode.
The number of shots has to be explicitly set on the device when using sample-based measurements:
This template changes the sign of the basis state passed as an argument.
In this example, when passing the element ``[1, 0]``, we will change the sign of the state :math:`|10\rangle`.
We could alternatively pass the integer ``2`` and get the same result since its binary representation is ``[1, 0]``.

.. code-block:: python
.. code-block:: python

basis_state = [1, 0]
basis_state = [1, 0]

dev = qml.device("default.qubit", wires=2)
dev = qml.device("default.qubit", wires=2)

KetpuntoG marked this conversation as resolved.
Show resolved Hide resolved
@qml.qnode(dev)
def circuit():
for wire in list(range(2)):
qml.Hadamard(wires=wire)
qml.FlipSign(basis_state, wires=list(range(2)))
return qml.state()

KetpuntoG marked this conversation as resolved.
Show resolved Hide resolved
@qml.qnode(dev)
def circuit():
for wire in list(range(2)):
qml.Hadamard(wires=wire)
qml.FlipSign(basis_state, wires=list(range(2)))
return qml.state()
circuit()

The result for the above circuit is:

circuit()
.. code-block:: python

The result for the above circuit is:

.. code-block:: python

>>> print(circuit())
[ 0.5+0.j 0.5+0.j -0.5+0.j 0.5+0.j]
>>> print(circuit())
[ 0.5+0.j 0.5+0.j -0.5+0.j 0.5+0.j]

"""

Expand Down