From 44711b4c987299fe1c9463a5663665e777236b0e Mon Sep 17 00:00:00 2001 From: Jake Lishman Date: Fri, 22 Sep 2023 16:51:37 +0100 Subject: [PATCH] Tweak documentation wording --- qiskit/circuit/parameter.py | 10 +++++----- .../notes/fix-parameter-hash-d22c270090ffc80e.yaml | 2 +- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/qiskit/circuit/parameter.py b/qiskit/circuit/parameter.py index 665f10f0134a..e354a708eace 100644 --- a/qiskit/circuit/parameter.py +++ b/qiskit/circuit/parameter.py @@ -145,11 +145,11 @@ def __eq__(self, other): return False def _hash_key(self): - # This isn't the entirety of the object that's passed to `hash`, just the "key" part of - # individual parameters. The hash of a full `ParameterExpression` needs to depend on the - # "keys" of `Parameter`s, and our hash needs to be computable before we can be fully - # initialised as a `ParameterExpression`, so we break the cycle by making our "key" - # accessible separately. + # `ParameterExpression` needs to be able to hash all its contained `Parameter` instances in + # its hash as part of the equality comparison but has its own more complete symbolic + # expression, so its full hash key is split into `(parameter_keys, symbolic_expression)`. + # This method lets containing expressions get only the bits they need for equality checks in + # the first value, without wasting time re-hashing individual Sympy/Symengine symbols. return (self._name, self._uuid) def __hash__(self): diff --git a/releasenotes/notes/fix-parameter-hash-d22c270090ffc80e.yaml b/releasenotes/notes/fix-parameter-hash-d22c270090ffc80e.yaml index c325ea30e648..e03fa8555a48 100644 --- a/releasenotes/notes/fix-parameter-hash-d22c270090ffc80e.yaml +++ b/releasenotes/notes/fix-parameter-hash-d22c270090ffc80e.yaml @@ -10,4 +10,4 @@ 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. + :class:`.ParameterExpression` values were mixed in the same map as it violated Python's data model.