Skip to content

Commit

Permalink
Add get_parameter_by_uuid to CircuitData (#12926)
Browse files Browse the repository at this point in the history
* Initial: Add `parameter_by_uuid` to `CircuitData`
- This method receives a `uuid` instance from Python and returns the parameter object identified by said `uuid`.

* Fix: Make `get_parameter_by_uuid` a rust only method.
  • Loading branch information
raynelfss committed Aug 9, 2024
1 parent 20b51e6 commit a4f28f2
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 0 deletions.
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

0 comments on commit a4f28f2

Please sign in to comment.