Пример #1
0
    def test_tensor_inplace(self):
        """Test inplace tensor method."""
        rho0, rho1 = np.diag([1, 0]), np.diag([0, 1])
        rho_init = np.kron(rho0, rho0)

        # X \otimes I
        chan1 = Stinespring(self.matI)
        chan2 = Stinespring(self.matX)
        chan2.tensor(chan1, inplace=True)
        rho_targ = np.kron(rho1, rho0)
        self.assertEqual(chan2.dims, (4, 4))
        self.assertAllClose(chan2._evolve(rho_init), rho_targ)

        # I \otimes X
        chan1 = Stinespring(self.matI)
        chan2 = Stinespring(self.matX)
        chan1.tensor(chan2, inplace=True)
        rho_targ = np.kron(rho0, rho1)
        self.assertEqual(chan1.dims, (4, 4))
        self.assertAllClose(chan1._evolve(rho_init), rho_targ)

        # Completely depolarizing
        chan = Stinespring(self.depol_stine(1))
        chan.tensor(chan, inplace=True)
        rho_targ = np.diag([1, 1, 1, 1]) / 4
        self.assertEqual(chan.dims, (4, 4))
        self.assertAllClose(chan._evolve(rho_init), rho_targ)
Пример #2
0
    def test_multiply(self):
        """Test multiply method."""
        # Random initial state and Stinespring ops
        rho = self.rand_rho(2)
        val = 0.5
        stine1, stine2 = self.rand_matrix(16, 2), self.rand_matrix(16, 2)

        # Single Stinespring set
        chan1 = Stinespring(stine1, input_dim=2, output_dim=4)
        targ = val * chan1._evolve(rho)
        chan = chan1.multiply(val)
        self.assertAllClose(chan._evolve(rho), targ)
        chan = val * chan1
        self.assertAllClose(chan._evolve(rho), targ)
        chan = chan1 * val
        self.assertAllClose(chan._evolve(rho), targ)

        # Double Stinespring set
        chan2 = Stinespring((stine1, stine2), input_dim=2, output_dim=4)
        targ = val * chan2._evolve(rho)
        chan = chan2.multiply(val)
        self.assertAllClose(chan._evolve(rho), targ)
        chan = val * chan2
        self.assertAllClose(chan._evolve(rho), targ)
        chan = chan2 * val
        self.assertAllClose(chan._evolve(rho), targ)
Пример #3
0
    def test_compose_front_inplace(self):
        """Test inplace front compose method."""
        # Random input test state
        rho = self.rand_rho(2)

        # UnitaryChannel evolution
        chan1 = Stinespring(self.matX)
        chan2 = Stinespring(self.matY)
        chan1.compose(chan2, inplace=True, front=True)
        targ = Stinespring(self.matZ)._evolve(rho)
        self.assertAllClose(chan1._evolve(rho), targ)

        # 50% depolarizing channel
        chan = Stinespring(self.depol_stine(0.5))
        chan.compose(chan, inplace=True, front=True)
        targ = Stinespring(self.depol_stine(0.75))._evolve(rho)
        self.assertAllClose(chan._evolve(rho), targ)

        # Compose different dimensions
        stine1, stine2 = self.rand_matrix(16, 2), self.rand_matrix(8, 4)
        chan1 = Stinespring(stine1, input_dim=2, output_dim=4)
        chan2 = Stinespring(stine2, input_dim=4, output_dim=2)
        targ = chan2._evolve(chan1._evolve(rho))
        chan2.compose(chan1, inplace=True, front=True)
        self.assertEqual(chan2.dims, (2, 2))
        self.assertAllClose(chan2._evolve(rho), targ)
Пример #4
0
    def test_compose(self):
        """Test compose method."""
        # Random input test state
        rho = self.rand_rho(2)

        # UnitaryChannel evolution
        chan1 = Stinespring(self.UX)
        chan2 = Stinespring(self.UY)
        chan = chan1.compose(chan2)
        targ = Stinespring(self.UZ)._evolve(rho)
        self.assertAllClose(chan._evolve(rho), targ)

        # 50% depolarizing channel
        chan1 = Stinespring(self.depol_stine(0.5))
        chan = chan1.compose(chan1)
        targ = Stinespring(self.depol_stine(0.75))._evolve(rho)
        self.assertAllClose(chan._evolve(rho), targ)

        # Compose different dimensions
        stine1, stine2 = self.rand_matrix(16, 2), self.rand_matrix(8, 4)
        chan1 = Stinespring(stine1, input_dims=2, output_dims=4)
        chan2 = Stinespring(stine2, input_dims=4, output_dims=2)
        targ = chan2._evolve(chan1._evolve(rho))
        chan = chan1.compose(chan2)
        self.assertEqual(chan.dim, (2, 2))
        self.assertAllClose(chan._evolve(rho), targ)
        chan = chan1 @ chan2
        self.assertEqual(chan.dim, (2, 2))
        self.assertAllClose(chan._evolve(rho), targ)
