The Measurements quantum kata is a series of exercises designed to get you familiar with the concept of measurements and with programming in Q#. It covers the following topics:
A detailed introduction into single-qubit measurements work can be found in this tutorial.
Each task is wrapped in one operation preceded by the description of the task.
Your goal is to fill in the blank (marked with // ...
comments)
with some Q# code that solves the task. To verify your answer, run the cell using Ctrl+Enter (⌘+Enter on macOS).
The tasks are given in approximate order of increasing difficulty; harder ones are marked with asterisks.
Input: A qubit which is guaranteed to be in either the $|0\rangle$ or the $|1\rangle$ state.
Output: true
if the qubit was in the $|1\rangle$ state, or false
if it was in the $|0\rangle$ state. The state of the qubit at the end of the operation does not matter.
%kata T101_IsQubitOne
operation IsQubitOne (q : Qubit) : Bool {
// The operation M will measure a qubit in the Z basis (|0⟩ and |1⟩ basis)
// and return Zero if the observed state was |0⟩ or One if the state was |1⟩.
// To answer the question, you need to perform the measurement and check whether the result
// equals One - either directly or using library function IsResultOne.
//
// Type the following: return M(q) == One;
// Then run the cell using Ctrl+Enter (⌘+Enter on macOS).
// ...
}
Can't come up with a solution? See the explained solution in the Measurements Workbook.
Input: A qubit in an arbitrary state.
Goal: Change the state of the qubit to $|0\rangle$.
%kata T102_InitializeQubit
operation InitializeQubit (q : Qubit) : Unit {
// ...
}
Can't come up with a solution? See the explained solution in the Measurements Workbook.
Input: A qubit which is guaranteed to be in either the $|+\rangle$ or the $|-\rangle$ state. As a reminder, $|+\rangle = \frac{1}{\sqrt{2}} \big(|0\rangle + |1\rangle\big)$, $|-\rangle = \frac{1}{\sqrt{2}} \big(|0\rangle - |1\rangle\big)$.
Output: true
if the qubit was in the $|+\rangle$ state, or false
if it was in the $|-\rangle$ state. The state of the qubit at the end of the operation does not matter.
%kata T103_IsQubitPlus
operation IsQubitPlus (q : Qubit) : Bool {
// ...
}
Can't come up with a solution? See the explained solution in the Measurements Workbook.
Inputs:
Double
.Output: true
if the qubit was in the $|A\rangle$ state, or false
if it was in the $|B\rangle$ state. The state of the qubit at the end of the operation does not matter.
%kata T104_IsQubitA
operation IsQubitA (alpha : Double, q : Qubit) : Bool {
// ...
}
Can't come up with a solution? See the explained solution in the Measurements Workbook.
Input: Two qubits (stored in an array of length 2) which are guaranteed to be in either the $|00\rangle$ or the $|11\rangle$ state.
Output: 0 if the qubits were in the $|00\rangle$ state, or 1 if they were in the $|11\rangle$ state. The state of the qubits at the end of the operation does not matter.
%kata T105_ZeroZeroOrOneOne
operation ZeroZeroOrOneOne (qs : Qubit[]) : Int {
// ...
}
Can't come up with a solution? See the explained solution in the Measurements Workbook.
Input: Two qubits (stored in an array of length 2) which are guaranteed to be in one of the four basis states ($|00\rangle$, $|01\rangle$, $|10\rangle$, or $|11\rangle$).
Output:
In this task and the subsequent ones the order of qubit states in task description matches the order of qubits in the array (i.e., $|10\rangle$ state corresponds to qs[0]
in state $|1\rangle$ and qs[1]
in state $|0\rangle$).
The state of the qubits at the end of the operation does not matter.
%kata T106_BasisStateMeasurement
operation BasisStateMeasurement (qs : Qubit[]) : Int {
// ...
}
Can't come up with a solution? See the explained solution in the Measurements Workbook.
Inputs:
Bool[]
s.Output:
Bit values false
and true
correspond to $|0\rangle$ and $|1\rangle$ states. You are guaranteed that both bit strings have the same length as the qubit array, and that the bit strings differ in at least one bit.
You can use exactly one measurement. The state of the qubits at the end of the operation does not matter.
Example: for bit strings
[false, true, false]
and[false, false, true]
return 0 corresponds to state $|010\rangle$, and return 1 corresponds to state $|001\rangle$.
%kata T107_TwoBitstringsMeasurement
operation TwoBitstringsMeasurement (qs : Qubit[], bits1 : Bool[], bits2 : Bool[]) : Int {
// ...
}
Can't come up with a solution? See the explained solution in the Measurements Workbook.
Inputs:
Bool[][]
s.The arrays have dimensions $M_1 \times N$ and $M_2 \times N$ respectively, where $N$ is the number of qubits and $M_1$ and $M_2$ are the numbers of bit strings in each array. Note that in general $M_1 \neq M_2$.
An array of bit strings [b₁, ..., bₘ]
defines a state that is an equal superposition of all basis states defined by bit strings $b_1, ..., b_m$.
For example, an array of bit strings [[false, true, false], [false, true, true]]
defines a superposition state $\frac{1}{\sqrt2}\big(|010\rangle + |011\rangle\big)$.
You are guaranteed that there exists an index of a qubit Q for which:
bits1[j][Q]
are the same),bits2[j][Q]
are the same),For example, for arrays
[[false, true, false], [false, true, true]]
and[[true, false, true], [false, false, true]]
return 0 corresponds to state $\frac{1}{\sqrt2}\big(|010\rangle + |011\rangle\big)$, return 1 - to state $\frac{1}{\sqrt2}\big(|101\rangle + |001\rangle\big)$, and you can distinguish these states perfectly by measuring the second qubit.
Output:
You are allowed to use exactly one measurement. The state of the qubits at the end of the operation does not matter.
%kata T108_SuperpositionOneMeasurement
operation SuperpositionOneMeasurement (qs : Qubit[], bits1 : Bool[][], bits2 : Bool[][]) : Int {
// ...
}
Can't come up with a solution? See the explained solution in the Measurements Workbook.
Inputs:
Bool[][]
s.The arrays describe the superposition states in the same way as in the previous task, i.e. they have dimensions $M_1 \times N$ and $M_2 \times N$ respectively, $N$ being the number of qubits.
The only constraint on the bit strings is that all bit strings in the two arrays are distinct.
Example: for bit strings
[[false, true, false], [false, false, true]]
and[[true, true, true], [false, true, true]]
return 0 corresponds to state $\frac{1}{\sqrt2}\big(|010\rangle + |001\rangle\big)$, return 1 to state $\frac{1}{\sqrt2}\big(|111\rangle + |011\rangle\big)$.
Output:
You can use as many measurements as you wish. The state of the qubits at the end of the operation does not matter.
%kata T109_SuperpositionMeasurement
operation SuperpositionMeasurement (qs : Qubit[], bits1 : Bool[][], bits2 : Bool[][]) : Int {
// ...
}
Can't come up with a solution? See the explained solution in the Measurements Workbook.
Input: $N$ qubits (stored in an array of length $N$) which are guaranteed to be either in the $|0...0\rangle$ state or in the W state.
Output:
The state of the qubits at the end of the operation does not matter.
%kata T110_AllZerosOrWState
operation AllZerosOrWState (qs : Qubit[]) : Int {
// ...
}
Can't come up with a solution? See the explained solution in the Measurements Workbook.
Input: $N \ge 2$ qubits (stored in an array of length $N$) which are guaranteed to be either in the GHZ state or in the W state.
Output:
The state of the qubits at the end of the operation does not matter.
%kata T111_GHZOrWState
operation GHZOrWState (qs : Qubit[]) : Int {
// ...
}
Can't come up with a solution? See the explained solution in the Measurements Workbook.
Input: Two qubits (stored in an array of length 2) which are guaranteed to be in one of the four Bell states.
Output:
The state of the qubits at the end of the operation does not matter.
%kata T112_BellState
operation BellState (qs : Qubit[]) : Int {
// ...
}
Can't come up with a solution? See the explained solution in the Measurements Workbook.
Input: Two qubits (stored in an array of length 2) which are guaranteed to be in one of the four orthogonal states.
Output:
The state of the qubits at the end of the operation does not matter.
%kata T113_TwoQubitState
operation TwoQubitState (qs : Qubit[]) : Int {
// ...
}
Can't come up with a solution? See the explained solution in the Measurements Workbook.
Input: Two qubits (stored in an array of length 2) which are guaranteed to be in one of the four orthogonal states.
Output:
The state of the qubits at the end of the operation does not matter.
%kata T114_TwoQubitStatePartTwo
operation TwoQubitStatePartTwo (qs : Qubit[]) : Int {
// ...
}
Can't come up with a solution? See the explained solution in the Measurements Workbook.
Input: Three qubits (stored in an array of length 3) which are guaranteed to be in one of the two orthogonal states.
Output:
Here $\omega = e^{2i \pi/ 3}$.
The state of the qubits at the end of the operation does not matter.
%kata T115_ThreeQubitMeasurement
operation ThreeQubitMeasurement (qs : Qubit[]) : Int {
// ...
}
Can't come up with a solution? See the explained solution in the Measurements Workbook.
Variations of quantum state discrimination tasks are covered in the paper "Quantum State Discrimination".
Task 2.1 is an example of hypothesis testing for two pure states.
Task 2.2 is an example of unambiguous state discrimination. See also the paper "Unambiguous quantum measurement of nonorthogonal states" for further information and hints about how to implement the unambiguous measurements required for this task.
Task 2.3 is the so-called Wootters/Peres game. See the following three references for more information and in particular the book [3, p. 287] for a nice description of the optimal POVM.
[1] A. Holevo, “Information-theoretical aspects of quantum measurement,” Problems of Information Transmission, vol. 9, no. 2, pp. 110–118 (1973)
[2] A. Peres and W. K. Wootters, “Optimal detection of quantum information,” Phys. Rev. Lett., vol. 66, pp. 1119-1122, Mar. 1991.
[3] A. Peres, “Quantum Theory: Concepts and Methods,” Kluwer Academic Publishers, 2002.
Input: A qubit which is guaranteed to be in either the $|0\rangle$ or the $|+\rangle$ state.
Output: true
if the qubit was in the $|0\rangle$ state, or false
if it was in the $|+\rangle$ state. The state of the qubit at the end of the operation does not matter.
In this task your solution will be called multiple times, with one of the states picked with equal probability every time. You have to get overall accuracy of at least 80%.
This task is an example of quantum hypothesis testing, or state discrimination with minimum error.
%kata T201_IsQubitZeroOrPlus
operation IsQubitPlusOrZero (q : Qubit) : Bool {
// ...
}
Can't come up with a solution? See the explained solution in the Measurements Workbook.
Input: A qubit which is guaranteed to be in either the $|0\rangle$ or the $|+\rangle$ state.
Output:
Your solution:
The state of the qubit at the end of the operation does not matter.
This task is an example of unambiguous state discrimination.
%kata T202_IsQubitZeroOrPlusSimpleUSD
operation IsQubitPlusZeroOrInconclusiveSimpleUSD (q : Qubit) : Int {
// ...
}
Can't come up with a solution? See the explained solution in the Measurements Workbook.
Input: A qubit which is guaranteed to be in one of the three states:
Here $\omega = e^{2i \pi/ 3}$.
Output:
You are never allowed to give an incorrect answer. Your solution will be called multiple times, with one of the states picked with equal probability every time.
The state of the qubit at the end of the operation does not matter.
%kata T203_IsQubitNotInABC
operation IsQubitNotInABC (q : Qubit) : Int {
// ...
}
Can't come up with a solution? See the explained solution in the Measurements Workbook.