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 get_parameter_by_uuid to CircuitData #12926

Merged
merged 3 commits into from
Aug 9, 2024

Conversation

raynelfss
Copy link
Contributor

Summary

The following commits add a method get_parameter_by_uuid to obtain the Parameter object from CircuitData by uuid.

Details and comments

The method retrieves a Parameter object from the ParameterTable based on its uuid without exposing any extra data. This could be useful when performing mapping based parameter assignment (as one of the methods from #12913 attempts to do), from rust-space, without having to necessarily pass the a Parameter object to do so.

Known issues:

Nothing so far but, if anything is found, leave a comment or review. Thank you!

- This method receives a `uuid` instance from Python and returns the parameter object identified by said `uuid`.
@raynelfss raynelfss requested a review from a team as a code owner August 8, 2024 16:10
@qiskit-bot
Copy link
Collaborator

One or more of the following people are relevant to this code:

  • @Qiskit/terra-core
  • @kevinhartman
  • @mtreinish

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 Ray, this looks very sensible to me.

Comment on lines 363 to 369

pub fn get_parameter_by_uuid(&self, py: Python, uuid: ParameterUuid) -> Option<Py<PyAny>> {
self.param_table
.py_parameter_by_uuid(uuid)
.map(|ob| ob.clone_ref(py))
}

Copy link
Member

Choose a reason for hiding this comment

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

Does this need to be a pymethod?

Do you think there might any reason to call this without needing the GIL? If so, we could return the Option<&Py<PyAny>> directly and let the caller handle cloning the reference if they need it. I can't think of a huge amount of use for that, though.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I don't see a need for it to be a pymethod mainly other than keeping it consistent with the counterpart method that allows for you to look for a parameter by name. Now, I could turn it into a rust-native method and then have a pymethod call directly to it, unless we won't use this at all.

@coveralls
Copy link

coveralls commented Aug 8, 2024

Pull Request Test Coverage Report for Build 10308429432

Details

  • 0 of 6 (0.0%) changed or added relevant lines in 2 files are covered.
  • 7 unchanged lines in 2 files lost coverage.
  • Overall coverage decreased (-0.009%) to 89.741%

Changes Missing Coverage Covered Lines Changed/Added Lines %
crates/circuit/src/circuit_data.rs 0 3 0.0%
crates/circuit/src/parameter_table.rs 0 3 0.0%
Files with Coverage Reduction New Missed Lines %
crates/qasm2/src/lex.rs 1 93.23%
crates/qasm2/src/parse.rs 6 97.61%
Totals Coverage Status
Change from base Build 10307373210: -0.009%
Covered Lines: 67374
Relevant Lines: 75076

💛 - Coveralls

@raynelfss raynelfss requested a review from jakelishman August 8, 2024 19:33
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.

Cool, thanks!

@jakelishman jakelishman added this pull request to the merge queue Aug 9, 2024
@jakelishman jakelishman added Changelog: None Do not include in changelog Rust This PR or issue is related to Rust code in the repository mod: circuit Related to the core of the `QuantumCircuit` class or the circuit library labels Aug 9, 2024
@jakelishman jakelishman added this to the 1.3.0 milestone Aug 9, 2024
Merged via the queue into Qiskit:main with commit a4f28f2 Aug 9, 2024
15 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Changelog: None Do not include in changelog mod: circuit Related to the core of the `QuantumCircuit` class or the circuit library Rust This PR or issue is related to Rust code in the repository
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants