Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
76 commits
Select commit Hold shift + click to select a range
2cd787a
direction elbow
KetpuntoG May 23, 2025
a31e4fa
adjoint as new direction
KetpuntoG May 23, 2025
88c20d8
move to templates
KetpuntoG May 23, 2025
9c40e7e
isort
KetpuntoG May 23, 2025
a0208f3
capture test
KetpuntoG May 23, 2025
905c6f2
coverage
KetpuntoG May 23, 2025
e63660a
changelog
KetpuntoG May 23, 2025
ca46aa0
adding thumbnail
KetpuntoG May 23, 2025
5585845
fixing thumbnail
KetpuntoG May 23, 2025
f272ac8
remove TODO
KetpuntoG May 23, 2025
278fd78
Merge branch 'master' into elbow
KetpuntoG May 27, 2025
32fe8f6
[skip-ci]
KetpuntoG May 27, 2025
c92dca0
adding test isometry
KetpuntoG May 27, 2025
27a04c6
Merge branch 'master' into elbow
KetpuntoG May 27, 2025
e4f1d0c
[skip-ci]
KetpuntoG May 28, 2025
36bc15b
Update elbow.py
KetpuntoG May 28, 2025
03bc4d2
Merge branch 'elbow' of https://github.com/PennyLaneAI/pennylane into…
KetpuntoG May 28, 2025
fbfb17f
Update test_elbow.py
KetpuntoG May 28, 2025
90a7215
refactor name
KetpuntoG May 29, 2025
013ce5f
remove elbows
KetpuntoG May 29, 2025
57f74ba
Merge branch 'master' into elbow
dwierichs May 30, 2025
4aa043d
Update pennylane/templates/subroutines/temporary_and.py
KetpuntoG May 30, 2025
af74d69
renaming image
KetpuntoG May 30, 2025
bbbbef7
adding control_values
KetpuntoG Jun 2, 2025
4e805ba
Merge branch 'master' into elbow
KetpuntoG Jun 2, 2025
78f9701
Update test_temporary_and.py
KetpuntoG Jun 3, 2025
af13a29
Update temporary_and.py
KetpuntoG Jun 3, 2025
8e509a5
Update temporary_and.py
KetpuntoG Jun 3, 2025
c4da2dc
Merge branch 'master' into elbow
KetpuntoG Jun 3, 2025
708b452
Apply suggestions from code review
KetpuntoG Jun 5, 2025
45b1183
removing resource_params + efficient compute_matrix
KetpuntoG Jun 5, 2025
b4c39c3
Apply suggestions from code review
KetpuntoG Jun 5, 2025
f38c893
Update temporary_and.py
KetpuntoG Jun 5, 2025
ef72d87
Update doc/releases/changelog-dev.md
KetpuntoG Jun 5, 2025
a3d66d5
Merge branch 'master' into elbow
KetpuntoG Jun 5, 2025
2840b0f
Update test_temporary_and.py
KetpuntoG Jun 5, 2025
f46dcb3
Merge branch 'elbow' of https://github.com/PennyLaneAI/pennylane into…
KetpuntoG Jun 5, 2025
aaf9e99
Apply suggestions from code review
KetpuntoG Jun 6, 2025
213dcc6
rename TemporaryAND + Elbow alias
KetpuntoG Jun 6, 2025
94eb116
Merge branch 'master' into elbow
KetpuntoG Jun 6, 2025
023f585
unary_iter
KetpuntoG Jun 6, 2025
78b4a87
isort
KetpuntoG Jun 6, 2025
e1b3c82
test error
KetpuntoG Jun 6, 2025
4b671aa
Update test_select.py
KetpuntoG Jun 6, 2025
cd61993
updating names temporary and
KetpuntoG Jun 6, 2025
04424a9
Update select.py
KetpuntoG Jun 6, 2025
63e5022
documentation
dwierichs Jun 10, 2025
9cede39
test xfail remove. format
dwierichs Jun 10, 2025
371770f
edge cases of empty ops
dwierichs Jun 10, 2025
13e4492
fix doc
dwierichs Jun 10, 2025
76800f3
doc fix 2
dwierichs Jun 10, 2025
7d66260
Merge branch 'master' into unary_iterator_select
dwierichs Jun 10, 2025
263e3c8
review
dwierichs Jun 12, 2025
0306534
Merge branch 'master' into unary_iterator_select
dwierichs Jun 12, 2025
b90355d
number of ops in validity check
dwierichs Jun 12, 2025
ca03abc
fixing resources (codecov)
KetpuntoG Jun 12, 2025
334b541
review
dwierichs Jun 12, 2025
27bdfab
Merge branch 'master' into unary_iterator_select
dwierichs Jun 12, 2025
ec43e81
[skip-ci] Update pennylane/templates/subroutines/select.py
dwierichs Jun 12, 2025
2fb1fe8
changelog
dwierichs Jun 12, 2025
6b5d087
Merge branch 'master' into unary_iterator_select
dwierichs Jun 12, 2025
4014657
Apply suggestions from code review
dwierichs Jun 13, 2025
3c64319
fixing bug in new decomposition system
KetpuntoG Jun 13, 2025
601bd64
Merge branch 'unary_iterator_select' of https://github.com/PennyLaneA…
KetpuntoG Jun 13, 2025
96cf090
Apply suggestions from code review
KetpuntoG Jun 13, 2025
e0f6cca
black
KetpuntoG Jun 13, 2025
a37c377
isort
KetpuntoG Jun 13, 2025
17f6ad7
Update pennylane/templates/subroutines/select.py
KetpuntoG Jun 13, 2025
0cdc302
Update select.py
KetpuntoG Jun 13, 2025
828d91f
[skip ci]
KetpuntoG Jun 13, 2025
2a4d981
Merge branch 'master' into unary_iterator_select
KetpuntoG Jun 13, 2025
bb63790
[skip ci]
KetpuntoG Jun 16, 2025
be57316
Merge branch 'master' into unary_iterator_select
KetpuntoG Jun 16, 2025
1b75a48
Update select.py
KetpuntoG Jun 16, 2025
22734ce
Merge branch 'unary_iterator_select' of https://github.com/PennyLaneA…
KetpuntoG Jun 16, 2025
68f5c8a
Merge branch 'master' into unary_iterator_select
dwierichs Jun 16, 2025
File filter

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
[skip-ci]
[skip-ci]

