amazon-braket-sdk-python icon indicating copy to clipboard operation
amazon-braket-sdk-python copied to clipboard

Addition of controlled rotation gates

Open mho291 opened this issue 7 months ago • 3 comments

Would it be possible to add support for controlled rotation gates (CRx(gate), CRy(gate), CRz(gate)) in the braket.circuits.gate module?

class CRx(Gate):
    r"""Controlled Rx gate.

    Unitary matrix:

        .. math:: \mathtt{CRx} = \begin{bmatrix}
                1 & 0 & 0                 & 0                 \\
                0 & 1 & 0                 & 0                 \\
                0 & 0 & \cos{(\phi/2)}    & -i \sin{(\phi/2)} \\
                0 & 0 & -i \sin{(\phi/2)} & \cos{(\phi/2)}    \\
                \end{bmatrix}.
    """

Thank you!

mho291 avatar May 20 '25 02:05 mho291

@mho291 Thanks for creating this issue! Just want to point out that you can do this today by passing a control parameter to the Rx gate. Something like:

Circuit().rx(1, 0.15, control=0)

rmshaffer avatar May 20 '25 13:05 rmshaffer

Thank you @rmshaffer for pointing that out!

Let me provide a little more background to my query. I'm part of the Qibo team, and one of the recent developments in partnership with @speller26 and @licedric was the addition of BraketClientBackend to our cloud backends. We've been actively using it to run stuff on the Amazon Braket backends.

In another project, we use the Controlled-RX gate as an integral part of our circuit. In this case, BraketClientBackend can't be used because of the absence of the CRx gate in the braket.circuits.gate module.

We would appreciate if you could let us know if support can be added for controlled rotation gates. I am most happy to contribute as well. :)

mho291 avatar May 21 '25 01:05 mho291

@mho291 Ryan's suggestion should still actually work; you'll have to rework braket_translation to take in targets as well, but with that, you could just add a dispatch for CRx, perhaps something like

@_translate_op.register
def _(g: qibo_gates.RX, targets):
    return Instruction(braket_gates.Rx(g.parameters[0]), targets[1], control=targets[0])

speller26 avatar Aug 21 '25 17:08 speller26