Example #1
0
def test_phase_flip(simulator, p):

    qubit = 0
    H = paulis.X(qubit)
    U = gates.H(target=qubit)
    O = ExpectationValue(U=U, H=H)
    NM = PhaseFlip(p, 1)
    E = simulate(O, backend=simulator, samples=1, noise=NM)
Example #2
0
def test_phase_flip(simulator, p):
    qubit = 0
    H = paulis.X(qubit)
    U = gates.H(target=qubit)
    O = ExpectationValue(U=U, H=H)
    NM = PhaseFlip(p, 1)
    E = simulate(O, backend=simulator, samples=1000, noise=NM)
    assert (numpy.isclose(E, 1.0 - 2 * p, atol=1.e-1))
Example #3
0
def test_rz_phase_flip_1(simulator, p, angle):
    U = gates.X(target=0) + gates.H(1) + gates.CRz(control=0, target=1, angle=Variable('a')) + gates.H(1)
    H = paulis.Z(1) * paulis.I(0)
    O = ExpectationValue(U, H)
    NM = PhaseFlip(p, 2)
    E = simulate(O, backend=simulator, variables={'a': angle}, samples=1000, noise=NM)
    print(E)
    assert (numpy.isclose(E, ((1.0 - 2 * p) ** 2) * numpy.cos(angle), atol=1.e-1))
Example #4
0
def test_rz_phase_flip_0(simulator, p, angle):
    qubit = 0
    H = paulis.Y(qubit)
    U = gates.H(target=qubit) + gates.Rz(angle=Variable('a'), target=qubit) + gates.H(target=qubit)
    O = ExpectationValue(U=U, H=H)
    NM = PhaseFlip(p, 1)
    E = simulate(O, backend=simulator, variables={'a': angle}, samples=1000, noise=NM)
    assert (numpy.isclose(E, ((-1. + 2 * p) ** 3) * numpy.sin(angle), atol=1.e-1))
Example #5
0
def test_rz_phase_flip_1(simulator, p, angle):

    U = gates.X(target=0) + gates.H(1) + gates.CRz(
        control=0, target=1, angle=Variable('a')) + gates.H(1)
    H = paulis.Z(1) * paulis.I(0)
    O = ExpectationValue(U, H)
    NM = PhaseFlip(p, 2)
    E = simulate(O,
                 backend=simulator,
                 variables={'a': angle},
                 samples=1,
                 noise=NM)
    print(E)
Example #6
0
def test_rz_phase_flip_0(simulator, p, angle):

    qubit = 0
    H = paulis.Y(qubit)
    U = gates.H(target=qubit) + gates.Rz(angle=Variable('a'),
                                         target=qubit) + gates.H(target=qubit)
    O = ExpectationValue(U=U, H=H)
    NM = PhaseFlip(p, 1)
    E = simulate(O,
                 backend=simulator,
                 variables={'a': angle},
                 samples=1,
                 noise=NM)
    print(E)