Update samples for circuit compatibility, relax RCA dynamic string checks#2999
Update samples for circuit compatibility, relax RCA dynamic string checks#2999
Conversation
…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.
swernli
left a comment
There was a problem hiding this comment.
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)]; |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
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
Messagewith 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
samples/algorithmsandsamples/getting_startedsource/compiler/qsc_partial_eval/src/lib.rssource/compiler/qsc_rca/src/core.rs