Skip to content

Prepare for Qiskit 2.0 by addressing removed classes and methods#1526

Merged
wshanks merged 11 commits intoqiskit-community:mainfrom
wshanks:prepare-qiskit2-qobj-backendv1-rebase
Mar 7, 2025
Merged

Prepare for Qiskit 2.0 by addressing removed classes and methods#1526
wshanks merged 11 commits intoqiskit-community:mainfrom
wshanks:prepare-qiskit2-qobj-backendv1-rebase

Conversation

@wshanks
Copy link
Copy Markdown
Collaborator

@wshanks wshanks commented Mar 5, 2025

This change prepares for Qiskit 2.0 by guarding or replacing references to objects removed in Qiskit 2.0.

Detailed list of changes:

Compatibility changes:

  • Guard references to BackendV1. BackendV1 was removed in Qiskit 2.0. There were only a few remaining references to BackendV1 after the previous removal of pulse support, so it was not hard to keep the remaining support for now but it should be removed when Qiskit 1 is no longer supported.
  • Update usage of qiskit.result.Result.header to expect a dict (Qiskit 2) as well as a class (Qiskit 1). ExperimentData gets the circuit metadata from the header (by convention the metadata is copied into the result and ExperimentData relies on this).
  • Add classes MeasLevel and MeasReturnType to enumerate the expected measurement level (kerneled or classified) and return type (averaged or not). Previously, private classes of Qiskit were inadvertently used for these purposes but they were removed in Qiskit 2.0.
  • Remove null default inst_map transpile options from experiments. These should have been removed along with the rest of pulse support.
  • Update tests to use GenericBackendV2 or a custom BackendV2 in place of removed FakeOpenPulse2Q and Fake5QV1 backends from Qiskit.
  • Remove suppression of Qiskit deprecation warnings from the tests.
  • Remove stray references to ProviderV1 in tests.
  • Update the saved QuantumVolume results for Qiskit 2.0's change in the quantum volume algorithm.
  • Vendor deprecation decorators to prepare for their removal from Qiskit's public API (see here). At first it appeared that these methods would be changed late in the Qiskit 2.0 cycle but the change was pushed back in time. Still the plan is to make the functions private, so we need to stop using them.

Other changes

  • Provide a more specific warning in LocalReadouMitigator if it is used with a backend without a properties() method or with a backend that does not the required readout error properties.
  • Fix a performance issue in QuantumVolume. When Qiskit Aer is installed, QuantumVolume uses AerSimulator to simulate the outcomes of the quantum volume circuits to determine the heavy output probabilities. In its default instantiation, AerSimulator regenerates its Target every time it is accessed and this generation takes an appreciable amount of time. Because the target was being accessed separately for every circuit, this overhead could accumulate to over a minute in the standard 100 circuit experiment. This overhead was reduced by processing all the circuits in one pass.
  • Switch FineFrequency tests to use T2HahnBackend in place MockIQBackend since it provides a more realistic backend emulation.
  • Fix the stacklevel on the deprecation warning for RestlessNode.

@eliarbel
Copy link
Copy Markdown
Contributor

eliarbel commented Mar 5, 2025

Thanks @wshanks for including my BackendV1 Removal commit here. This is still in draft and I'm sure you'll cover everything eventually, but dropping a couple things just as a reminder:

  1. qiskit.qobj has been removed. So MeasLevel and MeasReturnType should now be imported from qiskit.result. No QobjExperimentHeader and PulseQobjInstruction anymore.
  2. qobj_id is not required anymore when initializing Result (though it can be passed via *kwargs).

@wshanks
Copy link
Copy Markdown
Collaborator Author

wshanks commented Mar 5, 2025

Thanks, @eliarbel. I have been keeping an eye on Qiskit/qiskit#13793, but I have only been testing against Qiskit main so there are things being removed there that I haven't caught yet. For MeasLevel, I think I will vendor it in as suggested in Qiskit/qiskit#13793 (comment). In my most recent test with this branch and Qiskit main there were 6 failures, so there is still a little bit of other work to do, too.

@eliarbel
Copy link
Copy Markdown
Contributor

eliarbel commented Mar 5, 2025

FYI @wshanks, I've opened a PR in qiskit-neko to skip the failing test there: Qiskit/qiskit-neko#55. This will allow us to make progress with the SDK removals while you are still working on your PR.

mtreinish pushed a commit to Qiskit/qiskit-neko that referenced this pull request Mar 5, 2025
…55)

