Search code examples
q#qubit

Can you send a subarray of qubits as a parameter in Q#?


Is it possible to send array slices of qubits as parameters? Something like this:

using(q : Qubit[5]){
    myOp(q[2:3]);
}

Solution

  • Yes, Q# supports array slicing: https://learn.microsoft.com/en-us/quantum/quantum-qr-expressions#array-expressions. You can use Range data type as an index to create a subarray of elements of the array indexed by elements of the range.

    Your example will look like this:

    using (q = Qubit[5]) {
        myOp(q[2..3]);
    }