@@ -1216,6 +1216,8 @@ mod tests {
12161216 } ;
12171217 use crate :: parameter:: parameter_expression:: ParameterExpression ;
12181218 use crate :: parameter:: symbol_expr:: Symbol ;
1219+ #[ cfg( feature = "cache_pygates" ) ]
1220+ use std:: sync:: OnceLock ;
12191221
12201222 fn basic_circuit ( ) -> CircuitData {
12211223 let qreg = QuantumRegister :: new_owning ( "q" , 2 ) ;
@@ -1407,6 +1409,8 @@ q_1: ┤ H ├┤1 ├┤1 ├┤ my_ch ├
14071409 clbits : circuit. cargs_interner ( ) . get_default ( ) ,
14081410 params : None ,
14091411 label : None ,
1412+ #[ cfg( feature = "cache_pygates" ) ]
1413+ py_op : OnceLock :: new ( ) ,
14101414 } ;
14111415 circuit. push ( inst) . unwrap ( ) ;
14121416 let inst = PackedInstruction {
@@ -1418,6 +1422,8 @@ q_1: ┤ H ├┤1 ├┤1 ├┤ my_ch ├
14181422 clbits : circuit. cargs_interner ( ) . get_default ( ) ,
14191423 params : None ,
14201424 label : Some ( Box :: new ( "my little identity" . to_string ( ) ) ) ,
1425+ #[ cfg( feature = "cache_pygates" ) ]
1426+ py_op : OnceLock :: new ( ) ,
14211427 } ;
14221428 circuit. push ( inst) . unwrap ( ) ;
14231429 let inst = PackedInstruction {
@@ -1429,6 +1435,8 @@ q_1: ┤ H ├┤1 ├┤1 ├┤ my_ch ├
14291435 clbits : circuit. cargs_interner ( ) . get_default ( ) ,
14301436 params : None ,
14311437 label : None ,
1438+ #[ cfg( feature = "cache_pygates" ) ]
1439+ py_op : OnceLock :: new ( ) ,
14321440 } ;
14331441 circuit. push ( inst) . unwrap ( ) ;
14341442 let inst = PackedInstruction {
@@ -1440,6 +1448,8 @@ q_1: ┤ H ├┤1 ├┤1 ├┤ my_ch ├
14401448 clbits : circuit. cargs_interner ( ) . get_default ( ) ,
14411449 params : None ,
14421450 label : Some ( Box :: new ( "my small identity" . to_string ( ) ) ) ,
1451+ #[ cfg( feature = "cache_pygates" ) ]
1452+ py_op : OnceLock :: new ( ) ,
14431453 } ;
14441454 circuit. push ( inst) . unwrap ( ) ;
14451455 let inst = PackedInstruction {
@@ -1451,6 +1461,8 @@ q_1: ┤ H ├┤1 ├┤1 ├┤ my_ch ├
14511461 clbits : circuit. cargs_interner ( ) . get_default ( ) ,
14521462 params : None ,
14531463 label : None ,
1464+ #[ cfg( feature = "cache_pygates" ) ]
1465+ py_op : OnceLock :: new ( ) ,
14541466 } ;
14551467 circuit. push ( inst) . unwrap ( ) ;
14561468 let inst = PackedInstruction {
@@ -1462,6 +1474,8 @@ q_1: ┤ H ├┤1 ├┤1 ├┤ my_ch ├
14621474 clbits : circuit. cargs_interner ( ) . get_default ( ) ,
14631475 params : None ,
14641476 label : Some ( Box :: new ( "my medium identity" . to_string ( ) ) ) ,
1477+ #[ cfg( feature = "cache_pygates" ) ]
1478+ py_op : OnceLock :: new ( ) ,
14651479 } ;
14661480 circuit. push ( inst) . unwrap ( ) ;
14671481 let inst = PackedInstruction {
@@ -1473,6 +1487,8 @@ q_1: ┤ H ├┤1 ├┤1 ├┤ my_ch ├
14731487 clbits : circuit. cargs_interner ( ) . get_default ( ) ,
14741488 params : None ,
14751489 label : None ,
1490+ #[ cfg( feature = "cache_pygates" ) ]
1491+ py_op : OnceLock :: new ( ) ,
14761492 } ;
14771493 circuit. push ( inst) . unwrap ( ) ;
14781494 let inst = PackedInstruction {
@@ -1484,6 +1500,8 @@ q_1: ┤ H ├┤1 ├┤1 ├┤ my_ch ├
14841500 clbits : circuit. cargs_interner ( ) . get_default ( ) ,
14851501 params : None ,
14861502 label : Some ( Box :: new ( "my bigger identity" . to_string ( ) ) ) ,
1503+ #[ cfg( feature = "cache_pygates" ) ]
1504+ py_op : OnceLock :: new ( ) ,
14871505 } ;
14881506 circuit. push ( inst) . unwrap ( ) ;
14891507 let result = draw_circuit ( & circuit, false , false , Some ( 80 ) ) . unwrap ( ) ;
@@ -1535,7 +1553,7 @@ q_3: ──────────────────────┤1
15351553 . map ( |x| Qubit ( x + ( i as u32 % ( num_wires - num_qubits) ) ) )
15361554 . collect :: < Vec < _ > > ( ) ;
15371555 let params = ( 0 ..num_params)
1538- . map ( |_x| 3.141 . into ( ) )
1556+ . map ( |_x| std :: f64 :: consts :: PI . into ( ) )
15391557 . collect :: < Vec < Param > > ( ) ;
15401558 circuit. push_standard_gate ( op, & params, & qubits) . unwrap ( ) ;
15411559 }
@@ -1624,7 +1642,9 @@ q_4: ─────────────────────────
16241642 #[ test]
16251643 fn test_global_phase ( ) {
16261644 let mut circuit = basic_circuit ( ) ;
1627- circuit. set_global_phase_param ( 3.14 . into ( ) ) . unwrap ( ) ;
1645+ circuit
1646+ . set_global_phase_param ( std:: f64:: consts:: PI . into ( ) )
1647+ . unwrap ( ) ;
16281648 let result = draw_circuit ( & circuit, true , false , None ) . unwrap ( ) ;
16291649
16301650 let expected = "
@@ -1729,6 +1749,8 @@ q_1: ┤1 ├┤1 ├┤1 ├
17291749 clbits : circuit. cargs_interner ( ) . get_default ( ) ,
17301750 params : None ,
17311751 label : None ,
1752+ #[ cfg( feature = "cache_pygates" ) ]
1753+ py_op : OnceLock :: new ( ) ,
17321754 } ;
17331755 circuit. push ( inst) . unwrap ( ) ;
17341756 }
@@ -1747,18 +1769,22 @@ q_1: ┤1 ├┤1 ├┤1 ├
17471769 clbits : circuit. cargs_interner ( ) . get_default ( ) ,
17481770 params : Some ( Box :: new ( Parameters :: Params ( smallvec ! [ param] ) ) ) ,
17491771 label : None ,
1772+ #[ cfg( feature = "cache_pygates" ) ]
1773+ py_op : OnceLock :: new ( ) ,
17501774 } ;
17511775 circuit. push ( inst) . unwrap ( ) ;
17521776 }
17531777 }
17541778 for i in [ 1 , 2 , 3 , 4 ] {
1755- let qubits = ( 0 ..i) . map ( |x| Qubit :: new ( x ) ) . collect :: < Vec < _ > > ( ) ;
1779+ let qubits = ( 0 ..i) . map ( Qubit :: new) . collect :: < Vec < _ > > ( ) ;
17561780 let inst = PackedInstruction {
17571781 op : StandardInstruction :: Barrier ( i as u32 ) . into ( ) ,
17581782 qubits : circuit. add_qargs ( & qubits) ,
17591783 clbits : circuit. cargs_interner ( ) . get_default ( ) ,
17601784 params : None ,
17611785 label : None ,
1786+ #[ cfg( feature = "cache_pygates" ) ]
1787+ py_op : OnceLock :: new ( ) ,
17621788 } ;
17631789 circuit. push ( inst) . unwrap ( ) ;
17641790 }
@@ -1769,6 +1795,8 @@ q_1: ┤1 ├┤1 ├┤1 ├
17691795 clbits : circuit. add_cargs ( & [ Clbit :: new ( i) ] ) ,
17701796 params : None ,
17711797 label : None ,
1798+ #[ cfg( feature = "cache_pygates" ) ]
1799+ py_op : OnceLock :: new ( ) ,
17721800 } ;
17731801 circuit. push ( inst) . unwrap ( ) ;
17741802 }
0 commit comments