@@ -16,7 +16,7 @@ use std::cell::OnceCell;
16
16
use crate :: bit_data:: BitData ;
17
17
use crate :: circuit_instruction:: { CircuitInstruction , OperationFromPython } ;
18
18
use crate :: imports:: { ANNOTATED_OPERATION , CLBIT , QUANTUM_CIRCUIT , QUBIT } ;
19
- use crate :: interner:: { Index , IndexedInterner , Interner } ;
19
+ use crate :: interner:: { Interned , Interner } ;
20
20
use crate :: operations:: { Operation , OperationRef , Param , StandardGate } ;
21
21
use crate :: packed_instruction:: { PackedInstruction , PackedOperation } ;
22
22
use crate :: parameter_table:: { ParameterTable , ParameterTableError , ParameterUse , ParameterUuid } ;
@@ -91,9 +91,9 @@ pub struct CircuitData {
91
91
/// The packed instruction listing.
92
92
data : Vec < PackedInstruction > ,
93
93
/// The cache used to intern instruction bits.
94
- qargs_interner : IndexedInterner < Vec < Qubit > > ,
94
+ qargs_interner : Interner < [ Qubit ] > ,
95
95
/// The cache used to intern instruction bits.
96
- cargs_interner : IndexedInterner < Vec < Clbit > > ,
96
+ cargs_interner : Interner < [ Clbit ] > ,
97
97
/// Qubits registered in the circuit.
98
98
qubits : BitData < Qubit > ,
99
99
/// Clbits registered in the circuit.
@@ -148,8 +148,8 @@ impl CircuitData {
148
148
global_phase,
149
149
) ?;
150
150
for ( operation, params, qargs, cargs) in instruction_iter {
151
- let qubits = ( & mut res. qargs_interner ) . intern ( qargs) ? ;
152
- let clbits = ( & mut res. cargs_interner ) . intern ( cargs) ? ;
151
+ let qubits = res. qargs_interner . insert_owned ( qargs) ;
152
+ let clbits = res. cargs_interner . insert_owned ( cargs) ;
153
153
let params = ( !params. is_empty ( ) ) . then ( || Box :: new ( params) ) ;
154
154
res. data . push ( PackedInstruction {
155
155
op : operation,
@@ -199,9 +199,9 @@ impl CircuitData {
199
199
instruction_iter. size_hint ( ) . 0 ,
200
200
global_phase,
201
201
) ?;
202
- let no_clbit_index = ( & mut res. cargs_interner ) . intern ( Vec :: new ( ) ) ? ;
202
+ let no_clbit_index = res. cargs_interner . insert ( & [ ] ) ;
203
203
for ( operation, params, qargs) in instruction_iter {
204
- let qubits = ( & mut res. qargs_interner ) . intern ( qargs. to_vec ( ) ) ? ;
204
+ let qubits = res. qargs_interner . insert ( & qargs) ;
205
205
let params = ( !params. is_empty ( ) ) . then ( || Box :: new ( params) ) ;
206
206
res. data . push ( PackedInstruction {
207
207
op : operation. into ( ) ,
@@ -227,8 +227,8 @@ impl CircuitData {
227
227
) -> PyResult < Self > {
228
228
let mut res = CircuitData {
229
229
data : Vec :: with_capacity ( instruction_capacity) ,
230
- qargs_interner : IndexedInterner :: new ( ) ,
231
- cargs_interner : IndexedInterner :: new ( ) ,
230
+ qargs_interner : Interner :: new ( ) ,
231
+ cargs_interner : Interner :: new ( ) ,
232
232
qubits : BitData :: new ( py, "qubits" . to_string ( ) ) ,
233
233
clbits : BitData :: new ( py, "clbits" . to_string ( ) ) ,
234
234
param_table : ParameterTable :: new ( ) ,
@@ -258,9 +258,9 @@ impl CircuitData {
258
258
params : & [ Param ] ,
259
259
qargs : & [ Qubit ] ,
260
260
) -> PyResult < ( ) > {
261
- let no_clbit_index = ( & mut self . cargs_interner ) . intern ( Vec :: new ( ) ) ? ;
261
+ let no_clbit_index = self . cargs_interner . insert ( & [ ] ) ;
262
262
let params = ( !params. is_empty ( ) ) . then ( || Box :: new ( params. iter ( ) . cloned ( ) . collect ( ) ) ) ;
263
- let qubits = ( & mut self . qargs_interner ) . intern ( qargs. to_vec ( ) ) ? ;
263
+ let qubits = self . qargs_interner . insert ( qargs) ;
264
264
self . data . push ( PackedInstruction {
265
265
op : operation. into ( ) ,
266
266
qubits,
@@ -351,8 +351,8 @@ impl CircuitData {
351
351
) -> PyResult < Self > {
352
352
let mut self_ = CircuitData {
353
353
data : Vec :: new ( ) ,
354
- qargs_interner : IndexedInterner :: new ( ) ,
355
- cargs_interner : IndexedInterner :: new ( ) ,
354
+ qargs_interner : Interner :: new ( ) ,
355
+ cargs_interner : Interner :: new ( ) ,
356
356
qubits : BitData :: new ( py, "qubits" . to_string ( ) ) ,
357
357
clbits : BitData :: new ( py, "clbits" . to_string ( ) ) ,
358
358
param_table : ParameterTable :: new ( ) ,
@@ -572,10 +572,10 @@ impl CircuitData {
572
572
let qubits = PySet :: empty_bound ( py) ?;
573
573
let clbits = PySet :: empty_bound ( py) ?;
574
574
for inst in self . data . iter ( ) {
575
- for b in self . qargs_interner . intern ( inst. qubits ) {
575
+ for b in self . qargs_interner . get ( inst. qubits ) {
576
576
qubits. add ( self . qubits . get ( * b) . unwrap ( ) . clone_ref ( py) ) ?;
577
577
}
578
- for b in self . cargs_interner . intern ( inst. clbits ) {
578
+ for b in self . cargs_interner . get ( inst. clbits ) {
579
579
clbits. add ( self . clbits . get ( * b) . unwrap ( ) . clone_ref ( py) ) ?;
580
580
}
581
581
}
@@ -737,8 +737,8 @@ impl CircuitData {
737
737
// Get a single item, assuming the index is validated as in bounds.
738
738
let get_single = |index : usize | {
739
739
let inst = & self . data [ index] ;
740
- let qubits = self . qargs_interner . intern ( inst. qubits ) ;
741
- let clbits = self . cargs_interner . intern ( inst. clbits ) ;
740
+ let qubits = self . qargs_interner . get ( inst. qubits ) ;
741
+ let clbits = self . cargs_interner . get ( inst. clbits ) ;
742
742
CircuitInstruction {
743
743
operation : inst. op . clone ( ) ,
744
744
qubits : PyTuple :: new_bound ( py, self . qubits . map_indices ( qubits) ) . unbind ( ) ,
@@ -894,7 +894,7 @@ impl CircuitData {
894
894
for inst in other. data . iter ( ) {
895
895
let qubits = other
896
896
. qargs_interner
897
- . intern ( inst. qubits )
897
+ . get ( inst. qubits )
898
898
. iter ( )
899
899
. map ( |b| {
900
900
Ok ( self
@@ -905,7 +905,7 @@ impl CircuitData {
905
905
. collect :: < PyResult < Vec < Qubit > > > ( ) ?;
906
906
let clbits = other
907
907
. cargs_interner
908
- . intern ( inst. clbits )
908
+ . get ( inst. clbits )
909
909
. iter ( )
910
910
. map ( |b| {
911
911
Ok ( self
@@ -915,8 +915,8 @@ impl CircuitData {
915
915
} )
916
916
. collect :: < PyResult < Vec < Clbit > > > ( ) ?;
917
917
let new_index = self . data . len ( ) ;
918
- let qubits_id = Interner :: intern ( & mut self . qargs_interner , qubits) ? ;
919
- let clbits_id = Interner :: intern ( & mut self . cargs_interner , clbits) ? ;
918
+ let qubits_id = self . qargs_interner . insert_owned ( qubits) ;
919
+ let clbits_id = self . cargs_interner . insert_owned ( clbits) ;
920
920
self . data . push ( PackedInstruction {
921
921
op : inst. op . clone ( ) ,
922
922
qubits : qubits_id,
@@ -1113,14 +1113,12 @@ impl CircuitData {
1113
1113
}
1114
1114
1115
1115
fn pack ( & mut self , py : Python , inst : & CircuitInstruction ) -> PyResult < PackedInstruction > {
1116
- let qubits = Interner :: intern (
1117
- & mut self . qargs_interner ,
1118
- self . qubits . map_bits ( inst. qubits . bind ( py) ) ?. collect ( ) ,
1119
- ) ?;
1120
- let clbits = Interner :: intern (
1121
- & mut self . cargs_interner ,
1122
- self . clbits . map_bits ( inst. clbits . bind ( py) ) ?. collect ( ) ,
1123
- ) ?;
1116
+ let qubits = self
1117
+ . qargs_interner
1118
+ . insert_owned ( self . qubits . map_bits ( inst. qubits . bind ( py) ) ?. collect ( ) ) ;
1119
+ let clbits = self
1120
+ . cargs_interner
1121
+ . insert_owned ( self . clbits . map_bits ( inst. clbits . bind ( py) ) ?. collect ( ) ) ;
1124
1122
Ok ( PackedInstruction {
1125
1123
op : inst. operation . clone ( ) ,
1126
1124
qubits,
@@ -1138,12 +1136,12 @@ impl CircuitData {
1138
1136
}
1139
1137
1140
1138
/// Returns an immutable view of the Interner used for Qargs
1141
- pub fn qargs_interner ( & self ) -> & IndexedInterner < Vec < Qubit > > {
1139
+ pub fn qargs_interner ( & self ) -> & Interner < [ Qubit ] > {
1142
1140
& self . qargs_interner
1143
1141
}
1144
1142
1145
1143
/// Returns an immutable view of the Interner used for Cargs
1146
- pub fn cargs_interner ( & self ) -> & IndexedInterner < Vec < Clbit > > {
1144
+ pub fn cargs_interner ( & self ) -> & Interner < [ Clbit ] > {
1147
1145
& self . cargs_interner
1148
1146
}
1149
1147
@@ -1162,14 +1160,14 @@ impl CircuitData {
1162
1160
& self . clbits
1163
1161
}
1164
1162
1165
- /// Unpacks from InternerIndex to `[Qubit]`
1166
- pub fn get_qargs ( & self , index : Index ) -> & [ Qubit ] {
1167
- self . qargs_interner ( ) . intern ( index)
1163
+ /// Unpacks from interned value to `[Qubit]`
1164
+ pub fn get_qargs ( & self , index : Interned < [ Qubit ] > ) -> & [ Qubit ] {
1165
+ self . qargs_interner ( ) . get ( index)
1168
1166
}
1169
1167
1170
1168
/// Unpacks from InternerIndex to `[Clbit]`
1171
- pub fn get_cargs ( & self , index : Index ) -> & [ Clbit ] {
1172
- self . cargs_interner ( ) . intern ( index)
1169
+ pub fn get_cargs ( & self , index : Interned < [ Clbit ] > ) -> & [ Clbit ] {
1170
+ self . cargs_interner ( ) . get ( index)
1173
1171
}
1174
1172
1175
1173
fn assign_parameters_inner < I > ( & mut self , py : Python , iter : I ) -> PyResult < ( ) >
0 commit comments