Mutable result arrays in QIR
- Dominant language
- Rust
- Stars
- 1k
- Forks
- 212
- Avg merge
- 3d 8h
- Merged PRs (30d)
- 65
Description
It seems reasonable to want to be able to loop over some operations on qubits, and then return the results from measuring those qubits in the successful iteration. I can't get something like the below to compile to QIR due to the restrictions on 'dynamic results' (and variation thereof that avoid other issues).
We should consider how we can support such code.
```qsharp
operation Foo() : Result[] {
use q = Qubit[2];
mutable redo = true;
mutable results = [Zero, Zero];
mutable loop_count = 0;
while redo {
// Psuedo "X with noise" operation
Rx(2.5, q[0]);
Rx(2.5, q[1]);
results[0] = MResetZ(q[0]);
results[1] = MResetZ(q[1]);
loop_count += 1;
redo = (
IsLossResult(results[0]) or
IsLossResult(results[1]) or
results[0] == Zero or
results[1] == Zero
) and loop_count <= 100;
}
results
}
```
Contributor guide
Research direction
Start by reproducing the Q# example and reviewing the QIR restrictions on dynamic results and the listed variations that avoid other issues. Done means the loop can compile to QIR while returning the measured results from the successful iteration, with the relevant behavior covered by tests.
Written by the indexing model from the issue text.
Assessment
- Domain
- compilers, quantum-computing
- Issue type
- Feature
- Difficulty
- 5/5
- Estimated time
- Over a week
- Activity status
- Quiet
- Clarity
- Mostly clear
- Newbie friendliness
- 45/100