-
Notifications
You must be signed in to change notification settings - Fork 2.3k
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
Allow shots
to be a numpy.int64
#7824
Conversation
I've noticed that the Aer backends, all work properly if the `shots` count is passed as a `numpy.int64`, but the BasicAer and hardware backends both fail in this case. The simplest way to make it work on all backends is by making this change in terra, inspired by Qiskit#4591.
Pull Request Test Coverage Report for Build 2161409796
💛 - Coveralls |
qiskit/compiler/assembler.py
Outdated
@@ -321,7 +322,7 @@ def _parse_common_args( | |||
shots = min(1024, max_shots) | |||
else: | |||
shots = 1024 | |||
elif not isinstance(shots, int): | |||
elif not isinstance(shots, numbers.Integral): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think it would be better to use numpy.integer
here instead of the abstract numbers class from stdlib. We've tried to use the abstract numbers
classes before and had performance regressions each time (because of how the abstract classes hook into the checks for isinstance). While assemble isn't super performance critical it's still used in job submission path a surprising number of place and this is only just a single isinstance
call so the extra overhead isn't as huge as something checked on each instruction in a circuit, I still think it would probably be better to just use numpy.integer
even if that means other int
types from other external libraries can't be used. In practice I don't think anything besides numpy ints will really come up.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sounds reasonable; I've pushed a fix.
* Allow `shots` to be a `numpy.int64` I've noticed that the Aer backends, all work properly if the `shots` count is passed as a `numpy.int64`, but the BasicAer and hardware backends both fail in this case. The simplest way to make it work on all backends is by making this change in terra, inspired by #4591. * Allow shots to be either an int or a numpy.integer, explicitly Co-authored-by: mergify[bot] <37929162+mergify[bot]@users.noreply.github.com> (cherry picked from commit d9a6f0b)
* Allow `shots` to be a `numpy.int64` I've noticed that the Aer backends, all work properly if the `shots` count is passed as a `numpy.int64`, but the BasicAer and hardware backends both fail in this case. The simplest way to make it work on all backends is by making this change in terra, inspired by #4591. * Allow shots to be either an int or a numpy.integer, explicitly Co-authored-by: mergify[bot] <37929162+mergify[bot]@users.noreply.github.com> (cherry picked from commit d9a6f0b) Co-authored-by: Jim Garrison <garrison@ibm.com>
which was fixed in Qiskit/qiskit#7824 which made it into Terra 0.20.1 but we now depend on Terra 0.22 or higher
Summary
I've noticed that the Aer backends all work properly if the
shots
count is passed as anumpy.int64
, but the BasicAer and hardware backends both fail in this case. The simplest way to make it work on all backends is by making this change in terra, inspired by #4591.Details and comments
Basic test program for reproducing the bug: