Joint Measurements quantum kata is a series of exercises designed to get you familiar with programming in Q#. It covers the joint parity measurements and using them for distinguishing quantum states or for performing multi-qubit gates.
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: Two qubits (stored in an array) which are guaranteed to be either in superposition of states $|00\rangle$ and $|11\rangle$ or in superposition of states $|01\rangle$ and $|10\rangle$.
Output: 0 if qubits were in the first superposition, 1 if they were in the second superposition.
The state of the qubits at the end of the operation does not matter.
%kata T01_SingleQubitMeasurement
operation SingleQubitMeasurement (qs : Qubit[]) : Int {
// ...
return -1;
}
Can't come up with a solution? See the explained solution in the Joint Measurements Workbook.
Inputs: Two qubits (stored in an array) which are guaranteed to be either in superposition of states $|00\rangle$ and $|11\rangle$ or in superposition of states $|01\rangle$ and $|10\rangle$.
Output: 0 if qubits were in the first superposition, 1 if they were in the second superposition.
The state of the qubits at the end of the operation should be the same as the starting state.
%kata T02_ParityMeasurement
operation ParityMeasurement (qs : Qubit[]) : Int {
// ...
return -1;
}
Can't come up with a solution? See the explained solution in the Joint Measurements Workbook.
Inputs: Four qubits (stored in an array) which are guaranteed to be either in superposition of states $|0000\rangle$ and $|1111\rangle$ or in superposition of states $|0011\rangle$ and $|1100\rangle$.
Output : 0 if qubits were in the first superposition, 1 if they were in the second superposition.
The state of the qubits at the end of the operation should be the same as the starting state.
%kata T03_GHZOrGHZWithX
operation GHZOrGHZWithX (qs : Qubit[]) : Int {
// ...
return -1;
}
Can't come up with a solution? See the explained solution in the Joint Measurements Workbook.
Inputs: An even number of qubits (stored in an array) which are guaranteed to be either in a superposition of states $|0..0\rangle$ and $|1..1\rangle$ (the GHZ state) or in the W state.
Output: 0 if qubits were in the first superposition, 1 if they were in the second superposition.
The state of the qubits at the end of the operation should be the same as the starting state.
%kata T04_GHZOrWState
operation GHZOrWState (qs : Qubit[]) : Int {
// ...
return -1;
}
Can't come up with a solution? See the explained solution in the Joint Measurements Workbook.
Inputs: Two qubits (stored in an array) which are guaranteed to be
Output: 0 if qubits were in the first superposition, 1 if they were in the second superposition.
The state of the qubits at the end of the operation should be the same as the starting state.
%kata T05_DifferentBasis
operation DifferentBasis (qs : Qubit[]) : Int {
// ...
return -1;
}
Can't come up with a solution? See the explained solution in the Joint Measurements Workbook.
Input: Two unentangled qubits (stored in an array of length 2). The first qubit (qs[0]
) will be in state $|\psi\rangle = \alpha |0\rangle + \beta |1\rangle$ , the second (qs[1]
) - in state $|0\rangle$ (this can be written as two-qubit state $\big(\alpha |0\rangle + \beta |1\rangle\big) \otimes |0\rangle$).
Output: Change the two-qubit state to $\alpha |00\rangle + \beta |11\rangle$ using only single-qubit gates and joint measurements. Do not use two-qubit gates. You do not need to allocate extra qubits.
%kata T06_ControlledX
operation ControlledX (qs : Qubit[]) : Unit {
// ...
}
Can't come up with a solution? See the explained solution in the Joint Measurements Workbook.
Input: Two qubits (stored in an array of length 2) in an arbitrary two-qubit state $\alpha |00\rangle + \beta |01\rangle + \color{blue}\gamma |10\rangle + \color{blue}\delta |11\rangle$.
Goal: Change the two-qubit state to $\alpha |00\rangle + \beta |01\rangle + \color{red}\delta |10\rangle + \color{red}\gamma |11\rangle$ using only single-qubit gates and joint measurements. Do not use two-qubit gates.
A general-case implementation of CNOT gate via joint measurements is described in this paper.
%kata T07_ControlledX_General
operation ControlledX_General (qs : Qubit[]) : Unit {
// ...
}
Can't come up with a solution? See the explained solution in the Joint Measurements Workbook.