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

qml.AmplitudeAmplification #5160

Merged
merged 156 commits into from
Mar 15, 2024
Merged
Show file tree
Hide file tree
Changes from 124 commits
Commits
Show all changes
156 commits
Select commit Hold shift + click to select a range
8c2af6b
Add Reflection
KetpuntoG Feb 5, 2024
da5faae
updating some docs
KetpuntoG Feb 9, 2024
39a18cf
reflection operator tests
KetpuntoG Feb 9, 2024
49d45d2
Merge branch 'master' into ReflectionOperation
KetpuntoG Feb 9, 2024
20e69af
tests
KetpuntoG Feb 9, 2024
ad20cca
Merge branch 'ReflectionOperation' of https://github.com/PennyLaneAI/…
KetpuntoG Feb 9, 2024
378c368
black
KetpuntoG Feb 9, 2024
82d58de
Update test_reflection.py
KetpuntoG Feb 9, 2024
aa40aad
Docs
KetpuntoG Feb 10, 2024
b1a4e41
queeing test
KetpuntoG Feb 12, 2024
9fabf46
Update reflection.py
KetpuntoG Feb 12, 2024
283a82a
Merge branch 'master' into ReflectionOperation
KetpuntoG Feb 12, 2024
4f1c85c
Update reflection.py
KetpuntoG Feb 17, 2024
91cab7b
Update pennylane/templates/subroutines/reflection.py
KetpuntoG Feb 17, 2024
3800fbb
Update pennylane/templates/subroutines/reflection.py
KetpuntoG Feb 17, 2024
c8032ba
Update tests/templates/test_subroutines/test_reflection.py
KetpuntoG Feb 17, 2024
ece1c63
compute_decomposition
KetpuntoG Feb 17, 2024
7729441
Merge branch 'ReflectionOperation' of https://github.com/PennyLaneAI/…
KetpuntoG Feb 17, 2024
1092c3d
test and feedback
KetpuntoG Feb 17, 2024
8d00fe5
fixing test
KetpuntoG Feb 17, 2024
cc50227
Update test_reflection.py
KetpuntoG Feb 17, 2024
f1478e6
Update test_reflection.py
KetpuntoG Feb 17, 2024
477091b
jax jit - not casting - numpy error
KetpuntoG Feb 18, 2024
8509886
Merge branch 'master' into ReflectionOperation
KetpuntoG Feb 18, 2024
de9bedc
Update reflection.py
KetpuntoG Feb 18, 2024
88bd40c
Merge branch 'ReflectionOperation' of https://github.com/PennyLaneAI/…
KetpuntoG Feb 18, 2024
fb1aea0
docs correction
KetpuntoG Feb 18, 2024
a08a6bb
Update reflection.py
KetpuntoG Feb 20, 2024
8c35834
Update reflection.py
KetpuntoG Feb 20, 2024
e502da9
Update reflection.py
KetpuntoG Feb 20, 2024
814a5d2
Update reflection.py
KetpuntoG Feb 20, 2024
dd842ef
fixing things
KetpuntoG Feb 20, 2024
d3c8457
Update doc/releases/changelog-dev.md
KetpuntoG Feb 20, 2024
ae899c1
Update pennylane/templates/subroutines/reflection.py
KetpuntoG Feb 20, 2024
4bf0acb
Update pennylane/templates/subroutines/reflection.py
KetpuntoG Feb 20, 2024
caf2236
Update reflection.py
KetpuntoG Feb 20, 2024
79c26a1
Merge branch 'ReflectionOperation' of https://github.com/PennyLaneAI/…
KetpuntoG Feb 20, 2024
56236b7
fixing issues
KetpuntoG Feb 20, 2024
5263eb1
docs
KetpuntoG Feb 20, 2024
5d00e44
pylint
KetpuntoG Feb 20, 2024
200d093
Update reflection.py
KetpuntoG Feb 20, 2024
5e7fa4f
Update test_reflection.py
KetpuntoG Feb 20, 2024
c2c1377
hyper parameteres
KetpuntoG Feb 20, 2024
ec4dec3
update reflection op
Jaybsoni Feb 21, 2024
93cc201
lint
Jaybsoni Feb 21, 2024
ad28d6c
Merge branch 'master' into ReflectionOperation
Jaybsoni Feb 21, 2024
b5ff2d0
extra test + image
KetpuntoG Feb 21, 2024
e4e8091
jay suggestions
KetpuntoG Feb 21, 2024
b5d1789
Update pennylane/templates/subroutines/reflection.py
KetpuntoG Feb 21, 2024
40a185b
Update pennylane/templates/subroutines/reflection.py
KetpuntoG Feb 21, 2024
4540d2f
Update pennylane/templates/subroutines/reflection.py
KetpuntoG Feb 21, 2024
39992c8
Merge branch 'ReflectionOperation' of https://github.com/PennyLaneAI/…
KetpuntoG Feb 21, 2024
df96942
Merge branch 'master' into ReflectionOperation
KetpuntoG Feb 21, 2024
cf340fe
pylint
KetpuntoG Feb 21, 2024
1f3726f
black
KetpuntoG Feb 21, 2024
938811e
Merge branch 'master' into ReflectionOperation
Jaybsoni Feb 22, 2024
677e4bf
typo
KetpuntoG Feb 22, 2024
ce36af7
Create amplitude_amplification.py
KetpuntoG Feb 5, 2024
ce3e865
adding template
KetpuntoG Feb 5, 2024
939e39c
Update test_amplitude_amplification.py
KetpuntoG Feb 5, 2024
93acd76
[ci-skip]
KetpuntoG Feb 6, 2024
3228c72
[ci-skip]
KetpuntoG Feb 7, 2024
3aca7a7
aux_wire to work_wire
KetpuntoG Feb 9, 2024
0891f17
black
KetpuntoG Feb 14, 2024
617d127
pylint is crying
KetpuntoG Feb 14, 2024
0ada898
disable many-arguments
KetpuntoG Feb 14, 2024
183ddb5
aux_wire -> work_wire
KetpuntoG Feb 14, 2024
60bd61f
tests
KetpuntoG Feb 14, 2024
3a549f7
Update test_amplitude_amplification.py
KetpuntoG Feb 14, 2024
b742b12
changes
KetpuntoG Feb 15, 2024
07f9240
undo changes
KetpuntoG Feb 20, 2024
040d265
undo undo
KetpuntoG Feb 20, 2024
ba9f356
new amplitude amplification based of Reflection feedback
KetpuntoG Feb 20, 2024
8869212
Update amplitude_amplification.py
KetpuntoG Feb 20, 2024
7fe4b3c
Update test_amplitude_amplification.py
KetpuntoG Feb 20, 2024
f22bca9
black
KetpuntoG Feb 20, 2024
d16f02e
fixing test
KetpuntoG Feb 20, 2024
b320ce4
Update test_amplitude_amplification.py
KetpuntoG Feb 20, 2024
1be3325
Update amplitude_amplification.py
KetpuntoG Feb 20, 2024
da9c653
Update amplitude_amplification.py
KetpuntoG Feb 21, 2024
b0ca5ec
tests
KetpuntoG Feb 21, 2024
acae46f
Reflection suggestions
KetpuntoG Feb 21, 2024
1ba154e
pylint
KetpuntoG Feb 21, 2024
338ab47
unused parameter
KetpuntoG Feb 21, 2024
ae2afc9
suggestions
KetpuntoG Feb 21, 2024
5a45bea
Update pennylane/templates/subroutines/amplitude_amplification.py
KetpuntoG Feb 21, 2024
282245f
Update pennylane/templates/subroutines/amplitude_amplification.py
KetpuntoG Feb 21, 2024
a482108
pylint
KetpuntoG Feb 21, 2024
355da3c
Update test_amplitude_amplification.py
KetpuntoG Feb 21, 2024
0d6484a
Update controlled.py
KetpuntoG Feb 22, 2024
f45c92b
Update controlled.py
KetpuntoG Feb 22, 2024
efc3afd
thumbnail
KetpuntoG Feb 22, 2024
735967d
docs
KetpuntoG Feb 22, 2024
0eee74c
typo
KetpuntoG Feb 22, 2024
8ea603f
p_min changes
KetpuntoG Feb 28, 2024
496360a
Merge branch 'master' into AmplitudeAmplification
KetpuntoG Mar 6, 2024
9b0aea1
Update pennylane/templates/subroutines/amplitude_amplification.py
KetpuntoG Mar 6, 2024
27477ed
Update pennylane/templates/subroutines/amplitude_amplification.py
KetpuntoG Mar 6, 2024
3a673bb
Update pennylane/templates/subroutines/amplitude_amplification.py
KetpuntoG Mar 6, 2024
2d4b53e
Update pennylane/templates/subroutines/amplitude_amplification.py
KetpuntoG Mar 6, 2024
2da47d6
Update pennylane/templates/subroutines/amplitude_amplification.py
KetpuntoG Mar 6, 2024
dbadec7
Update pennylane/templates/subroutines/amplitude_amplification.py
KetpuntoG Mar 6, 2024
6d56eb3
Update pennylane/templates/subroutines/amplitude_amplification.py
KetpuntoG Mar 6, 2024
56857dd
black
KetpuntoG Mar 6, 2024
30447c6
[skip-ci]
KetpuntoG Mar 7, 2024
eb8e9fc
diff tests
KetpuntoG Mar 8, 2024
cb925eb
Update test_amplitude_amplification.py
KetpuntoG Mar 8, 2024
b637ec3
black
KetpuntoG Mar 8, 2024
46430e8
simplify tests
KetpuntoG Mar 8, 2024
a2fc687
Merge branch 'master' into AmplitudeAmplification
KetpuntoG Mar 8, 2024
23b8321
Update doc/releases/changelog-dev.md
KetpuntoG Mar 8, 2024
14c5bb0
Update pennylane/templates/subroutines/amplitude_amplification.py
KetpuntoG Mar 8, 2024
9339b93
Update pennylane/templates/subroutines/amplitude_amplification.py
KetpuntoG Mar 8, 2024
5288acc
Update pennylane/templates/subroutines/amplitude_amplification.py
KetpuntoG Mar 8, 2024
458e54f
Update pennylane/templates/subroutines/amplitude_amplification.py
KetpuntoG Mar 8, 2024
f58255f
Update pennylane/templates/subroutines/amplitude_amplification.py
KetpuntoG Mar 8, 2024
404f870
Update pennylane/templates/subroutines/amplitude_amplification.py
KetpuntoG Mar 8, 2024
13725ca
Tom suggestions
KetpuntoG Mar 8, 2024
3651136
Merge branch 'AmplitudeAmplification' of https://github.com/PennyLane…
KetpuntoG Mar 8, 2024
fc7b7fa
fix tests
KetpuntoG Mar 8, 2024
463e9b1
fix torch test
KetpuntoG Mar 8, 2024
55da08a
wires test
KetpuntoG Mar 8, 2024
dbb831f
Update test_amplitude_amplification.py
KetpuntoG Mar 8, 2024
9bdcc1a
Fixing tolerance test
KetpuntoG Mar 8, 2024
0dbcb4f
Update pennylane/templates/subroutines/amplitude_amplification.py
KetpuntoG Mar 11, 2024
f444671
Update pennylane/templates/subroutines/amplitude_amplification.py
KetpuntoG Mar 11, 2024
086ad51
Update pennylane/templates/subroutines/amplitude_amplification.py
KetpuntoG Mar 11, 2024
1393cb5
Update pennylane/templates/subroutines/amplitude_amplification.py
KetpuntoG Mar 11, 2024
9f8ebf8
Update tests/templates/test_subroutines/test_amplitude_amplification.py
KetpuntoG Mar 11, 2024
d4cdcb9
Update tests/templates/test_subroutines/test_amplitude_amplification.py
KetpuntoG Mar 11, 2024
62b8c8b
Update tests/templates/test_subroutines/test_amplitude_amplification.py
KetpuntoG Mar 11, 2024
33cb1ad
Update tests/templates/test_subroutines/test_amplitude_amplification.py
KetpuntoG Mar 11, 2024
de6731a
Update tests/templates/test_subroutines/test_amplitude_amplification.py
KetpuntoG Mar 11, 2024
b5bef1b
Update tests/templates/test_subroutines/test_amplitude_amplification.py
KetpuntoG Mar 11, 2024
7310668
Soran suggestions
KetpuntoG Mar 12, 2024
c6c2410
Merge branch 'master' into AmplitudeAmplification
Jaybsoni Mar 12, 2024
c5dca39
Update test_amplitude_amplification.py
KetpuntoG Mar 12, 2024
9690a3e
Merge branch 'AmplitudeAmplification' of https://github.com/PennyLane…
KetpuntoG Mar 12, 2024
553c8b5
Update test_amplitude_amplification.py
KetpuntoG Mar 12, 2024
2468582
Update pennylane/templates/subroutines/amplitude_amplification.py
KetpuntoG Mar 12, 2024
1299702
jay review
KetpuntoG Mar 12, 2024
2faeb5b
Merge branch 'AmplitudeAmplification' of https://github.com/PennyLane…
KetpuntoG Mar 12, 2024
9eea161
Update test_amplitude_amplification.py
KetpuntoG Mar 12, 2024
09830b7
Update tests/templates/test_subroutines/test_amplitude_amplification.py
KetpuntoG Mar 12, 2024
8c6b64a
soran comments
KetpuntoG Mar 12, 2024
807c003
Merge branch 'AmplitudeAmplification' of https://github.com/PennyLane…
KetpuntoG Mar 12, 2024
ef58ab5
Merge branch 'master' into AmplitudeAmplification
KetpuntoG Mar 12, 2024
8fb287f
Merge branch 'master' into AmplitudeAmplification
KetpuntoG Mar 13, 2024
870ea10
Apply suggestions from code review
soranjh Mar 14, 2024
6047d2a
update docstring
soranjh Mar 14, 2024
9fd0853
update image
soranjh Mar 14, 2024
5994548
update changelog
soranjh Mar 14, 2024
4d161a4
update docstring
soranjh Mar 14, 2024
c056a56
update image
soranjh Mar 14, 2024
7efcde2
Merge branch 'master' into AmplitudeAmplification
soranjh Mar 14, 2024
052f99d
Merge branch 'master' into AmplitudeAmplification
soranjh Mar 15, 2024
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
Binary file added doc/_static/templates/subroutines/ampamp.png
KetpuntoG marked this conversation as resolved.
Show resolved Hide resolved
soranjh marked this conversation as resolved.
Show resolved Hide resolved
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
4 changes: 4 additions & 0 deletions doc/introduction/templates.rst
Original file line number Diff line number Diff line change
Expand Up @@ -215,6 +215,10 @@ Other useful templates which do not belong to the previous categories can be fou
:description: :doc:`Reflection Operator <../code/api/pennylane.Reflection>`
:figure: _static/templates/subroutines/reflection.png

