-
Notifications
You must be signed in to change notification settings - Fork 2.3k
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
Change Parameter equality from python id() to internal uuid(). #2947
Conversation
cd767e4
to
1d45bb2
Compare
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.
This LGTM, I like this method of building a unique persistent id for the parameter objects so that we can safely pass them between processes
Azure is acting up once again. The test jobs all succeeded here: https://dev.azure.com/qiskit-ci/qiskit-terra/_build/results?buildId=1852 but the github <-> azure communication fell apart and the checks list didn't update for 2 of the jobs. Since the tests all passed I'm merging this now. |
…t#2947) Parameters were defined such that they would only ever __eq__ self. That way, if a user defined a Parameter('theta') and wanted to compose in a subcircuit defined elsewhere which contained a different Parameter('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 through multiprocessing.Pool or qiskit.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. Unlike id(self), self._uuid will be preserved across pickling and de-pickling, but should otherwise preserve Parameter's equality behavior. Fixes Qiskit#2429 Fixes Qiskit#2864
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.