dakk / qlasskit

A python-to-quantum compiler
https://dakk.github.io/qlasskit/
Apache License 2.0
56 stars 11 forks source link

Implement ast.Pow Operator Rewriting Rule in AstRewriter #49

Closed tomv42 closed 4 months ago

tomv42 commented 4 months ago

Description:

This PR addresses the issue of implementing the ast.Pow operator (**) between a variable and an integer constant. The goal is to rewrite the exponentiation operation as a series of multiplication operations. The following changes have been made:

Testing:

Explanation:

I focused on overriding the visit_BinOp method to handle the ast.Pow operator. My understanding is that visit_Pow is not applicable here because ast.Pow is an operator within a BinOp node rather than a standalone node. Thus, visit_BinOp seemed to be the appropriate place to implement this transformation. I'm not entirely sure if this is the best approach, but it appears to work based on my testing.

Related Issue:

This PR resolves issue #23


Please review these changes and provide feedback :smile:

dakk commented 4 months ago

Hi Tom, great work; I will try the code tomorrow, but I already have some requests:

tomv42 commented 4 months ago

Thank you for your feedback.