Skip to content

[Circuit diagrams] 4 - Show conditionals in circuits based on RIR debug metadata#2943

Open
minestarks wants to merge 56 commits intomainfrom
minestarks/rir-and-conditionals-working
Open

[Circuit diagrams] 4 - Show conditionals in circuits based on RIR debug metadata#2943
minestarks wants to merge 56 commits intomainfrom
minestarks/rir-and-conditionals-working

Conversation

@minestarks
Copy link
Member

@minestarks minestarks commented Feb 12, 2026

This PR completes the feature for rendering classical control flow and conditionals in quantum circuit diagrams. The changes span the compiler, code generation, circuit visualization, and VS Code integration.

Circuit Generation from RIR

  • Implemented new RIR-to-circuit conversion (rir_to_circuit.rs module) that reconstructs control flow structure from RIR blocks
  • Added structured control flow analysis to properly traverse branches in execution order
  • Built logic to handle complex scenarios:
    • Measurement-based conditionals (if-else based on qubit measurement results)
    • Nested conditionals and loops with quantum operations
    • Binary operation short-circuit evaluation
    • Multiple possible values in function arguments based on control flow branches

VS Code Extension Fallback Logic

  • Added fallback mechanism: if circuit generation fails due to adaptive profile compliance issues when using "static" method, the extension automatically retries with "classicalEval" method and "Unrestricted" profile
  • Preserves existing fallback for result comparison errors in "classicalEval" mode

Usage Example

For Q# code with measurement-based conditionals:

operation TestConditional(q : Qubit) : Unit {
    H(q);
    let r = M(q);
    if (r == One) {
        X(q);
    }
}

The circuit diagram now displays the conditional control flow structure, showing which gates execute based on measurement outcomes, alongside the quantum operations.

Copy link

@github-advanced-security github-advanced-security bot left a comment

Choose a reason for hiding this comment

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

devskim found more than 20 potential problems in the proposed changes. Check the Files changed tab for more details.

@minestarks minestarks force-pushed the minestarks/rir-and-conditionals-working branch from 6d0da64 to 48d9f1f Compare February 12, 2026 23:48
@minestarks minestarks changed the base branch from main to minestarks/rir-and-conditionals February 23, 2026 21:01
minestarks and others added 23 commits February 24, 2026 13:24
@minestarks minestarks changed the base branch from minestarks/rir-and-conditionals to main February 26, 2026 01:28
@minestarks minestarks marked this pull request as ready for review February 26, 2026 01:40
@minestarks minestarks changed the title [Circuit diagrams] 4 - Show conditionals in circuits based on RIR debug metadata (remaining changes) [Circuit diagrams] 4 - Show conditionals in circuits based on RIR debug metadata Feb 26, 2026
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.

1 participant