-
Notifications
You must be signed in to change notification settings - Fork 2.5k
Deprecate legacy primitive attributes in base classes #11051
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
Conversation
These attributes should have already been deprecated when the Estimator and Sampler run signatures were changed to take circuits instead of indices.
One or more of the the following people are requested to review this:
|
I've nothing against this PR, I've just killed its tests til tomorrow to free up CI runners for the release-queue pipeline. |
It causes an infinite recursion for other primitive implementations. from qiskit_aer.primitives import Sampler as AerSampler
from qiskit import QuantumCircuit
qc = QuantumCircuit(2, 2)
qc.measure([0, 1], [0, 1])
sampler = AerSampler()
_ = sampler.run(qc).result() output
According to Python documentation, hasattr is realized by calling getattr. So, calling hasattr in getattr causes the infinite recursion.
https://docs.python.org/3/library/functions.html?highlight=hasattr#hasattr It might be good to check attributes by dir(self). |
It is also necessary to raise appropriate AttributeError if an unknown attribute is given. from qiskit.primitives import Sampler
sampler = Sampler()
sampler.foo output
Should be |
I made a PR to address the two issues above chriseclectic#57. |
The whole In [1]: class A:
...: def __init__(self):
...: self.a = "hello"
...: def __getattr__(self, key):
...: print(f"__getattr__: '{key}'")
...: raise AttributeError(f"'{type(self).__name__}' object has no attribute '{key}'")
...:
...: a = A()
...: a.a, a.b
__getattr__ : 'b'
---------------------------------------------------------------------------
AttributeError Traceback (most recent call last)
Cell In[1], line <
8000
span class="pl-c1">9
6 raise AttributeError(f"'{type(self).__name__}' object has no attribute '{key}'")
8 a = A()
----> 9 a.a, a.b
Cell In[1], line 6, in A.__getattr__(self, key)
4 def __getattr__(self, key):
5 print(f"__getattr__ : '{key}'")
----> 6 raise AttributeError(f"'{type(self).__name__}' object has no attribute '{key}'")
AttributeError: 'A' object has no attribute 'b' Note that there's no (If in the future you want a magic method that's always called: |
Thank you, Jake. I simplified the PR chriseclectic#57 |
* fix attribute access * simplify
Thanks for fixing that @t-imamichi |
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.
Thanks. Looks good to me.
Pull Request Test Coverage Report for Build 6714657297
💛 - Coveralls |
Summary
These attributes should have already been deprecated when the Estimator and Sampler run signatures were changed to take circuits instead of indices.
Details and comments