-
Notifications
You must be signed in to change notification settings - Fork 6
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat: Python bindings for TASO #142
Conversation
lmondada
commented
Sep 27, 2023
- feat: Serialisation for ECCRewriter
- feat: Python bindings for TASO
|
compile-rewriter/src/main.rs
Outdated
@@ -0,0 +1,75 @@ | |||
use std::fs; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
git doesn't seem to have picked up this rename
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think it's because there were too many changes, so it views it as a new file. Can I do anything about it? Pretty sure I git mv
ed it.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
no don't worry
src/optimiser/taso/pyo3.rs
Outdated
impl PyDefaultTasoOptimiser { | ||
/// Create a new [`PyDefaultTasoOptimiser`] from a precompiled rewriter. | ||
#[staticmethod] | ||
pub fn load_precompiled(path: &str) -> Self { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I believe you can use Path or PathBuf objects and they will be mapped to python pathlib.Path
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Awesome! It seems I need to pass a PathBuf
by value, but I assume given this is just for Python bindings it doesn't matter anyways.
src/optimiser/taso/pyo3.rs
Outdated
n_threads: Option<NonZeroUsize>, | ||
) -> PyResult<PyObject> { | ||
let circ = pyobj_as_hugr(circ)?; | ||
let circ_candidates_csv = fs::File::create("best_circs.csv").unwrap(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
make this path a (optional?) function parameter?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
For sure, done.
src/optimiser/taso/pyo3.rs
Outdated
); | ||
let ser_circ = | ||
SerialCircuit::encode(&opt_circ).map_err(|e| PyTypeError::new_err(e.to_string()))?; | ||
let tk1_circ = ser_circ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
you should be able to use try_update_hugr
from circuit.rs for this?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Turns out: had never known about the goodness in this file! I had to move the pyo3.rs
file out of tket2 and into pyrs
to use it. That was probably the right thing to do in the first place.
src/utils.rs
Outdated
use crate::json::TKETDecode; | ||
|
||
pub(crate) fn pyobj_as_hugr(circ: PyObject) -> PyResult<Hugr> { | ||
let ser_c = SerialCircuit::_from_tket1(circ); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
again see utilities in src/circuit.rs
Voilà! Your review made me also add #148 |
Co-authored-by: Agustín Borgna <[email protected]> # Conflicts: # compile-rewriter/src/main.rs # src/rewrite/ecc_rewriter.rs
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
looks good