-
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 numbers.Integral instead of only built-in int for QuantumRegister index #4591
Conversation
Thanks for the contribution @arunraja-hub! Can you add a test that checks passing different types of integers as register sizes? I.e. a test that fails without your PR but works afterwards. |
Hi @Cryoris , Thank you! Could you provide more info on implementing the test? is there any documentation on that? |
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.
Here are some comments on the contribution 🙂
releasenotes/notes/allowIntegerforQuantumRegisterSize-2e9a6cc033bc962e.yaml
Outdated
Show resolved
Hide resolved
releasenotes/notes/allowIntegerforQuantumRegisterSize-2e9a6cc033bc962e.yaml
Outdated
Show resolved
Hide resolved
I don't think there's a dedicated documentation for the tests, but essentially a test is a short snippet of code that checks your new feature works. In a bugfix test, you ideally have a snippet that didn't work before but now does. E.g. something like def test_register_int_types(self):
ints = [int(2), int64(2), np.int(2), np.integer(2), ... ] # all int types you can think of
for size in ints:
with self.subTest(size=size): # technically not necessary, but nicer for debugging if you add this
qr = QuantumRegister(size)
cr = ClassicalRegister(size)
self.assertEqual(qr.size, 2)
self.assertEqual(cr.size, 2) See test/python/circuit/test_circuit_registers.py for where you could implement the test and how others look like. Let me know if you have any questions! |
Co-authored-by: Julien Gacon <gaconju@gmail.com>
…33bc962e.yaml Co-authored-by: Julien Gacon <gaconju@gmail.com>
…33bc962e.yaml Co-authored-by: Julien Gacon <gaconju@gmail.com>
|
The CI also runs a linter and stylechecker on the code, you can do this locally by doing
If you fix this, the tests will passs. |
@Cryoris Completed the tests for int32 and int64. I believe this PR is all set |
Actually I misunderstood the goal, I though the size should accept all types not the index. The tests should be changed accordingly to check that all these integer types work as indices of for index in [np.int(2), np.int32(2), ... ]:
# ... sub test as before, and the same for classical register
qr = QuantumRegister(3)
self.assertEqual(qr[index], qr[2]) |
Ths issue was that I had a newline. So I removed. Now the lint error is that I have removed a newline. So it is contradictory |
Co-authored-by: Kevin Krsulich <kevin@krsulich.net>
Hi @Cryoris, May I confirm that this PR is complete? Also, could you assign this issue to me? Thank you |
Yes, it is! Thanks a lot for the contribution 🚀 |
Thank you @Cryoris |
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.
* 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>
* 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>
Summary
Fixes #3929
Details and comments
-I changed line 120/121 of register.py such that it includes numbers.Integral as an allowable type for an index of a QuantumRegister. This is my first issue! Excited to contribute more
Issue: #3929