Fix double-unroll ValidationError when consolidate_qubits=True#297
Fix double-unroll ValidationError when consolidate_qubits=True#297TheGupta2012 merged 4 commits intomainfrom
Conversation
`consolidate_qubit_registers` mutates AST nodes in-place (renaming qubit identifiers to `__PYQASM_QUBITS__`). Since `self._statements` holds a reference to the original program statements, these mutations corrupt the source AST. A subsequent `unroll(consolidate_qubits=True)` then encounters barrier qubits named `__PYQASM_QUBITS__[...]` that do not exist in the fresh scope, raising a `ValidationError`. Deep-copy `unrolled_stmts` at the entry of `consolidate_qubit_registers` so the transformer operates on isolated copies, leaving the original AST intact for re-processing. Closes #296 Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
|
Warning Rate limit exceeded
⌛ How to resolve this issue?After the wait time has elapsed, a review can be triggered using the We recommend that you space out your commits to avoid hitting the rate limit. 🚦 How do rate limits work?CodeRabbit enforces hourly rate limits for each developer per organization. Our paid plans have higher rate limits than the trial, open-source and free plans. In all cases, we re-allow further reviews after a brief timeout. Please see our FAQ for further information. ℹ️ Review info⚙️ Run configurationConfiguration used: Organization UI Review profile: ASSERTIVE Plan: Pro Run ID: 📒 Files selected for processing (3)
✨ Finishing Touches🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Verifies that calling unroll(consolidate_qubits=True) twice on the same module produces identical output without raising a ValidationError. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Codecov Report✅ All modified and coverable lines are covered by tests. 📢 Thoughts on this report? Let us know! |
Bug Fix — Fix double-unroll crash when
consolidate_qubits=TrueCalling
module.unroll(consolidate_qubits=True)twice on the sameQasmModuleraised aValidationErrorbecauseconsolidate_qubit_registers()was mutating AST nodes in-place. Sinceself._statementsholds a reference to the originalprogram.statements, these mutations corrupted the source AST. On the second unroll, the visitor encountered barrier qubits named__PYQASM_QUBITS__[...]that did not exist in the fresh scope.Closes #296.
Changes
unrolled_stmts = deepcopy(unrolled_stmts)at the entry ofconsolidate_qubit_registersinsrc/pyqasm/transformer.py, so all in-place identifier renames operate on isolated copies and the original AST remains intact for re-processing.Reproduction