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))
def v(self, idx: int): self.apply1(ops.Vgate(), idx, 'v')
def cv_adj(self, idx0: int, idx1: int): self.applyc(ops.Vgate().adjoint(), idx0, idx1, 'cv_adj')
def cv(self, idx0: int, idx1: int): self.applyc(ops.Vgate(), idx0, idx1, 'cv')
def test_v_gate(self): """V^2 == X.""" s = ops.Vgate() @ ops.Vgate() self.assertTrue(s.is_close(ops.PauliX()))
def test_v_gate(self): """Test that V^2 == X.""" t = ops.Vgate() self.assertTrue(t(t).is_close(ops.PauliX()))
def cv_adj(self, idx0, idx1): self.apply_controlled(ops.Vgate().adjoint(), idx0, idx1, 'cv_adj')
def cv(self, idx0, idx1): self.apply_controlled(ops.Vgate(), idx0, idx1, 'cv')