.. gallery-item::
:description: :doc:`Amplitude Amplification <../code/api/pennylane.AmplitudeAmplification>`
:figure: _static/templates/subroutines/ampamp.png

.. gallery-item::
:description: :doc:`Interferometer <../code/api/pennylane.Interferometer>`
:figure: _static/templates/subroutines/interferometer.png
Expand Down
35 changes: 32 additions & 3 deletions doc/releases/changelog-dev.md
KetpuntoG marked this conversation as resolved.
Show resolved Hide resolved
Original file line number Diff line number Diff line change
Expand Up @@ -58,8 +58,6 @@
* Added new function `qml.operation.convert_to_legacy_H` to convert `Sum`, `SProd`, and `Prod` to `Hamiltonian` instances.
[(#5309)](https://github.com/PennyLaneAI/pennylane/pull/5309)

<h3>Improvements 🛠</h3>

* Create the `qml.Reflection` operator, useful for amplitude amplification and its variants.
[(##5159)](https://github.com/PennyLaneAI/pennylane/pull/5159)
soranjh marked this conversation as resolved.
Show resolved Hide resolved

Expand Down Expand Up @@ -89,6 +87,38 @@
tensor([1.+6.123234e-17j, 0.-6.123234e-17j], requires_grad=True)
```

* The `qml.AmplitudeAmplification` operator is introduced, which is a high-level interface for amplitude amplification and its variants.
[(#5160)](https://github.com/PennyLaneAI/pennylane/pull/5160)

```python
@qml.prod
KetpuntoG marked this conversation as resolved.
Show resolved Hide resolved
def generator(wires):
for wire in wires:
qml.Hadamard(wires = wire)

U = generator(wires = range(3))
O = qml.FlipSign(2, wires = range(3))
soranjh marked this conversation as resolved.
Show resolved Hide resolved

dev = qml.device("default.qubit")

@qml.qnode(dev)
def circuit():

generator(wires = range(3))
qml.AmplitudeAmplification(U, O, iters = 5, fixed_point=True, work_wire=3)

return qml.probs(wires = range(3))

```

```pycon
>>> print(np.round(circuit(),3))
soranjh marked this conversation as resolved.
Show resolved Hide resolved
[0.009 0.009 0.94 0.009 0.009 0.009 0.009 0.009]
KetpuntoG marked this conversation as resolved.
Show resolved Hide resolved

KetpuntoG marked this conversation as resolved.
Show resolved Hide resolved
```

<h3>Improvements 🛠</h3>
KetpuntoG marked this conversation as resolved.
Show resolved Hide resolved

* The `molecular_hamiltonian` function calls `PySCF` directly when `method='pyscf'` is selected.
[(#5118)](https://github.com/PennyLaneAI/pennylane/pull/5118)

Expand Down Expand Up @@ -132,7 +162,6 @@

This release contains contributions from (in alphabetical order):

Korbinian Kottmann,
Guillermo Alonso,
Astral Cai,
Amintor Dusko,
Expand Down
1 change: 1 addition & 0 deletions pennylane/templates/subroutines/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,3 +40,4 @@
from .trotter import TrotterProduct
from .aqft import AQFT
from .reflection import Reflection
from .amplitude_amplification import AmplitudeAmplification
184 changes: 184 additions & 0 deletions pennylane/templates/subroutines/amplitude_amplification.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,184 @@
# Copyright 2018-2024 Xanadu Quantum Technologies Inc.

# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at

# http://www.apache.org/licenses/LICENSE-2.0

# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

"""
This submodule contains the template for Amplitude Amplification.
"""

# pylint: disable-msg=too-many-arguments
import numpy as np
from pennylane.operation import Operation
import pennylane as qml


def get_fixed_point_angles(iters, p_min):
KetpuntoG marked this conversation as resolved.
Show resolved Hide resolved
KetpuntoG marked this conversation as resolved.
Show resolved Hide resolved
"""
Returns the angles needed for the fixed-point amplitude amplification algorithm.
The angles are computed using equation (11) of `arXiv:1409.3305v2 <https://arxiv.org/abs/1409.3305>`__.
"""

delta = np.sqrt(1 - p_min)
gamma = np.cos(np.arccos(1 / delta, dtype=np.complex128) / iters, dtype=np.complex128) ** -1

alphas = [
2 * np.arctan(1 / (np.tan(2 * np.pi * j / iters) * np.sqrt(1 - gamma**2)))
for j in range(1, iters // 2 + 1)
]
betas = [-alphas[-j] for j in range(1, iters // 2 + 1)]
return alphas[: iters // 2], betas[: iters // 2]


class AmplitudeAmplification(Operation):
r"""Applies amplitude amplification.

Given a state :math:`|\Psi\rangle = \alpha |\phi\rangle + \beta|\phi^{\perp}\rangle`, this subroutine amplifies the amplitude of the state :math:`|\phi\rangle`
KetpuntoG marked this conversation as resolved.
Show resolved Hide resolved

.. math::

\text{A}(U, O)|\Psi\rangle \sim |\phi\rangle
KetpuntoG marked this conversation as resolved.
Show resolved Hide resolved

The implementation of the algorithm is based on `[arXiv:quant-ph/0005055] <https://arxiv.org/abs/quant-ph/0005055>`__.
soranjh marked this conversation as resolved.
Show resolved Hide resolved
The template also unlocks advanced techniques such as fixed-point quantum search [`arXiv:1409.3305 <https://arxiv.org/abs/1409.3305>`__] and oblivious amplitude amplification [`arXiv:1312.1414 <https://arxiv.org/abs/1312.1414>`__] by reflecting on a subset of the wires.

Args:
soranjh marked this conversation as resolved.
Show resolved Hide resolved
U (Operator): operator that prepares the state :math:`|\Psi\rangle`
O (Operator): the oracle that flips the sign of the state :math:`|\phi\rangle` and does nothing to the state :math:`|\phi^{\perp}\rangle`
KetpuntoG marked this conversation as resolved.
Show resolved Hide resolved
iters (int): the number of iterations of the amplitude amplification subroutine, default is ``1``
fixed_point (bool): whether to use the fixed-point amplitude amplification algorithm, default is ``False``
work_wire (int): the auxiliary wire to use for the fixed-point amplitude amplification algorithm, default is ``None``
reflection_wires (Wires): the wires to reflect on, default is the wires of ``U``
p_min (int): the lower bound for the probability of success in fixed-point amplitude amplification, default is ``0.9``

Raises:
ValueError: work_wire must be specified if ``fixed_point == True``.
ValueError: work_wire must be different from the wires of O.
KetpuntoG marked this conversation as resolved.
Show resolved Hide resolved

**Example**

Amplification of state :math:`|2\rangle` using Grover's algorithm with 3 qubits.
Uniform superposition will be taken as :math:`|\Psi\rangle`:
KetpuntoG marked this conversation as resolved.
Show resolved Hide resolved

.. code-block::

@qml.prod
KetpuntoG marked this conversation as resolved.
Show resolved Hide resolved
def generator(wires):
for wire in wires:
qml.Hadamard(wires = wire)

U = generator(wires = range(3))
O = qml.FlipSign(2, wires = range(3))

dev = qml.device("default.qubit")

@qml.qnode(dev)
def circuit():

generator(wires = range(3))
qml.AmplitudeAmplification(U, O, iters = 5, fixed_point=True, work_wire=3)

return qml.probs(wires = range(3))

.. code-block:: pycon

>>> print(np.round(circuit(),3))
[0.009 0.009 0.94 0.009 0.009 0.009 0.009 0.009]
trbromley marked this conversation as resolved.
Show resolved Hide resolved
KetpuntoG marked this conversation as resolved.
Show resolved Hide resolved
"""

def _flatten(self):
data = (self.hyperparameters["U"], self.hyperparameters["O"])
metadata = tuple(
value for key, value in self.hyperparameters.items() if key not in ["O", "U"]
)
return data, metadata

@classmethod
def _unflatten(cls, data, metadata):
U, O = (data[0], data[1])
return cls(
U,
O,
iters=metadata[0],
fixed_point=metadata[1],
work_wire=metadata[2],
p_min=metadata[3],
reflection_wires=metadata[4],
)
KetpuntoG marked this conversation as resolved.
Show resolved Hide resolved

def __init__(
self, U, O, iters=1, fixed_point=False, work_wire=None, p_min=0.9, reflection_wires=None
):
self._name = "AmplitudeAmplification"
if reflection_wires is None:
reflection_wires = U.wires

if fixed_point and work_wire is None:
raise qml.wires.WireError("work_wire must be specified if fixed_point == True.")

if fixed_point and len(O.wires + qml.wires.Wires(work_wire)) == len(O.wires):
raise ValueError("work_wire must be different from the wires of O.")

if fixed_point:
wires = U.wires + qml.wires.Wires(work_wire)
else:
wires = U.wires

self.hyperparameters["U"] = U
self.hyperparameters["O"] = O
self.hyperparameters["iters"] = iters
self.hyperparameters["fixed_point"] = fixed_point
self.hyperparameters["work_wire"] = work_wire
self.hyperparameters["p_min"] = p_min
self.hyperparameters["reflection_wires"] = qml.wires.Wires(reflection_wires)

super().__init__(wires=wires)

# pylint:disable=arguments-differ
@staticmethod
def compute_decomposition(**kwargs):
U = kwargs["U"]
O = kwargs["O"]
iters = kwargs["iters"]
fixed_point = kwargs["fixed_point"]
work_wire = kwargs["work_wire"]
p_min = kwargs["p_min"]
reflection_wires = kwargs["reflection_wires"]

ops = []

if fixed_point:
alphas, betas = get_fixed_point_angles(iters, p_min)

for iter in range(iters // 2):
ops.append(qml.Hadamard(wires=work_wire))
ops.append(qml.ctrl(O, control=work_wire))
ops.append(qml.Hadamard(wires=work_wire))
ops.append(qml.PhaseShift(betas[iter], wires=work_wire))
ops.append(qml.Hadamard(wires=work_wire))
ops.append(qml.ctrl(O, control=work_wire))
ops.append(qml.Hadamard(wires=work_wire))

ops.append(qml.Reflection(U, -alphas[iter], reflection_wires=reflection_wires))
else:
for _ in range(iters):
ops.append(O)
ops.append(qml.Reflection(U, np.pi, reflection_wires=reflection_wires))

return ops

# pylint: disable=protected-access
KetpuntoG marked this conversation as resolved.
Show resolved Hide resolved
def queue(self, context=qml.QueuingManager):
for op in [self.hyperparameters["U"], self.hyperparameters["O"]]:
context.remove(op)
context.append(self)
return self
Loading
Loading