Skip to content

Commit 76c8cef

Browse files
committed
Enable extra_subgraph test, add another to-be-fixed test
1 parent 5fe1846 commit 76c8cef

File tree

2 files changed

+37
-15
lines changed

2 files changed

+37
-15
lines changed

tket/src/serialize/pytket/decoder/subgraph.rs

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -179,8 +179,9 @@ impl<'h> PytketDecoderContext<'h> {
179179
// to track new qubits and bits, re-connect it to some output, or
180180
// leave it untouched.
181181
let wire = Wire::new(*src, *src_port);
182-
if let Some(counts) = self.config().type_to_pytket(ty) {
182+
if let Some(counts) = self.config().type_to_pytket(ty).filter(|c| c.params == 0) {
183183
// This port declares new outputs to be tracked by the decoder.
184+
// Output parameters from a subgraph are always marked as not supported (they don't map to any pytket argument variable).
184185

185186
// Make sure to disconnect the old wire.
186187
self.builder.hugr_mut().disconnect(*src, *src_port);
@@ -402,8 +403,11 @@ impl<'h> PytketDecoderContext<'h> {
402403
{
403404
let node = *insertion_result.node_map.get(&to_insert_node).unwrap();
404405
let wire = Wire::new(node, port);
405-
match self.config().type_to_pytket(ty) {
406+
match self.config().type_to_pytket(ty).filter(|c| c.params == 0) {
406407
Some(counts) => {
408+
// Track the registers in the subgraph output wires.
409+
// Output parameters from a subgraph are always marked as not supported (they don't map to any pytket argument variable).
410+
// We only track qubit/bit wires here.
407411
let wire_qubits = split_off(&mut output_qubits, ..counts.qubits);
408412
let wire_bits = split_off(&mut output_bits, ..counts.bits);
409413
if wire_qubits.is_none() || wire_bits.is_none() {

tket/src/serialize/pytket/tests.rs

Lines changed: 31 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -582,27 +582,44 @@ fn circ_nested_dfgs() -> Circuit {
582582
// A circuit with some simple circuit and an unsupported subgraph that does not interact with it.
583583
#[fixture]
584584
fn circ_independent_subgraph() -> Circuit {
585-
let input_t = vec![
586-
qb_t(),
587-
qb_t(),
588-
option_type(rotation_type()).into(),
589-
option_type(qb_t()).into(),
590-
];
591-
let output_t = vec![qb_t(), qb_t(), rotation_type(), option_type(qb_t()).into()];
585+
let input_t = vec![qb_t(), qb_t(), option_type(bool_t()).into()];
586+
let output_t = vec![qb_t(), qb_t(), bool_t()];
592587
let mut h =
593588
FunctionBuilder::new("independent_subgraph", Signature::new(input_t, output_t)).unwrap();
594589

595-
let [q1, q2, maybe_rot, maybe_q] = h.input_wires_arr();
590+
let [q1, q2, maybe_b] = h.input_wires_arr();
596591

597592
let [q1, q2] = h
598593
.add_dataflow_op(TketOp::CX, [q1, q2])
599594
.unwrap()
600595
.outputs_arr();
601-
let [rot] = h
602-
.build_unwrap_sum(1, option_type(rotation_type()), maybe_rot)
596+
let [maybe_b] = h
597+
.build_unwrap_sum(1, option_type(bool_t()), maybe_b)
603598
.unwrap();
604599

605-
let hugr = h.finish_hugr_with_outputs([q1, q2, rot, maybe_q]).unwrap();
600+
let hugr = h.finish_hugr_with_outputs([q1, q2, maybe_b]).unwrap();
601+
hugr.into()
602+
}
603+
604+
// A circuit with an unsupported wire from the input to the output.
605+
#[fixture]
606+
fn circ_unsupported_io_wire() -> Circuit {
607+
let input_t = vec![qb_t(), qb_t(), option_type(qb_t()).into()];
608+
let output_t = vec![qb_t(), qb_t(), option_type(qb_t()).into()];
609+
let mut h = FunctionBuilder::new(
610+
"unsupported_input_to_output",
611+
Signature::new(input_t, output_t),
612+
)
613+
.unwrap();
614+
615+
let [q1, q2, maybe_q] = h.input_wires_arr();
616+
617+
let [q1, q2] = h
618+
.add_dataflow_op(TketOp::CX, [q1, q2])
619+
.unwrap()
620+
.outputs_arr();
621+
622+
let hugr = h.finish_hugr_with_outputs([q1, q2, maybe_q]).unwrap();
606623
hugr.into()
607624
}
608625

@@ -847,8 +864,9 @@ fn fail_on_modified_hugr(circ_tk1_ops: Circuit) {
847864
//#[case::unsupported_subtree(circ_unsupported_subtree(), 3, CircuitRoundtripTestConfig::Default)]
848865
#[case::global_defs(circ_global_defs(), 1, CircuitRoundtripTestConfig::Default)]
849866
#[case::recursive(circ_recursive(), 1, CircuitRoundtripTestConfig::Default)]
850-
// TODO: Encoding of independent subgraphs needs more debugging.
851-
//#[case::independent_subgraph(circ_independent_subgraph(), 3, CircuitRoundtripTestConfig::Default)]
867+
#[case::independent_subgraph(circ_independent_subgraph(), 3, CircuitRoundtripTestConfig::Default)]
868+
// TODO: An unsupported wire from the input to the output causes an error.
869+
//#[case::unsupported_io_wire(circ_unsupported_io_wire(), 1, CircuitRoundtripTestConfig::Default)]
852870
// TODO: fix edge case: non-local edge from an unsupported node inside a nested CircBox
853871
// to/from the input of the head region being encoded...
854872
//#[case::non_local(circ_non_local(), 1)]

0 commit comments

Comments
 (0)