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

Add uuid property to Parameter #11647

Merged
merged 4 commits into from
Jan 26, 2024
Merged

Conversation

wshanks
Copy link
Contributor

@wshanks wshanks commented Jan 25, 2024

This change adds a public, read-only uuid property to Parameter which can be used in advanced use cases for getting the uuid value to pass to the Parameter constructor.

This change adds a public, read-only uuid property to Parameter which
can be used in advanced use cases for getting the uuid value to pass to
the Parameter constructor.
@wshanks wshanks requested a review from a team as a code owner January 25, 2024 23:05
@qiskit-bot
Copy link
Collaborator

One or more of the the following people are requested to review this:

  • @Qiskit/terra-core

@wshanks
Copy link
Contributor Author

wshanks commented Jan 25, 2024

I tried building the docs locally but I didn't see my release note in the notes. Is there a trick to it? I am never sure if I have written valid sphinx restructured text without compiling it.

A couple questions:

  • Add a test?
  • Modify the qpy code that accesses _uuid to access uuid?

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.

Overall this LGTM, it makes sense to enable a read only attribute for the uuid since it's already a documented part of the constructor. Just one small inline comment/question about the docstring.

qiskit/circuit/parameter.py Outdated Show resolved Hide resolved
@mtreinish
Copy link
Member

I tried building the docs locally but I didn't see my release note in the notes. Is there a trick to it? I am never sure if I have written valid sphinx restructured text without compiling it.

A couple questions:

* Add a test?

A test wouldn't hurt but this is also so simple I'm not going to say it's required.

* Modify the qpy code that accesses `_uuid` to access `uuid`?

This is a good idea, and would actually take care of the test coverage for you so you definitely don't need a bespoke test for this attribute.

@mtreinish mtreinish added this to the 1.1.0 milestone Jan 25, 2024
@mtreinish
Copy link
Member

mtreinish commented Jan 25, 2024

I tagged this for 1.1.0 because it is technically a new feature past the proposal deadline for 1.0.0, but I think it's simple enough to grant an exception to the freeze deadline, but I'll wait for someone else to confirm before re-tagging for 1.0.0

@coveralls
Copy link

coveralls commented Jan 25, 2024

Pull Request Test Coverage Report for Build 7670104958

  • 0 of 6 (100.0%) changed or added relevant lines in 2 files are covered.
  • 3 unchanged lines in 1 file lost coverage.
  • Overall coverage increased (+0.04%) to 89.558%

Files with Coverage Reduction New Missed Lines %
crates/qasm2/src/lex.rs 3 91.69%
Totals Coverage Status
Change from base Build 7665707920: 0.04%
Covered Lines: 59594
Relevant Lines: 66542

💛 - Coveralls

@wshanks
Copy link
Contributor Author

wshanks commented Jan 25, 2024

This is a good idea, and would actually take care of the test coverage for you so you definitely don't need a bespoke test for this attribute.

I pushed a commit that does this. The one thing about it is that other places still refer to _name which I didn't change though there is a name property as well. I don't know if that makes it undesirably inconsistent?

I tagged this for 1.1.0 because it is technically a new feature past the proposal deadline for 1.0.0, but I think it's simple enough to grant an exception to the freeze deadline, but I'll wait for someone else to confirm before re-tagging for 1.0.0

It is not urgent since _uuid can be used in the meantime, but I just wanted to avoid using private attributes if I could.

@jakelishman
Copy link
Member

I'm ok on granting a freeze exception to a getter that I think was just an oversight in the interface when the UUID was added in #2947.

Copying in an above comment, because I think it might be in a thread GitHub had already collapsed:

you can't use . suffix matches with intersphinx - it needs to be a fully specified name. In this case, :class:`~uuid.UUID` should do what you want.

@wshanks
Copy link
Contributor Author

wshanks commented Jan 26, 2024

I didn't see a basic test of Parameter._eq__(), so I added one, including a check that using .uuid could produce something that would equal the original instance (I was surprised to learn that the parameter name doesn't matter for equality).

@jakelishman
Copy link
Member

I was surprised to learn that the parameter name doesn't matter for equality

Huh, me too, although I suppose that once we've made a UUID, it's wasting time to compare a string as well.

@wshanks
Copy link
Contributor Author

wshanks commented Jan 26, 2024

Huh, me too, although I suppose that once we've made a UUID, it's wasting time to compare a string as well.

Technically, though, Parameter is violating the requirement from the Python data model (which often seems to bite me): "The only required property is that objects which compare equal have the same hash value." Likely, either the name should be included in the hash or the hash key should be just the uuid.

@jakelishman
Copy link
Member

Oh, in that case it's a bug yeah thanks - I guess we should add the name to the equality check, since the documentation around the class says they need to have the same name to be equal.

Copy link
Member

@jakelishman jakelishman left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for this, Will. We were already ok with granting this a freeze exception, but I think the discussion in #11654 around how Pulse could use this to more easily adapt to the necessary bugfix of #11652 puts it beyond doubt.

@jakelishman jakelishman modified the milestones: 1.1.0, 1.0.0 Jan 26, 2024
@jakelishman jakelishman added Changelog: New Feature Include in the "Added" section of the changelog mod: circuit Related to the core of the `QuantumCircuit` class or the circuit library labels Jan 26, 2024
@jakelishman jakelishman added this pull request to the merge queue Jan 26, 2024
Merged via the queue into Qiskit:main with commit f783fe8 Jan 26, 2024
12 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Changelog: New Feature Include in the "Added" section of the changelog mod: circuit Related to the core of the `QuantumCircuit` class or the circuit library
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

5 participants