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

chore: Update to hugr 0.6.0, fix breaking changes #464

Merged
merged 1 commit into from
Jul 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
16 changes: 8 additions & 8 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 3 additions & 3 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,9 @@ missing_docs = "warn"
[workspace.dependencies]

tket2 = { path = "./tket2" }
hugr = "0.5.1"
hugr-cli = "0.1.1"
hugr-core = "0.2.0"
hugr = "0.6.1"
hugr-cli = "0.1.2"
hugr-core = "0.3.1"
portgraph = "0.12"
pyo3 = "0.21.2"
itertools = "0.13.0"
Expand Down
17 changes: 5 additions & 12 deletions tket2/src/circuit.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ use hugr_core::hugr::internal::HugrMutInternals;
use itertools::Either::{Left, Right};

use hugr::hugr::hugrmut::HugrMut;
use hugr::hugr::NodeType;
use hugr::ops::dataflow::IOTrait;
use hugr::ops::{Input, NamedOp, OpParent, OpTag, OpTrait, Output};
use hugr::types::{FunctionType, PolyFuncType};
Expand Down Expand Up @@ -528,10 +527,7 @@ fn update_signature(
types.remove(in_index);
types.into()
};
let new_inp_op = Input::new(inp_types.clone());
let inp_exts = hugr.get_nodetype(inp).input_extensions().cloned();
hugr.replace_op(inp, NodeType::new(new_inp_op, inp_exts))
.unwrap();
hugr.replace_op(inp, Input::new(inp_types.clone())).unwrap();

// Update output node if necessary.
let out_types = out_index.map(|out_index| {
Expand All @@ -544,17 +540,14 @@ fn update_signature(
types.remove(out_index);
types.into()
};
let new_out_op = Output::new(out_types.clone());
let inp_exts = hugr.get_nodetype(out).input_extensions().cloned();
hugr.replace_op(out, NodeType::new(new_out_op, inp_exts))
hugr.replace_op(out, Output::new(out_types.clone()))
.unwrap();
out_types
});

// Update the parent's signature
let nodetype = hugr.get_nodetype(parent).clone();
let input_extensions = nodetype.input_extensions().cloned();
let mut optype = nodetype.into_op();
let mut optype = hugr.get_optype(parent).clone();

// Replace the parent node operation with the right operation type
// This must be able to process all implementers of `DataflowParent`.
match &mut optype {
Expand Down Expand Up @@ -594,7 +587,7 @@ fn update_signature(
})?,
}

hugr.replace_op(parent, NodeType::new(optype, input_extensions))?;
hugr.replace_op(parent, optype)?;

Ok(())
}
Expand Down
8 changes: 1 addition & 7 deletions tket2/src/circuit/command.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ use std::collections::{HashMap, HashSet};
use std::iter::FusedIterator;

use hugr::hugr::views::{HierarchyView, SiblingGraph};
use hugr::hugr::{NodeMetadata, NodeType};
use hugr::hugr::NodeMetadata;
use hugr::ops::{OpTag, OpTrait};
use hugr::{HugrView, IncomingPort, OutgoingPort};
use itertools::Either::{self, Left, Right};
Expand Down Expand Up @@ -40,12 +40,6 @@ impl<'circ, T: HugrView> Command<'circ, T> {
self.node
}

/// Returns the [`NodeType`] of the command.
#[inline]
pub fn nodetype(&self) -> &NodeType {
self.circ.hugr().get_nodetype(self.node)
}

/// Returns the [`OpType`] of the command.
#[inline]
pub fn optype(&self) -> &OpType {
Expand Down
20 changes: 3 additions & 17 deletions tket2/src/circuit/extract_dfg.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
//! Internal implementation of `Circuit::extract_dfg`.

use hugr::hugr::hugrmut::HugrMut;
use hugr::hugr::NodeType;
use hugr::ops::{OpTrait, OpType, Output, DFG};
use hugr::types::{FunctionType, SumType, TypeEnum};
use hugr::HugrView;
Expand All @@ -26,10 +25,7 @@ pub(super) fn rewrite_into_dfg(circ: &mut Circuit) -> Result<(), CircuitMutError
};

