@@ -594,18 +594,19 @@ fn json_file_roundtrip(#[case] circ: impl AsRef<std::path::Path>) {
594594 compare_serial_circs ( & ser, & reser) ;
595595}
596596
597- /// Test the serialisation roundtrip from a tket circuit.
597+ /// Test the standalone serialisation roundtrip from a tket circuit.
598598///
599- /// Note: this is not a pure roundtrip as the encoder may add internal qubits/bits to the circuit.
599+ /// This is not a pure roundtrip as the encoder may add internal qubits/bits to
600+ /// the circuit.
601+ ///
602+ /// Standalone circuit do not currently support unsupported subgraphs with
603+ /// nested structure or non-local edges.
600604#[ rstest]
601605#[ case:: meas_ancilla( circ_measure_ancilla( ) , 1 ) ]
602606#[ case:: preset_qubits( circ_preset_qubits( ) , 1 ) ]
603607#[ case:: preset_parameterized( circ_parameterized( ) , 1 ) ]
604608#[ case:: nested_dfgs( circ_nested_dfgs( ) , 1 ) ]
605- #[ case:: global_defs( circ_global_defs( ) , 1 ) ]
606- #[ case:: recursive( circ_recursive( ) , 1 ) ]
607- #[ case:: non_local( circ_non_local( ) , 1 ) ]
608- fn circuit_roundtrip ( #[ case] circ : Circuit , #[ case] num_circuits : usize ) {
609+ fn circuit_standalone_roundtrip ( #[ case] circ : Circuit , #[ case] num_circuits : usize ) {
609610 let circ_signature = circ. circuit_signature ( ) . into_owned ( ) ;
610611
611612 let encoded = EncodedCircuit :: new_standalone ( & circ, EncodeOptions :: new_with_subcircuits ( ) )
@@ -619,6 +620,8 @@ fn circuit_roundtrip(#[case] circ: Circuit, #[case] num_circuits: usize) {
619620 . decode ( DecodeOptions :: new ( ) . with_signature ( circ_signature. clone ( ) ) )
620621 . unwrap_or_else ( |e| panic ! ( "{e}" ) ) ;
621622
623+ deser. hugr ( ) . validate ( ) . unwrap_or_else ( |e| panic ! ( "{e}" ) ) ;
624+
622625 let deser_sig = deser. circuit_signature ( ) ;
623626 assert_eq ! (
624627 & circ_signature. input, & deser_sig. input,
@@ -636,6 +639,46 @@ fn circuit_roundtrip(#[case] circ: Circuit, #[case] num_circuits: usize) {
636639 compare_serial_circs ( ser, & reser) ;
637640}
638641
642+ /// Test the serialisation roundtrip from a tket circuit into an EncodedCircuit and back.
643+ #[ rstest]
644+ #[ case:: meas_ancilla( circ_measure_ancilla( ) , 1 ) ]
645+ #[ case:: preset_qubits( circ_preset_qubits( ) , 1 ) ]
646+ #[ case:: preset_parameterized( circ_parameterized( ) , 1 ) ]
647+ #[ case:: nested_dfgs( circ_nested_dfgs( ) , 1 ) ]
648+ #[ case:: global_defs( circ_global_defs( ) , 1 ) ]
649+ #[ case:: recursive( circ_recursive( ) , 1 ) ]
650+ // TODO: fix edge case: non-local edge from an unsupported node inside a nested CircBox
651+ // to/from the input of the head region being encoded...
652+ //#[case::non_local(circ_non_local(), 1)]
653+ fn encoded_circuit_roundtrip ( #[ case] circ : Circuit , #[ case] num_circuits : usize ) {
654+ let circ_signature = circ. circuit_signature ( ) . into_owned ( ) ;
655+
656+ let encoded = EncodedCircuit :: new ( & circ, EncodeOptions :: new_with_subcircuits ( ) )
657+ . unwrap_or_else ( |e| panic ! ( "{e}" ) ) ;
658+
659+ assert ! ( encoded. contains_circuit( circ. parent( ) ) ) ;
660+ assert_eq ! ( encoded. len( ) , num_circuits) ;
661+
662+ let mut deser = circ. clone ( ) ;
663+ encoded
664+ . reassemble_inline ( deser. hugr_mut ( ) , None )
665+ . unwrap_or_else ( |e| panic ! ( "{e}" ) ) ;
666+
667+ deser. hugr ( ) . validate ( ) . unwrap_or_else ( |e| panic ! ( "{e}" ) ) ;
668+
669+ let deser_sig = deser. circuit_signature ( ) ;
670+ assert_eq ! (
671+ & circ_signature. input, & deser_sig. input,
672+ "Input signature mismatch\n Expected: {}\n Actual: {}" ,
673+ & circ_signature, & deser_sig
674+ ) ;
675+ assert_eq ! (
676+ & circ_signature. output, & deser_sig. output,
677+ "Output signature mismatch\n Expected: {}\n Actual: {}" ,
678+ & circ_signature, & deser_sig
679+ ) ;
680+ }
681+
639682/// Test serialisation of circuits with a symbolic expression.
640683///
641684/// Note: this is not a proper roundtrip as the symbols f0 and f1 are not
0 commit comments