Skip to content

feat: supported openqasm support to the playground along with its ast, hir and rir#3289

Open
Gmin2 wants to merge 4 commits into
microsoft:mainfrom
Gmin2:openqasm-playground
Open

feat: supported openqasm support to the playground along with its ast, hir and rir#3289
Gmin2 wants to merge 4 commits into
microsoft:mainfrom
Gmin2:openqasm-playground

Conversation

@Gmin2
Copy link
Copy Markdown

@Gmin2 Gmin2 commented Jun 3, 2026

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_hir and get_rir now 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

@Gmin2
Copy link
Copy Markdown
Author

Gmin2 commented Jun 3, 2026

cc @minestarks

@Gmin2
Copy link
Copy Markdown
Author

Gmin2 commented Jun 4, 2026

@microsoft-github-policy-service agree

@minestarks
Copy link
Copy Markdown
Member

@Gmin2 Thank you for your contribution! We'll take a look shortly. Per UnitaryHACK's AI Policy could you please disclose to what extent you used AI for this pull request?

@Gmin2
Copy link
Copy Markdown
Author

Gmin2 commented Jun 4, 2026

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

@minestarks
Copy link
Copy Markdown
Member

@Gmin2 Your code isn't passing the CI checks. Please run ./build.py from your dev environment and ensure it runs cleanly.

@minestarks
Copy link
Copy Markdown
Member

@Gmin2 to be clear, it's just minor stuff like lints and formatting - the ./build.py errors should point you in the right direction.

Our workflow is here, and should hopefully match the errors you see locally! https://github.com/microsoft/qdk/actions/runs/26913329686/job/79600772588

@Gmin2
Copy link
Copy Markdown
Author

Gmin2 commented Jun 4, 2026

Hey @minestarks thw CI should be green now !

@joao-boechat
Copy link
Copy Markdown
Contributor

@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#.

@Gmin2
Copy link
Copy Markdown
Author

Gmin2 commented Jun 5, 2026

thnx for the review, just pushed the test @joao-boechat

Copy link
Copy Markdown
Member

@minestarks minestarks left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looking really good - another round of requests (hopefully last). Thank you!

Comment thread source/wasm/src/lib.rs
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)?;
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Comment thread source/wasm/src/lib.rs
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)?;
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Comment thread source/wasm/src/lib.rs
Comment on lines +265 to +275
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))
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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(
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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)

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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)

Comment thread source/wasm/src/lib.rs
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Support OpenQASM in the Playground

3 participants