{
"cells": [
{
"cell_type": "markdown",
"metadata": {},
"source": [
"# Superposition Kata\n",
"\n",
"**Superposition** quantum kata is a series of exercises designed\n",
"to get you familiar with the concept of superposition and with programming in Q#.\n",
"It covers the following topics:\n",
"* basic single-qubit and multi-qubit gates,\n",
"* superposition,\n",
"* flow control and recursion in Q#.\n",
"\n",
"It is recommended to complete the [BasicGates kata](./../BasicGates/BasicGates.ipynb) before this one to get familiar with the basic gates used in quantum computing. The list of basic gates available in Q# can be found at [Microsoft.Quantum.Intrinsic](https://docs.microsoft.com/qsharp/api/qsharp/microsoft.quantum.intrinsic).\n",
"\n",
"Each task is wrapped in one operation preceded by the description of the task.\n",
"Your goal is to fill in the blank (marked with `// ...` comments)\n",
"with some Q# code that solves the task. To verify your answer, run the cell using Ctrl+Enter (⌘+Enter on macOS).\n",
"\n",
"The tasks are given in approximate order of increasing difficulty; harder ones are marked with asterisks."
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Part I. Simple gates."
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"### Task 1.1. Plus state.\n",
"\n",
"**Input:** A qubit in the $|0\\rangle$ state.\n",
"\n",
"**Goal:** Change the state of the qubit to $|+\\rangle = \\frac{1}{\\sqrt{2}} \\big(|0\\rangle + |1\\rangle\\big)$."
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"%kata T101_PlusState \n",
"\n",
"operation PlusState (q : Qubit) : Unit {\n",
" // Hadamard gate H will convert |0⟩ state to |+⟩ state.\n",
" // Type the following: H(q);\n",
" // Then run the cell using Ctrl+Enter (⌘+Enter on macOS).\n",
"\n",
" // ...\n",
"}"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"*Can't come up with a solution? See the explained solution in the [Superposition Workbook](./Workbook_Superposition.ipynb#plus-state).*"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"### Task 1.2. Minus state.\n",
"\n",
"**Input**: A qubit in the $|0\\rangle$ state.\n",
"\n",
"**Goal**: Change the state of the qubit to $|-\\rangle = \\frac{1}{\\sqrt{2}} \\big(|0\\rangle - |1\\rangle\\big)$."
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"%kata T102_MinusState \n",
"\n",
"operation MinusState (q : Qubit) : Unit {\n",
" // ...\n",
"}"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"*Can't come up with a solution? See the explained solution in the [Superposition Workbook](./Workbook_Superposition.ipynb#minus-state).*"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"### Task 1.3. Superposition of all basis vectors on two qubits.\n",
"\n",
"**Input:** Two qubits in the $|00\\rangle$ state (stored in an array of length 2).\n",
"\n",
"**Goal:** Change the state of the qubits to $|+\\rangle \\otimes |+\\rangle = \\frac{1}{2} \\big(|00\\rangle + |01\\rangle + |10\\rangle + |11\\rangle\\big)$."
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"%kata T103_AllBasisVectors_TwoQubits\n",
"\n",
"operation AllBasisVectors_TwoQubits (qs : Qubit[]) : Unit {\n",
" // ...\n",
"}"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"*Can't come up with a solution? See the explained solution in the [Superposition Workbook](./Workbook_Superposition.ipynb#superposition-of-all-basis-vectors-on-two-qubits).*"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"### Task 1.4. Superposition of basis vectors with phase flip.\n",
"\n",
"**Input:** Two qubits in the $|00\\rangle$ sate (stored in an array of length 2).\n",
"\n",
"**Goal:** Change the state of the qubits to $\\frac{1}{2}\\big(|00\\rangle+|01\\rangle+|10\\rangle-|11\\rangle \\big)$."
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"%kata T104_AllBasisVectorWithPhaseFlip_TwoQubits\n",
"\n",
"operation AllBasisVectorWithPhaseFlip_TwoQubits (qs : Qubit[]) : Unit {\n",
" // ...\n",
"}"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"*Can't come up with a solution? See the explained solution in the [Superposition Workbook](./Workbook_Superposition.ipynb#superposition-of-basis-vectors-with-phase-flip).*"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"### Task 1.5. Superposition of basis vectors with phases.\n",
"\n",
"**Input:** Two qubits in the $|00\\rangle$ state (stored in an array of length 2).\n",
"\n",
"**Goal:** Change the state of the qubits to $\\frac{1}{2} \\big(|00\\rangle + i|01\\rangle - |10\\rangle - i|11\\rangle\\big)$.\n",
"\n",
"
\n",
"Need a hint? Click here
\n",
" Is this state separable?\n",
"
Index | \n", "State | \n", "
---|---|
0 | \n", "$|\\Phi^{+}\\rangle = \\frac{1}{\\sqrt{2}} \\big (|00\\rangle + |11\\rangle\\big)$ | \n", "
1 | \n", "$|\\Phi^{-}\\rangle = \\frac{1}{\\sqrt{2}} \\big (|00\\rangle - |11\\rangle\\big)$ | \n", "
2 | \n", "$|\\Psi^{+}\\rangle = \\frac{1}{\\sqrt{2}} \\big (|01\\rangle + |10\\rangle\\big)$ | \n", "
3 | \n", "$|\\Psi^{-}\\rangle = \\frac{1}{\\sqrt{2}} \\big (|01\\rangle - |10\\rangle\\big)$ | \n", "
open Microsoft.Quantum.Math;to the code before the operation definition.\n", "
open Microsoft.Quantum.Math;to the code before the operation definition.\n", "
open Microsoft.Quantum.Math;to the code before the operation definition.\n", "