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) proc.pulses[0].tlist = tlist proc.pulses[0].coeff = np.array([1]) 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.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)
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_dynamics(pulses=pulses) assert_allclose(noisy_pulses[2].qobj, sigmay()) assert_allclose(noisy_pulses[1].coherent_noise[0].qobj, sigmax()) 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_dynamics(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))
import matplotlib.pyplot as plt from qutip import sigmaz, sigmay from qutip.qip.device import Processor from qutip.qip.noise import RandomNoise # add control Hamiltonians processor = Processor(N=1) processor.add_control(sigmaz(), targets=0) # define pulse coefficients and tlist for all pulses processor.pulses[0].coeff = np.array([0.3, 0.5, 0.]) processor.set_all_tlist( np.array([0., np.pi / 2., 2 * np.pi / 2, 3 * np.pi / 2])) # define noise, loc and scale are keyword arguments for np.random.normal gaussnoise = RandomNoise(dt=0.01, rand_gen=np.random.normal, loc=0.00, scale=0.02) processor.add_noise(gaussnoise) # Plot the ideal pulse fig1, axis1 = processor.plot_pulses(title="Original control amplitude", figsize=(5, 3)) # Plot the noisy pulse qobjevo, _ = processor.get_qobjevo(noisy=True) noisy_coeff = qobjevo.to_list()[1][1] + qobjevo.to_list()[2][1] fig2, axis2 = processor.plot_pulses(title="Noisy control amplitude", figsize=(5, 3)) axis2[0].step(qobjevo.tlist, noisy_coeff)