Esempio n. 1
0
def test_bit_flip(simulator, p, controlled):

    qubit = 0

    if controlled:
        U = gates.X(target=1) + gates.CX(1, 0)
        H = paulis.Qm(0)
        NM = BitFlip(p, 2)
    else:
        U = gates.X(target=0)
        NM = BitFlip(p, 1)
        H = paulis.Qm(qubit)
    O = ExpectationValue(U=U, H=H)

    E = simulate(O, backend=simulator, samples=1, noise=NM)
Esempio n. 2
0
def test_bit_flip(simulator, p, controlled):
    qubit = 0

    if controlled:
        U = gates.X(target=1) + gates.CX(1, 0)
        H = paulis.Qm(0)
        NM = BitFlip(p, 2)
    else:
        U = gates.X(target=0)
        NM = BitFlip(p, 1)
        H = paulis.Qm(qubit)
    O = ExpectationValue(U=U, H=H)

    E = simulate(O, backend=simulator, samples=1000, noise=NM)
    assert (numpy.isclose(E, 1.0 - p, atol=1.e-1))
Esempio n. 3
0
def test_repetition_works(simulator, p):
    qubit = 0
    H = paulis.Qm(qubit)
    U = gates.X(target=qubit) + gates.X(target=qubit)
    O = ExpectationValue(U=U, H=H)
    NM = BitFlip(p, 1)
    E = simulate(O, backend=simulator, samples=1, noise=NM)
Esempio n. 4
0
def test_double_cnot_bit_flip(simulator, p):

    qubit = 1
    U = gates.X(0) + gates.X(2) + gates.CX(0, 1) + gates.CX(2, 1)
    H = paulis.Qm(qubit)
    O = ExpectationValue(U=U, H=H)
    NM = BitFlip(p, 2)

    E = simulate(O, backend=simulator, samples=1, noise=NM)
Esempio n. 5
0
def test_double_cnot_bit_flip(simulator, p):
    qubit = 1
    U = gates.X(0) + gates.X(2) + gates.CX(0, 1) + gates.CX(2, 1)
    H = paulis.Qm(qubit)
    O = ExpectationValue(U=U, H=H)
    NM = BitFlip(p, 2)

    E = simulate(O, backend=simulator, samples=1000, noise=NM)
    assert (numpy.isclose(E, 2 * (p - p * p), atol=1.e-1))
Esempio n. 6
0
def test_rx_bit_flip_0(simulator, p, angle):
    U = gates.Rx(target=0, angle=Variable('a'))
    H = paulis.Z(0)
    NM = BitFlip(p, 1)

    O = ExpectationValue(U=U, H=H)

    E = simulate(O, backend=simulator, samples=1000, variables={'a': angle}, noise=NM)
    assert (numpy.isclose(E, (1 - 2 * p) * numpy.cos(angle), atol=1.e-1))
Esempio n. 7
0
def test_rx_bit_flip_1(simulator, p, angle):
    U = gates.X(target=0) + gates.CRx(control=0, target=1, angle="a")
    H = paulis.Z(1) * paulis.I(0)
    NM = BitFlip(p, 2)
    O = ExpectationValue(U=U, H=H)

    E = simulate(O, backend=simulator, samples=1000, variables={'a': angle}, noise=NM)
    print(E)
    print(p + numpy.cos(angle) - p * numpy.cos(angle))
    assert (numpy.isclose(E, p + numpy.cos(angle) - p * numpy.cos(angle), atol=1.e-1))
Esempio n. 8
0
def test_bit_flip_phoenics(simulator, p):
    qubit = 0
    H = paulis.Qm(qubit)
    U = gates.Rx(target=qubit, angle=tq.Variable('a'))
    O = ExpectationValue(U=U, H=H)
    NM = BitFlip(p, 1)
    result = tq.optimizers.optimizer_phoenics.minimize(objective=O,
                                                       maxiter=3,
                                                       samples=1,
                                                       backend=simulator,
                                                       noise=NM)
Esempio n. 9
0
def test_rx_bit_flip_0(simulator, p, angle):

    U = gates.Rx(target=0, angle=Variable('a'))
    H = paulis.Z(0)
    NM = BitFlip(p, 1)

    O = ExpectationValue(U=U, H=H)

    E = simulate(O,
                 backend=simulator,
                 samples=1,
                 variables={'a': angle},
                 noise=NM)
Esempio n. 10
0
def test_bit_flip_scipy_hessian(simulator, p, method):
    qubit = 0
    H = paulis.Qm(qubit)
    U = gates.Rx(target=qubit, angle=tq.Variable('a'))
    O = ExpectationValue(U=U, H=H)
    NM = BitFlip(p, 1)
    result = tq.optimizer_scipy.minimize(objective=O,
                                         samples=1,
                                         backend=simulator,
                                         method=method,
                                         noise=NM,
                                         tol=1.e-4,
                                         silent=False)
Esempio n. 11
0
def test_rx_bit_flip_1(simulator, p, angle):

    qubit = 1
    U = gates.X(target=0) + gates.CRx(control=0, target=1, angle=Variable('a'))
    H = paulis.Z(1) * paulis.I(0)
    NM = BitFlip(p, 2)

    O = ExpectationValue(U=U, H=H)

    E = simulate(O,
                 backend=simulator,
                 samples=1,
                 variables={'a': angle},
                 noise=NM)
    print(E)
    print(p + numpy.cos(angle) - p * numpy.cos(angle))