@@ -573,7 +573,8 @@ pub(in crate::hugr::patch) mod test {
573
573
DataflowSubContainer , HugrBuilder , ModuleBuilder ,
574
574
} ;
575
575
use crate :: extension:: prelude:: { bool_t, qb_t} ;
576
- use crate :: hugr:: patch:: PatchVerification ;
576
+ use crate :: hugr:: patch:: simple_replace:: OutputBoundaryMap ;
577
+ use crate :: hugr:: patch:: { PatchVerification , ReplacementPort } ;
577
578
use crate :: hugr:: views:: { HugrView , SiblingSubgraph } ;
578
579
use crate :: hugr:: { Hugr , HugrMut , Patch } ;
579
580
use crate :: ops:: dataflow:: DataflowOpTrait ;
@@ -584,7 +585,7 @@ pub(in crate::hugr::patch) mod test {
584
585
use crate :: std_extensions:: logic:: LogicOp ;
585
586
use crate :: types:: { Signature , Type } ;
586
587
use crate :: utils:: test_quantum_extension:: { cx_gate, h_gate} ;
587
- use crate :: { IncomingPort , Node , OutgoingPort } ;
588
+ use crate :: { Direction , IncomingPort , Node , OutgoingPort , Port } ;
588
589
589
590
use super :: SimpleReplacement ;
590
591
@@ -801,6 +802,17 @@ pub(in crate::hugr::patch) mod test {
801
802
nu_inp,
802
803
nu_out : nu_out. into ( ) ,
803
804
} ;
805
+
806
+ // Check output boundary
807
+ assert_eq ! (
808
+ r. map_host_output( ( h_outp_node, h_port_2) ) . unwrap( ) ,
809
+ ReplacementPort :: from( ( r. get_replacement_io( ) . unwrap( ) [ 1 ] , n_port_2) )
810
+ ) ;
811
+ assert ! ( r
812
+ . map_host_output( ( h_outp_node, OutgoingPort :: from( 0 ) ) )
813
+ . is_none( ) ) ;
814
+
815
+ // Check invalidation set
804
816
assert_eq ! (
805
817
HashSet :: <_>:: from_iter( r. invalidation_set( ) ) ,
806
818
HashSet :: <_>:: from_iter( [ h_node_cx, h_node_h0, h_node_h1, h_outp_node] ) ,
@@ -1209,6 +1221,58 @@ pub(in crate::hugr::patch) mod test {
1209
1221
assert_eq ! ( h. validate( ) , Ok ( ( ) ) ) ;
1210
1222
}
1211
1223
1224
+ #[ rstest]
1225
+ fn test_output_boundary_map ( dfg_hugr2 : Hugr ) {
1226
+ let [ inp, out] = dfg_hugr2. get_io ( dfg_hugr2. root ( ) ) . unwrap ( ) ;
1227
+ let map = [
1228
+ ( ( inp, OutgoingPort :: from ( 0 ) ) , IncomingPort :: from ( 0 ) ) ,
1229
+ ( ( inp, OutgoingPort :: from ( 1 ) ) , IncomingPort :: from ( 1 ) ) ,
1230
+ ]
1231
+ . into_iter ( )
1232
+ . collect ( ) ;
1233
+ let map = OutputBoundaryMap :: ByOutgoing ( map) ;
1234
+
1235
+ // Basic check: map as just defined
1236
+ assert_eq ! (
1237
+ map. get( inp, OutgoingPort :: from( 0 ) ) ,
1238
+ Some ( IncomingPort :: from( 0 ) )
1239
+ ) ;
1240
+ assert_eq ! (
1241
+ map. get( inp, OutgoingPort :: from( 1 ) ) ,
1242
+ Some ( IncomingPort :: from( 1 ) )
1243
+ ) ;
1244
+
1245
+ // Now check the map in terms of incoming ports
1246
+ assert ! ( map. get( out, IncomingPort :: from( 0 ) ) . is_none( ) ) ;
1247
+ assert_eq ! (
1248
+ map. get_as_incoming( out, IncomingPort :: from( 0 ) , & dfg_hugr2) ,
1249
+ Some ( IncomingPort :: from( 0 ) )
1250
+ ) ;
1251
+
1252
+ // Finally, check iterators
1253
+ assert_eq ! (
1254
+ map. iter( ) . collect:: <HashSet <_>>( ) ,
1255
+ HashSet :: from_iter( [
1256
+ (
1257
+ ( inp, Port :: new( Direction :: Outgoing , 0 ) ) ,
1258
+ IncomingPort :: from( 0 )
1259
+ ) ,
1260
+ (
1261
+ ( inp, Port :: new( Direction :: Outgoing , 1 ) ) ,
1262
+ IncomingPort :: from( 1 )
1263
+ ) ,
1264
+ ] )
1265
+ ) ;
1266
+ let h_gate = dfg_hugr2. output_neighbours ( inp) . nth ( 1 ) . unwrap ( ) ;
1267
+ assert_eq ! (
1268
+ map. iter_as_incoming( & dfg_hugr2) . collect:: <HashSet <_>>( ) ,
1269
+ HashSet :: from_iter( [
1270
+ ( ( out, IncomingPort :: from( 0 ) ) , IncomingPort :: from( 0 ) ) ,
1271
+ ( ( h_gate, IncomingPort :: from( 0 ) ) , IncomingPort :: from( 1 ) ) ,
1272
+ ] )
1273
+ ) ;
1274
+ }
1275
+
1212
1276
use crate :: hugr:: patch:: replace:: Replacement ;
1213
1277
fn to_replace ( h : & impl HugrView < Node = Node > , s : SimpleReplacement ) -> Replacement {
1214
1278
use crate :: hugr:: patch:: replace:: { NewEdgeKind , NewEdgeSpec } ;
0 commit comments