Skip to content

Commit

Permalink
Initial: Add parameter_by_uuid to CircuitData
Browse files Browse the repository at this point in the history
- This method receives a `uuid` instance from Python and returns the parameter object identified by said `uuid`.
  • Loading branch information
raynelfss committed Aug 8, 2024
1 parent 154601b commit 2b60687
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 0 deletions.
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))
}

/// 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

0 comments on commit 2b60687

Please sign in to comment.