microsoft / microsoft/qdk

Attempt to generate controlled/adjoint variant when it is not requested

Open
#1,929 1 comment 0 reactions 0 assignees View on GitHub
design needed enhancement
Dominant language
Rust
Stars
1k
Forks
212
Avg merge
3d 8h
Merged PRs (30d)
65

Description

**Describe the bug**

I'm trying to pick a random gate from an array, and using `DrawRandomInt` as the index fails because it doesn't support controlled and thus adjoint cannot be generated.

**To Reproduce**

```qsharp
operation Test3() : Bool {
let ind = DrawRandomInt(0, 2);
let op = [Rx, Ry, Rz][ind](1., _);
let op1 = [Rx, Ry, Rz][DrawRandomInt(0, 2)](1., _);
true
}
```

`op` and `op1` are initialized in the same way (except the variable `ind`), but the second one yields an error.

**Expected behavior**

Two initializations of `op` and `op1` should behave the same, since they do the same thing.

**Screenshots**

![image](https://github.com/user-attachments/assets/fbbdc997-0213-4eb2-ad9a-93faaf6c2852)

**System information**

- VS Code 1.93.0
- QDK 1.8.0

Contributor guide

Open the contributing guide

Research direction

Start by running the Q# reproduction in the issue and compare the `op` and `op1` initializations. Trace how controlled and adjoint variants are generated for operations selected through arrays, especially when the index expression is an inline `DrawRandomInt` call. Done means both equivalent initializations compile and behave consistently without requesting unsupported variants.

Written by the indexing model from the issue text.

Assessment

Domain
compilers
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.