39
39
//! Use a [`SiblingSubgraph`] to define a region of a `HUGR`, within which
40
40
//! resources should be tracked. You can then construct a resource-tracked scope
41
41
//! using [`ResourceScope::new`].
42
+ //!
43
+ //! [`SiblingSubgraph`]: hugr::hugr::views::SiblingSubgraph
42
44
43
45
// Public API exports
44
46
pub use flow:: { DefaultResourceFlow , ResourceFlow , UnsupportedOp } ;
47
+ pub use interval:: { Interval , InvalidInterval } ;
45
48
pub use scope:: { ResourceScope , ResourceScopeConfig } ;
46
49
pub use types:: { CopyableValueId , OpValue , Position , ResourceAllocator , ResourceId } ;
47
50
48
51
// Internal modules
49
52
mod flow;
53
+ mod interval;
50
54
mod scope;
51
55
mod types;
52
56
53
57
#[ cfg( test) ]
54
- mod tests {
58
+ pub ( crate ) mod tests {
55
59
use hugr:: {
56
60
builder:: { DFGBuilder , Dataflow , DataflowHugr } ,
57
61
extension:: prelude:: qb_t,
58
- hugr:: views:: SiblingSubgraph ,
59
- ops:: handle:: DataflowParentID ,
60
62
types:: Signature ,
61
63
CircuitUnit , Hugr ,
62
64
} ;
@@ -67,13 +69,14 @@ mod tests {
67
69
use crate :: {
68
70
extension:: rotation:: { rotation_type, ConstRotation } ,
69
71
resource:: scope:: tests:: ResourceScopeReport ,
70
- TketOp ,
72
+ utils:: build_simple_circuit,
73
+ Circuit , TketOp ,
71
74
} ;
72
75
73
76
use super :: ResourceScope ;
74
77
75
78
// Gate being commuted has a non-linear input
76
- fn circ ( n_qubits : usize , add_rz : bool , add_const_rz : bool ) -> Hugr {
79
+ pub fn cx_rz_circuit ( n_qubits : usize , add_rz : bool , add_const_rz : bool ) -> Hugr {
77
80
let build = || {
78
81
let out_qb_row = vec ! [ qb_t( ) ; n_qubits] ;
79
82
let mut inp_qb_row = out_qb_row. clone ( ) ;
@@ -123,6 +126,18 @@ mod tests {
123
126
build ( ) . unwrap ( )
124
127
}
125
128
129
+ /// A two-qubit circuit with `n_cx` CNOTs.
130
+ pub fn cx_circuit ( n_cx : usize ) -> Hugr {
131
+ build_simple_circuit ( 2 , |circ| {
132
+ for _ in 0 ..n_cx {
133
+ circ. append ( TketOp :: CX , [ 0 , 1 ] ) ?;
134
+ }
135
+ Ok ( ( ) )
136
+ } )
137
+ . unwrap ( )
138
+ . into_hugr ( )
139
+ }
140
+
126
141
#[ rstest]
127
142
#[ case( 2 , false , false ) ]
128
143
#[ case( 2 , true , false ) ]
@@ -137,9 +152,8 @@ mod tests {
137
152
#[ case] add_rz : bool ,
138
153
#[ case] add_const_rz : bool ,
139
154
) {
140
- let circ = circ ( n_qubits, add_rz, add_const_rz) ;
141
- let subgraph =
142
- SiblingSubgraph :: try_new_dataflow_subgraph :: < _ , DataflowParentID > ( & circ) . unwrap ( ) ;
155
+ let circ = cx_rz_circuit ( n_qubits, add_rz, add_const_rz) ;
156
+ let subgraph = Circuit :: from ( & circ) . subgraph ( ) ;
143
157
let scope = ResourceScope :: new ( & circ, subgraph) ;
144
158
let info = ResourceScopeReport :: from ( & scope) ;
145
159
0 commit comments