Ejemplo n.º 1
0
    def _decompose_outside_control(self,
                                   control: raw_types.QubitId,
                                   near_target: raw_types.QubitId,
                                   far_target: raw_types.QubitId
                                   ) -> op_tree.OP_TREE:
        """A decomposition assuming one of the targets is in the middle.

        control: ───T──────@────────@───@────────────@────────────────
                           │        │   │            │
           near: ─X─T──────X─@─T^-1─X─@─X────@─X^0.5─X─@─X^0.5────────
                  │          │        │      │         │
            far: ─@─Y^-0.5─T─X─T──────X─T^-1─X─T^-1────X─S─────X^-0.5─
        """
        a, b, c = control, near_target, far_target

        t = common_gates.T
        sweep_abc = [common_gates.CNOT(a, b),
                     common_gates.CNOT(b, c)]

        yield common_gates.CNOT(c, b)
        yield common_gates.Y(c)**-0.5
        yield t(a), t(b), t(c)
        yield sweep_abc
        yield t(b) ** -1, t(c)
        yield sweep_abc
        yield t(c) ** -1
        yield sweep_abc
        yield t(c) ** -1
        yield common_gates.X(b)**0.5
        yield sweep_abc
        yield common_gates.S(c)
        yield common_gates.X(b)**0.5
        yield common_gates.X(c)**-0.5
Ejemplo n.º 2
0
    def test_valid_powers(self):
        gcirq = cirq.Circuit()
        qreg = [cirq.LineQubit(i) for i in range(5)]

        gcirq.append(g_ops.X(qreg[0])**-3.67)
        gcirq.append(g_ops.Y(qreg[0])**7.9)
        gcirq.append(g_ops.Z(qreg[0])**sqrt(5))
        gcirq.append(g_ops.S(qreg[0])**-pi)
        gcirq.append(g_ops.T(qreg[0])**(sqrt(7) - pi))
        gcirq.append(g_ops.SWAP(qreg[0], qreg[1])**-0.5)
        gcirq.append(g_ops.ISWAP(qreg[0], qreg[1])**16.0)

        result = cirq_to_qlm(gcirq)
        for i, op in enumerate(result.ops):
            name, params = extract_syntax(result.gateDic[op.gate],
                                          result.gateDic)
            if i == 0:
                self.assertEqual(params[0], -3.67 * pi)
            elif i == 1:
                self.assertEqual(params[0], 7.9 * pi)
            elif i == 2:
                self.assertEqual(params[0], sqrt(5) * pi)
            elif i == 3:
                self.assertEqual(params[0], -pi * pi / 2)
            elif i == 4:
                self.assertEqual(params[0], (sqrt(7) - pi) * pi / 4)
            else:
                continue