-
Notifications
You must be signed in to change notification settings - Fork 57
Issue #1714: Add variable names to the IR #2054
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
Open
rturrado
wants to merge
26
commits into
PennyLaneAI:main
Choose a base branch
from
rturrado:issue_1714_add_variable_names_to_the_ir
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Issue #1714: Add variable names to the IR #2054
rturrado
wants to merge
26
commits into
PennyLaneAI:main
from
rturrado:issue_1714_add_variable_names_to_the_ir
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add test_alice_and_bob_parameters. Rename test_alice to test_alice_qubit. Rename test_alice_and_bob to test_alice_and_bob_qubits.
lower_jaxpr_to_mlir: add arg_names, and pass them on to jaxpr_to_mlir. jaxpr_to_mlir: change parameter order, add arg_names, and pass them on to custom_lower_jaxpr_to_module. custom_lower_jaxpr_to_module: add arg_names, and pass them on to lower_jaxpr_to_fun. This latter function builds arg_locs with the arg_names and appends them to the function's entry_block. qjit: add use_nameloc parameter. CompileOptions: add use_nameloc option. _options_to_cli_flags: add '-mlir-use-nameloc-as-prefix' if use_nameloc=True. test_debug.py: add test_option_use_nameloc.Add frontend/test/lit/test_option_use_nameloc.py. TODO: the name location information is added to the MLIR module, but still not consumed by quantum-opt. TODO: should we try adding name location information for other than funcion arguments?
… name location information in Catalyst Add QJIT.get_arg_names() to construct a list of argument names for a qjit function. Change QJIT.mlir and QJIT.mlir_opt to optionally use an MLIR string with debug info. Change canonicalize function to optionally pass --use-nameloc-as-prefix. Add --use-nameloc-as-prefix to Catalyst CLI options. Change QuantumDriverMain to optionally use useNameLocAsPrefix printing flag when printing the MLIR module. Add test_get_arg_names.py. Change test_option_use_nameloc.py to check that: 1) MLIR module contains location information. 2) MLIR code contains location information. 3) f.mlir uses the qjit function parameter names, %x and %y, instead of %arg0 and %arg1.
Thanks @rturrado for the submission. |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Labels
external
PRs where the author is not a part of PennyLane Org (or part of external contributors team)
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Context:
We can investigate the option of passing down source code information like variable names from the frontend down to the generated ir, using MLIR's location mechanism. The additional info will make generated code more readable.
Description of the Change:
User -> Frontend:
@qjit(use_nameloc=True)
to use name location information in the generated MLIR code.Frontend -> Catalyst CLI: whenever
use_nameloc
is enabled:stdin=self.mlir_module.operation.get_asm(enable_debug_info=True)
instead ofstdin=str(self.mlir_module)
.--use-nameloc-as-prefix
inoptions
.Catalyst CLI -> frontend: whenever
--use-nameloc-as-prefix
is enabled:useNameLocAsPrefix
printing flag.mlirModule->print(oss, opPrintingFlags)
instead ofoss << *mlirModule
.Benefits:
@qjit(use_nameloc=True)
is an eay way for the user to specify that they want to use name location information.--use-nameloc-as-prefix
option.Possible Drawbacks:
get_arg_names
function may not be robust enough.%x
instead of%arg0
), but maybe not so nicely for results of equations (e.g.,%jit28ok292Fjit28jit_f292Fmul
instead of%0
). An option would be to add name location information only for function parameters.Related GitHub Issues:
#1714