Skip to content

Commit

Permalink
Docs reflection (#5605)
Browse files Browse the repository at this point in the history
Making more clear Reflection docs

---------

Co-authored-by: Thomas R. Bromley <49409390+trbromley@users.noreply.github.com>
Co-authored-by: Astral Cai <astral.cai@xanadu.ai>
Co-authored-by: Isaac De Vlugt <34751083+isaacdevlugt@users.noreply.github.com>
  • Loading branch information
4 people authored May 3, 2024
1 parent d5f436e commit 88e87f3
Showing 1 changed file with 23 additions and 13 deletions.
36 changes: 23 additions & 13 deletions pennylane/templates/subroutines/reflection.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,9 @@
class Reflection(Operation):
r"""Apply a reflection about a state :math:`|\Psi\rangle`.
Given an operator :math:`U` such that :math:`|\Psi\rangle = U|0\rangle` and a reflection angle :math:`\alpha`,
this template creates the operation:
This operator works by providing an operation, :math:`U`, that prepares the desired state, :math:`\vert \Psi \rangle`,
that we want to reflect about. We can also provide a reflection angle :math:`\alpha`
to define the operation in a more generic form:
.. math::
Expand All @@ -46,28 +47,37 @@ class Reflection(Operation):
.. code-block::
@qml.prod
def generator(wires):
qml.Hadamard(wires=wires)
U = generator(wires=0)
U = qml.Hadamard(wires=0)
dev = qml.device(‘default.qubit’)
dev = qml.device('default.qubit')
@qml.qnode(dev)
def circuit():
# Initialize to the state |1>
qml.PauliX(wires=0)
# Apply the reflection
qml.Reflection(U)
return qml.state()
>>> circuit()
tensor([1.+6.123234e-17j, 0.-6.123234e-17j], requires_grad=True)
For cases when :math:`U` comprises many operations, you can create a quantum
function containing each operation, one per line, then decorate the quantum
function with ``@qml.prod``:
.. code-block::
@qml.prod
def U(wires):
qml.Hadamard(wires=wires[0])
qml.RY(0.1, wires=wires[1])
@qml.qnode(dev)
def circuit():
qml.Reflection(U([0, 1]))
return qml.state()
>>> circuit()
tensor([-0.00249792-6.13852933e-17j, 0.04991671+3.05651685e-18j,
0.99750208+6.10793866e-17j, 0.04991671+3.05651685e-18j], requires_grad=True)
.. details::
:title: Theory
Expand Down

0 comments on commit 88e87f3

Please sign in to comment.