Skip to content

Commit

Permalink
Migrate to EstimatorV2 in tests
Browse files Browse the repository at this point in the history
Partially addresses #506.
  • Loading branch information
garrison committed Jul 17, 2024
1 parent b4db37e commit c63728f
Showing 1 changed file with 8 additions and 7 deletions.
15 changes: 8 additions & 7 deletions test/cutting/test_cutting_roundtrip.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,10 +41,10 @@
DCXGate,
)
from qiskit.quantum_info import PauliList, random_unitary
from qiskit.primitives import Estimator
from qiskit.transpiler.preset_passmanagers import generate_preset_pass_manager
from qiskit_ibm_runtime import SamplerV2
from qiskit_aer import AerSimulator
from qiskit_aer.primitives import Sampler
from qiskit_aer.primitives import Sampler, EstimatorV2

from circuit_knitting.utils.simulation import ExactSampler
from circuit_knitting.cutting import (
Expand Down Expand Up @@ -138,13 +138,14 @@ def test_cutting_exact_reconstruction(example_circuit):
"""Test gate-cut circuit vs original circuit on statevector simulator"""
qc = example_circuit

observables = PauliList(["III", "IIY", "XII", "XYZ", "iZZZ", "-XZI"])
observables = PauliList(["III", "IIY", "XII", "XYZ", "ZZZ", "-XZI"])
phases = np.array([(-1j) ** obs.phase for obs in observables])
observables_nophase = PauliList(["III", "IIY", "XII", "XYZ", "ZZZ", "XZI"])

estimator = Estimator()
estimator = EstimatorV2()
pm = generate_preset_pass_manager(optimization_level=1, basis_gates=["u", "cz"])
exact_expvals = (
estimator.run([qc] * len(observables), list(observables)).result().values
estimator.run([(pm.run(qc), list(observables))]).result()[0].data.evs
)
subcircuits, bases, subobservables = partition_problem(
qc, "AAB", observables=observables_nophase
Expand Down Expand Up @@ -216,9 +217,9 @@ def test_sampler_with_identity_subobservable(sampler, is_exact_sampler):

if is_exact_sampler:
# Determine exact expectation values
estimator = Estimator()
estimator = EstimatorV2()
exact_expvals = (
estimator.run([qc] * len(observables), list(observables)).result().values
estimator.run([(qc, list(observables))]).result()[0].data.evs
)

logger.info(
Expand Down

0 comments on commit c63728f

Please sign in to comment.