1
1
use std:: {
2
2
borrow:: Borrow ,
3
+ collections:: HashMap ,
3
4
fmt:: Display ,
4
5
fs,
5
6
io:: { self , BufReader } ,
@@ -20,7 +21,7 @@ use powdr_ast::{
20
21
} ;
21
22
use powdr_backend:: { Backend , BackendOptions , BackendType , Proof } ;
22
23
use powdr_executor:: {
23
- constant_evaluator:: { self , get_uniquely_sized_cloned , VariablySizedColumn } ,
24
+ constant_evaluator:: { self , VariablySizedColumn } ,
24
25
witgen:: {
25
26
chain_callbacks, extract_publics, unused_query_callback, QueryCallback , WitgenCallback ,
26
27
WitgenCallbackContext , WitnessGenerator ,
@@ -549,9 +550,30 @@ impl<T: FieldElement> Pipeline<T> {
549
550
550
551
if self . arguments . export_witness_csv {
551
552
if let Some ( path) = self . path_if_should_write ( |name| format ! ( "{name}_columns.csv" ) ) ? {
552
- // TODO: Handle multiple sizes
553
- let fixed = get_uniquely_sized_cloned ( fixed) . unwrap ( ) ;
554
- let columns = fixed. iter ( ) . chain ( witness. iter ( ) ) . collect :: < Vec < _ > > ( ) ;
553
+ // get the column size for each namespace. This assumes all witness columns of the same namespace have the same size.
554
+ let witness_sizes: HashMap < & str , u64 > = witness
555
+ . iter ( )
556
+ . map ( |( name, values) | {
557
+ let namespace = name. split ( "::" ) . next ( ) . unwrap ( ) ;
558
+ ( namespace, values. len ( ) as u64 )
559
+ } )
560
+ . collect ( ) ;
561
+
562
+ // choose the fixed column of the correct size. This assumes any namespace with no witness columns has a unique size
563
+ let fixed = fixed. iter ( ) . map ( |( name, columns) | {
564
+ let namespace = name. split ( "::" ) . next ( ) . unwrap ( ) ;
565
+ let columns = witness_sizes
566
+ . get ( & namespace)
567
+ // if we have witness columns, use their size
568
+ . map ( |size| columns. get_by_size ( * size) . unwrap ( ) )
569
+ // otherwise, return the unique size
570
+ . unwrap_or_else ( || columns. get_uniquely_sized ( ) . unwrap ( ) ) ;
571
+ ( name, columns)
572
+ } ) ;
573
+
574
+ let columns = fixed
575
+ . chain ( witness. iter ( ) . map ( |( name, values) | ( name, values. as_ref ( ) ) ) )
576
+ . collect :: < Vec < _ > > ( ) ;
555
577
556
578
let csv_file = fs:: File :: create ( path) . map_err ( |e| vec ! [ format!( "{}" , e) ] ) ?;
557
579
write_polys_csv_file ( csv_file, self . arguments . csv_render_mode , & columns) ;
0 commit comments