Пример #5
0
    def test_power_inplace(self):
        """Test inplace power method."""
        # 10% depolarizing channel
        rho = np.diag([1, 0])
        p_id = 0.9
        chan = Stinespring(self.depol_stine(1 - p_id))

        # Compose 3 times
        p_id3 = p_id**3
        targ3a = chan._evolve(chan._evolve(chan._evolve(rho)))
        targ3b = Stinespring(self.depol_stine(1 - p_id3))._evolve(rho)
        chan.power(3, inplace=True)
        self.assertAllClose(chan._evolve(rho), targ3a)
        self.assertAllClose(chan._evolve(rho), targ3b)
Пример #6
0
    def test_subtract(self):
        """Test subtract method."""
        # Random input test state
        rho = self.rand_rho(2)
        stine1, stine2 = self.rand_matrix(16, 2), self.rand_matrix(16, 2)

        # Random Single-Stinespring maps
        chan1 = Stinespring(stine1, input_dim=2, output_dim=4)
        chan2 = Stinespring(stine2, input_dim=2, output_dim=4)
        targ = chan1._evolve(rho) - chan2._evolve(rho)
        chan = chan1.subtract(chan2)
        self.assertAllClose(chan._evolve(rho), targ)
        chan = chan1 - chan2
        self.assertAllClose(chan._evolve(rho), targ)

        # Random Single-Stinespring maps
        chan = Stinespring((stine1, stine2))
        targ = 0 * chan._evolve(rho)
        chan = chan.subtract(chan)
        self.assertAllClose(chan._evolve(rho), targ)
Пример #7
0
    def test_add(self):
        """Test add method."""
        # Random input test state
        rho = self.rand_rho(2)
        stine1, stine2 = self.rand_matrix(16, 2), self.rand_matrix(16, 2)

        # Random Single-Stinespring maps
        chan1 = Stinespring(stine1, input_dims=2, output_dims=4)
        chan2 = Stinespring(stine2, input_dims=2, output_dims=4)
        targ = chan1._evolve(rho) + chan2._evolve(rho)
        chan = chan1.add(chan2)
        self.assertAllClose(chan._evolve(rho), targ)
        chan = chan1 + chan2
        self.assertAllClose(chan._evolve(rho), targ)

        # Random Single-Stinespring maps
        chan = Stinespring((stine1, stine2))
        targ = 2 * chan._evolve(rho)
        chan = chan.add(chan)
        self.assertAllClose(chan._evolve(rho), targ)
Пример #8
0
    def test_evolve(self):
        """Test evolve method."""
        input_psi = [0, 1]
        input_rho = [[0, 0], [0, 1]]

        # Identity channel
        chan = Stinespring(self.matI)
        target_psi = np.array([0, 1])
        self.assertAllClose(chan._evolve(input_psi), target_psi)
        self.assertAllClose(chan._evolve(np.array(input_psi)), target_psi)
        target_rho = np.array([[0, 0], [0, 1]])
        self.assertAllClose(chan._evolve(input_rho), target_rho)
        self.assertAllClose(chan._evolve(np.array(input_rho)), target_rho)

        # Hadamard channel
        mat = np.array([[1, 1], [1, -1]]) / np.sqrt(2)
        chan = Stinespring(mat)
        target_psi = np.array([1, -1]) / np.sqrt(2)
        self.assertAllClose(chan._evolve(input_psi), target_psi)
        self.assertAllClose(chan._evolve(np.array(input_psi)), target_psi)
        target_rho = np.array([[1, -1], [-1, 1]]) / 2
        self.assertAllClose(chan._evolve(input_rho), target_rho)
        self.assertAllClose(chan._evolve(np.array(input_rho)), target_rho)

        # Completely depolarizing channel
        chan = Stinespring(self.depol_stine(1))
        target_rho = np.eye(2) / 2
        self.assertAllClose(chan._evolve(input_psi), target_rho)
        self.assertAllClose(chan._evolve(np.array(input_psi)), target_rho)
        self.assertAllClose(chan._evolve(input_rho), target_rho)
        self.assertAllClose(chan._evolve(np.array(input_rho)), target_rho)