Пример #1
0
 def test_coherent_noise(self):
     """
     Test for pulse genration with coherent noise.
     """
     coeff = np.array([0.1, 0.2, 0.3, 0.4])
     tlist = np.array([0., 1., 2., 3.])
     ham = sigmaz()
     pulse1 = Pulse(ham, 1, tlist, coeff)
     # Add coherent noise with the same tlist
     pulse1.add_coherent_noise(sigmay(), 0, tlist, coeff)
     assert_allclose(
         pulse1.get_ideal_qobjevo(2)(0).full(),
         tensor(identity(2), sigmaz()).full() * 0.1)
     assert_(len(pulse1.coherent_noise) == 1)
     noise_qu, c_ops = pulse1.get_noisy_qobjevo(2)
     assert_allclose(c_ops, [])
     assert_allclose(pulse1.get_full_tlist(), np.array([0., 1., 2., 3.]))
Пример #2
0
    def test_noisy_pulse(self):
        """
        Test for lindblad noise and different tlist
        """
        coeff = np.array([0.1, 0.2, 0.3, 0.4])
        tlist = np.array([0., 1., 2., 3.])
        ham = sigmaz()
        pulse1 = Pulse(ham, 1, tlist, coeff)
        # Add coherent noise and lindblad noise with different tlist
        pulse1.spline_kind = "step_func"
        tlist_noise = np.array([0., 1., 2.5, 3.])
        coeff_noise = np.array([0., 0.5, 0.1, 0.5])
        pulse1.add_coherent_noise(sigmay(), 0, tlist_noise, coeff_noise)
        tlist_noise2 = np.array([0., 0.5, 2, 3.])
        coeff_noise2 = np.array([0., 0.1, 0.2, 0.3])
        pulse1.add_lindblad_noise(sigmax(), 1, coeff=True)
        pulse1.add_lindblad_noise(sigmax(),
                                  0,
                                  tlist=tlist_noise2,
                                  coeff=coeff_noise2)

        assert_allclose(
            pulse1.get_ideal_qobjevo(2)(0).full(),
            tensor(identity(2), sigmaz()).full() * 0.1)
        noise_qu, c_ops = pulse1.get_noisy_qobjevo(2)
        assert_allclose(pulse1.get_full_tlist(),
                        np.array([0., 0.5, 1., 2., 2.5, 3.]))
        if parse_version(qutip.__version__) >= parse_version('5.dev'):
            expected = QobjEvo([[
                tensor(identity(2), sigmaz()),
                np.array([0.1, 0.1, 0.2, 0.3, 0.3, 0.4])
            ],
                                [
                                    tensor(sigmay(), identity(2)),
                                    np.array([0., 0., 0.5, 0.5, 0.1, 0.5])
                                ]],
                               tlist=np.array([0., 0.5, 1., 2., 2.5, 3.]),
                               order=0)
        else:
            expected = QobjEvo([[
                tensor(identity(2), sigmaz()),
                np.array([0.1, 0.1, 0.2, 0.3, 0.3, 0.4])
            ],
                                [
                                    tensor(sigmay(), identity(2)),
                                    np.array([0., 0., 0.5, 0.5, 0.1, 0.5])
                                ]],
                               tlist=np.array([0., 0.5, 1., 2., 2.5, 3.]),
                               args={"_step_func_coeff": True})
        _compare_qobjevo(noise_qu, expected, 0, 3)

        for c_op in c_ops:
            try:
                isconstant = c_op.isconstant
            except AttributeError:
                isconstant = (len(c_op.ops) == 0)
            if isconstant:
                assert_allclose(
                    c_op(0).full(),
                    tensor(identity(2), sigmax()).full())
            else:
                if parse_version(qutip.__version__) >= parse_version('5.dev'):
                    expected = QobjEvo([
                        tensor(sigmax(), identity(2)),
                        np.array([0., 0.1, 0.1, 0.2, 0.2, 0.3])
                    ],
                                       tlist=np.array(
                                           [0., 0.5, 1., 2., 2.5, 3.]),
                                       order=0)
                else:
                    expected = QobjEvo([
                        tensor(sigmax(), identity(2)),
                        np.array([0., 0.1, 0.1, 0.2, 0.2, 0.3])
                    ],
                                       tlist=np.array(
                                           [0., 0.5, 1., 2., 2.5, 3.]),
                                       args={"_step_func_coeff": True})
                _compare_qobjevo(c_op, expected, 0, 3)