File tree Expand file tree Collapse file tree 2 files changed +8
-6
lines changed Expand file tree Collapse file tree 2 files changed +8
-6
lines changed Original file line number Diff line number Diff line change @@ -470,17 +470,14 @@ def to_ast(self, program: Program) -> ast.Expression:
470
470
def to_ast (program : Program , item : AstConvertible ) -> ast .Expression :
471
471
"""Convert an object to an AST node."""
472
472
if hasattr (item , "_to_oqpy_expression" ):
473
- item = cast (ExpressionConvertible , item )
474
- return item ._to_oqpy_expression ().to_ast (program )
473
+ item = cast (ExpressionConvertible , item )._to_oqpy_expression ()
475
474
if hasattr (item , "_to_cached_oqpy_expression" ):
476
475
item = cast (CachedExpressionConvertible , item )
477
476
if item ._oqpy_cache_key is None :
478
477
item ._oqpy_cache_key = uuid .uuid1 ()
479
478
if item ._oqpy_cache_key not in program .expr_cache :
480
- program .expr_cache [item ._oqpy_cache_key ] = item ._to_cached_oqpy_expression ().to_ast (
481
- program
482
- )
483
- return program .expr_cache [item ._oqpy_cache_key ]
479
+ program .expr_cache [item ._oqpy_cache_key ] = item ._to_cached_oqpy_expression ()
480
+ item = program .expr_cache [item ._oqpy_cache_key ]
484
481
if isinstance (item , (complex , np .complexfloating )):
485
482
if item .imag == 0 :
486
483
return to_ast (program , item .real )
Original file line number Diff line number Diff line change @@ -1586,21 +1586,26 @@ def _to_oqpy_expression(self):
1586
1586
class C :
1587
1587
def _to_oqpy_expression (self ):
1588
1588
return 1e-7
1589
+ def __rmul__ (self , other ):
1590
+ return other * self ._to_oqpy_expression ()
1589
1591
1590
1592
frame = FrameVar (name = "f1" )
1591
1593
prog = Program ()
1592
1594
prog .set (A ("a1" ), 2 )
1595
+ prog .set (FloatVar (name = "c1" ), 3 * C ())
1593
1596
prog .delay (A ("a2" ), frame )
1594
1597
prog .delay (B ("b1" ), frame )
1595
1598
prog .delay (C (), frame )
1596
1599
expected = textwrap .dedent (
1597
1600
"""
1598
1601
OPENQASM 3.0;
1599
1602
duration a1 = 100.0ns;
1603
+ float[64] c1;
1600
1604
duration a2 = 100.0ns;
1601
1605
frame f1;
1602
1606
float[64] b1 = 1e-07;
1603
1607
a1 = 2;
1608
+ c1 = 3e-07;
1604
1609
delay[a2] f1;
1605
1610
delay[b1 * 1s] f1;
1606
1611
delay[100.0ns] f1;
You can’t perform that action at this time.
0 commit comments