Co-authored-by: David Wierichs <david.wierichs@xanadu.ai>
  • Loading branch information
KetpuntoG and dwierichs authored May 27, 2025
commit 32fe8f6011274c20a5843e4f95a1a3f76b15c70f
4 changes: 2 additions & 2 deletions doc/releases/changelog-dev.md
Original file line number Diff line number Diff line change
Expand Up @@ -104,8 +104,8 @@
* Two new functions called :func:`~.math.convert_to_su2` and :func:`~.math.convert_to_su4` have been added to `qml.math`, which convert unitary matrices to SU(2) or SU(4), respectively, and optionally a global phase.
[(#7211)](https://github.com/PennyLaneAI/pennylane/pull/7211)

* A new template :class:`~.Elbow` has been added. The Elbow operator is a three-qubit gate analogous to an AND or Toffoli gate that leverages extra information
in the target wire to enable more efficient a decomposition. It is useful in context such as efficient decomposition of the :class:`~.Select` gate.
* A new template :class:`~.Elbow` has been added. The Elbow operator is a three-qubit gate equivalent to an AND, or Toffoli, gate that leverages extra information
about the target wire to enable a more efficient decomposition. It is useful for an efficient decomposition of the :class:`~.Select` template, for example.
[(#7472)](https://github.com/PennyLaneAI/pennylane/pull/7472)

* The transform `convert_to_mbqc_formalism` is added to the `ftqc` module to convert a circuit already
Expand Down
30 changes: 14 additions & 16 deletions pennylane/templates/subroutines/elbow.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Copyright 2024 Xanadu Quantum Technologies Inc.
# Copyright 2025 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.
Expand Down Expand Up @@ -26,15 +26,15 @@
class Elbow(Operation):
r"""Elbow(wires)

The Elbow operator is a three-qubit gate analogous to an AND or Toffoli gate that leverages extra information
in the target wire to enable more efficient circuit decompositions: the ``Elbow`` assumes the target qubit
is initialized in :math:`|0\rangle`, while the ``Adjoint(Elbow)`` assumes the target output in :math:`|0\rangle`.
The Elbow operator is a three-qubit gate equivalent to an AND, or Toffoli, gate that leverages extra information
about the target wire to enable more efficient circuit decompositions: the ``Elbow`` assumes the target qubit
to be initialized in :math:`|0\rangle`, while the ``Adjoint(Elbow)`` assumes the target output to be :math:`|0\rangle`.
For more details, see `Ryan Babbush et al.(2018), Fig 4 <https://arxiv.org/abs/1805.03662>`_.

.. note::

For correct usage of the operator, the user must ensure that the input or output is :math:`|0\rangle`
on the target wire when using ``Elbow`` or ``Adjoint(Elbow)`` respectively. Otherwise, the behavior could be
on the target wire when using ``Elbow`` or ``Adjoint(Elbow)``, respectively. Otherwise, the behavior could be
different from the expected AND.

**Details:**
Expand Down Expand Up @@ -108,14 +108,14 @@ def compute_matrix(): # pylint: disable=arguments-differ
**Example**

>>> print(qml.Elbow.compute_matrix())
[[1 0 0 0 0 0 0 0]
[0 -1j 0 0 0 0 0 0]
[0 0 1 0 0 0 0 0]
[0 0 0 -1j 0 0 0 0]
[0 0 0 0 1 0 0 0]
[0 0 0 0 0 1j 0 0]
[0 0 0 0 0 0 0 -1j]
[0 0 0 0 0 0 1 0]]
[[ 1.+0.j 0.+0.j 0.+0.j 0.+0.j 0.+0.j 0.+0.j 0.+0.j 0.+0.j]
[ 0.+0.j -0.-1.j 0.+0.j 0.+0.j 0.+0.j 0.+0.j 0.+0.j 0.+0.j]
[ 0.+0.j 0.+0.j 1.+0.j 0.+0.j 0.+0.j 0.+0.j 0.+0.j 0.+0.j]
[ 0.+0.j 0.+0.j 0.+0.j -0.-1.j 0.+0.j 0.+0.j 0.+0.j 0.+0.j]
[ 0.+0.j 0.+0.j 0.+0.j 0.+0.j 1.+0.j 0.+0.j 0.+0.j 0.+0.j]
[ 0.+0.j 0.+0.j 0.+0.j 0.+0.j 0.+0.j 0.+1.j 0.+0.j 0.+0.j]
[ 0.+0.j 0.+0.j 0.+0.j 0.+0.j 0.+0.j 0.+0.j 0.+0.j -0.-1.j]
[ 0.+0.j 0.+0.j 0.+0.j 0.+0.j 0.+0.j 0.+0.j 1.+0.j 0.+0.j]]
"""

return qml.math.array(
Expand All @@ -132,9 +132,7 @@ def compute_matrix(): # pylint: disable=arguments-differ
)

@staticmethod
def compute_decomposition(
wires: WiresLike,
): # pylint: disable=arguments-differ
def compute_decomposition(wires: WiresLike): # pylint: disable=arguments-differ
r"""Representation of the operator as a product of other operators (static method).

.. math:: O = O_1 O_2 \dots O_n.
Expand Down
4 changes: 1 addition & 3 deletions tests/capture/test_templates.py
Original file line number Diff line number Diff line change
Expand Up @@ -1190,9 +1190,7 @@ def qfunc():
def test_elbow(self):
"""Test the primitive bind call of Elbow."""

kwargs = {
"wires": [0, 1, 2],
}
kwargs = {"wires": [0, 1, 2]}

def qfunc():
qml.Elbow(**kwargs)
Expand Down
8 changes: 3 additions & 5 deletions tests/templates/test_subroutines/test_elbow.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Copyright 2018-2024 Xanadu Quantum Technologies Inc.
# Copyright 2025 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.
Expand Down Expand Up @@ -28,9 +28,7 @@ class TestElbow:
def test_standard_validity(self):
"""Check the operation using the assert_valid function."""

op = qml.Elbow(
wires=[0, 1, 2],
)
op = qml.Elbow(wires=[0, 1, 2])
qml.ops.functions.assert_valid(op)

def test_correctness(self):
Expand Down Expand Up @@ -78,7 +76,7 @@ def test_elbow_decompositions(self):
for rule in qml.list_decomps(qml.Elbow):
_test_decomposition_rule(qml.Elbow([0, 1, 2]), rule)

def test_matrix(self):
def test_compute_matrix(self):

matrix = qml.Elbow([0, 1, 2]).compute_matrix()
matrix_target = qml.math.array(
Expand Down
Loading