Commit e132c0d
Fix double-unroll ValidationError when consolidate_qubits=True (#297)
* Fix double unroll with consolidate_qubits=True corrupting original AST
`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>1 parent 79901de commit e132c0d
File tree
3 files changed
+33
-0
lines changed- src/pyqasm
- tests/qasm3
3 files changed
+33
-0
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
26 | 26 | | |
27 | 27 | | |
28 | 28 | | |
| 29 | + | |
29 | 30 | | |
30 | 31 | | |
31 | 32 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
469 | 469 | | |
470 | 470 | | |
471 | 471 | | |
| 472 | + | |
| 473 | + | |
| 474 | + | |
| 475 | + | |
472 | 476 | | |
473 | 477 | | |
474 | 478 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
223 | 223 | | |
224 | 224 | | |
225 | 225 | | |
| 226 | + | |
| 227 | + | |
| 228 | + | |
| 229 | + | |
| 230 | + | |
| 231 | + | |
| 232 | + | |
| 233 | + | |
| 234 | + | |
| 235 | + | |
| 236 | + | |
| 237 | + | |
| 238 | + | |
| 239 | + | |
| 240 | + | |
| 241 | + | |
| 242 | + | |
| 243 | + | |
| 244 | + | |
| 245 | + | |
| 246 | + | |
| 247 | + | |
| 248 | + | |
| 249 | + | |
| 250 | + | |
| 251 | + | |
| 252 | + | |
| 253 | + | |
226 | 254 | | |
227 | 255 | | |
228 | 256 | | |
| |||
0 commit comments