Reset returns a qubit to the computational-basis state |0⟩ by measuring it and applying an X gate when the result is 1. Q# requires qubits to be reset before release, helping ensure they are no longer entangled with qubits still in use. section 2.1.3
Use reset to manage qubit lifetime safely:
- Prepare and manipulate the qubit, then call Reset before releasing it. section 2.1.3
- Avoid releasing entangled qubits or measuring them automatically at release, because either action can affect the remaining computation. 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
}
The Q# example allocates a qubit, prepares a state with Ry, and finishes with Reset(q). section 2.1.3
