Skip to content

Commit

Permalink
chore: Update to tket-json-rs 0.6 and pyo3 0.22
Browse files Browse the repository at this point in the history
  • Loading branch information
aborgna-q committed Oct 21, 2024
1 parent ed8d3d4 commit 107854b
Show file tree
Hide file tree
Showing 8 changed files with 33 additions and 82 deletions.
90 changes: 18 additions & 72 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,9 @@ hugr = "0.13.1"
hugr-core = "0.13.1"
hugr-cli = "0.13.1"
portgraph = "0.12"
pyo3 = "0.21.2"
pyo3 = "0.22.5"
itertools = "0.13.0"
tket-json-rs = "0.5.1"
tket-json-rs = "0.6.2"
tracing = "0.1.37"
portmatching = "0.3.1"
bytemuck = "1.19.0"
Expand Down
2 changes: 1 addition & 1 deletion tket2-py/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ serde_json = { workspace = true }
tket-json-rs = { workspace = true, features = ["pyo3"] }
hugr = { workspace = true }
portgraph = { workspace = true, features = ["serde"] }
pyo3 = { workspace = true }
pyo3 = { workspace = true, features = ["py-clone"] }
num_cpus = { workspace = true }
derive_more = { workspace = true, features = ["into", "from"] }
itertools = { workspace = true }
Expand Down
2 changes: 1 addition & 1 deletion tket2-py/src/circuit/tk2circuit.rs
Original file line number Diff line number Diff line change
Expand Up @@ -237,7 +237,7 @@ impl Tk2Circuit {
/// Tries to extract a Tk2Circuit from a python object.
///
/// Returns an error if the py object is not a Tk2Circuit.
pub fn try_extract(circ: &PyAny) -> PyResult<Self> {
pub fn try_extract(circ: &Bound<PyAny>) -> PyResult<Self> {
circ.extract::<Tk2Circuit>()
}
}
5 changes: 4 additions & 1 deletion tket2-py/src/optimiser.rs
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ pub enum BadgerCostFunction {
}

impl<'py> FromPyObject<'py> for BadgerCostFunction {
fn extract(ob: &'py PyAny) -> PyResult<Self> {
fn extract_bound(ob: &Bound<'py, PyAny>) -> PyResult<Self> {
let str = ob.extract::<&str>()?;
match str {
"cx" => Ok(BadgerCostFunction::CXCount),
Expand All @@ -53,6 +53,7 @@ impl<'py> FromPyObject<'py> for BadgerCostFunction {
impl PyBadgerOptimiser {
/// Create a new [`PyDefaultBadgerOptimiser`] from a precompiled rewriter.
#[staticmethod]
#[pyo3(signature = (path, cost_fn=None))]
pub fn load_precompiled(path: PathBuf, cost_fn: Option<BadgerCostFunction>) -> Self {
let opt = match cost_fn.unwrap_or_default() {
BadgerCostFunction::CXCount => {
Expand All @@ -69,6 +70,7 @@ impl PyBadgerOptimiser {
///
/// This will compile the rewriter from the provided ECC JSON file.
#[staticmethod]
#[pyo3(signature = (path, cost_fn=None))]
pub fn compile_eccs(path: &str, cost_fn: Option<BadgerCostFunction>) -> Self {
let opt = match cost_fn.unwrap_or_default() {
BadgerCostFunction::CXCount => {
Expand Down Expand Up @@ -130,6 +132,7 @@ impl PyBadgerOptimiser {
///
#[pyo3(name = "optimise")]
#[allow(clippy::too_many_arguments)]
#[pyo3(signature = (circ, timeout=None, progress_timeout=None, max_circuit_count=None, n_threads=None, split_circ=None, queue_size=None, log_progress=None))]
pub fn py_optimise<'py>(
&self,
circ: &Bound<'py, PyAny>,
Expand Down
1 change: 1 addition & 0 deletions tket2-py/src/passes.rs
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,7 @@ fn lower_to_pytket<'py>(circ: &Bound<'py, PyAny>) -> PyResult<Bound<'py, PyAny>>
/// Log files will be written to the directory `log_dir` if specified.
#[pyfunction]
#[allow(clippy::too_many_arguments)]
#[pyo3(signature = (circ, optimiser, max_threads=None, timeout=None, progress_timeout=None, max_circuit_count=None, log_dir=None, rebase=None))]
fn badger_optimise<'py>(
circ: &Bound<'py, PyAny>,
optimiser: &PyBadgerOptimiser,
Expand Down
2 changes: 1 addition & 1 deletion tket2-py/src/types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ pub fn module(py: Python<'_>) -> PyResult<Bound<'_, PyModule>> {
}

/// Bounds on the valid operations on a type in a HUGR program.
#[pyclass]
#[pyclass(eq, eq_int)]
#[pyo3(name = "TypeBound")]
#[derive(PartialEq, Clone, Debug)]
pub enum PyTypeBound {
Expand Down
9 changes: 5 additions & 4 deletions tket2/src/serialize/pytket/encoder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -228,6 +228,7 @@ impl Tk1Encoder {
qubits,
bits,
implicit_permutation,
number_of_ws: None,
}
}

Expand Down Expand Up @@ -320,7 +321,7 @@ impl QubitTracker {
pub fn finish(
mut self,
_circ: &Circuit<impl HugrView>,
) -> (Vec<RegisterUnit>, Vec<circuit_json::Permutation>) {
) -> (Vec<RegisterUnit>, Vec<circuit_json::ImplicitPermutation>) {
// Ensure the input and output lists have the same registers.
let mut outputs = self.outputs.unwrap_or_default();
let mut input_regs: HashSet<RegisterHash> =
Expand Down Expand Up @@ -354,7 +355,7 @@ impl QubitTracker {
let permutation = outputs
.into_iter()
.zip(&self.inputs)
.map(|(out, inp)| circuit_json::Permutation(inp.clone(), out))
.map(|(out, inp)| circuit_json::ImplicitPermutation(inp.clone(), out))
.collect_vec();

(self.inputs, permutation)
Expand Down Expand Up @@ -470,7 +471,7 @@ impl BitTracker {
pub fn finish(
mut self,
circ: &Circuit<impl HugrView>,
) -> (Vec<RegisterUnit>, Vec<circuit_json::Permutation>) {
) -> (Vec<RegisterUnit>, Vec<circuit_json::ImplicitPermutation>) {
let mut circuit_output_order: Vec<RegisterUnit> = Vec::with_capacity(self.inputs.len());
for (node, port) in circ.hugr().all_linked_outputs(circ.output_node()) {
let wire = Wire::new(node, port);
Expand Down Expand Up @@ -534,7 +535,7 @@ impl BitTracker {
let permutation = original_permutation
.into_iter()
.map(|(inp, out)| {
circuit_json::Permutation(inp, circuit_permutation.remove(&out).unwrap())
circuit_json::ImplicitPermutation(inp, circuit_permutation.remove(&out).unwrap())
})
.collect_vec();

Expand Down

0 comments on commit 107854b

Please sign in to comment.