-
Notifications
You must be signed in to change notification settings - Fork 27
Rename duplicate argument variables internally #355
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -34,6 +34,7 @@ | |
|
|
||
| from pyqasm.analyzer import Qasm3Analyzer | ||
| from pyqasm.elements import ( | ||
| INTERNAL_QUANTUM_ARGUMENT, | ||
| INTERNAL_QUBIT_REGISTER, | ||
| Capture, | ||
| ClbitDepthNode, | ||
|
|
@@ -1499,11 +1500,24 @@ def _visit_generic_gate_operation( # pylint: disable=too-many-branches, too-man | |
| for transform_map, size_map in zip( | ||
| reversed(self._function_qreg_transform_map), reversed(self._function_qreg_size_map) | ||
| ): | ||
| operation.qubits = ( | ||
| Qasm3Transformer.transform_function_qubits( # type: ignore [assignment] | ||
| operation, transform_map, size_map | ||
| try: | ||
| operation.qubits = ( | ||
| Qasm3Transformer.transform_function_qubits( # type: ignore [assignment] | ||
| operation, transform_map, size_map | ||
| ) | ||
| ) | ||
| except KeyError: | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is compensated here, but needed in three places. The rename happens in So these still fail, now with a raw def f(qubit q) { reset q; } // KeyError: ('q', 0) (barrier too)
def inner(qubit p) { h p; }
def outer(qubit q) { inner(q); }
outer(q[1]); // KeyError: 'q' — works on mainSuggestion: keep the keys and the body consistent from the start — register the transform map under the name the body uses, or rename the body's references when you rename the parameter. Then no call site needs a retry and all three fix together. Worth noting too: |
||
| for qubit in operation.qubits: | ||
| # Each qubit may be an IndexedIdentifier or an Identifier | ||
| if isinstance(qubit, qasm3_ast.IndexedIdentifier): | ||
| qubit.name.name += INTERNAL_QUANTUM_ARGUMENT | ||
| else: | ||
| qubit.name += INTERNAL_QUANTUM_ARGUMENT | ||
| operation.qubits = ( | ||
| Qasm3Transformer.transform_function_qubits( # type: ignore [assignment] | ||
| operation, transform_map, size_map | ||
| ) | ||
| ) | ||
| ) | ||
|
|
||
| operation.qubits = self._get_op_bits(operation, qubits=True) # type: ignore | ||
|
|
||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
_argcan collide with a name already in use:mainemitsh q[0]; x r[1];. Here it'sValueError: Variable 'q_arg' already exists in current scope— and a rawValueError, not aValidationError.Suggestion: use a name that can't appear in user code.
INTERNAL_QUBIT_REGISTERinelements.py("__PYQASM_QUBITS__") is the existing pattern for this.