def test_phase_amp_damp(simulator, p): qubit = 0 H = paulis.Z(0) U = gates.X(target=qubit) O = ExpectationValue(U=U, H=H) NM = PhaseAmplitudeDamp(p, 1 - p, 1) E = simulate(O, backend=simulator, samples=1, noise=NM)
def test_amp_damp(simulator, p): qubit = 0 H = (0.5) * (paulis.I(0) - paulis.Z(0)) U = gates.X(target=qubit) O = ExpectationValue(U=U, H=H) NM = AmplitudeDamp(p, 1) E = simulate(O, backend=simulator, samples=1, noise=NM)
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))
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))
def test_qubit_excitations(): H = paulis.Projector("1.0*|100>") U1 = gates.X(0) + gates.QubitExcitation( target=[0, 1], angle="a", assume_real=True) U2 = gates.X(0) + gates.Trotterized( generators=[U1.gates[1].make_generator()], angles=["a"], steps=1) E1 = ExpectationValue(H=H, U=U1) E2 = ExpectationValue(H=H, U=U2) dE1 = grad(E1, "a") dE2 = grad(E2, "a") for a in numpy.random.uniform(-numpy.pi, numpy.pi, 5): a = float(a) variables = {"a": a} wfn1 = simulate(U1, variables=variables) wfn2 = simulate(U2, variables=variables) F = numpy.abs(wfn1.inner(wfn2))**2 assert numpy.isclose(F, 1.0, 1.e-4) eval1 = simulate(dE1, variables=variables) eval2 = simulate(dE2, variables=variables) assert numpy.isclose(eval1, eval2, 1.e-4) H = paulis.Projector("1.0*|0110>") U1 = gates.X([1, 2]) + gates.QubitExcitation( target=[0, 1, 3, 2], angle="a", assume_real=True) U2 = gates.X([1, 2]) + gates.Trotterized( generators=[U1.gates[2].make_generator()], angles=["a"], steps=1) E1 = ExpectationValue(H=H, U=U1) E2 = ExpectationValue(H=H, U=U2) dE1 = grad(E1, "a") dE2 = grad(E2, "a") for a in numpy.random.uniform(-numpy.pi, numpy.pi, 5): a = float(a) variables = {"a": a} wfn1 = simulate(U1, variables=variables) wfn2 = simulate(U2, variables=variables) F = numpy.abs(wfn1.inner(wfn2))**2 assert numpy.isclose(F, 1.0, 1.e-4) eval1 = simulate(dE1, variables=variables) eval2 = simulate(dE2, variables=variables) assert numpy.isclose(eval1, eval2, 1.e-4)
def test_phase_amp_damp_is_both(simulator, p): qubit = 0 H = paulis.Z(0) U = gates.X(target=qubit) O = ExpectationValue(U=U, H=H) NM1 = PhaseDamp(1 - p, 1) + AmplitudeDamp(p, 1) E1 = simulate(O, backend=simulator, samples=1, noise_model=NM1) NM2 = PhaseAmplitudeDamp(p, 1 - p, 1) E2 = simulate(O, backend=simulator, samples=1, noise_model=NM2)