tket2
tket2 copied to clipboard
How can 3rd party pyo3 projects do Circuit manipulation?
Scenario:
Someone writes a pass in rust code:
pub fn my_pass(circ: Circuit) -> Circuit;
and wants to make it available as a python method using pyo3.
How are they supposed to go about it?
In the tket2-py we define a Tk2Circuit wrapper marked with pyo3's #[pyclass], and some utilities to read it from python inputs:
#[pyfunction]
pub fn my_python_pass<'py>(circ: &Bound<'py, PyAny>) -> PyResult<Bound<'py, PyAny>> {
tket2_py::circuit::convert::update_circ(circ, |circ, _| my_pass(circ))
}
These conversion utilities are part of the private tket2-py, so they are not available for external crates. How can we expose these?
One option is to move the pyo3 dependency into tket2 (under a pyo3 feature), and expose convert there.
Thanks for making an issue :) Currently have to export the python circuit to json... load it in... modify in rust and then export the json back out again. Can construct a circuit from this output json though.
Related: https://github.com/CQCL/hugr/discussions/2616