Repository navigation
Fixed dumping after single-statement unrolling (#493) - #495
ShiveshDragon wants to merge 4 commits into
Conversation
Argus reviewAuto-review is off for this repo. Tick the box below to run a review on this PR.
Estimated cost
Tip: you can also comment |
Codecov Report✅ All modified and coverable lines are covered by tests. 📢 Thoughts on this report? Let us know! |
| curr_module._has_barriers = False | ||
| curr_module._statements = stmts_without_barriers | ||
| curr_module._unrolled_ast.statements = stmts_without_barriers | ||
| curr_module._is_unrolled = True |
There was a problem hiding this comment.
Why is this unrolled? Barriers could be removed from a program even if it is not unrolled
There was a problem hiding this comment.
I added that flag because remove_barriers() updates _unrolled_ast, but str() uses original program when _is_unrolled is False. This has caused the removed barriers to still appear in output.
I set the flag to True to make sure that the updated AST was used. However, I understand your point . The removal of barriers doesn't necessarily mean the program has been unrolled. I'll try to find better way to handle this issue.
| if not kwargs: | ||
| kwargs = {} | ||
|
|
||
| self._is_unrolled = False |
There was a problem hiding this comment.
Why is this required? Wouldn't we already have this attribute as False if we are doing unrolling for the first time?
There was a problem hiding this comment.
You are correct about that but it is redundant only during the first unroll, since the flag is already False initially. I added it so that it can handle the next unroll attempts, where the flag might still be True from previous successful unroll. Resetting it to False will ensure that a failed attempt doesn't leave the module incorrectly marked as unrolled. The Error Handler resets the AST but not the flag _is_unrolled which stays True because of previous successful attempt. But i will make sure to check the intended use and change it if necessary .
|
Hi @ShiveshDragon , thanks for contributing to the project and fixing #493 ! I wanted to discuss about whether the |
|
Thank you for taking the time to review my changes and for the guidance. And I have tried comparing _unrolled_ast before and after unrolling, but the AST might remain the same if the program doesn't have anything that needs expansion. So an unchanged AST wouldn't necessarily mean that unrolling hasn't occurred. That's why I thought of using an explicit flag would be more reliable . I would be happy to hear your suggestions. |
|
I have updated the implementation so that remove_barriers() doesn't change _is_unrolled . Instead of that, when the module hasn't been unrolled, str() creates a shallow copy of original_program and replaces its statements with the current _statements. I have used shallow copy and not deep copy to save memory . As for the issue of redundancy of the flag _is_unrolled , I think its better to keep it just in case the unroll attempt is unsuccessful and instead of showing False at the start , it could show True from previous successful attempt because Resetting didn't reset the flag. If there are any other ways to correct it , please guide me . |
Summary
Fixes #493
Previously, QasmModule.str() used the count of statements in the unrolled AST to find if unrolling had occurred or not.
This has caused incorrect output when unrolling gave zero or one statement, because the method returned the original program instead of giving the unrolled AST.
The changes done are as follows:
Testing
pytest tests/qasm3/test_printer.py -v— 16 passed.