A use statement allocates qubits within a Q# program scope. The allocated value has type Qubit and can be passed to quantum operations alongside ordinary parameters. section 2.1.3
Manage allocated qubits deliberately:
- Return every allocated qubit to the |0⟩ state before releasing it; Reset measures the qubit and applies X when the result is 1. section 2.1.3
- Avoid releasing qubits entangled with qubits still in use, because release can alter the computation and prevent interference. section 2.1.3
Listing 2.2 Q# code to prepare a single-qubit state
import Std.Math.ArcTan2; #1
@EntryPoint() #2
operation SingleQubitDemo() : Unit { #3
use q = Qubit(); #4
let (alpha, beta) = (0.6, 0.8);
let theta = 2.0 * ArcTan2(beta, alpha); #5
Ry(theta, q); #6
Reset(q); #7
}
Inspect a complete Q# example that allocates q with use, applies Ry, and resets the qubit before release. section 2.1.3
