Skip to content

Update samples for circuit compatibility, relax RCA dynamic string checks#2999

Open
swernli wants to merge 3 commits intomainfrom
swernli/relax-dynamic-string-checks
Open

Update samples for circuit compatibility, relax RCA dynamic string checks#2999
swernli wants to merge 3 commits intomainfrom
swernli/relax-dynamic-string-checks

Conversation

@swernli
Copy link
Collaborator

@swernli swernli commented Mar 5, 2026

This change updates the samples for more circuits compatibility (as well as QIR generation for Adaptive) where needed. It enables some of this via a relaxation of RCA checks on dyanmic strings by avoiding marking the program as requiring the string capability just because of a dynamic string. Since Q# strings can only be concatenated and copared for equality, only the latter can affect program control flow and output. So the capability is now associated with the use of equality comparison on dynamic strings, enabling programs that use Message with interpolated strings to now successfully generate RIR for circuits and QIR codegen.

In addition, this change adds new expect-based tests for the samples that verify both the circuit generation and the QIR generation. This fixes #2442.

Note for reviewers: only the following files have production changes, the rest are updates to test snapshots or test infra

  • Updates to some samples under samples/algorithms and samples/getting_started
  • source/compiler/qsc_partial_eval/src/lib.rs
  • source/compiler/qsc_rca/src/core.rs

…ecks

This change updates the samples for more circuits compatibility (as well as QIR generation for Adaptive) where needed. It enables some of this via a relaxation of RCA checks on dyanmic strings by avoiding marking the program as requiring the string capability just because of a dynamic string. Since Q# strings can only be concatenated and copared for equality, only the latter can affect program control flow and output. So the capability is now associated with the use of equality comparison on dynamic strings, enabling programs that use `Message` with interpolated strings to now successfully generate RIR for circuits and QIR codegen.

In addition, this change adds new expect-based tests for the samples that verify both the circuit generation and the QIR generation. This fixes #2442.
Copy link
Collaborator Author

@swernli swernli left a comment

Choose a reason for hiding this comment

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

I'm going to take a crack at tweaking the string display for circuits to make this a bit smaller.

let isConstantStr = isConstant ? "constant" | "balanced";
Message($"{name} is {isConstantStr}");
results += [(name, isConstant)];
results += [(idx, isConstant)];
Copy link
Member

Choose a reason for hiding this comment

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

I feel like Main could just return Unit at this point - the return value was already kind of pointless before your change, now it's also more obscure.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

The one thing it is still useful for is histograms. With this content, the (admittedly obscure) output would be 100% of results, but introducing noise would show some differences. If I change the output to Unit then adding noise to histogram runs would not change anything (and the Message output is not visible on histograms, so you don't get to see that either). At least this way there is still some hope of seeing the affect of noise on execution.

Copy link
Member

Choose a reason for hiding this comment

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

For this - and other samples where you removed some fails and state checks - I wonder if we can take advantage of Test()s to illustrate checking for correctness. We did do a bunch of work so that Test()s could be runnable and excluded for QIR generation, and this could be an opportunity to leverage all that work we did.

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.

Automated QIR generation tests for samples

3 participants