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 all commits
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
5 changes: 5 additions & 0 deletions crates/circuit/src/circuit_data.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1284,6 +1284,11 @@ impl CircuitData {
}
Ok(())
}

/// Retrieves the python `Param` object based on its `ParameterUuid`.
pub fn get_parameter_by_uuid(&self, uuid: ParameterUuid) -> Option<&Py<PyAny>> {
self.param_table.py_parameter_by_uuid(uuid)
}
}

/// Helper struct for `assign_parameters` to allow use of `Param::extract_no_coerce` in
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