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

fix: Correctly detect custom ops by name #281

Merged
merged 3 commits into from
Jan 8, 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
23 changes: 16 additions & 7 deletions tket2/src/json/encoder.rs
Original file line number Diff line number Diff line change
@@ -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;
Expand Down Expand Up @@ -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;
}

Expand Down Expand Up @@ -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
Expand Down
6 changes: 2 additions & 4 deletions tket2/src/ops.rs
Original file line number Diff line number Diff line change
@@ -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},
Expand Down Expand Up @@ -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() == <Tk2Op as Into<OpType>>::into(tk2op).name()
}

#[derive(Clone, Copy, Debug, Serialize, Deserialize, EnumIter, Display, PartialEq, PartialOrd)]
Expand Down