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

Deprecating isinstance(qr[0], tuple) #2474

Merged
merged 10 commits into from
May 23, 2019
Merged

Conversation

1ucian0
Copy link
Member

@1ucian0 1ucian0 commented May 22, 2019

This PR deprecates the isinstance for a Bit when checked for a tuple. It is some sort of hack, however, many users are checking for isinstance(qr[0], tuple) and that is not supported after #2414

qr = QuantumRegister(4)

print(isinstance(qr[0], tuple)) # True
print(isinstance(qr[0], Qubit)) # True
print(type(qr[0])) # <class 'qiskit.circuit.quantumregister.Qubit'>

By overwriting __class__, we pretend to be a tuple when isinstance is called in a context that mentions tuple.

@CLAassistant
Copy link

CLAassistant commented May 22, 2019

CLA assistant check
All committers have signed the CLA.

Copy link
Member

@mtreinish mtreinish left a comment

Choose a reason for hiding this comment

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

This looks fine to me, it's a pretty big hack to inspect the call stack and look for a reference to tuple and dynamically change the response. But, I can't think of a better way. I do wonder if there will be a performance overhead for doing this in a property on a class that will be used everywhere, but we'll find out.

Before I hit Approve I do wonder if we want to clean up the tests at all. There are a bunch of deprecation warnings being emitted because of this and other tuple vs bit things, mostly in layout.

Copy link
Member

@mtreinish mtreinish left a comment

Choose a reason for hiding this comment

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

Actually I just checked and all the warnings being emitted from the layout module are about accessing or creating the layout with tuples, not anything to do with this. We can go and clean that up later.

@jaygambetta jaygambetta merged commit 3f60d53 into Qiskit:master May 23, 2019
@hushaohan
Copy link
Contributor

This has made Aqua run much slower. for example, test_amplitude_estimation used to finish within 2 minutes; now it would take more than 13 minutes.

@nonhermitian
Copy link
Contributor

I can confim that this is also the reason for the slow down observed in #2489

@1ucian0 1ucian0 deleted the __class__ branch May 25, 2019 17:04
@1ucian0 1ucian0 mentioned this pull request May 25, 2019
lia-approves pushed a commit to edasgupta/qiskit-terra that referenced this pull request Jul 30, 2019
* initial from 2470

* __repr__

* undo repr

* is_bit

* silence when layout
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.

6 participants