Example #1
0
    def test_v_vdag_v(self):
        """Figure 4.8 Nielson, Chuang."""

        # Make Toffoli out of V = sqrt(X).
        #
        v = ops.Vgate()  # Could be any unitary, in principle!
        ident = ops.Identity()
        cnot = ops.Cnot(0, 1)

        o0 = ident * ops.ControlledU(1, 2, v)
        c2 = cnot * ident
        o2 = (ident * ops.ControlledU(1, 2, v.adjoint()))
        o4 = ops.ControlledU(0, 2, v)
        final = o4 @ c2 @ o2 @ c2 @ o0

        v2 = v @ v
        cv1 = ops.ControlledU(1, 2, v2)
        cv0 = ops.ControlledU(0, 1, cv1)

        self.assertTrue(final.is_close(cv0))
Example #2
0
 def v(self, idx: int):
     self.apply1(ops.Vgate(), idx, 'v')
Example #3
0
 def cv_adj(self, idx0: int, idx1: int):
     self.applyc(ops.Vgate().adjoint(), idx0, idx1, 'cv_adj')
Example #4
0
 def cv(self, idx0: int, idx1: int):
     self.applyc(ops.Vgate(), idx0, idx1, 'cv')
Example #5
0
    def test_v_gate(self):
        """V^2 == X."""

        s = ops.Vgate() @ ops.Vgate()
        self.assertTrue(s.is_close(ops.PauliX()))
Example #6
0
  def test_v_gate(self):
    """Test that V^2 == X."""

    t = ops.Vgate()
    self.assertTrue(t(t).is_close(ops.PauliX()))
Example #7
0
 def cv_adj(self, idx0, idx1):
     self.apply_controlled(ops.Vgate().adjoint(), idx0, idx1, 'cv_adj')
Example #8
0
 def cv(self, idx0, idx1):
     self.apply_controlled(ops.Vgate(), idx0, idx1, 'cv')