Skip to content

Commit

Permalink
Replace observables with observables_nophase
Browse files Browse the repository at this point in the history
The previous code passed `observables_nophase` to the cutting code,
so it wasn't even testing the phases through the workflow.  The
correct way to handle such observables with nontrivial phase is to
use the utility introduced in #587.
  • Loading branch information
garrison committed Jul 18, 2024
1 parent 9e00b70 commit e8dd340
Showing 1 changed file with 2 additions and 5 deletions.
7 changes: 2 additions & 5 deletions test/cutting/test_cutting_roundtrip.py
Original file line number Diff line number Diff line change
Expand Up @@ -138,17 +138,15 @@ 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", "ZZZ", "-XZI"])
phases = np.array([(-1j) ** obs.phase for obs in observables])
observables_nophase = PauliList(["III", "IIY", "XII", "XYZ", "ZZZ", "XZI"])
observables = PauliList(["III", "IIY", "XII", "XYZ", "ZZZ", "XZI"])

estimator = EstimatorV2()
pm = generate_preset_pass_manager(optimization_level=1, basis_gates=["u", "cz"])
exact_expvals = (
estimator.run([(pm.run(qc), list(observables))]).result()[0].data.evs
)
subcircuits, bases, subobservables = partition_problem(
qc, "AAB", observables=observables_nophase
qc, "AAB", observables=observables
)
subexperiments, coefficients = generate_cutting_experiments(
subcircuits, subobservables, num_samples=np.inf
Expand All @@ -167,7 +165,6 @@ def test_cutting_exact_reconstruction(example_circuit):
reconstructed_expvals = reconstruct_expectation_values(
results, coefficients, subobservables
)
reconstructed_expvals *= phases

logger.info("Max error: %f", np.max(np.abs(exact_expvals - reconstructed_expvals)))

Expand Down

0 comments on commit e8dd340

Please sign in to comment.