liveBook · Manning

Result

As explained in Quantum Programming in Depth

Result is the Q# data type whose values represent quantum measurement outcomes as Zero or One.

Result is Q#’s domain-specific type for quantum measurement outcomes. Its only values are Zero and One, corresponding to measurement results 0 and 1. section 4.1.3

Use Result values as measurement data rather than ordinary numeric or Boolean values:

  • Measure computational-basis qubits with MResetZ, which returns a Result and resets each qubit to ket-zero. section 4.1.3
  • Print or otherwise process results as classical information, but convert explicitly before using numeric or Boolean operations. section 4.1.3
  • Store multiple outcomes in Result[] arrays; mutable accumulation supports collecting results during execution. section 4.1.3

Read and validate measurement results

A Q# operation can measure every qubit with MResetZ and return Result[]. A validation routine converts Zero and One values into an integer, compares it with the prepared basis state, and repeats randomized cases. section 4.1.3

Listing 4.3 Q# code to measure all qubits and return the results
operation ReadInformation(qs : Qubit[]) : Result[] {
  mutable res = [];           #1
  for q in qs {
    set res += [MResetZ(q)];  #2
  }
  return res;
}

Inspect the Q# ReadInformation operation that accumulates MResetZ outcomes and returns them as a Result array. section 4.1.3

How Quantum Programming in Depth covers it

How deep it goes
Defines Zero and One, explains explicit conversion, and demonstrates measurement, printing, array collection, and randomized validation.
Examples
Uses MResetZ, ReadInformation, Result[] arrays, integer conversion, basis-state preparation, and randomized tests.
What it assumes
Assumes basic Q# operations and qubits while clarifying measurement outcomes, classical processing, and explicit conversion.
What you can do after
Apply via Q# to measure qubits, return outcomes, print them, and validate converted results.
How it connects
Connects quantum measurement, qubits, computational-basis measurement, classical information, and explicit type conversion.

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.