@@ -12,6 +12,7 @@ use quil_rs::{
12
12
SetFrequency , SetPhase , SetScale , ShiftFrequency , ShiftPhase , Vector ,
13
13
} ,
14
14
program:: { FrameSet , MemoryRegion } ,
15
+ quil:: { Quil , ToQuilError } ,
15
16
Program ,
16
17
} ;
17
18
@@ -125,7 +126,12 @@ pub fn get_substitutions(
125
126
. map ( |substitution : & Expression | {
126
127
substitution
127
128
. evaluate ( & HashMap :: new ( ) , & params)
128
- . map_err ( |e| format ! ( "Could not evaluate expression {substitution}: {e:?}" ) )
129
+ . map_err ( |e| {
130
+ format ! (
131
+ "Could not evaluate expression {}: {e:?}" ,
132
+ substitution. to_quil_or_debug( )
133
+ )
134
+ } )
129
135
. and_then ( |complex| {
130
136
if complex. im == 0.0 {
131
137
Ok ( complex. re )
@@ -356,16 +362,16 @@ impl TryFrom<Program> for RewrittenProgram {
356
362
}
357
363
358
364
impl RewrittenProgram {
359
- pub ( crate ) fn to_string ( & self ) -> RewrittenQuil {
360
- RewrittenQuil ( self . inner . to_string ( ) )
365
+ pub ( crate ) fn to_string ( & self ) -> Result < RewrittenQuil , ToQuilError > {
366
+ Ok ( RewrittenQuil ( self . inner . to_quil ( ) ? ) )
361
367
}
362
368
}
363
369
364
370
#[ cfg( test) ]
365
371
mod describe_rewrite_arithmetic {
366
372
use std:: str:: FromStr ;
367
373
368
- use quil_rs:: Program ;
374
+ use quil_rs:: { quil :: Quil , Program } ;
369
375
370
376
use crate :: qpu:: rewrite_arithmetic:: rewrite_arithmetic;
371
377
@@ -378,7 +384,7 @@ mod describe_rewrite_arithmetic {
378
384
let ( actual, substitutions) = rewrite_arithmetic ( program) . unwrap ( ) ;
379
385
assert_eq ! ( actual, expected) ;
380
386
assert_eq ! ( substitutions. len( ) , 1 ) ;
381
- insta:: assert_snapshot!( substitutions[ 0 ] . to_string ( ) ) ;
387
+ insta:: assert_snapshot!( substitutions[ 0 ] . to_quil_or_debug ( ) ) ;
382
388
}
383
389
384
390
#[ test]
@@ -400,7 +406,7 @@ mod describe_rewrite_arithmetic {
400
406
let ( actual, substitutions) = rewrite_arithmetic ( program) . unwrap ( ) ;
401
407
assert_eq ! ( actual, expected) ;
402
408
assert_eq ! ( substitutions. len( ) , 1 ) ;
403
- insta:: assert_snapshot!( substitutions[ 0 ] . to_string ( ) ) ;
409
+ insta:: assert_snapshot!( substitutions[ 0 ] . to_quil_or_debug ( ) ) ;
404
410
}
405
411
406
412
#[ test]
@@ -427,8 +433,8 @@ RZ(__SUBST[1]) 0
427
433
let ( actual, substitutions) = rewrite_arithmetic ( program) . unwrap ( ) ;
428
434
assert_eq ! ( actual, expected) ;
429
435
assert_eq ! ( substitutions. len( ) , 2 ) ;
430
- insta:: assert_snapshot!( substitutions[ 0 ] . to_string ( ) ) ;
431
- insta:: assert_snapshot!( substitutions[ 1 ] . to_string ( ) ) ;
436
+ insta:: assert_snapshot!( substitutions[ 0 ] . to_quil_or_debug ( ) ) ;
437
+ insta:: assert_snapshot!( substitutions[ 1 ] . to_quil_or_debug ( ) ) ;
432
438
}
433
439
434
440
#[ test]
@@ -453,7 +459,7 @@ SET-SCALE 0 "rf" __SUBST[0]
453
459
let ( actual, substitutions) = rewrite_arithmetic ( program) . unwrap ( ) ;
454
460
assert_eq ! ( actual, expected) ;
455
461
assert_eq ! ( substitutions. len( ) , 1 ) ;
456
- insta:: assert_snapshot!( substitutions[ 0 ] . to_string ( ) ) ;
462
+ insta:: assert_snapshot!( substitutions[ 0 ] . to_quil_or_debug ( ) ) ;
457
463
}
458
464
459
465
#[ test]
@@ -490,8 +496,8 @@ SET-FREQUENCY 1 "rf" __SUBST[1]
490
496
let ( actual, substitutions) = rewrite_arithmetic ( program) . unwrap ( ) ;
491
497
assert_eq ! ( actual, expected) ;
492
498
assert_eq ! ( substitutions. len( ) , 2 ) ;
493
- insta:: assert_snapshot!( substitutions[ 0 ] . to_string ( ) ) ;
494
- insta:: assert_snapshot!( substitutions[ 1 ] . to_string ( ) ) ;
499
+ insta:: assert_snapshot!( substitutions[ 0 ] . to_quil_or_debug ( ) ) ;
500
+ insta:: assert_snapshot!( substitutions[ 1 ] . to_quil_or_debug ( ) ) ;
495
501
}
496
502
497
503
#[ test]
@@ -550,7 +556,7 @@ SHIFT-PHASE 0 "rf" __SUBST[0]
550
556
let ( actual, substitutions) = rewrite_arithmetic ( program) . unwrap ( ) ;
551
557
assert_eq ! ( actual, expected) ;
552
558
assert_eq ! ( substitutions. len( ) , 1 ) ;
553
- insta:: assert_snapshot!( substitutions[ 0 ] . to_string ( ) ) ;
559
+ insta:: assert_snapshot!( substitutions[ 0 ] . to_quil_or_debug ( ) ) ;
554
560
}
555
561
}
556
562
0 commit comments