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
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions crates/circuit/src/circuit_data.rs
Original file line number Diff line number Diff line change
Expand Up @@ -361,6 +361,12 @@ impl CircuitData {
.map(|ob| ob.clone_ref(py))
}

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.

/// Return the width of the circuit. This is the number of qubits plus the
/// number of clbits.
///
Expand Down
5 changes: 5 additions & 0 deletions crates/circuit/src/parameter_table.rs
Original file line number Diff line number Diff line change
Expand Up @@ -225,6 +225,11 @@ impl ParameterTable {
.map(|uuid| &self.by_uuid[uuid].object)
}

/// Lookup the Python parameter object by uuid.
pub fn py_parameter_by_uuid(&self, uuid: ParameterUuid) -> Option<&Py<PyAny>> {
self.by_uuid.get(&uuid).map(|param| &param.object)
}

/// Get the (maybe cached) Python list of the sorted `Parameter` objects.
pub fn py_parameters<'py>(&mut self, py: Python<'py>) -> Bound<'py, PyList> {
if let Some(py_parameters) = self.py_parameters.as_ref() {
Expand Down
Loading