Skip to content
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

Merged
merged 13 commits into from
Sep 29, 2023
Merged

feat: Python bindings for TASO #142

merged 13 commits into from
Sep 29, 2023

Conversation

lmondada
Copy link
Contributor

  • feat: Serialisation for ECCRewriter
  • feat: Python bindings for TASO

@lmondada lmondada marked this pull request as ready for review September 28, 2023 06:51
@lmondada lmondada requested review from aborgna-q and ss2165 and removed request for aborgna-q September 28, 2023 06:51
@lmondada
Copy link
Contributor Author

pytest will pass once #140 is merged in!

@@ -0,0 +1,75 @@
use std::fs;
Copy link
Member

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

Copy link
Contributor Author

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 mved it.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

no don't worry

impl PyDefaultTasoOptimiser {
/// Create a new [`PyDefaultTasoOptimiser`] from a precompiled rewriter.
#[staticmethod]
pub fn load_precompiled(path: &str) -> Self {
Copy link
Member

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

Copy link
Contributor Author

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.

n_threads: Option<NonZeroUsize>,
) -> PyResult<PyObject> {
let circ = pyobj_as_hugr(circ)?;
let circ_candidates_csv = fs::File::create("best_circs.csv").unwrap();
Copy link
Member

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?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For sure, done.

);
let ser_circ =
SerialCircuit::encode(&opt_circ).map_err(|e| PyTypeError::new_err(e.to_string()))?;
let tk1_circ = ser_circ
Copy link
Member

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?

Copy link
Contributor Author

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);
Copy link
Member

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

@lmondada
Copy link
Contributor Author

Voilà! Your review made me also add #148

@lmondada lmondada requested a review from ss2165 September 29, 2023 11:05
Copy link
Member

@ss2165 ss2165 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

looks good

@lmondada lmondada merged commit ca2d3df into main Sep 29, 2023
7 checks passed
@lmondada lmondada deleted the feat/opt-bindings branch September 29, 2023 13:29
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants