-
Notifications
You must be signed in to change notification settings - Fork 2.4k
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
Parameter has inconsistent hash #9299
Comments
In this case we have to be a bit careful, I think: a So would say the |
To put it concretely, you are saying that in my example,
But both are ParameterExpressions (Parameter inherits from ParameterExpression). |
It depends: should |
Perhaps part of the solution is that Also, currently Even with that, there are other issues with |
At that point, I feel we might as well abandon |
The main difference that I see is |
Another difference is that a |
These differences don't seem particularly compelling to me. In fact, they seem to cause user surprise, and bugs.
The behavior of
I am also not aware of how this "feature" is used, and as you point out, it is in fact a source of at least one bug. |
I think a motivation is also to decouple the |
Another reason to drop
For what it's worth, symengine integration is on the sympy roadmap:
|
We use Personally, I agree that this linking is confusing and would like qiskit-experiments to move away from it if possible (just treat parameters in each schedule independently by name; for linking parameters, build up larger gates/schedules referencing the smaller ones rather than linking parameters; or use code to redefine things that should be linked, which is more work but more clear). Still, I think phasing out the UUID aspect of
where it is reusing the same parameter name many times in different gates/qubits and relying on the UUIDs to differentiate things (the example is oversimplified but a more accurate example would be a lot of code; imagine different functions generating different gates or subcircuits each with the same parameter name). |
Environment
What is happening?
Objects which compare equal must have the same hash value; see https://docs.python.org/3/reference/datamodel.html#object.hash. This property is violated by Parameter.
How can we reproduce the issue?
Note that
a
has type Parameter butaa
has type ParameterExpressionWhat should happen?
Any one of the following is acceptable in theory:
a == aa
andhash(a) == hash(aa)
both evaluate toTrue
.a == aa
andhash(a) == hash(aa)
both evaluate toFalse
.hash(a)
raisesTypeError: unhashable type
Any suggestions?
Another option would be to deprecate
Parameter
and instead usesympy.Symbol
directly.The text was updated successfully, but these errors were encountered: