diff --git a/tket2/src/json/encoder.rs b/tket2/src/json/encoder.rs index d222344e..c86e564a 100644 --- a/tket2/src/json/encoder.rs +++ b/tket2/src/json/encoder.rs @@ -1,9 +1,10 @@ //! Intermediate structure for converting encoding [`Circuit`]s into [`SerialCircuit`]s. +use core::panic; use std::collections::HashMap; use hugr::extension::prelude::QB_T; -use hugr::ops::OpType; +use hugr::ops::{OpName, OpType}; use hugr::std_extensions::arithmetic::float_types::ConstF64; use hugr::values::Value; use hugr::Wire; @@ -179,10 +180,14 @@ impl JsonEncoder { }) .collect_vec(); if inputs.len() != command.input_count() { - debug_assert!(!matches!( - optype, - OpType::Const(_) | OpType::LoadConstant(_) - )); + debug_assert!( + !matches!(optype, OpType::Const(_) | OpType::LoadConstant(_)), + "Found a {} with {} inputs, of which {} are non-linear. In node {:?}", + optype.name(), + command.input_count(), + inputs.len(), + command.node() + ); return false; } @@ -220,8 +225,12 @@ impl JsonEncoder { }; for (unit, _, _) in command.outputs() { - if let CircuitUnit::Wire(wire) = unit { - self.add_parameter(wire, param.clone()); + match unit { + CircuitUnit::Wire(wire) => self.add_parameter(wire, param.clone()), + CircuitUnit::Linear(_) => panic!( + "Found a non-wire output {unit:?} for a {} command.", + optype.name() + ), } } true diff --git a/tket2/src/ops.rs b/tket2/src/ops.rs index 1bb8d067..87fc90d4 100644 --- a/tket2/src/ops.rs +++ b/tket2/src/ops.rs @@ -1,6 +1,7 @@ use crate::extension::{ SYM_EXPR_T, SYM_OP_ID, TKET2_EXTENSION as EXTENSION, TKET2_EXTENSION_ID as EXTENSION_ID, }; +use hugr::ops::OpName; use hugr::{ extension::{ prelude::{BOOL_T, QB_T}, @@ -68,10 +69,7 @@ pub enum Tk2Op { /// Whether an op is a given Tk2Op. pub fn op_matches(op: &OpType, tk2op: Tk2Op) -> bool { - let Some(ext_op) = tk2op.to_extension_op() else { - return false; - }; - op.as_leaf_op().and_then(|op| op.as_extension_op()) == Some(&ext_op) + op.name() == >::into(tk2op).name() } #[derive(Clone, Copy, Debug, Serialize, Deserialize, EnumIter, Display, PartialEq, PartialOrd)]