Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Treat resilience_level=0 for EstimatorV2 properly #1541

Closed
wants to merge 1 commit into from

Conversation

t-imamichi
Copy link
Member

Summary

EstimatorV2 applies TREX even if resilience_level is set 0 as follows.
This PR fixes the issue. The current code treat 0 as same as Unset. So, null will be delivered to the runtime server.

TODO:

  • I'm wondering what kind of unit test to add. I need a help by experts.
from qiskit import QuantumCircuit
from qiskit.quantum_info import SparsePauliOp
from qiskit.transpiler.preset_passmanagers import generate_preset_pass_manager

from qiskit_ibm_runtime import QiskitRuntimeService, EstimatorV2, Session

circuit = QuantumCircuit(2)
circuit.h(0)
circuit.cx(0, 1)

obs = [SparsePauliOp("XY"), SparsePauliOp("YZ")]

service = QiskitRuntimeService()
backend = service.get_backend("ibm_kyiv")
pm = generate_preset_pass_manager(optimization_level=1, backend=backend)
isa_circuit = pm.run(circuit)
isa_obs = [ob.apply_layout(isa_circuit.layout) for ob in obs]

with Session(backend=backend) as session:
    estimator = EstimatorV2(session=session, backend=backend)
    jobs = []
    for lev in [0, 1]:
        estimator.options.resilience_level = lev
        jobs.append(estimator.run([(isa_circuit, isa_obs)]))
    results = [job.result() for job in jobs]

for level, result in enumerate(results):
    print('resilience_level', level)
    print(result[0].data.evs)
    print(result[0].metadata)
    print()

output

resilience_level 0
[ 0.0495992 -0.001002 ]
{'shots': 4096, 'target_precision': 0.015625, 'circuit_metadata': {}, 'resilience': {'twirled_readout_errors': [[0, 0.00439453125], [1, 0.00830078125]]}, 'num_randomizations': 32}
# TREX looks applied though resilience_level=0

resilience_level 1
[ 0.03233831 -0.01144279]
{'shots': 4096, 'target_precision': 0.015625, 'circuit_metadata': {}, 'resilience': {'twirled_readout_errors': [[0, 0.00146484375], [1, 0.0087890625]]}, 'num_randomizations': 32}

Details and comments

@t-imamichi t-imamichi changed the title treat resilience_level=0 properly Treat resilience_level=0 for EstimatorV2 properly Mar 21, 2024
@t-imamichi t-imamichi requested a review from jyu00 March 21, 2024 03:21
@coveralls
Copy link

Pull Request Test Coverage Report for Build 8369626913

Details

  • 1 of 1 (100.0%) changed or added relevant line in 1 file are covered.
  • No unchanged relevant lines lost coverage.
  • Overall coverage remained the same at 83.476%

Totals Coverage Status
Change from base Build 8345950818: 0.0%
Covered Lines: 6163
Relevant Lines: 7383

💛 - Coveralls

@@ -163,7 +163,7 @@ def _set_if_exists(name: str, _inputs: dict, _options: dict) -> None:
remove_empty_dict(output_options)

inputs = {"options": output_options, "version": OptionsV2._VERSION, "support_qiskit": True}
if options_copy.get("resilience_level"):
if options_copy.get("resilience_level", Unset) != Unset:
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah, good old None and 0 evaluating to False bugs

@kt474
Copy link
Member

kt474 commented Mar 21, 2024

Replaced with #1542

@kt474 kt474 closed this Mar 21, 2024
@t-imamichi t-imamichi deleted the fix-res-level0 branch March 22, 2024 01:44
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants