feat: supported openqasm support to the playground along with its ast, hir and rir#3289
feat: supported openqasm support to the playground along with its ast, hir and rir#3289Gmin2 wants to merge 4 commits into
Conversation
|
cc @minestarks |
|
@microsoft-github-policy-service agree |
|
I was stuck on why the rir, hir and ast were not shown for openqasm AI help me with that and also at first understanding the flow and of code like how it is being rendered |
|
@Gmin2 Your code isn't passing the CI checks. Please run |
|
@Gmin2 to be clear, it's just minor stuff like lints and formatting - the Our workflow is here, and should hopefully match the errors you see locally! https://github.com/microsoft/qdk/actions/runs/26913329686/job/79600772588 |
|
Hey @minestarks thw CI should be green now ! |
|
@Gmin2 , thanks for your contribution, we really appreciate it! At a first glance the code looks good, but it would be really nice if we had more test coverage for the new methods you added. Nothing fancy, just replicating what we already have for the same features in Q#. |
|
thnx for the review, just pushed the test @joao-boechat |
minestarks
left a comment
There was a problem hiding this comment.
Looking really good - another round of requests (hopefully last). Thank you!
| pub fn get_ast(program: ProgramConfig) -> Result<String, String> { | ||
| if is_openqasm_program(&program) { | ||
| let (sources, _capabilities) = into_openqasm_arg(program); | ||
| let (store, package_id) = compile_openqasm_to_store(&sources)?; |
There was a problem hiding this comment.
The existing Q# version of this actually swallows errors. In order to match the existing error handling, we should copy that pattern and ignore compiler errors here (just return the AST as is).
Currently, notice if you start typing in the editor while the AST or HIR tab is open, you get QdkDiagnostics errors in the JS console. If you ignore the errors here, the AST/HIR should propagate to the UI without errors.
| pub fn get_hir(program: ProgramConfig) -> Result<String, String> { | ||
| if is_openqasm_program(&program) { | ||
| let (sources, _capabilities) = into_openqasm_arg(program); | ||
| let (store, package_id) = compile_openqasm_to_store(&sources)?; |
There was a problem hiding this comment.
See comment in get_ast - I think we should ignore compiler errors here just to copy the existing pattern for Q#, and to avoid JS console errors.
| let (source_map, _capabilities, language_features, store, deps) = | ||
| into_qsc_args(program, None, false).map_err(compile_errors_into_qsharp_errors_json)?; | ||
| let (unit, _) = compile::compile( | ||
| store, | ||
| &[(*std, None)], | ||
| sources, | ||
| &store, | ||
| &deps[..], | ||
| source_map, | ||
| PackageType::Exe, | ||
| profile.into(), | ||
| Profile::Unrestricted.into(), | ||
| language_features, | ||
| ); | ||
| unit.ast.package | ||
| }); | ||
| Ok(format!("{package}")) | ||
| Ok(format!("{}", unit.ast.package)) |
There was a problem hiding this comment.
Not super important, but there's a minor optimization we're losing here by not using the cached STORE_CORE_STD . I think I prefer the original Q#-specific code in the else case here.
| } | ||
|
|
||
| /// Generates the RIR (raw and SSA forms) from an AST package, mirroring `get_qir_from_ast`. | ||
| pub fn get_rir_from_ast( |
There was a problem hiding this comment.
This seems unused (except in tests). Seems like you achieved the same purpose with get_rir in interpret.rs. I think you can delete this one (and the corresponding tests)
There was a problem hiding this comment.
The code-sharing feature (copy link with ?code= in the URL) isn't working fully for OpenQASM, since the editor language defaults to Q#. Can we get that working? Perhaps encode the language in the URL somehow (default to qsharp so existing links continue to work)
There was a problem hiding this comment.
The current UI tabs work well, but for completeness, would you consider adding another, OpenQASM-specific view in the UI?
OpenQASM has two ASTs, the OpenQASM AST, and the transformed Q# AST. In your PR, we shows the second one (the Q# AST) in the tab.
Could we also display the original OpenQASM AST pre-transformation? That would be very useful for debugging. It could be its separate tab, or both could be concatenated in the AST tab perhaps.
this adds openqasm support to the q# playground, which only handled q# before. the playground now registers a basic openqasm syntax highlighting grammar in monaco, shows the openqasm samples in their own "Samples (OpenQASM)" nav section, and passes the right languageId and projectType through to the existing language service and compiler. so openqasm programs get live diagnostics, can run for shots, and render their ast, hir, rir and qir just like q#. the ir views needed a small backend change:
get_ast,get_hirandget_rirnow branch on the project type, and a new Interpreter::get_rir produces rir for openqasm, whose entry point is a generated expression instead of a q#@EntryPoint. multi file openqasm projects and openqasm katas are out of scope.Fixes #3233
Screen.Recording.2026-06-04.at.2.40.27.AM.mov