Skip to content

Commit

Permalink
Initial: Add assign_parameter methods that can be used from Rust.
Browse files Browse the repository at this point in the history
  • Loading branch information
raynelfss committed Aug 1, 2024
1 parent 1214d51 commit 3aefcff
Showing 1 changed file with 30 additions and 0 deletions.
30 changes: 30 additions & 0 deletions crates/circuit/src/circuit_data.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1025,6 +1025,36 @@ impl CircuitData {
self.data.iter()
}

/// Assigns parameters to circuit data based on a slice of `Param`.
pub fn assign_parameters_from_slice(&mut self, py: Python, slice: &[Param]) -> PyResult<()> {
if slice.len() != self.param_table.num_parameters() {
todo!()
}
let mut old_table = std::mem::take(&mut self.param_table);
self.assign_parameters_inner(
py,
slice
.iter()
.cloned()
.zip(old_table.drain_ordered())
.map(|(value, (param_ob, uses))| (param_ob, value, uses)),
)
}

/// Assigns parameters to circuit data based on a mapping of `Param` : `Param`.
pub fn assign_parameters_from_mapping<'a, I>(&mut self, py: Python, iter: I) -> PyResult<()>
where
I: IntoIterator<Item = (&'a Param, &'a Param)>,
{
let mut items = Vec::new();
for (param_obj, value) in iter {
let param_obj = param_obj.to_object(py);
let uuid = ParameterUuid::from_parameter(param_obj.bind(py))?;
items.push((param_obj, value.clone(), self.param_table.pop(uuid)?));
}
self.assign_parameters_inner(py, items)
}

fn assign_parameters_inner<I>(&mut self, py: Python, iter: I) -> PyResult<()>
where
I: IntoIterator<Item = (Py<PyAny>, Param, HashSet<ParameterUse>)>,
Expand Down

0 comments on commit 3aefcff

Please sign in to comment.