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

chore!: Update pyo3 to 0.21 #33

Merged
merged 1 commit into from
Apr 4, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@ name = "tket_json_rs"
serde = { version = "1.0", features = ["derive"] }
serde_json = "1.0"
uuid = { version = "1.4", features = ["serde"] }
pyo3 = { version = "0.20.0", optional = true }
pythonize = { version = "0.20.0", optional = true }
pyo3 = { version = "0.21.1", optional = true }
pythonize = { version = "0.21.1", optional = true }


[features]
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ Serializable Rust definition for circuits and operations of the

## Features

- `pyo3`: Enable Python bindings via pyo3.
- `pyo3`: Enable Python bindings and `pytket.Circuit` conversion via pyo3.

## Recent Changes

Expand Down
12 changes: 6 additions & 6 deletions src/pytket.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,26 +2,26 @@

use crate::circuit_json::SerialCircuit;
use pyo3::prelude::*;
use pythonize::{depythonize, pythonize};
use pythonize::{depythonize_bound, pythonize};

impl SerialCircuit {
/// Create a new `SerialCircuit` from a `pytket.Circuit`.
pub fn from_tket1(circ: &PyAny) -> PyResult<Self> {
let circ = depythonize(circ.call_method0("to_dict").unwrap())?;
pub fn from_tket1(circ: &Bound<PyAny>) -> PyResult<Self> {
let circ = depythonize_bound(circ.call_method0("to_dict").unwrap())?;
Ok(circ)
}

/// Create a new `SerialCircuit` from a `pytket.Circuit`.
///
/// Utility function that calls [`SerialCircuit::from_tket1`] after acquiring the GIL.
pub fn from_tket1_with_gil(circ: Py<PyAny>) -> PyResult<Self> {
Python::with_gil(|py| Self::from_tket1(circ.as_ref(py)))
Python::with_gil(|py| Self::from_tket1(circ.bind(py)))
}

/// Convert a `SerialCircuit` to a `pytket.Circuit`.
pub fn to_tket1<'py>(&self, py: Python<'py>) -> PyResult<&'py PyAny> {
pub fn to_tket1<'py>(&self, py: Python<'py>) -> PyResult<Bound<'py, PyAny>> {
let dict = pythonize(py, self).unwrap();
let circ_module = PyModule::import(py, "pytket.circuit")?;
let circ_module = PyModule::import_bound(py, "pytket.circuit")?;

circ_module
.getattr("Circuit")?
Expand Down
Loading