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 primitive classes for BackendV1 with no max_experiments #9069

Merged
merged 3 commits into from
Nov 3, 2022

Conversation

mtreinish
Copy link
Member

Summary

The max_experiments field in the BackendConfiguration for a BackendV1 backend is not a required field. While in practice most real backends set it, some simulators (including aer) do not. This causes a failure when using the Backend primitive classes with these backends as we were previously assuming the max_experiments attribute was always present.

Details and comments

The ``max_experiments`` field in the BackendConfiguration for a BackendV1
backend is not a required field. While in practice most real backends
set it, some simulators (including aer) do not. This causes a failure
when using the Backend primitive classes with these backends as we were
previously assuming the ``max_experiments`` attribute was always
present.
@mtreinish mtreinish added stable backport potential The bug might be minimal and/or import enough to be port to stable Changelog: Bugfix Include in the "Fixed" section of the changelog labels Nov 3, 2022
@mtreinish mtreinish requested review from a team, ikkoham and t-imamichi as code owners November 3, 2022 13:01
t-imamichi
t-imamichi previously approved these changes Nov 3, 2022
Copy link
Member

@t-imamichi t-imamichi left a comment

Choose a reason for hiding this comment

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

Thank you for a very rapid fix.

Comment on lines 58 to +59
if isinstance(backend, BackendV1):
max_circuits = backend.configuration().max_experiments
max_circuits = getattr(backend.configuration(), "max_experiments", None)
Copy link
Member

Choose a reason for hiding this comment

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

Not ideal that we're effectively switching on out-of-interface behaviour, but probably we're in a situation for BackendV1 where the ship has sailed (and we can always backdate and say it's an "optional" field).

Copy link
Member Author

@mtreinish mtreinish Nov 3, 2022

Choose a reason for hiding this comment

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

Yeah, I agree it's weird but I think it's probably defined behavior for the interface at this point (it's just really bad/weird behavior). I did check the schema that BackendConfiguration was originally based on and max_experiments isn't a required field: https://github.com/Qiskit/ibm-quantum-schemas/blob/main/schemas/backend_configuration_schema.json#L32 which was mirrored in the class when the schema was still coupled with the class definition. It's definitely a weird interface though and why I've been so keen to get everything on BackendV2.

Copy link
Member

@pedrorrivero pedrorrivero Nov 3, 2022

Choose a reason for hiding this comment

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

I have taken a look at BackendConfiguration and there seems to be a lot of code like:

...
if max_experiments:
    self.max_experiments = max_experiments
if sample_name is not None:
    self.sample_name = sample_name
...

Wouldn't it make things easier to use properties and return None by default? Seems more stable than needing hasattr() checks, and it is not a breaking change...

@coveralls
Copy link

coveralls commented Nov 3, 2022

Pull Request Test Coverage Report for Build 3388739457

  • 1 of 1 (100.0%) changed or added relevant line in 1 file are covered.
  • 3 unchanged lines in 1 file lost coverage.
  • Overall coverage decreased (-0.004%) to 84.539%

Files with Coverage Reduction New Missed Lines %
qiskit/pulse/library/waveform.py 3 91.49%
Totals Coverage Status
Change from base Build 3387677130: -0.004%
Covered Lines: 62453
Relevant Lines: 73875

💛 - Coveralls

@mtreinish mtreinish added this to the 0.22.2 milestone Nov 3, 2022
Copy link
Member

@pedrorrivero pedrorrivero left a comment

Choose a reason for hiding this comment

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

Thanks so much for putting this together @mtreinish !

Comment on lines 58 to +59
if isinstance(backend, BackendV1):
max_circuits = backend.configuration().max_experiments
max_circuits = getattr(backend.configuration(), "max_experiments", None)
Copy link
Member

@pedrorrivero pedrorrivero Nov 3, 2022

Choose a reason for hiding this comment

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

I have taken a look at BackendConfiguration and there seems to be a lot of code like:

...
if max_experiments:
    self.max_experiments = max_experiments
if sample_name is not None:
    self.sample_name = sample_name
...

Wouldn't it make things easier to use properties and return None by default? Seems more stable than needing hasattr() checks, and it is not a breaking change...

@mergify mergify bot merged commit b2d3dcf into Qiskit:main Nov 3, 2022
mergify bot pushed a commit that referenced this pull request Nov 3, 2022
…9069)

* Fix Backend primitive classes for BackendV1 with no max_experiments

The ``max_experiments`` field in the BackendConfiguration for a BackendV1
backend is not a required field. While in practice most real backends
set it, some simulators (including aer) do not. This causes a failure
when using the Backend primitive classes with these backends as we were
previously assuming the ``max_experiments`` attribute was always
present.

* Update test/python/primitives/test_backend_estimator.py

Co-authored-by: mergify[bot] <37929162+mergify[bot]@users.noreply.github.com>
(cherry picked from commit b2d3dcf)
mergify bot added a commit that referenced this pull request Nov 3, 2022
…9069) (#9072)

* Fix Backend primitive classes for BackendV1 with no max_experiments

The ``max_experiments`` field in the BackendConfiguration for a BackendV1
backend is not a required field. While in practice most real backends
set it, some simulators (including aer) do not. This causes a failure
when using the Backend primitive classes with these backends as we were
previously assuming the ``max_experiments`` attribute was always
present.

* Update test/python/primitives/test_backend_estimator.py

Co-authored-by: mergify[bot] <37929162+mergify[bot]@users.noreply.github.com>
(cherry picked from commit b2d3dcf)

Co-authored-by: Matthew Treinish <mtreinish@kortar.org>
@mtreinish mtreinish deleted the fix-backendv1-access branch November 3, 2022 23:29
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.

BackendEstimator and BackendSampler raise an error with a bare Aer or BasicAer simulator
6 participants