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

Fix backend_util.py and test cases to support Aer 0.13 #11172

Merged
merged 14 commits into from
Nov 20, 2023

Conversation

doichanj
Copy link
Contributor

@doichanj doichanj commented Nov 2, 2023

Summary

This PR is fix of qiskit/utils/backend_utils.py to support Aer 0.13

Details and comments

Some test cases with noise model fails with Aer 0.13 release because of

if is_simulator_backend(self._backend) and not is_basicaer_provider(self._backend):

is_simulator_backend always returns False with BackendV2.
This function will be deprecated, but I think we have to add support for V2 to pass test cases.

In test/python/providers/test_fake_backends.py, ignore running test
when backend is V2.

In test/python/pulse/test_block.py test case is removed because
Aer does not have pulse simulator anymore.

@doichanj doichanj requested review from woodsp-ibm and a team as code owners November 2, 2023 02:14
@qiskit-bot
Copy link
Collaborator

One or more of the the following people are requested to review this:

  • @Qiskit/terra-core

@coveralls
Copy link

coveralls commented Nov 2, 2023

Pull Request Test Coverage Report for Build 6901577447

  • 0 of 4 (0.0%) changed or added relevant lines in 1 file are covered.
  • 19 unchanged lines in 4 files lost coverage.
  • Overall coverage decreased (-0.007%) to 85.89%

Changes Missing Coverage Covered Lines Changed/Added Lines %
qiskit/utils/backend_utils.py 0 4 0.0%
Files with Coverage Reduction New Missed Lines %
qiskit/utils/backend_utils.py 2 78.95%
crates/qasm2/src/lex.rs 4 91.16%
crates/qasm2/src/parse.rs 6 97.6%
qiskit/providers/fake_provider/fake_backend.py 7 88.42%
Totals Coverage Status
Change from base Build 6897835680: -0.007%
Covered Lines: 65937
Relevant Lines: 76769

💛 - Coveralls

@doichanj doichanj changed the title Fix backend_util.py to support Aer 0.13 Fix backend_util.py and test cases to support Aer 0.13 Nov 2, 2023
@woodsp-ibm
Copy link
Member

backend_utils module was part of algorithms support logic around use of QuantumInstance (came from Aqua) and all the methods were deprecated and this code will shortly be removed - I would have expected the whole module to removed. The fake_backends test fix should not add a dependence this file.

Out of curiosity I did a search just to see if either private methods got used elsewhere - seems not - but.... it seems to have been copied elsewhere

def _get_backend_interface_version(backend):
backend_interface_version = getattr(backend, "version", None)
return backend_interface_version

Maybe as such having some common function somewhere is useful - I'll leave that to the terra-core team to decide. For me its just getattr(backend, "version", None) which could simply be inlined to the test.

test/python/providers/test_fake_backends.py Outdated Show resolved Hide resolved
Comment on lines 8 to 12
In `test/python/providers/test_fake_backends.py`, ignore running test
when backend is V2.

In `test/python/pulse/test_block.py` test case is removed because
Aer does not have pulse simulator anymore.
Copy link
Member

Choose a reason for hiding this comment

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

You can remove these lines as we typically don't need to document test suite changes for our end users as it's not a user facing change.

@mtreinish mtreinish added this to the 0.45.1 milestone Nov 7, 2023
@mtreinish mtreinish added Changelog: Bugfix Include in the "Fixed" section of the changelog stable backport potential The bug might be minimal and/or import enough to be port to stable labels Nov 7, 2023
@@ -226,6 +226,9 @@ def is_simulator_backend(backend):
backend_interface_version = _get_backend_interface_version(backend)
if backend_interface_version <= 1:
return backend.configuration().simulator
else:
if "simulator" in backend.name:
Copy link
Member

Choose a reason for hiding this comment

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

My concern with this would the that the remote simulator "ibmq_qasm_simulator" would now be treated as local simulator wouldn't it. There is logic in run_circuits that dealt with max circuits around whether things were being run locally or not.

Copy link
Contributor

Choose a reason for hiding this comment

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

I think that with the upcoming changes in runtime simulators we shouldn't worry about this too much.

Copy link
Member

Choose a reason for hiding this comment

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

🙈

Copy link
Contributor

@ElePT ElePT left a comment

Choose a reason for hiding this comment

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

The PR looks good to me, I just had one question to understand how the controlled gate test relates to the rest of changes in the PR, in case this is something to keep in mind even after backend_utils.py is removed.

Comment on lines +1027 to +1030
# set number of control qubits
for i in range(num_free_params):
if gate_params[i] == "num_ctrl_qubits":
free_params[i] = 3
Copy link
Contributor

Choose a reason for hiding this comment

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

I understand that this change is to make the code a bit general and not only work for MCU1Gate, MCPhaseGate and MCXGate, but I was wondering, why did this fail with the new Aer?

Copy link
Member

Choose a reason for hiding this comment

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

The test discovery attempts to discover every registered subclass of ControlledGate (Python makes that information easily accessible), without restriction to the Qiskit standard library, where it would make sense.

We ideally should probably fix the test discovery to limit it only to controlled gates defined in qiskit.circuit.library.standard_gates.

Copy link
Contributor

@ElePT ElePT Nov 16, 2023

Choose a reason for hiding this comment

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

So you are suggesting changing the current code on line 1017:
@data(*ControlledGate.__subclasses__())
with something like:
@data([cls for cls in allGates.__dict__.values() if isinstance(cls,type) and issubclass(cls,ControlledGate)])?

Copy link
Member

Choose a reason for hiding this comment

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

I'm not a huge fan of the automatic discovery in its current form at all, but given the current file, yeah, something like that would be fine. Something a little less magic would be

from qiskit.circuit.library.standard_gates import get_standard_gate_name_mapping

standard_controlled_types = [x.base_class for x in get_standard_gate_name_mapping().values() if isinstance(x, ControlledGate)]

That would exclude the multi-controlled gates, which imo should be handled specially if they're not going to follow the conventions of standard-library gates.

(really, I don't think the mcx etc gates should be in standard_gates at all, they should be in generalized_gates, but that's an argument for another time)

Copy link
Contributor

Choose a reason for hiding this comment

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

Given that it looks like there is a lot of room for improvement in these tests, let's keep the current fix as-is and consider improving the tests in a follow-up.

Copy link
Contributor

@ElePT ElePT left a comment

Choose a reason for hiding this comment

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

LGTM, let's merge this PR to further unblock the removal of backend_utils.py. Thanks a lot @doichanj.

Comment on lines +1027 to +1030
# set number of control qubits
for i in range(num_free_params):
if gate_params[i] == "num_ctrl_qubits":
free_params[i] = 3
Copy link
Contributor

Choose a reason for hiding this comment

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

Given that it looks like there is a lot of room for improvement in these tests, let's keep the current fix as-is and consider improving the tests in a follow-up.

@ElePT ElePT added this pull request to the merge queue Nov 20, 2023
Merged via the queue into Qiskit:main with commit 45efe66 Nov 20, 2023
14 checks passed
mergify bot pushed a commit that referenced this pull request Nov 20, 2023
* fix backend_util.py to support Aer 0.13

* Fix test cases for Aer 0.13.0

* format

* remove unused imports

* Update test/python/providers/test_fake_backends.py

Co-authored-by: Matthew Treinish <mtreinish@kortar.org>

* fix setting num_control_qubits param in test.python.circuit.test_controlled_gate

* remove unused import

---------

Co-authored-by: Matthew Treinish <mtreinish@kortar.org>
(cherry picked from commit 45efe66)
github-merge-queue bot pushed a commit that referenced this pull request Nov 20, 2023
* fix backend_util.py to support Aer 0.13

* Fix test cases for Aer 0.13.0

* format

* remove unused imports

* Update test/python/providers/test_fake_backends.py

Co-authored-by: Matthew Treinish <mtreinish@kortar.org>

* fix setting num_control_qubits param in test.python.circuit.test_controlled_gate

* remove unused import

---------

Co-authored-by: Matthew Treinish <mtreinish@kortar.org>
(cherry picked from commit 45efe66)

Co-authored-by: Jun Doi <doichan@jp.ibm.com>
FabianBrings pushed a commit to FabianBrings/qiskit that referenced this pull request Nov 27, 2023
* fix backend_util.py to support Aer 0.13

* Fix test cases for Aer 0.13.0

* format

* remove unused imports

* Update test/python/providers/test_fake_backends.py

Co-authored-by: Matthew Treinish <mtreinish@kortar.org>

* fix setting num_control_qubits param in test.python.circuit.test_controlled_gate

* remove unused import

---------

Co-authored-by: Matthew Treinish <mtreinish@kortar.org>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Changelog: Bugfix Include in the "Fixed" section of the changelog stable backport potential The bug might be minimal and/or import enough to be port to stable
Projects
None yet
Development

Successfully merging this pull request may close these issues.

7 participants