Ejemplo n.º 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)
Ejemplo n.º 2
0
 def testMultiLevelSystem(self):
     """
     Test for processor with multi-level system
     """
     N = 2
     proc = Processor(N=N, dims=[2, 3])
     proc.add_control(tensor(sigmaz(), rand_dm(3, density=1.)), label="sz0")
     proc.set_all_coeffs({"sz0": np.array([1, 2])})
     proc.set_all_tlist(np.array([0., 1., 2]))
     proc.run_state(init_state=tensor([basis(2, 0), basis(3, 1)]))
Ejemplo n.º 3
0
 def testMultiLevelSystem(self):
     """
     Test for processor with multi-level system
     """
     N = 2
     proc = Processor(N=N, dims=[2, 3])
     proc.add_control(tensor(sigmaz(), rand_dm(3, density=1.)))
     proc.pulses[0].coeff = np.array([1, 2])
     proc.pulses[0].tlist = np.array([0., 1., 2])
     proc.run_state(init_state=tensor([basis(2, 0), basis(3, 1)]))
Ejemplo n.º 4
0
    def test_id_with_T1_T2(self):
        """
        Test for identity evolution with relaxation t1 and t2
        """
        # setup
        a = destroy(2)
        Hadamard = hadamard_transform(1)
        ex_state = basis(2, 1)
        mines_state = (basis(2, 1) - basis(2, 0)).unit()
        end_time = 2.
        tlist = np.arange(0, end_time + 0.02, 0.02)
        t1 = 1.
        t2 = 0.5

        # test t1
        test = Processor(1, t1=t1)
        # zero ham evolution
        test.add_pulse(Pulse(identity(2), 0, tlist, False))
        result = test.run_state(ex_state, e_ops=[a.dag() * a])
        assert_allclose(result.expect[0][-1],
                        np.exp(-1. / t1 * end_time),
                        rtol=1e-5,
                        err_msg="Error in t1 time simulation")

        # test t2
        test = Processor(1, t2=t2)
        test.add_pulse(Pulse(identity(2), 0, tlist, False))
        result = test.run_state(init_state=mines_state,
                                e_ops=[Hadamard * a.dag() * a * Hadamard])
        assert_allclose(result.expect[0][-1],
                        np.exp(-1. / t2 * end_time) * 0.5 + 0.5,
                        rtol=1e-5,
                        err_msg="Error in t2 time simulation")

        # test t1 and t2
        t1 = np.random.rand(1) + 0.5
        t2 = np.random.rand(1) * 0.5 + 0.5
        test = Processor(1, t1=t1, t2=t2)
        test.add_pulse(Pulse(identity(2), 0, tlist, False))
        result = test.run_state(init_state=mines_state,
                                e_ops=[Hadamard * a.dag() * a * Hadamard])
        assert_allclose(result.expect[0][-1],
                        np.exp(-1. / t2 * end_time) * 0.5 + 0.5,
                        rtol=1e-5,
                        err_msg="Error in t1 & t2 simulation, "
                        "with t1={} and t2={}".format(t1, t2))
Ejemplo n.º 5
0
 def test_no_saving_intermidiate_state(self):
     processor = Processor(1)
     processor.add_pulse(pulse=Pulse(sigmax(),
                                     coeff=np.ones(10),
                                     tlist=np.linspace(0, 1, 10),
                                     targets=0))
     result = processor.run_state(basis(2, 0), tlist=[0, 1])
     assert (len(result.states) == 2)
Ejemplo n.º 6
0
 def test_user_defined_noise(self):
     """
     Test for the user-defined noise object
     """
     dr_noise = DriftNoise(sigmax())
     proc = Processor(1)
     proc.add_noise(dr_noise)
     tlist = np.array([0, np.pi / 2.])
     proc.add_pulse(Pulse(identity(2), 0, tlist, False))
     result = proc.run_state(init_state=basis(2, 0))
     assert_allclose(fidelity(result.states[-1], basis(2, 1)),
                     1,
                     rtol=1.0e-6)
Ejemplo n.º 7
0
 def testChooseSolver(self):
     # 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, solver="mcsolve")
     assert_allclose(
         fidelity(result.states[-1], qubit_states(2, [0, 1, 0, 0])),
         1, rtol=1.e-7)
Ejemplo n.º 8
0
 def test_id_evolution(self):
     """
     Test for identity evolution
     """
     N = 1
     proc = Processor(N=N)
     init_state = rand_ket(2)
     tlist = [0., 1., 2.]
     proc.add_pulse(Pulse(identity(2), 0, tlist, False))
     result = proc.run_state(
         init_state, options=Options(store_final_state=True))
     global_phase = init_state.data[0, 0]/result.final_state.data[0, 0]
     assert_allclose(global_phase*result.final_state, init_state)
Ejemplo n.º 9
0
 def testChooseSolver(self):
     # setup and fidelity without noise
     init_state = qubit_states(2, [0, 0, 0, 0])
     tlist = np.linspace(0., np.pi / 2., 10)
     a = destroy(2)
     proc = Processor(N=2, t2=100)
     proc.add_control(sigmax(), targets=1, label="sx")
     proc.set_all_coeffs({"sx": np.array([1.] * len(tlist))})
     proc.set_all_tlist(tlist)
     observerable = tensor([qutip.qeye(2), qutip.sigmax()])
     result1 = proc.run_state(init_state=init_state,
                              solver="mcsolve",
                              e_ops=observerable)
     assert result1.solver == "mcsolve"
Ejemplo n.º 10
0
 def test_repeated_use_of_processor(self):
     processor = Processor(1, t1=1.)
     processor.add_pulse(Pulse(sigmax(), targets=0, coeff=True))
     result1 = processor.run_state(basis(2, 0), tlist=np.linspace(0, 1, 10))
     result2 = processor.run_state(basis(2, 0), tlist=np.linspace(0, 1, 10))
     assert_allclose(result1.states[-1].full(), result2.states[-1].full())