Skip to content

refactor!: More flexible pytket encoding #849

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

Open
wants to merge 8 commits into
base: main
Choose a base branch
from
Open
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 tket2-exts/pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -34,4 +34,4 @@ repository = "https://github.com/CQCL/tket2/tree/main/tket2-exts"

[build-system]
requires = ["hatchling"]
build-backend = "hatchling.build"
build-backend = "hatchling.build"
2 changes: 1 addition & 1 deletion tket2-py/src/circuit.rs
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ create_py_exception!(
);

create_py_exception!(
tket2::serialize::pytket::TK1ConvertError,
tket2::serialize::pytket::Tk1ConvertError,
PyTK1ConvertError,
"Error type for the conversion between tket2 and tket1 operations."
);
Expand Down
7 changes: 5 additions & 2 deletions tket2/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -50,14 +50,17 @@ itertools = { workspace = true }
petgraph = { workspace = true }
portmatching = { workspace = true, optional = true, features = ["serde"] }
derive_more = { workspace = true, features = [
"error",
"debug",
"display",
"error",
"from",
"into",
"sum",
"add",
] }
hugr = { workspace = true }
hugr-core = { workspace = true }
portgraph = { workspace = true, features = ["serde"] }
portgraph = { workspace = true, features = ["serde", "petgraph"] }
strum = { workspace = true, features = ["derive"] }
fxhash = { workspace = true }
indexmap = { workspace = true }
Expand Down
6 changes: 3 additions & 3 deletions tket2/src/extension.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

use std::sync::Arc;

use crate::serialize::pytket::OpaqueTk1Op;
use crate::serialize::pytket::extension::OpaqueTk1Op;
use crate::Tk2Op;
use hugr::extension::simple_op::MakeOpDef;
use hugr::extension::{
Expand Down Expand Up @@ -32,10 +32,10 @@ use sympy::SympyOpDef;
pub const TKET1_EXTENSION_ID: ExtensionId = IdentList::new_unchecked("TKET1");

/// The name for opaque TKET1 operations.
pub const TKET1_OP_NAME: SmolStr = SmolStr::new_inline("TKET1 Json Op");
pub const TKET1_OP_NAME: SmolStr = SmolStr::new_inline("tk1op");

/// The ID of an opaque TKET1 operation metadata.
pub const TKET1_PAYLOAD_NAME: SmolStr = SmolStr::new_inline("TKET1 Json Payload");
pub const TKET1_PAYLOAD_NAME: SmolStr = SmolStr::new_inline("TKET1-json-payload");

/// Current version of the TKET 1 extension
pub const TKET1_EXTENSION_VERSION: Version = Version::new(0, 1, 0);
Expand Down
2 changes: 1 addition & 1 deletion tket2/src/extension/rotation.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ lazy_static! {
}

/// Identifier for the rotation type.
const ROTATION_TYPE_ID: SmolStr = SmolStr::new_inline("rotation");
pub const ROTATION_TYPE_ID: SmolStr = SmolStr::new_inline("rotation");
/// Rotation type (as [CustomType])
pub fn rotation_custom_type(extension_ref: &Weak<Extension>) -> CustomType {
CustomType::new(
Expand Down
27 changes: 2 additions & 25 deletions tket2/src/ops.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ use std::sync::{Arc, Weak};

use crate::extension::bool::bool_type;
use crate::extension::rotation::rotation_type;
use crate::extension::sympy::{SympyOpDef, SYM_OP_ID};
use crate::extension::sympy::SympyOpDef;
use crate::extension::{TKET2_EXTENSION, TKET2_EXTENSION_ID as EXTENSION_ID};
use hugr::ops::custom::ExtensionOp;
use hugr::types::Type;
Expand All @@ -14,7 +14,7 @@ use hugr::{
},
ops::OpType,
type_row,
types::{type_param::TypeArg, Signature},
types::Signature,
};

use derive_more::{Display, Error};
Expand Down Expand Up @@ -190,29 +190,6 @@ pub fn symbolic_constant_op(arg: String) -> OpType {
SympyOpDef.with_expr(arg).into()
}

/// match against a symbolic constant
pub(crate) fn match_symb_const_op(op: &OpType) -> Option<String> {
// Extract the symbol for a symbolic operation node.
let symbol_from_typeargs = |args: &[TypeArg]| -> String {
args.first()
.and_then(|arg| match arg {
TypeArg::String { arg } => Some(arg.clone()),
_ => None,
})
.unwrap_or_else(|| panic!("Found an invalid type arg in a symbolic operation node."))
};

if let OpType::ExtensionOp(e) = op {
if e.def().name() == &SYM_OP_ID && e.def().extension_id() == &EXTENSION_ID {
Some(symbol_from_typeargs(e.args()))
} else {
None
}
} else {
None
}
}

#[cfg(test)]
pub(crate) mod test {

Expand Down
Loading
Loading