liveBook · Manning

Use statement

As explained in Quantum Programming in Depth

A use statement is a Q# construct that allocates qubits for use within a program scope.

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

How Quantum Programming in Depth covers it

How deep it goes
Defines allocation and release discipline, including resetting qubits and avoiding unsafe entanglement.
Examples
Demonstrates use q = Qubit() in a single-qubit state-preparation operation followed by Ry and Reset.
What it assumes
Assumes familiarity with Q# operations and Qubit values while treating allocated qubits as variables usable by gates.
What you can do after
Build Q# operations that allocate, use, and safely release qubits.
How it connects
Connects Qubit values with quantum gates, Reset, measurement, entanglement, and quantum-state preparation.

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Quantum Programming in Depth. The section links point to the parts of the book it draws on.