-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
With this we can drop the `pyo3` features in hugr and portgraph. `tket2` and `tket-json-rs` still require it, as they define some non-error pyclasses. This requires manually converting errors by calling `convert_pyerrs` before `?`, but it is a small price to pay for not dealing with pyo3 versions across crates.
- Loading branch information
Showing
12 changed files
with
125 additions
and
92 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
//! Utility functions for the python interface. | ||
/// A trait for types wrapping rust errors that may be converted into python exception. | ||
/// | ||
/// In addition to raw errors, this is implemented for wrapper types such as `Result`. | ||
/// [`ConvertPyErr::convert_errors`] will be called on the internal error type. | ||
pub trait ConvertPyErr { | ||
/// The output type after conversion. | ||
type Output; | ||
|
||
/// Convert any internal errors to python errors. | ||
fn convert_pyerrs(self) -> Self::Output; | ||
} | ||
|
||
impl ConvertPyErr for pyo3::PyErr { | ||
type Output = Self; | ||
|
||
fn convert_pyerrs(self) -> Self::Output { | ||
self | ||
} | ||
} | ||
|
||
impl<T, E> ConvertPyErr for Result<T, E> | ||
where | ||
E: ConvertPyErr, | ||
{ | ||
type Output = Result<T, E::Output>; | ||
|
||
fn convert_pyerrs(self) -> Self::Output { | ||
self.map_err(|e| e.convert_pyerrs()) | ||
} | ||
} | ||
|
||
macro_rules! create_py_exception { | ||
($err:path, $py_err:ident, $doc:expr) => { | ||
pyo3::create_exception!(tket2, $py_err, pyo3::exceptions::PyException, $doc); | ||
|
||
impl $crate::utils::ConvertPyErr for $err { | ||
type Output = pyo3::PyErr; | ||
|
||
fn convert_pyerrs(self) -> Self::Output { | ||
$py_err::new_err(<Self as std::string::ToString>::to_string(&self)) | ||
} | ||
} | ||
}; | ||
} | ||
pub(crate) use create_py_exception; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,7 @@ | ||
//! Optimisation passes and related utilities for circuits. | ||
mod commutation; | ||
pub use commutation::apply_greedy_commutation; | ||
#[cfg(feature = "pyo3")] | ||
pub use commutation::PyPullForwardError; | ||
pub use commutation::{apply_greedy_commutation, PullForwardError}; | ||
|
||
pub mod chunks; | ||
pub use chunks::CircuitChunks; |
Oops, something went wrong.