def test_compose_front(self):
        """Test deprecated front compose method."""
        # Random input test state
        rho_init = DensityMatrix(self.rand_rho(2))

        # UnitaryChannel evolution
        chan1 = Stinespring(self.UX)
        chan2 = Stinespring(self.UY)
        chan = chan1.compose(chan2, front=True)
        rho_targ = rho_init @ Stinespring(self.UZ)
        self.assertEqual(rho_init.evolve(chan), rho_targ)

        # 50% depolarizing channel
        chan1 = Stinespring(self.depol_stine(0.5))
        chan = chan1.compose(chan1, front=True)
        rho_targ = rho_init @ Stinespring(self.depol_stine(0.75))
        self.assertEqual(rho_init.evolve(chan), 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)
        rho_targ = rho_init @ chan1 @ chan2
        chan = chan2.compose(chan1, front=True)
        self.assertEqual(chan.dim, (2, 2))
        self.assertEqual(rho_init.evolve(chan), rho_targ)
Example #2
0
    def test_compose_front(self):
        """Test front compose method."""
        # Random input test state
        rho = self.rand_rho(2)

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

        # 50% depolarizing channel
        chan1 = Stinespring(self.depol_stine(0.5))
        chan = chan1.compose(chan1, 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))
        chan = chan2.compose(chan1, front=True)
        self.assertEqual(chan.dims, (2, 2))
        self.assertAllClose(chan._evolve(rho), targ)