BackendV1 and qiskit.qobj removals in Qiskit/qiskit#13793 cause the test in qiskit_neko/tests/experiments/test_tomography.py to fail. This is part of the tests that are blocking the Qiskit/qiskit#13793 and Qiskit/qiskit#13872 PR in Qiskit from being merged.

There is a PR in Qiskit Experiments that address these removals: qiskit-community/qiskit-experiments#1526. Until it is merged, we need to skip this failing test.

Tracked in #54
@wshanks
Copy link
Copy Markdown
Collaborator Author

wshanks commented Mar 5, 2025

Sounds good @eliarbel. It is a bit hard to complete this PR right now because testing it requires Qiskit/qiskit#13793 and qiskit-ibm-runtime is not ready for that change plus other changes in Qiskit main so it is hard to test.

eliarbel and others added 8 commits March 5, 2025 23:32
* Vendor MeasLevel/MeasReturnType from qiskit.qobj.utils. These classes
  were never public and the usage here does not rely class identity,
just class member values.
* Address `Result` header now being a dict rather than a class.
* Address removal of `calibrate_instructions` from `GenericBackendV2`.
* Fix performance issue with `QuantumVolume` and Qiskit Aer. When Aer
  was used to calculate the ideal probabilities for quantum volume
circuits it was spending most of its time generating a `Target` for
transpiling the circuit before simulating it. This was addressed by
transpiling all the circuits in one `transpile` call.
* Update `QuantumVolume` stored results in tests for Qiskit 2.0 (circuit
  generation algorithm changed).
@wshanks wshanks force-pushed the prepare-qiskit2-qobj-backendv1-rebase branch from 4a6ee21 to 375fea0 Compare March 6, 2025 04:56
@wshanks wshanks marked this pull request as ready for review March 6, 2025 04:58
@wshanks wshanks force-pushed the prepare-qiskit2-qobj-backendv1-rebase branch from 375fea0 to 5274970 Compare March 6, 2025 05:19
@wshanks
Copy link
Copy Markdown
Collaborator Author

wshanks commented Mar 6, 2025

Note -- this PR passes the tests for me with Qiskit main which I think at this point has merged all the relevant qobj/backend/pulse removals. I had to test with my own branch of qiskit-ibm-runtime because its main branch still has some pulse references, so we can't say for sure this branch will be good with Qiskit 2.0 and the next qiskit-ibm-runtime release but it is looking good.

Copy link
Copy Markdown
Collaborator

@nkanazawa1989 nkanazawa1989 left a comment

Choose a reason for hiding this comment

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

LGTM. Just one comment

if "u_channel_lo" not in self._backend._conf_dict:
self._backend._conf_dict["u_channel_lo"] = [] # to avoid qiskit bug
self._pulse_conf = PulseBackendConfiguration.from_dict(self._backend._conf_dict)
self._v1 = isinstance(backend, BackendV1)
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

We should at least add deprecation warning in here. I prefer completely removing BackendV1 usage because we cannot guarantee the rest of our software properly works with this backend.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

The release note had a line about support for BackendV1 being removed in a future release, but I added an explicit deprecations entry about it as well. Also, I added a deprecation warning here. It is hard to do because this code gets called at varying levels of the stack and Python by default only shows deprecation warnings if the stack level is right. Python 3.12 added a cool skip_file_prefixes option so I used that and it seemed to work well on 3.12+ -- it showed my user level code as responsible for the warning whether I created BackendData directly or created a T1 experiment that creates BackendData four levels lower down in the stack. Users on <=3.11 might not see the warning depending on how they are using BackendV1.

My thought was that we are not planning much change to the repo in the near term and it was easy enough to hide the import here. Qiskit 1 will go out of support in six months and we don't need to support unsupported Qiskit versions, I think. I specified this in the deprecation note.

@wshanks wshanks force-pushed the prepare-qiskit2-qobj-backendv1-rebase branch from 95690c5 to 352264a Compare March 6, 2025 14:43
@wshanks wshanks force-pushed the prepare-qiskit2-qobj-backendv1-rebase branch from 352264a to 1a11e89 Compare March 6, 2025 14:47
These functions are planned to be removed from the public Qiskit API in
a future release (see
Qiskit/qiskit#11296 (review)).
Copy link
Copy Markdown
Collaborator

@nkanazawa1989 nkanazawa1989 left a comment

Choose a reason for hiding this comment

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

Thanks, let's merge this for #1529

@wshanks wshanks added this pull request to the merge queue Mar 7, 2025
Merged via the queue into qiskit-community:main with commit 974ad78 Mar 7, 2025
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.

3 participants