@@ -2,7 +2,7 @@ use qsc::{
22 LanguageFeatures , PackageType , SourceMap ,
33 interpret:: { CircuitEntryPoint , CircuitGenerationMethod , Interpreter } , target:: Profile ,
44} ;
5- use qsc_circuit:: { Circuit , Operation , TracerConfig } ;
5+ use qsc_circuit:: { Circuit , ComponentColumn , Operation , TracerConfig } ;
66use std:: collections:: HashMap ;
77
88use crate :: sim:: QsError ;
@@ -56,10 +56,20 @@ fn generate_quantikz_circuit(
5656
5757pub fn circuit_to_quantikz ( c : & Circuit ) -> String {
5858 let ( mut rows, register_to_row) = build_rows ( c) ;
59- let col_count = c. component_grid . len ( ) ;
59+
60+ let grid = if c. component_grid . len ( ) == 1
61+ && c. component_grid [ 0 ] . components . len ( ) == 1
62+ && !c. component_grid [ 0 ] . components [ 0 ] . children ( ) . is_empty ( )
63+ {
64+ c. component_grid [ 0 ] . components [ 0 ] . children ( )
65+ } else {
66+ & c. component_grid
67+ } ;
68+
69+ let col_count = grid. len ( ) ;
6070 let mut table = initialize_table ( rows. len ( ) , col_count, & rows) ;
6171
62- populate_table ( c , & register_to_row, & mut table, & mut rows) ;
72+ populate_table ( grid , & register_to_row, & mut table, & mut rows) ;
6373
6474 render_latex ( & rows, & table)
6575}
@@ -103,12 +113,12 @@ fn initialize_table(row_count: usize, col_count: usize, rows: &[Row]) -> Vec<Vec
103113}
104114
105115fn populate_table (
106- c : & Circuit ,
116+ grid : & [ ComponentColumn ] ,
107117 register_to_row : & RegisterMap ,
108118 table : & mut [ Vec < String > ] ,
109119 rows : & mut [ Row ] ,
110120) {
111- for ( col_index, col) in c . component_grid . iter ( ) . enumerate ( ) {
121+ for ( col_index, col) in grid . iter ( ) . enumerate ( ) {
112122 let table_col = col_index;
113123 for op in & col. components {
114124 // For measurements, we want to draw on the qubit line, so we treat qubits as targets for visual placement
0 commit comments