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

refactor!: Rename tket2::json into tket2::serialize::pytket #392

Merged
merged 1 commit into from
Jun 10, 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
2 changes: 1 addition & 1 deletion badger-optimiser/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,10 @@ use std::path::PathBuf;
use std::process::exit;

use clap::Parser;
use tket2::json::{load_tk1_json_file, save_tk1_json_file};
use tket2::optimiser::badger::log::BadgerLogger;
use tket2::optimiser::badger::BadgerOptions;
use tket2::optimiser::{BadgerOptimiser, DefaultBadgerOptimiser};
use tket2::serialize::{load_tk1_json_file, save_tk1_json_file};

#[cfg(feature = "peak_alloc")]
#[global_allocator]
Expand Down
4 changes: 2 additions & 2 deletions tket2-py/src/circuit.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@ use std::fmt;

use hugr::{type_row, Hugr, HugrView, PortIndex};
use tket2::extension::{LINEAR_BIT, REGISTRY};
use tket2::json::TKETDecode;
use tket2::rewrite::CircuitRewrite;
use tket2::serialize::TKETDecode;
use tket_json_rs::circuit_json::SerialCircuit;

use crate::utils::create_py_exception;
Expand Down Expand Up @@ -83,7 +83,7 @@ create_py_exception!(
);

create_py_exception!(
tket2::json::OpConvertError,
tket2::serialize::pytket::OpConvertError,
PyOpConvertError,
"Error type for the conversion between tket2 and tket1 operations."
);
Expand Down
2 changes: 1 addition & 1 deletion tket2-py/src/circuit/convert.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@ use hugr::{Hugr, HugrView, Wire};
use serde::Serialize;
use tket2::circuit::CircuitHash;
use tket2::extension::REGISTRY;
use tket2::json::TKETDecode;
use tket2::passes::CircuitChunks;
use tket2::serialize::TKETDecode;
use tket2::{Circuit, Tk2Op};
use tket_json_rs::circuit_json::SerialCircuit;

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 @@ -20,8 +20,8 @@ use hugr::{Hugr, HugrView, Wire};
use serde::Serialize;
use tket2::circuit::CircuitHash;
use tket2::extension::REGISTRY;
use tket2::json::TKETDecode;
use tket2::passes::CircuitChunks;
use tket2::serialize::TKETDecode;
use tket2::{Circuit, Tk2Op};
use tket_json_rs::circuit_json::SerialCircuit;

Expand Down
5 changes: 3 additions & 2 deletions tket2/src/circuit.rs
Original file line number Diff line number Diff line change
Expand Up @@ -497,8 +497,9 @@ mod tests {
};

use super::*;
use crate::utils::build_module_with_circuit;
use crate::{json::load_tk1_json_str, utils::build_simple_circuit, Tk2Op};
use crate::serialize::load_tk1_json_str;
use crate::utils::{build_module_with_circuit, build_simple_circuit};
use crate::Tk2Op;

#[fixture]
fn tk1_circuit() -> Circuit {
Expand Down
2 changes: 1 addition & 1 deletion tket2/src/circuit/hash.rs
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,7 @@ pub enum HashError {
mod test {
use tket_json_rs::circuit_json;

use crate::json::TKETDecode;
use crate::serialize::TKETDecode;
use crate::utils::build_simple_circuit;
use crate::Tk2Op;

Expand Down
2 changes: 1 addition & 1 deletion tket2/src/extension.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
//!
//! This includes a extension for the opaque TKET1 operations.

use super::json::op::JsonOp;
use super::serialize::pytket::JsonOp;
use crate::Tk2Op;
use hugr::extension::prelude::PRELUDE;
use hugr::extension::simple_op::MakeOpDef;
Expand Down
4 changes: 2 additions & 2 deletions tket2/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
//! use hugr::HugrView;
//!
//! // Load a tket1 circuit.
//! let mut circ: Circuit = tket2::json::load_tk1_json_file("../test_files/barenco_tof_5.json").unwrap();
//! let mut circ: Circuit = tket2::serialize::load_tk1_json_file("../test_files/barenco_tof_5.json").unwrap();
//!
//! assert_eq!(circ.qubit_count(), 9);
//! assert_eq!(circ.num_operations(), 170);
Expand All @@ -45,11 +45,11 @@

pub mod circuit;
pub mod extension;
pub mod json;
pub(crate) mod ops;
pub mod optimiser;
pub mod passes;
pub mod rewrite;
pub mod serialize;

#[cfg(feature = "portmatching")]
pub mod portmatching;
Expand Down
2 changes: 1 addition & 1 deletion tket2/src/optimiser/badger.rs
Original file line number Diff line number Diff line change
Expand Up @@ -504,8 +504,8 @@ mod tests {
};
use rstest::{fixture, rstest};

use crate::json::load_tk1_json_str;
use crate::optimiser::badger::BadgerOptions;
use crate::serialize::load_tk1_json_str;
use crate::{extension::REGISTRY, Circuit, Tk2Op};

use super::{BadgerOptimiser, DefaultBadgerOptimiser};
Expand Down
9 changes: 9 additions & 0 deletions tket2/src/serialize.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
//! Utilities for serializing circuits.
//!
//! See [`crate::serialize::pytket`] for serialization to and from the legacy pytket format.
pub mod pytket;

pub use pytket::{
load_tk1_json_file, load_tk1_json_reader, load_tk1_json_str, save_tk1_json_file,
save_tk1_json_str, save_tk1_json_writer, TKETDecode,
};
6 changes: 4 additions & 2 deletions tket2/src/json.rs → tket2/src/serialize/pytket.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
//! Json serialization and deserialization.
//! Serialization and deserialization of circuits using the `pytket` JSON format.

mod decoder;
mod encoder;
pub mod op;
mod op;

pub(crate) use op::JsonOp;

#[cfg(test)]
mod tests;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@ use tket_json_rs::circuit_json::SerialCircuit;

use super::op::JsonOp;
use super::{try_param_to_constant, METADATA_IMPLICIT_PERM, METADATA_PHASE};
use super::{METADATA_B_REGISTERS, METADATA_Q_REGISTERS};
use crate::extension::{LINEAR_BIT, REGISTRY};
use crate::json::{METADATA_B_REGISTERS, METADATA_Q_REGISTERS};
use crate::symbolic_constant_op;

/// The state of an in-progress [`DFGBuilder`] being built from a [`SerialCircuit`].
Expand Down
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ use crate::Tk2Op;

/// A serialized operation, containing the operation type and all its attributes.
///
/// Wrapper around [`circuit_json::Operation`] with cached number of qubits and bits.
/// Wrapper around [`tket_json_rs::circuit_json::Operation`] with cached number of qubits and bits.
///
/// The `Operation` contained by this struct is guaranteed to have a signature.
#[derive(Clone, Debug, PartialEq, serde::Serialize, serde::Deserialize)]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,9 @@ use rstest::{fixture, rstest};
use tket_json_rs::circuit_json::{self, SerialCircuit};
use tket_json_rs::optype;

use super::TKETDecode;
use crate::circuit::Circuit;
use crate::extension::REGISTRY;
use crate::json::TKETDecode;
use crate::Tk2Op;

const SIMPLE_JSON: &str = r#"{
Expand Down
8 changes: 3 additions & 5 deletions tket2/tests/badger_termination.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,9 @@

use rstest::{fixture, rstest};
use tket2::optimiser::badger::BadgerOptions;
use tket2::{
json::TKETDecode,
optimiser::{BadgerOptimiser, DefaultBadgerOptimiser},
Circuit,
};
use tket2::optimiser::{BadgerOptimiser, DefaultBadgerOptimiser};
use tket2::serialize::TKETDecode;
use tket2::Circuit;
use tket_json_rs::circuit_json::SerialCircuit;

/// A set of equivalence circuit classes (ECC)
Expand Down