Skip to content
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

Merged
merged 4 commits into from
Aug 14, 2019

Conversation

kdk
Copy link
Member

@kdk kdk commented Aug 8, 2019

Summary

Fixes #2429
Fixes #2864

Details and comments

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.

Copy link
Member

@mtreinish mtreinish left a 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

@mtreinish
Copy link
Member

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.

@mtreinish mtreinish merged commit bb2ea37 into Qiskit:master Aug 14, 2019
faisaldebouni pushed a commit to faisaldebouni/qiskit-terra that referenced this pull request Aug 5, 2020
…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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
3 participants