Skip to content

Simplify STIM-to-QIR snapshot tests - #3698

Open
João Boechat (joao-boechat) wants to merge 4 commits into
mainfrom
joaoboechat/simplify-stim-to-qir-tests
Open

Simplify STIM-to-QIR snapshot tests#3698
João Boechat (joao-boechat) wants to merge 4 commits into
mainfrom
joaoboechat/simplify-stim-to-qir-tests

Conversation

@joao-boechat

Copy link
Copy Markdown
Contributor

This branch makes Stim-to-QIR snapshot tests smaller and easier to review by removing repeated QIR boilerplate from most expectations while retaining the generated instructions, helper definitions, declarations, resource counts, and noise details that distinguish each case. It also makes emitted QIR deterministic.

QIR emission

  • Sorts declarations and helper definitions for deterministic output.
  • Places the optional qdk_noise attribute before module flags.

Snapshot infrastructure

  • Formats successful compilation output into focused body, definitions, and declarations sections, followed by required qubit and result counts.
  • Omits standard entry-point initialization, output recording, runtime declarations, attributes, and module metadata from routine snapshots.
  • Preserves noise behavior through a uses_noise marker and the effective noise configuration; compiler error expectations remain unchanged.
  • Adds dedicated full-QIR checks for empty, measured, and noisy programs so shared entry-point boilerplate, output calls, runtime declarations, attributes, and module flags remain covered.

Comment on lines +196 to +204
body:
br label %select_0
select_0:
call void @__quantum__qis__m__body(ptr inttoptr (i64 0 to ptr), ptr inttoptr (i64 0 to ptr))
call void @__quantum__qis__m__body(ptr inttoptr (i64 1 to ptr), ptr inttoptr (i64 1 to ptr))
call void @__quantum__qis__m__body(ptr inttoptr (i64 2 to ptr), ptr inttoptr (i64 2 to ptr))

declarations:
declare void @__quantum__qis__m__body(ptr, ptr)

@orpuente-MS orpuente-MS Sep 9, 2026

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I think the choice of syntax is a bit confusing, since the headers body: and declarations: look like valid QIR tags.

Comment on lines +199 to +201
call void @__quantum__qis__m__body(ptr inttoptr (i64 0 to ptr), ptr inttoptr (i64 0 to ptr))
call void @__quantum__qis__m__body(ptr inttoptr (i64 1 to ptr), ptr inttoptr (i64 1 to ptr))
call void @__quantum__qis__m__body(ptr inttoptr (i64 2 to ptr), ptr inttoptr (i64 2 to ptr))

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Looks like we are missing the *_record_output calls in the body. I don't consider that to be boilerplate, but rather something that needs validation in the tests.

@orpuente-MS orpuente-MS left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

This is a nice simplification to aid visual validation. Some general thoughts on the PR:

First: whatever decision gets taken here, these tests will likely go away after the QIR -> Q# AST transition, which is the very next follow up work. With that being said:

  1. Just printing the body of the main function creates an asymmetry between the main definition and other function definitions.
  2. The main:, declarations: and definitions: headers can be confused with valid QIR tags by someone who didn't design the test format.
  3. I believe the *_record_output calls and the function's return instruction are valuable information to validate in the tests' output.

(This last note is a totally optional suggestion: I think you can achieve 80% of the boilerplate simplification by just omitting the declarations, attributes, and module flags. Definitions need review, so they shouldn't be omitted).

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.

2 participants