@@ -31,7 +31,9 @@ use qiskit_circuit::interner::Interned;
3131use qiskit_circuit:: operations:: StandardGate ;
3232use qiskit_circuit:: operations:: { ArrayType , Operation , Param , UnitaryGate } ;
3333use qiskit_circuit:: packed_instruction:: PackedOperation ;
34- use qiskit_quantum_info:: convert_2q_block_matrix:: { blocks_to_matrix, get_matrix_from_inst} ;
34+ use qiskit_quantum_info:: convert_2q_block_matrix:: {
35+ blocks_to_matrix, get_1q_matrix_from_inst, get_2q_matrix_from_inst, get_matrix_from_inst,
36+ } ;
3537use qiskit_synthesis:: linalg:: nalgebra_array_view;
3638use qiskit_synthesis:: two_qubit_decompose:: RXXEquivalent ;
3739use qiskit_synthesis:: two_qubit_decompose:: {
@@ -289,14 +291,31 @@ fn py_run_consolidate_blocks(
289291 phys_qargs. get ( dag, inst. qubits ) ,
290292 ) {
291293 all_block_gates. insert ( inst_node) ;
292- let matrix = match get_matrix_from_inst ( inst) {
293- Ok ( mat) => mat,
294- Err ( _) => continue ,
295- } ;
296- // TODO: Use Matrix2/ArrayType::OneQ when we're using nalgebra
297- // for consolidation
298- let unitary_gate = UnitaryGate {
299- array : ArrayType :: NDArray ( matrix) ,
294+ let num_qubits = inst. op . num_qubits ( ) ;
295+ let unitary_gate = if num_qubits == 1 {
296+ let matrix = match get_1q_matrix_from_inst ( inst) {
297+ Ok ( mat) => mat,
298+ Err ( _) => continue ,
299+ } ;
300+ UnitaryGate {
301+ array : ArrayType :: OneQ ( matrix) ,
302+ }
303+ } else if num_qubits == 2 {
304+ let matrix = match get_2q_matrix_from_inst ( inst) {
305+ Ok ( mat) => mat,
306+ Err ( _) => continue ,
307+ } ;
308+ UnitaryGate {
309+ array : ArrayType :: TwoQ ( matrix) ,
310+ }
311+ } else {
312+ let matrix = match get_matrix_from_inst ( inst) {
313+ Ok ( mat) => mat,
314+ Err ( _) => continue ,
315+ } ;
316+ UnitaryGate {
317+ array : ArrayType :: NDArray ( matrix) ,
318+ }
300319 } ;
301320 dag. substitute_op (
302321 inst_node,
@@ -450,12 +469,15 @@ fn py_run_consolidate_blocks(
450469 first_qubits,
451470 )
452471 {
453- let matrix = match get_matrix_from_inst ( first_inst) {
472+ // Runs are necessarily single qubit gates so if it has a matrix then it
473+ // must have a single qubit matrix or it's not a run and the blocks handling above
474+ // would have covered it
475+ let matrix = match get_1q_matrix_from_inst ( first_inst) {
454476 Ok ( mat) => mat,
455477 Err ( _) => continue ,
456478 } ;
457479 let unitary_gate = UnitaryGate {
458- array : ArrayType :: NDArray ( matrix) ,
480+ array : ArrayType :: OneQ ( matrix) ,
459481 } ;
460482 dag. substitute_op (
461483 first_inst_node,
0 commit comments