コード例 #1
0
ファイル: __init__.py プロジェクト: Blueqat/Blueqat
def margolus(c: Circuit, c0: int, c1: int) -> Circuit:
    """Simplified Toffoli gate implementation by Margolus.

    This gate is also as know as relative Toffoli gate.
    It's almost as same as Toffoli gate, but only relative phases are different.
    Refer https://arxiv.org/abs/quant-ph/0312225v1 for details.
    (Remarks: It's also described in Nielsen & Chuang, Exercise 4.26.)"""
    c.ry(math.pi * 0.25)[t].cx[c1, t].ry(math.pi * 0.25)[t].cx[c0, t]
    c.ry(math.pi * -0.25)[t].cx[c1, t].ry(math.pi * -0.25)[t]
    return c
コード例 #2
0
ファイル: __init__.py プロジェクト: Blueqat/Blueqat
def mcry_gray(c: Circuit, theta: float, ctrl: Sequence[int],
              target: int) -> Circuit:
    """A macro of multi controlled RY gate."""
    n_ctrl = len(ctrl)
    if n_ctrl == 0:
        return c.ry(theta)[target]
    angles = [theta / 2**(n_ctrl - 1), -theta / 2**(n_ctrl - 1)]
    for c0, c1, parity in gen_gray_controls(n_ctrl):
        if c0 >= 0:
            c.cx[ctrl[c0], ctrl[c1]]
        c.cry(angles[parity])[ctrl[c1], target]
    return c