Ejemplo n.º 1
0
    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()))
Ejemplo n.º 2
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.º 3
0
    def test_decoherence_noise(self):
        """
        Test for the decoherence noise
        """
        tlist = np.array([0, 1, 2, 3, 4, 5, 6])
        coeff = np.array([1, 1, 1, 1, 1, 1, 1])

        # Time-dependent
        decnoise = DecoherenceNoise(sigmaz(),
                                    coeff=coeff,
                                    tlist=tlist,
                                    targets=[1])
        dims = [2] * 2
        systematic_noise = Pulse(None,
                                 None,
                                 label="systematic_noise",
                                 spline_kind="step_func")
        pulses, systematic_noise = decnoise.get_noisy_pulses(
            systematic_noise=systematic_noise, dims=dims)
        noisy_qu, c_ops = systematic_noise.get_noisy_qobjevo(dims=dims)
        assert_allclose(c_ops[0](0).full(), tensor(qeye(2), sigmaz()).full())

        # Time-independent and all qubits
        decnoise = DecoherenceNoise(sigmax(), all_qubits=True)
        pulses, systematic_noise = decnoise.get_noisy_pulses(dims=dims)
        noisy_qu, c_ops = systematic_noise.get_noisy_qobjevo(dims=dims)
        c_ops = [qu(0) 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)
        systematic_noise = Pulse(None,
                                 None,
                                 label="systematic_noise",
                                 spline_kind="step_func")
        pulses, systematic_noise = decnoise.get_noisy_pulses(
            systematic_noise=systematic_noise, dims=dims)
        noisy_qu, c_ops = systematic_noise.get_noisy_qobjevo(dims=dims)
        assert_allclose(c_ops[0](0).full(),
                        tensor(sigmax(), qeye(2)).full() * 2)
        assert_allclose(c_ops[1](0).full(),
                        tensor(qeye(2), sigmax()).full() * 2)
Ejemplo n.º 4
0
    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)
Ejemplo n.º 5
0
 def test_collapse_with_different_tlist(self):
     """
     Test if there are errors raised because of wrong tlist handling.
     """
     qc = QubitCircuit(1)
     qc.add_gate("X", 0)
     proc = LinearSpinChain(1)
     proc.load_circuit(qc)
     tlist = np.linspace(0, 30., 100)
     coeff = tlist * 0.1
     noise = DecoherenceNoise(sigmam(), targets=0, coeff=coeff, tlist=tlist)
     proc.add_noise(noise)
     proc.run_state(basis(2, 0))