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 TestGetObjevo(self): tlist = np.array([1, 2, 3, 4, 5, 6], dtype=float) coeff = np.array([1, 1, 1, 1, 1, 1], dtype=float) processor = Processor(N=1) processor.add_control(sigmaz()) processor.pulses[0].tlist = tlist processor.pulses[0].coeff = coeff # without noise unitary_qobjevo, _ = processor.get_qobjevo( args={"test": True}, noisy=False) assert_allclose(unitary_qobjevo.ops[0].qobj, sigmaz()) assert_allclose(unitary_qobjevo.tlist, tlist) assert_allclose(unitary_qobjevo.ops[0].coeff, coeff[0]) assert_(unitary_qobjevo.args["test"], msg="Arguments not correctly passed on") # with decoherence noise dec_noise = DecoherenceNoise( c_ops=sigmax(), coeff=coeff, tlist=tlist) processor.add_noise(dec_noise) assert_equal(unitary_qobjevo.to_list(), processor.get_qobjevo(noisy=False)[0].to_list()) noisy_qobjevo, c_ops = processor.get_qobjevo( args={"test": True}, noisy=True) assert_(noisy_qobjevo.args["_step_func_coeff"], msg="Spline type not correctly passed on") assert_(noisy_qobjevo.args["test"], msg="Arguments not correctly passed on") assert_(sigmaz() in [pair[0] for pair in noisy_qobjevo.to_list()]) assert_equal(c_ops[0].ops[0].qobj, sigmax()) assert_equal(c_ops[0].tlist, tlist) # with amplitude noise processor = Processor(N=1, spline_kind="cubic") processor.add_control(sigmaz()) tlist = np.linspace(1, 6, int(5/0.2)) coeff = np.random.rand(len(tlist)) processor.pulses[0].tlist = tlist processor.pulses[0].coeff = coeff amp_noise = ControlAmpNoise(coeff=coeff, tlist=tlist) processor.add_noise(amp_noise) noisy_qobjevo, c_ops = processor.get_qobjevo( args={"test": True}, noisy=True) assert_(not noisy_qobjevo.args["_step_func_coeff"], msg="Spline type not correctly passed on") assert_(noisy_qobjevo.args["test"], msg="Arguments not correctly passed on") assert_equal(len(noisy_qobjevo.ops), 2) assert_equal(sigmaz(), noisy_qobjevo.ops[0].qobj) assert_allclose(coeff, noisy_qobjevo.ops[0].coeff, rtol=1.e-10)
def test_decoherence_noise(self): """ Test for the decoherence noise """ tlist = np.array([1, 2, 3, 4, 5, 6]) coeff = np.array([1, 1, 1, 1, 1, 1]) # Time-dependent decnoise = DecoherenceNoise(sigmaz(), coeff=coeff, tlist=tlist, targets=[1]) dims = [2] * 2 pulses, systematic_noise = decnoise.get_noisy_dynamics(dims=dims) noisy_qu, c_ops = systematic_noise.get_noisy_qobjevo(dims=dims) assert_allclose(c_ops[0].ops[0].qobj, tensor(qeye(2), sigmaz())) assert_allclose(c_ops[0].ops[0].coeff, coeff) assert_allclose(c_ops[0].tlist, tlist) # Time-indenpendent and all qubits decnoise = DecoherenceNoise(sigmax(), all_qubits=True) pulses, systematic_noise = decnoise.get_noisy_dynamics(dims=dims) noisy_qu, c_ops = systematic_noise.get_noisy_qobjevo(dims=dims) c_ops = [qu.cte for qu in c_ops] assert_(tensor([qeye(2), sigmax()]) in c_ops) assert_(tensor([sigmax(), qeye(2)]) in c_ops) # Time-denpendent and all qubits decnoise = DecoherenceNoise(sigmax(), all_qubits=True, coeff=coeff * 2, tlist=tlist) pulses, systematic_noise = decnoise.get_noisy_dynamics(dims=dims) noisy_qu, c_ops = systematic_noise.get_noisy_qobjevo(dims=dims) assert_allclose(c_ops[0].ops[0].qobj, tensor(sigmax(), qeye(2))) assert_allclose(c_ops[0].ops[0].coeff, coeff * 2) assert_allclose(c_ops[0].tlist, tlist) assert_allclose(c_ops[1].ops[0].qobj, tensor(qeye(2), sigmax()))