コード例 #1
0
    def testNoise(self):
        """
        Test for Processor with noise
        """
        # setup and fidelity without noise
        init_state = qubit_states(2, [0, 0, 0, 0])
        tlist = np.array([0., np.pi / 2.])
        a = destroy(2)
        proc = Processor(N=2)
        proc.add_control(sigmax(), targets=1, label="sx")
        proc.set_all_coeffs({"sx": np.array([1.])})
        proc.set_all_tlist(tlist)
        result = proc.run_state(init_state=init_state)
        assert_allclose(fidelity(result.states[-1],
                                 qubit_states(2, [0, 1, 0, 0])),
                        1,
                        rtol=1.e-7)

        # decoherence noise
        dec_noise = DecoherenceNoise([0.25 * a], targets=1)
        proc.add_noise(dec_noise)
        result = proc.run_state(init_state=init_state)
        assert_allclose(fidelity(result.states[-1],
                                 qubit_states(2, [0, 1, 0, 0])),
                        0.981852,
                        rtol=1.e-3)

        # white random noise
        proc.model._noise = []
        white_noise = RandomNoise(0.2, np.random.normal, loc=0.1, scale=0.1)
        proc.add_noise(white_noise)
        result = proc.run_state(init_state=init_state)
コード例 #2
0
ファイル: test_noise.py プロジェクト: qutip/qutip-qip
    def test_random_noise(self):
        """
        Test for the white noise
        """
        tlist = np.array([1, 2, 3, 4, 5, 6])
        coeff = np.array([1, 1, 1, 1, 1, 1])
        dummy_qobjevo = QobjEvo(sigmaz(), tlist=tlist)
        mean = 0.
        std = 0.5
        pulses = [
            Pulse(sigmaz(), 0, tlist, coeff),
            Pulse(sigmax(), 0, tlist, coeff * 2),
            Pulse(sigmay(), 0, tlist, coeff * 3)
        ]

        # random noise with operators from proc_qobjevo
        gaussnoise = RandomNoise(dt=0.1,
                                 rand_gen=np.random.normal,
                                 loc=mean,
                                 scale=std)
        noisy_pulses, systematic_noise = \
            gaussnoise.get_noisy_pulses(pulses=pulses)
        assert_allclose(noisy_pulses[2].qobj.full(), sigmay().full())
        assert_allclose(noisy_pulses[1].coherent_noise[0].qobj.full(),
                        sigmax().full())
        assert_allclose(len(noisy_pulses[0].coherent_noise[0].tlist),
                        len(noisy_pulses[0].coherent_noise[0].coeff))

        # random noise with dt and other random number generator
        pulses = [
            Pulse(sigmaz(), 0, tlist, coeff),
            Pulse(sigmax(), 0, tlist, coeff * 2),
            Pulse(sigmay(), 0, tlist, coeff * 3)
        ]
        gaussnoise = RandomNoise(lam=0.1, dt=0.2, rand_gen=np.random.poisson)
        assert_(gaussnoise.rand_gen is np.random.poisson)
        noisy_pulses, systematic_noise = \
            gaussnoise.get_noisy_pulses(pulses=pulses)
        assert_allclose(noisy_pulses[0].coherent_noise[0].tlist,
                        np.linspace(1, 6,
                                    int(5 / 0.2) + 1))
        assert_allclose(noisy_pulses[1].coherent_noise[0].tlist,
                        np.linspace(1, 6,
                                    int(5 / 0.2) + 1))
        assert_allclose(noisy_pulses[2].coherent_noise[0].tlist,
                        np.linspace(1, 6,
                                    int(5 / 0.2) + 1))