forked from Qiskit/qiskit
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix hash of
Parameter
and ParameterExpression
This fixes the construction paths for `Parameter` and its hash such that it will now correctly hash equal to any `ParameterExpression`s that it compares equal to. This is a requirement of the Python data model for hashmaps and hashsets, which previously we were breaking. In order to achieve this, we slightly modify the hash key such that the `Parameter` instances are no longer a part of the hash of `ParameterExpression`, which means we can use the same hashing strategy for both. This rearrangement has the benefit of removing the requirement for the `__new__` overrides on `Parameter` and `ParameterVectorElement`.
- Loading branch information
1 parent
d559659
commit 4913f11
Showing
7 changed files
with
121 additions
and
86 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
13 changes: 13 additions & 0 deletions
13
releasenotes/notes/fix-parameter-hash-d22c270090ffc80e.yaml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
--- | ||
features: | ||
- | | ||
:class:`.Parameter` now has an advanced-usage keyword argument ``uuid`` in its constructor, | ||
which can be used to make the :class:`.Parameter` compare equal to another of the same name. | ||
This should not typically be used by users, and is most useful for custom serialisation and | ||
deserialisation. | ||
fixes: | ||
- | | ||
The hash of a :class:`.Parameter` is now equal to the hashes of any | ||
:class:`.ParameterExpression` that it compares equal to. Previously the hashes were different, | ||
which would cause spurious additional entries in hashmaps when :class:`.Parameter` and | ||
:class:`.ParameterExpression` values were mixed in the same map. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters