Ejemplo n.º 1
0
    def test_1d_fit(self):

        D = {'I': ch.QuantumChannel(np.array(np.eye(4, dtype=complex)))}
        MA = SchWARMA.SchWMA([], [s_z], D)

        alpha = np.sqrt(.00001)
        sigma = 1.  #1./2.

        arg = lambda t: alpha**2 * sigma * (np.sqrt(np.pi) * t * sp.erf(
            t / sigma) + sigma * (np.exp(-t**2 / sigma**2) - 1))
        args = np.exp(-2 * np.array([arg(t) for t in range(100)]))
        args = (1. - args) / 2.

        MA.fit([args], 5)
        self.assertEqual(5, len(MA.models[0].b))
        self.assertEqual(0, len(MA.models[0].a))
        MA.init_ARMAs()
        MA['I']

        #Note now I have brackets on the second argument
        MA.fit([args], [7])
        self.assertEqual(7, len(MA.models[0].b))
        self.assertEqual(0, len(MA.models[0].a))
        MA.init_ARMAs()
        L = MA['I'].liouvillian()

        #Known structure of \sigma_z arma
        self.assertEqual(la.norm(L - np.diag(np.diag(L))), 0.0)
        self.assertEqual(L[0, 0], L[3, 3])
        self.assertAlmostEqual(L[0, 0], 1., 9)
        self.assertEqual(L[1, 1], np.conj(L[2, 2]))
Ejemplo n.º 2
0
    def test_init(self):

        ARMAS = [
            SchWARMA.ARMA([],
                          np.random.randn(np.random.randint(5)) + 2)
            for _ in range(3)
        ]
        D = {'I': ch.QuantumChannel(np.array(np.eye(4, dtype=complex)))}
        MA = SchWARMA.SchWMA(ARMAS, [s_x, s_y, s_z], D)
Ejemplo n.º 3
0
    def test_3d_fit(self):
        D = {'I': ch.QuantumChannel(np.array(np.eye(4, dtype=complex)))}
        MA = SchWARMA.SchWMA([], [s_z], D)

        alpha = np.sqrt(.00001)
        sigma = 1.  #1./2.

        arg = lambda t: alpha**2 * sigma * (np.sqrt(np.pi) * t * sp.erf(
            t / sigma) + sigma * (np.exp(-t**2 / sigma**2) - 1))
        args = np.exp(-2 * np.array([arg(t) for t in range(100)]))
        args = (1. - args) / 2.

        #Note now I have brackets on the second argument
        MA.fit([args, args, args], [3, 5, 7])
        self.assertEqual(3, len(MA.models[0].b))
        self.assertEqual(5, len(MA.models[1].b))
        self.assertEqual(7, len(MA.models[2].b))
        MA.init_ARMAs()
        L = MA['I']
Ejemplo n.º 4
0
    def test_avg(self):

        D = {'I': ch.QuantumChannel(np.array(np.eye(4, dtype=complex)))}
        MA = SchWARMA.SchWMA([], [s_z], D)

        alpha = np.sqrt(.00001)
        sigma = 1.  #1./2.

        arg = lambda t: alpha**2 * sigma * (np.sqrt(np.pi) * t * sp.erf(
            t / sigma) + sigma * (np.exp(-t**2 / sigma**2) - 1))
        args = np.exp(-2 * np.array([arg(t) for t in range(100)]))
        #args = (1.-args)/2.

        MA.fit([(1. - args) / 2.], 5)
        self.assertEqual(5, len(MA.models[0].b))
        self.assertEqual(0, len(MA.models[0].a))
        MA.init_ARMAs()
        MA['I']

        L1 = MA.avg(1,
                    [ch.QuantumChannel(s_z, 'unitary').choi()]).liouvillian()
        tL1 = np.array(np.eye(4, dtype=complex))
        tL1[1, 1] = args[1]
        tL1[2, 2] = args[1]

        self.assertAlmostEqual(la.norm(L1 - tL1), 0.0, 6)

        L2 = MA.avg(10,
                    [ch.QuantumChannel(s_z, 'unitary').choi()]).liouvillian()
        tL2 = np.eye(4, dtype=complex)
        tL2[1, 1] = args[10]
        tL2[2, 2] = args[10]

        self.assertAlmostEqual(la.norm(L2 - tL2), 0.0, 5)
        #Not a great test, but should be true
        self.assertLess(la.norm(L2 - tL2), la.norm(tL1**10 - L2))