Skip to content
This repository was archived by the owner on Jan 12, 2024. It is now read-only.
This repository was archived by the owner on Jan 12, 2024. It is now read-only.

Code generation failure when looping over array in an adjointable operation #132

@cgranade

Description

@cgranade

Describe the bug

The following operation fails to compile with C# errors:

operation PrepareCatState(register : Qubit[]) : Unit is Adj + Ctl {
    H(register[0]);
    for (target in register[1...]) {
        CNOT(register[0], target);
    }
}

image

Modifying the operation to not be adjointable works, as does storing the array slice in a local variable before looping:

operation PrepareCatState(register : Qubit[]) : Unit is Adj {
    H(register[0]);
    let targets = register[1...];
    for (target in targets) {
        CNOT(register[0], target);
    }
}

Using an array function also works around the issue:

open Microsoft.Quantum.Arrays;
operation PrepareCatState(register : Qubit[]) : Unit is Adj {
    H(register[0]);
    for (target in Rest(register)) {
        CNOT(register[0], target);
    }
}

To Reproduce

See reproduction at: https://mybinder.org/v2/gist/cgranade/471654e721ff80ca8de8c80a954f6d20/master

System information

image

Metadata

Metadata

Assignees

Labels

bugSomething isn't working

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions