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

Replace convert_to_target with the Qiskit version #1600

Merged
merged 14 commits into from
May 6, 2024

Conversation

t-imamichi
Copy link
Member

@t-imamichi t-imamichi commented Apr 11, 2024

Summary

This PR copies qiskit.providers.backend_compat.convert_to_target to utils.backend_converter.convert_to_target with some modifications for mypy and lint. Particularly, I added reset to required to ensure reset is included in target.

Fixes #1590

Details and comments

The script #1590 works fine as follows

from qiskit_ibm_runtime import QiskitRuntimeService

service = QiskitRuntimeService(channel="ibm_quantum")
backend = service.get_backend("ibm_sherbrooke")
print('ibm_sherbrooke')
print(type(backend.target["measure"][(0,)]._calibration))  # qiskit.pulse.calibration_entries.ScheduleDef
print(len(backend.target["measure"][(0,)].calibration.instructions))  # 381 -- this is not correct
print(len(backend.target["measure"][(1,)].calibration.instructions))  # 129
print()

from qiskit_ibm_runtime.fake_provider import FakeSherbrooke

backend = FakeSherbrooke()
print('fake_sherbrooke')
print(type(backend.target["measure"][(0,)]._calibration))  # qiskit.pulse.calibration_entries.PulseQobjDef
print(len(backend.target["measure"][(0,)].calibration.instructions))  # 129
print(len(backend.target["measure"][(1,)].calibration.instructions))  # 129

main

ibm_sherbrooke
<class 'qiskit.pulse.calibration_entries.ScheduleDef'>
381
129

fake_sherbrooke
<class 'qiskit.pulse.calibration_entries.PulseQobjDef'>
129
129

this PR

ibm_sherbrooke
<class 'qiskit.pulse.calibration_entries.PulseQobjDef'>
129
129

fake_sherbrooke
<class 'qiskit.pulse.calibration_entries.PulseQobjDef'>
129
129

@coveralls
Copy link

coveralls commented Apr 11, 2024

Pull Request Test Coverage Report for Build 8974814830

Details

  • 98 of 117 (83.76%) changed or added relevant lines in 3 files are covered.
  • 19 unchanged lines in 2 files lost coverage.
  • Overall coverage decreased (-0.2%) to 83.48%

Changes Missing Coverage Covered Lines Changed/Added Lines %
qiskit_ibm_runtime/utils/backend_converter.py 95 114 83.33%
Files with Coverage Reduction New Missed Lines %
qiskit_ibm_runtime/ibm_qubit_properties.py 9 0.0%
qiskit_ibm_runtime/utils/backend_converter.py 10 77.04%
Totals Coverage Status
Change from base Build 8974407177: -0.2%
Covered Lines: 6276
Relevant Lines: 7518

💛 - Coveralls

@jyu00
Copy link
Collaborator

jyu00 commented Apr 11, 2024

@t-imamichi we recently had an issue that the convert_to_target from Qiskit wasn't picking up reset:

from qiskit_ibm_runtime.utils.backend_converter import convert_to_target as qr_c2t
from qiskit.providers.backend_compat import convert_to_target as qk_c2t

qr_target = qr_c2t(backend.configuration(), backend.properties(), backend.defaults())
qk_target = qk_c2t(backend.configuration(), backend.properties(), backend.defaults())

# then qr_target.operation_names gives:
dict_keys(['id', 'rz', 'sx', 'x', 'cx', 'reset', 'measure', 'switch_case', 'if_else', 'for_loop', 'delay'])

# but qk_target.operation_names gives:
dict_keys(['id', 'rz', 'switch_case', 'if_else', 'cx', 'x', 'measure', 'for_loop', 'delay', 'sx'])

Presumably there was a reason for qiskit-ibm-runtime to have its own convert_to_target, so I'd also consult with @mtreinish before removing it.

@jyu00 jyu00 requested review from mtreinish and removed request for rathishcholarajan April 11, 2024 14:34
@mtreinish
Copy link
Member

We can look at fixing the issue in Qiskit's converter function; is there an issue open about it already? I assume reset is being put in a field in the configuration that's not being looked at for the reset instruction by the qiskit version, or there are conflicting fields and qiskit is looking at one that's missing the reset instruction.

Besides that the other consideration is that we're planning to deprecate the BackendV1 interface in 1.2.x which will include removing the BackendConfiguration, BackendProperties, PulseDefaults, and by extension this will include dropping convert_to_target because there is nothing to convert from. The removal won't be until Qiskit 2.0, but it might be better to just leave this in place since we'll need to add it back before too long.

@t-imamichi
Copy link
Member Author

I copied Qiskit convert_to_target to qiskit-ibm-runtime with some modifications.
Particularly, I added reset to required to ensure reset is included in target.

required = ["measure", "delay", "reset"]

@jyu00
Copy link
Collaborator

jyu00 commented Apr 12, 2024

We can look at fixing the issue in Qiskit's converter function; is there an issue open about it already?

@mtreinish I'm guessing no if you're not aware. Somehow I thought you were added to the thread where this was discussed. Is it worth opening an issue in Qiskit at this point if it's going to be deprecated in 1.2?

Besides that the other consideration is that we're planning to deprecate the BackendV1 interface in 1.2.x which will include removing the BackendConfiguration, BackendProperties, PulseDefaults

Sounds like we'll need to copy those over to qiskit-ibm-runtime, since that's still how we get data from the server.

@jyu00
Copy link
Collaborator

jyu00 commented Apr 12, 2024

I copied Qiskit convert_to_target to qiskit-ibm-runtime with some modifications.

@t-imamichi can you also add more tests? Like maybe copy the ones on faulty qubits from Qiskit (we already have one on control flow). They can just be unit tests using fake backends.

@mtreinish
Copy link
Member

We can look at fixing the issue in Qiskit's converter function; is there an issue open about it already?

@mtreinish I'm guessing no if you're not aware. Somehow I thought you were added to the thread where this was discussed. Is it worth opening an issue in Qiskit at this point if it's going to be deprecated in 1.2?

I vaguely remember the issue, but I don't remember the specifics. But yeah we still support the converter function for > 1 year so it's good to ensure we get this fixed.

Besides that the other consideration is that we're planning to deprecate the BackendV1 interface in 1.2.x which will include removing the BackendConfiguration, BackendProperties, PulseDefaults

Sounds like we'll need to copy those over to qiskit-ibm-runtime, since that's still how we get data from the server.

Yeah, I would think so. There's no rush until ~August 2025 (that's when the 1.x series goes EoL) but planning for that and taking ownership of the container objects for the api payloads in the medium term is probably prudent.

@t-imamichi
Copy link
Member Author

I copied unit tests on faulty qubits from https://github.com/Qiskit/qiskit/blob/main/test/python/providers/test_faulty_backend.py

@t-imamichi
Copy link
Member Author

t-imamichi commented Apr 15, 2024

I noticed some error occurs due to random seed issue. Need to merge #1616

@t-imamichi
Copy link
Member Author

Puala suggested replacing convert_to_target for fake backends too t-imamichi#2. Do you anyone have any suggestion or comment? If no, I will merge it.

@kt474
Copy link
Member

kt474 commented Apr 30, 2024

Puala suggested replacing convert_to_target for fake backends too t-imamichi#2. Do you anyone have any suggestion or comment? If no, I will merge it.

No objections, after that, this PR LGTM

@kt474 kt474 added the Changelog: New Feature Include in the Added section of the changelog label May 6, 2024
@kt474 kt474 merged commit 7e9708a into Qiskit:main May 6, 2024
20 checks passed
@t-imamichi t-imamichi deleted the fix-target branch May 7, 2024 03:01
@wshanks
Copy link

wshanks commented May 17, 2024

This is labeled as new feature. Can it not be backported to 0.23.1 if there will be one? Besides fixing #1570 and #1590, it also fixes another issue I am running into (where a backend defines pulse calibrations for a qubit pair that does not have an entry in the gate properties; the old code in 0.23.0 raises a KeyError while the version here skips the missing keys without an exception).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Changelog: New Feature Include in the Added section of the changelog
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Measurement instruction calibration bug
7 participants