From 2b6068779d919587a6a6b0c26d816a8cfd780fb4 Mon Sep 17 00:00:00 2001 From: Raynel Sanchez Date: Thu, 8 Aug 2024 12:04:10 -0400 Subject: [PATCH 1/2] Initial: Add `parameter_by_uuid` to `CircuitData` - This method receives a `uuid` instance from Python and returns the parameter object identified by said `uuid`. --- crates/circuit/src/circuit_data.rs | 6 ++++++ crates/circuit/src/parameter_table.rs | 5 +++++ 2 files changed, 11 insertions(+) diff --git a/crates/circuit/src/circuit_data.rs b/crates/circuit/src/circuit_data.rs index dd2618f03f9a..1b11afc60921 100644 --- a/crates/circuit/src/circuit_data.rs +++ b/crates/circuit/src/circuit_data.rs @@ -361,6 +361,12 @@ impl CircuitData { .map(|ob| ob.clone_ref(py)) } + pub fn get_parameter_by_uuid(&self, py: Python, uuid: ParameterUuid) -> Option> { + 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. /// diff --git a/crates/circuit/src/parameter_table.rs b/crates/circuit/src/parameter_table.rs index 8825fbd71772..38cabf10c69f 100644 --- a/crates/circuit/src/parameter_table.rs +++ b/crates/circuit/src/parameter_table.rs @@ -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> { + self.by_uuid.get(&uuid).map(|param| ¶m.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() { From 9c8b47f070ba50e06ede63c083a82bed419c2312 Mon Sep 17 00:00:00 2001 From: Raynel Sanchez Date: Thu, 8 Aug 2024 15:32:49 -0400 Subject: [PATCH 2/2] Fix: Make `get_parameter_by_uuid` a rust only method. --- crates/circuit/src/circuit_data.rs | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/crates/circuit/src/circuit_data.rs b/crates/circuit/src/circuit_data.rs index 1b11afc60921..646982461c96 100644 --- a/crates/circuit/src/circuit_data.rs +++ b/crates/circuit/src/circuit_data.rs @@ -361,12 +361,6 @@ impl CircuitData { .map(|ob| ob.clone_ref(py)) } - pub fn get_parameter_by_uuid(&self, py: Python, uuid: ParameterUuid) -> Option> { - 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. /// @@ -1239,6 +1233,11 @@ impl CircuitData { } Ok(()) } + + /// Retrieves the python `Param` object based on its `ParameterUuid`. + pub fn get_parameter_by_uuid(&self, uuid: ParameterUuid) -> Option<&Py> { + self.param_table.py_parameter_by_uuid(uuid) + } } /// Helper struct for `assign_parameters` to allow use of `Param::extract_no_coerce` in