Change Parameter equality from python id() to internal uuid(). #2947
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Summary
Fixes #2429
Fixes #2864
Details and comments
Parameter
s were defined such that they would only ever__eq__ self
. That way, if a user defined aParameter('theta')
and wanted to compose in a subcircuit defined elsewhere which contained a differentParameter('theta')
, we would be able to detect that the parameter names overlapped and raise an error.However, if a user sent a
Parameter
to a different python instance though (say throughmultiprocessing.Pool
orqiskit.tools.parallel_map
), it would be instantiated as a different python object and so no longer be considered equal to the original parameter.This PR changes
Parameter
to instead generate a random UUID on instantiation and use that for equality testing. Unlikeid(self)
,self._uuid
will be preserved across pickling and de-pickling, but should otherwise preserveParameter
's equality behavior.