From 1e692676b3b812ec276fd405518bb261fc3e8fcc Mon Sep 17 00:00:00 2001 From: Agustin Borgna Date: Thu, 7 Sep 2023 18:41:18 +0100 Subject: [PATCH] Bump HUGR dependency --- Cargo.toml | 2 +- src/circuit/command.rs | 3 +-- src/extension.rs | 10 ++++++---- src/json/encoder.rs | 6 ++++-- src/ops.rs | 10 +++++----- src/portmatching/matcher.rs | 22 ++++++++-------------- src/portmatching/pyo3.rs | 2 +- src/rewrite.rs | 9 +++------ src/rewrite/ecc_rewriter.rs | 2 +- 9 files changed, 30 insertions(+), 36 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 0ffe4a7c..dec2ddee 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -69,7 +69,7 @@ members = ["pyrs", "compile-matcher"] [workspace.dependencies] -quantinuum-hugr = { git = "https://github.com/CQCL-DEV/hugr", rev = "abfaba6" } +quantinuum-hugr = { git = "https://github.com/CQCL-DEV/hugr", rev = "5a97a635" } portgraph = { version = "0.8", features = ["serde"] } pyo3 = { version = "0.19" } itertools = { version = "0.11.0" } diff --git a/src/circuit/command.rs b/src/circuit/command.rs index 14fa6ad2..747a47cb 100644 --- a/src/circuit/command.rs +++ b/src/circuit/command.rs @@ -8,7 +8,6 @@ use std::iter::FusedIterator; use hugr::hugr::views::HierarchyView; use hugr::ops::{OpTag, OpTrait}; use petgraph::visit::{GraphBase, IntoNeighborsDirected, IntoNodeIdentifiers}; -use portgraph::PortOffset; use super::Circuit; @@ -107,7 +106,7 @@ where optype .static_input() // TODO query optype for this port once it is available in hugr. - .map(|_| PortOffset::new_incoming(sig.input.len()).into()), + .map(|_| Port::new_incoming(sig.input.len())), ) .filter_map(|port| { let (from, from_port) = self.circ.linked_ports(node, port).next()?; diff --git a/src/extension.rs b/src/extension.rs index ad54731f..634bbd7b 100644 --- a/src/extension.rs +++ b/src/extension.rs @@ -81,7 +81,9 @@ pub(crate) fn wrap_json_op(op: &JsonOp) -> ExternalOp { // .into() let sig = op.signature(); let op = serde_yaml::to_value(op).unwrap(); - let payload = TypeArg::Opaque(CustomTypeArg::new(TKET1_OP_PAYLOAD.clone(), op).unwrap()); + let payload = TypeArg::Opaque { + arg: CustomTypeArg::new(TKET1_OP_PAYLOAD.clone(), op).unwrap(), + }; OpaqueOp::new( TKET1_EXTENSION_ID, JSON_OP_NAME, @@ -100,17 +102,17 @@ pub(crate) fn try_unwrap_json_op(ext: &ExternalOp) -> Option { if ext.name() != format!("{TKET1_EXTENSION_ID}.{JSON_OP_NAME}") { return None; } - let Some(TypeArg::Opaque(op)) = ext.args().get(0) else { + let Some(TypeArg::Opaque { arg }) = ext.args().get(0) else { // TODO: Throw an error? We should never get here if the name matches. return None; }; - let op = serde_yaml::from_value(op.value.clone()).ok()?; + let op = serde_yaml::from_value(arg.value.clone()).ok()?; Some(op) } /// Compute the signature of a json-encoded TKET1 operation. fn json_op_signature(args: &[TypeArg]) -> Result { - let [TypeArg::Opaque(arg)] = args else { + let [TypeArg::Opaque { arg }] = args else { // This should have already been checked. panic!("Wrong number of arguments"); }; diff --git a/src/json/encoder.rs b/src/json/encoder.rs index 3711e401..ad81b653 100644 --- a/src/json/encoder.rs +++ b/src/json/encoder.rs @@ -163,8 +163,10 @@ impl JsonEncoder { OpType::Const(const_op) => { // New constant, register it if it can be interpreted as a parameter. match const_op.value() { - Value::Prim(PrimValue::Extension((v,))) => { - if let Some(f) = v.downcast_ref::() { + Value::Prim { + val: PrimValue::Extension { c: (val,) }, + } => { + if let Some(f) = val.downcast_ref::() { f.to_string() } else { return false; diff --git a/src/ops.rs b/src/ops.rs index 47c5ee2e..8783e698 100644 --- a/src/ops.rs +++ b/src/ops.rs @@ -184,9 +184,9 @@ pub fn symbolic_constant_op(s: &str) -> OpType { let l: LeafOp = EXTENSION .instantiate_extension_op( &SYM_OP_ID, - vec![TypeArg::Opaque( - CustomTypeArg::new(SYM_EXPR_T, value).unwrap(), - )], + vec![TypeArg::Opaque { + arg: CustomTypeArg::new(SYM_EXPR_T, value).unwrap(), + }], ) .unwrap() .into(); @@ -202,11 +202,11 @@ pub(crate) fn match_symb_const_op(op: &OpType) -> Option<&str> { { // TODO also check extension name - let Some(TypeArg::Opaque(s)) = e.args().get(0) else { + let Some(TypeArg::Opaque { arg }) = e.args().get(0) else { panic!("should be an opaque type arg.") }; - let serde_yaml::Value::String(s) = &s.value else { + let serde_yaml::Value::String(s) = &arg.value else { panic!("unexpected yaml value.") }; diff --git a/src/portmatching/matcher.rs b/src/portmatching/matcher.rs index a666451b..4dcd8915 100644 --- a/src/portmatching/matcher.rs +++ b/src/portmatching/matcher.rs @@ -8,17 +8,8 @@ use std::{ }; use super::{CircuitPattern, PEdge, PNode}; -use hugr::{ - hugr::views::{ - sibling::{ - ConvexChecker, InvalidReplacement, - InvalidSubgraph::{self}, - }, - SiblingSubgraph, - }, - ops::OpType, - Hugr, Node, Port, -}; +use hugr::hugr::views::sibling_subgraph::{ConvexChecker, InvalidReplacement, InvalidSubgraph}; +use hugr::{hugr::views::SiblingSubgraph, ops::OpType, Hugr, Node, Port}; use itertools::Itertools; use portmatching::{ automaton::{LineBuilder, ScopeAutomaton}, @@ -82,7 +73,7 @@ pub struct PatternMatch<'a, C> { pub(super) root: Node, } -impl<'a, C: Circuit<'a>> PatternMatch<'a, C> { +impl<'a, C: Circuit<'a> + Clone> PatternMatch<'a, C> { /// The matcher's pattern ID of the match. pub fn pattern_id(&self) -> PatternID { self.pattern @@ -246,7 +237,10 @@ impl PatternMatcher { } /// Find all convex pattern matches in a circuit. - pub fn find_matches<'a, C: Circuit<'a>>(&self, circuit: &'a C) -> Vec> { + pub fn find_matches<'a, C: Circuit<'a> + Clone>( + &self, + circuit: &'a C, + ) -> Vec> { let mut checker = ConvexChecker::new(circuit); circuit .commands() @@ -255,7 +249,7 @@ impl PatternMatcher { } /// Find all convex pattern matches in a circuit rooted at a given node. - fn find_rooted_matches<'a, C: Circuit<'a>>( + fn find_rooted_matches<'a, C: Circuit<'a> + Clone>( &self, circ: &'a C, root: Node, diff --git a/src/portmatching/pyo3.rs b/src/portmatching/pyo3.rs index ce146856..41faed6c 100644 --- a/src/portmatching/pyo3.rs +++ b/src/portmatching/pyo3.rs @@ -121,7 +121,7 @@ impl PyPatternMatch { /// /// Requires references to the circuit and pattern to resolve indices /// into these objects. - pub fn try_from_rust<'circ, C: Circuit<'circ>>( + pub fn try_from_rust<'circ, C: Circuit<'circ> + Clone>( m: PatternMatch<'circ, C>, circ: &C, matcher: &PatternMatcher, diff --git a/src/rewrite.rs b/src/rewrite.rs index 5947a339..d4919878 100644 --- a/src/rewrite.rs +++ b/src/rewrite.rs @@ -7,12 +7,9 @@ pub use ecc_rewriter::ECCRewriter; use delegate::delegate; use derive_more::{From, Into}; +use hugr::hugr::views::sibling_subgraph::InvalidReplacement; use hugr::{ - hugr::{ - hugrmut::HugrMut, - views::{sibling::InvalidReplacement, SiblingSubgraph}, - Rewrite, SimpleReplacementError, - }, + hugr::{hugrmut::HugrMut, views::SiblingSubgraph, Rewrite, SimpleReplacementError}, Hugr, HugrView, SimpleReplacement, }; @@ -55,5 +52,5 @@ impl CircuitRewrite { /// Generate rewrite rules for circuits. pub trait Rewriter { /// Get the rewrite rules for a circuit. - fn get_rewrites<'a, C: Circuit<'a>>(&'a self, circ: &'a C) -> Vec; + fn get_rewrites<'a, C: Circuit<'a> + Clone>(&'a self, circ: &'a C) -> Vec; } diff --git a/src/rewrite/ecc_rewriter.rs b/src/rewrite/ecc_rewriter.rs index 1bad0157..32d181ed 100644 --- a/src/rewrite/ecc_rewriter.rs +++ b/src/rewrite/ecc_rewriter.rs @@ -96,7 +96,7 @@ impl ECCRewriter { } impl Rewriter for ECCRewriter { - fn get_rewrites<'a, C: Circuit<'a>>(&'a self, circ: &'a C) -> Vec { + fn get_rewrites<'a, C: Circuit<'a> + Clone>(&'a self, circ: &'a C) -> Vec { let matches = self.matcher.find_matches(circ); matches .into_iter()