Qiskit / qiskit-ibm-runtime

IBM Client for Qiskit Runtime
https://docs.quantum.ibm.com/api/qiskit-ibm-runtime
Apache License 2.0
149 stars 154 forks source link

`Target` construction erroneously reports default gates as being user-provided #1712

Closed blakejohnson closed 4 months ago

blakejohnson commented 4 months ago

Describe the bug

Target construction in backend_converter.py erroneously creates a Target that reports default gates as being user-provided

Steps to reproduce

from qiskit_ibm_runtime import QiskitRuntimeService

service = QiskitRuntimeService()
backend = service.get_backend("ibm_kyiv")
print(backend.target["x"][(0,)]._calibration.user_provided)

returns True, but it should return False.

Suggested solutions

To quote @mtreinish, the issue is roughly here: https://github.com/Qiskit/qiskit-ibm-runtime/blob/33f296abd7c6f07a383d0ad5bae7415910ea4f86/qiskit_ibm_runtime/utils/backend_converter.py#L259

Which is directly setting a pulse Schedule which tells the target it's a user manually setting a calibration since it was updated after the properties object's instantiation (see: https://docs.quantum.ibm.com/api/qiskit/qiskit.transpiler.InstructionProperties#calibration). Also, doing so using a private method from the InstructionScheduleMap for some reason.

This code used to be like this: https://github.com/Qiskit/qiskit-ibm-provider/blob/main/qiskit_ibm_provider/utils/json_decoder.py#L248-L251 in the old provider which is when @nkanazawa1989 fixed this originally in https://github.com/Qiskit/qiskit-ibm-provider/pull/413.

The easiest fix here would be to change https://github.com/Qiskit/qiskit-ibm-runtime/blob/33f296abd7c6f07a383d0ad5bae7415910ea4f86/qiskit_ibm_runtime/utils/backend_converter.py#L262 to mirror the logic that was in the old provider. That also has the advantage of not creating instruction schedule maps eagerly either so backends and targets load more quickly.

Additional Information

kt474 commented 4 months ago

This is fixed in https://github.com/Qiskit/qiskit-ibm-runtime/pull/1600, aiming for a release tomorrow

kt474 commented 4 months ago

Fixed in latest release, 0.24.0