let dfg = DFG { signature };
let nodetype = circ.hugr.get_nodetype(circ.parent());
let input_extensions = nodetype.input_extensions().cloned();
let nodetype = NodeType::new(OpType::DFG(dfg), input_extensions);
circ.hugr.replace_op(circ.parent(), nodetype)?;
circ.hugr.replace_op(circ.parent(), OpType::DFG(dfg))?;

Ok(())
}
Expand All @@ -50,8 +46,7 @@ fn remove_cfg_empty_output_tuple(
let input_node = circ.input_node();

let output_node = circ.output_node();
let output_nodetype = circ.hugr.get_nodetype(output_node).clone();
let output_op = output_nodetype.op();
let output_op = circ.hugr.get_optype(output_node).clone();

let output_sig = output_op
.dataflow_signature()
Expand Down Expand Up @@ -89,16 +84,7 @@ fn remove_cfg_empty_output_tuple(
let new_op = Output {
types: new_types.clone().into(),
};
let new_node = hugr.add_node_after(
input_node,
NodeType::new(
new_op,
output_nodetype
.input_extensions()
.cloned()
.unwrap_or_default(),
),
);
let new_node = hugr.add_node_after(input_node, new_op);

// Reconnect the outputs.
for (i, (neigh, port)) in input_neighs.into_iter().enumerate() {
Expand Down
2 changes: 1 addition & 1 deletion tket2/src/passes/chunks.rs
Original file line number Diff line number Diff line change
Expand Up @@ -308,7 +308,7 @@ impl CircuitChunks {
.and_then(|s| s.as_str())
.unwrap_or("");

let mut builder = FunctionBuilder::new(name, self.signature.into()).unwrap();
let mut builder = FunctionBuilder::new(name, self.signature).unwrap();
// Take the unfinished Hugr from the builder, to avoid unnecessary
// validation checks that require connecting the inputs an outputs.
let mut reassembled = mem::take(builder.hugr_mut());
Expand Down
3 changes: 1 addition & 2 deletions tket2/src/passes/pytket.rs
Original file line number Diff line number Diff line change
Expand Up @@ -70,13 +70,12 @@ mod test {

let mut builder = ModuleBuilder::new();
let _func = {
let mut func = builder.define_function("main", circ_signature.into())?;
let mut func = builder.define_function("main", circ_signature)?;
let [q1, q2] = func.input_wires_arr();

let cfg = {
let mut cfg = func.cfg_builder(
[(QB_T, q1), (QB_T, q2)],
None,
two_qbs.clone(),
ExtensionSet::new(),
)?;
Expand Down
2 changes: 1 addition & 1 deletion tket2/src/serialize/pytket/decoder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ impl Tk1Decoder {
.with_extension_delta(TKET1_EXTENSION_ID);

let name = serialcirc.name.clone().unwrap_or_default();
let mut dfg = FunctionBuilder::new(name, sig.into()).unwrap();
let mut dfg = FunctionBuilder::new(name, sig).unwrap();
let dangling_wires = dfg.input_wires().collect::<Vec<_>>();

// Metadata. The circuit requires "name", and we store other things that
Expand Down
4 changes: 2 additions & 2 deletions tket2/src/utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ where
let qb_row = vec![QB_T; num_qubits];
let signature =
FunctionType::new(qb_row.clone(), qb_row).with_extension_delta(float_types::EXTENSION_ID);
let mut h = FunctionBuilder::new("main", signature.into())?;
let mut h = FunctionBuilder::new("main", signature)?;

let qbs = h.input_wires();

Expand All @@ -53,7 +53,7 @@ where
let circ = {
let qb_row = vec![QB_T; num_qubits];
let circ_signature = FunctionType::new(qb_row.clone(), qb_row);
let mut dfg = builder.define_function("main", circ_signature.into())?;
let mut dfg = builder.define_function("main", circ_signature)?;
let mut circ = dfg.as_circuit(dfg.input_wires());
f(&mut circ)?;
let qbs = circ.finish();
Expand Down
Loading