Beispiel #1
0
    def test_compose(self):
        """Test compose method."""
        # Random input test state
        rho = DensityMatrix(self.rand_rho(2))

        # UnitaryChannel evolution
        chan1 = Kraus(self.UX)
        chan2 = Kraus(self.UY)
        chan = chan1.compose(chan2)
        targ = rho @ Kraus(self.UZ)
        self.assertEqual(rho @ chan, targ)

        # 50% depolarizing channel
        chan1 = Kraus(self.depol_kraus(0.5))
        chan = chan1.compose(chan1)
        targ = rho @ Kraus(self.depol_kraus(0.75))
        self.assertEqual(rho @ chan, targ)

        # Compose different dimensions
        kraus1, kraus2 = self.rand_kraus(2, 4, 4), self.rand_kraus(4, 2, 4)
        chan1 = Kraus(kraus1)
        chan2 = Kraus(kraus2)
        targ = rho @ chan1 @ chan2
        chan = chan1.compose(chan2)
        self.assertEqual(chan.dim, (2, 2))
        self.assertEqual(rho @ chan, targ)
        chan = chan1 @ chan2
        self.assertEqual(chan.dim, (2, 2))
        self.assertEqual(rho @ chan, targ)
    def test_compose_front(self):
        """Test front compose method."""
        # Random input test state
        rho = self.rand_rho(2)

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

        # 50% depolarizing channel
        chan1 = Kraus(self.depol_kraus(0.5))
        chan = chan1.compose(chan1, front=True)
        targ = Kraus(self.depol_kraus(0.75))._evolve(rho)
        self.assertAllClose(chan._evolve(rho), targ)

        # Compose different dimensions
        kraus1, kraus2 = self.rand_kraus(2, 4, 4), self.rand_kraus(4, 2, 4)
        chan1 = Kraus(kraus1)
        chan2 = Kraus(kraus2)
        targ = chan2._evolve(chan1._evolve(rho))
        chan = chan2.compose(chan1, front=True)
        self.assertEqual(chan.dim, (2, 2))
        self.assertAllClose(chan._evolve(rho), targ)
    def test_compose_inplace(self):
        """Test inplace compose method."""
        # Random input test state
        rho = self.rand_rho(2)

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

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

        # Compose different dimensions
        kraus1, kraus2 = self.rand_kraus(2, 4, 4), self.rand_kraus(4, 2, 4)
        chan1 = Kraus(kraus1)
        chan2 = Kraus(kraus2)
        targ = chan2._evolve(chan1._evolve(rho))
        chan1.compose(chan2, inplace=True)
        self.assertEqual(chan1.dims, (2, 2))
        self.assertAllClose(chan1._evolve(rho), targ)
        chan1 = Kraus(kraus1)
        chan2 = Kraus(kraus2)
        chan1 @= chan2
        self.assertEqual(chan1.dims, (2, 2))
        self.assertAllClose(chan1._evolve(rho), targ)