Skip to content

Commit

Permalink
decompose CRY
Browse files Browse the repository at this point in the history
  • Loading branch information
renatomello committed Dec 17, 2024
1 parent 3713524 commit 8b28b83
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 0 deletions.
8 changes: 8 additions & 0 deletions src/qibo/gates/gates.py
Original file line number Diff line number Diff line change
Expand Up @@ -1384,6 +1384,14 @@ def __init__(self, q0, q1, theta, trainable=True):
def qasm_label(self):
return "cry"

def decompose(self) -> List[Gate]:
"""Decomposition of :math:`\\text{CRY}` gate."""
from qibo.transpiler.decompositions import ( # pylint: disable=C0415
standard_decompositions,
)

return standard_decompositions(self)


class CRZ(_CRn_):
"""Controlled rotation around the Z-axis for the Bloch sphere.
Expand Down
10 changes: 10 additions & 0 deletions src/qibo/transpiler/decompositions.py
Original file line number Diff line number Diff line change
Expand Up @@ -493,6 +493,16 @@ def _decomposition_generalized_RBS(ins, outs, theta, phi, controls):
standard_decompositions.add(
gates.CSXDG, [gates.H(1), gates.CU1(0, 1, -np.pi / 2), gates.H(1)]
)
standard_decompositions.add(
gates.CRY,
lambda gate: [
gates.RY(1, gate.parameters[0] / 4),
gates.CNOT(0, 1),
gates.RY(1, -gate.parameters[0] / 2),
gates.CNOT(0, 1),
gates.RY(1, gate.parameters[0] / 4),
],
)
standard_decompositions.add(
gates.RZX,
lambda gate: [
Expand Down
6 changes: 6 additions & 0 deletions tests/test_gates_gates.py
Original file line number Diff line number Diff line change
Expand Up @@ -722,6 +722,12 @@ def test_cun(backend, name, params):

backend.assert_allclose(final_state, target_state, atol=1e-6)

if name == "CRY":
decomposition = Circuit(2)
decomposition.add(gate.decompose())
decomposition = decomposition.unitary(backend=backend)
backend.assert_allclose(decomposition, _matrix)


def test_swap(backend):
final_state = apply_gates(backend, [gates.X(1), gates.SWAP(0, 1)], nqubits=2)
Expand Down

0 comments on commit 8b28b83

Please sign in to comment.