Example #1
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)
        test.tlist = tlist
        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.tlist = tlist
        result = test.run_state(rho0=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.tlist = tlist
        result = test.run_state(rho0=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))
Example #2
0
def test_dnorm_qubit_known_cases():
    """
    Metrics: check agreement for known qubit channels.
    """
    def case(chan1, chan2, expected, significant=4):
        # We again take a generous tolerance so that we don't kill off
        # SCS solvers.
        assert_approx_equal(dnorm(chan1, chan2),
                            expected,
                            significant=significant)

    id_chan = to_choi(qeye(2))
    S_eye = to_super(id_chan)
    X_chan = to_choi(sigmax())
    depol = to_choi(
        Qobj(diag(ones((4, ))), dims=[[[2], [2]], [[2], [2]]], superrep='chi'))
    S_H = to_super(hadamard_transform())

    W = swap()

    # We need to restrict the number of iterations for things on the boundary,
    # such as perfectly distinguishable channels.
    yield case, id_chan, X_chan, 2
    yield case, id_chan, depol, 1.5

    # Next, we'll generate some test cases based on comparisons to pre-existing
    # dnorm() implementations. In particular, the targets for the following
    # test cases were generated using QuantumUtils for MATLAB (https://goo.gl/oWXhO9).

    def overrotation(x):
        return to_super((1j * np.pi * x * sigmax() / 2).expm())

    for x, target in {
            1.000000e-03: 3.141591e-03,
            3.100000e-03: 9.738899e-03,
            1.000000e-02: 3.141463e-02,
            3.100000e-02: 9.735089e-02,
            1.000000e-01: 3.128689e-01,
            3.100000e-01: 9.358596e-01
    }.items():
        yield case, overrotation(x), id_chan, target

    def had_mixture(x):
        return (1 - x) * S_eye + x * S_H

    for x, target in {
            1.000000e-03: 2.000000e-03,
            3.100000e-03: 6.200000e-03,
            1.000000e-02: 2.000000e-02,
            3.100000e-02: 6.200000e-02,
            1.000000e-01: 2.000000e-01,
            3.100000e-01: 6.200000e-01
    }.items():
        yield case, had_mixture(x), id_chan, target

    def swap_map(x):
        S = (1j * x * W).expm()
        S._type = None
        S.dims = [[[2], [2]], [[2], [2]]]
        S.superrep = 'super'
        return S

    for x, target in {
            1.000000e-03: 2.000000e-03,
            3.100000e-03: 6.199997e-03,
            1.000000e-02: 1.999992e-02,
            3.100000e-02: 6.199752e-02,
            1.000000e-01: 1.999162e-01,
            3.100000e-01: 6.173918e-01
    }.items():
        yield case, swap_map(x), id_chan, target

    # Finally, we add a known case from Johnston's QETLAB documentation,
    # || Phi - I ||,_♢ where Phi(X) = UXU⁺ and U = [[1, 1], [-1, 1]] / sqrt(2).
    yield case, Qobj([[1, 1], [-1, 1]]) / np.sqrt(2), qeye(2), np.sqrt(2)
Example #3
0
def test_dnorm_qubit_known_cases():
    """
    Metrics: check agreement for known qubit channels.
    """
    def case(chan1, chan2, expected, significant=4):
        # We again take a generous tolerance so that we don't kill off
        # SCS solvers.
        assert_approx_equal(
            dnorm(chan1, chan2), expected,
            significant=significant
        )

    id_chan = to_choi(qeye(2))
    S_eye = to_super(id_chan)
    X_chan = to_choi(sigmax())
    depol = to_choi(Qobj(
        diag(ones((4,))),
        dims=[[[2], [2]], [[2], [2]]], superrep='chi'
    ))
    S_H = to_super(hadamard_transform())

    W = swap()

    # We need to restrict the number of iterations for things on the boundary,
    # such as perfectly distinguishable channels.
    yield case, id_chan, X_chan, 2
    yield case, id_chan, depol, 1.5

    # Next, we'll generate some test cases based on comparisons to pre-existing
    # dnorm() implementations. In particular, the targets for the following
    # test cases were generated using QuantumUtils for MATLAB (https://goo.gl/oWXhO9).

    def overrotation(x):
        return to_super((1j * np.pi * x * sigmax() / 2).expm())

    for x, target in {
        1.000000e-03: 3.141591e-03,
        3.100000e-03: 9.738899e-03,
        1.000000e-02: 3.141463e-02,
        3.100000e-02: 9.735089e-02,
        1.000000e-01: 3.128689e-01,
        3.100000e-01: 9.358596e-01
    }.items():
        yield case, overrotation(x), id_chan, target

    def had_mixture(x):
        return (1 - x) * S_eye + x * S_H

    for x, target in {
        1.000000e-03: 2.000000e-03,
        3.100000e-03: 6.200000e-03,
        1.000000e-02: 2.000000e-02,
        3.100000e-02: 6.200000e-02,
        1.000000e-01: 2.000000e-01,
        3.100000e-01: 6.200000e-01
    }.items():
        yield case, had_mixture(x), id_chan, target

    def swap_map(x):
        S = (1j * x * W).expm()
        S._type = None
        S.dims = [[[2], [2]], [[2], [2]]]
        S.superrep = 'super'
        return S

    for x, target in {
        1.000000e-03: 2.000000e-03,
        3.100000e-03: 6.199997e-03,
        1.000000e-02: 1.999992e-02,
        3.100000e-02: 6.199752e-02,
        1.000000e-01: 1.999162e-01,
        3.100000e-01: 6.173918e-01
    }.items():
        yield case, swap_map(x), id_chan, target

    # Finally, we add a known case from Johnston's QETLAB documentation,
    # || Phi - I ||,_♢ where Phi(X) = UXU⁺ and U = [[1, 1], [-1, 1]] / sqrt(2).
    yield case, Qobj([[1, 1], [-1, 1]]) / np.sqrt(2), qeye(2), np.sqrt(2)
print(qubit_states(N=2, states=[0, 0]))
print("\n")

x = sigmax()
print(x)
print("\n")

ket_zero = qubit_states(N=1, states=[0])

print(ket_zero)
print("\n")

print(x * ket_zero)
print("\n")

print(tensor([identity(N=2), hadamard_transform(N=1)]))
print("\n")

print(snot(N=2, target=1))
print("\n")

print(swap(N=2, targets=[0, 1]))
print("\n")

print(cnot(N=2, control=0, target=1))
print("\n")

print(cnot(N=4, control=0, target=3))
print("\n")

print(hadamard_transform(N=2) * qubit_states(N=2, states=[0, 0]))