Skip to content

Commit

Permalink
Add Multi Qubit Systems Measurements tutorial (microsoft#601)
Browse files Browse the repository at this point in the history
  • Loading branch information
PratikSathe authored Jan 5, 2022
1 parent adeaa8c commit 0cad7c5
Show file tree
Hide file tree
Showing 11 changed files with 1,797 additions and 0 deletions.
1 change: 1 addition & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ RUN cd ${HOME} && \
./scripts/prebuild-kata.sh tutorials/LinearAlgebra LinearAlgebra.ipynb && \
./scripts/prebuild-kata.sh tutorials/MultiQubitGates MultiQubitGates.ipynb && \
./scripts/prebuild-kata.sh tutorials/MultiQubitSystems MultiQubitSystems.ipynb && \
./scripts/prebuild-kata.sh tutorials/MultiQubitSystemMeasurements MultiQubitSystemMeasurements.ipynb && \
#./scripts/prebuild-kata.sh tutorials/Oracles Oracles.ipynb && \
./scripts/prebuild-kata.sh tutorials/Qubit Qubit.ipynb && \
./scripts/prebuild-kata.sh tutorials/RandomNumberGeneration RandomNumberGenerationTutorial.ipynb && \
Expand Down
2 changes: 2 additions & 0 deletions index.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,8 @@
"\n",
"* **[Single-qubit measurements (tutorial)](./tutorials/SingleQubitSystemMeasurements/SingleQubitSystemMeasurements.ipynb)**.\n",
" Learn what quantum measurement is and how to use it for single-qubit systems.\n",
"* **[Multi-qubit measurements (tutorial)](./tutorials/MultiQubitSystemMeasurements/MultiQubitSystemMeasurements.ipynb)**.\n",
" Learn to use measurements for multi-qubit systems.\n",
"* **[Measurements](./Measurements/Measurements.ipynb)**.\n",
" Learn to distinguish quantum states using measurements.\n",
"* **[Distinguish unitaries](./DistinguishUnitaries/DistinguishUnitaries.ipynb)**\\*.\n",
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{"dump.basisStateLabelingConvention":"Bitstring"}
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
<Project Sdk="Microsoft.Quantum.Sdk/0.21.2112180703">

<PropertyGroup>
<TargetFramework>netcoreapp3.1</TargetFramework>
<PlatformTarget>x64</PlatformTarget>
<RootNamespace>Quantum.Kata.MultiQubitSystemMeasurements</RootNamespace>
<IQSharpLoadAutomatically>true</IQSharpLoadAutomatically>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Microsoft.Quantum.Katas" Version="0.21.2112180703" />
<PackageReference Include="Microsoft.Quantum.Xunit" Version="0.21.2112180703" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="15.3.0" />
<PackageReference Include="xunit" Version="2.3.1" />
<PackageReference Include="xunit.runner.visualstudio" Version="2.3.1" />
<DotNetCliToolReference Include="dotnet-xunit" Version="2.3.1" />
</ItemGroup>

</Project>

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@

Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio Version 16
VisualStudioVersion = 16.0.32002.261
MinimumVisualStudioVersion = 10.0.40219.1
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "MultiQubitSystemMeasurements", "MultiQubitSystemMeasurements.csproj", "{4B6FFEA0-E257-4567-8FD8-26C79E7B7B55}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Release|Any CPU = Release|Any CPU
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{4B6FFEA0-E257-4567-8FD8-26C79E7B7B55}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{4B6FFEA0-E257-4567-8FD8-26C79E7B7B55}.Debug|Any CPU.Build.0 = Debug|Any CPU
{4B6FFEA0-E257-4567-8FD8-26C79E7B7B55}.Release|Any CPU.ActiveCfg = Release|Any CPU
{4B6FFEA0-E257-4567-8FD8-26C79E7B7B55}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {5B7089BA-08A6-44AB-BA1A-CA00B0185CB4}
EndGlobalSection
EndGlobal
8 changes: 8 additions & 0 deletions tutorials/MultiQubitSystemMeasurements/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
# Welcome!

This tutorial introduces the basics of quantum measurements for multi-qubit systems.

You can run the tutorial online [here](https://mybinder.org/v2/gh/Microsoft/QuantumKatas/main?filepath=tutorials/MultiQubitSystemMeasurements/MultiQubitSystemMeasurements.ipynb).
Alternatively, you can install Jupyter and Q# on your machine, as described [here](https://docs.microsoft.com/quantum/install-guide#develop-with-jupyter-notebooks), and run the tutorial locally by navigating to this folder and starting the notebook from the command line using the following command:

jupyter notebook MultiQubitSystemMeasurements.ipynb
64 changes: 64 additions & 0 deletions tutorials/MultiQubitSystemMeasurements/ReferenceImplementation.qs
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT license.

//////////////////////////////////////////////////////////////////////
// This file contains reference solutions to all tasks.
// You should not modify anything in this file.
// We recommend that you try to solve the tasks yourself first,
// but feel free to look up the solution if you get stuck.
//////////////////////////////////////////////////////////////////////

namespace Quantum.Kata.MultiQubitSystemMeasurements {
open Microsoft.Quantum.Intrinsic;
open Microsoft.Quantum.Math;
open Microsoft.Quantum.Canon;
open Microsoft.Quantum.Measurement;

// Exercise 3. Identify computational basis states
operation BasisStateMeasurement_Reference(qs : Qubit[]) : Int {
// Measurement on the first qubit gives the higher bit of the answer, on the second - the lower
let m1 = M(qs[0]) == Zero ? 0 | 1;
let m2 = M(qs[1]) == Zero ? 0 | 1;
return m1 * 2 + m2;
}
// Exercise 5. Distinguish orthogonal states
operation IsPlusPlusMinus_Reference (qs : Qubit[]) : Int {
return Measure([PauliX], [qs[0]]) == Zero ? 0 | 1;
}

// Exercise 7. State selection using partial measurements
operation StateSelction_Reference(qs : Qubit[], i : Int) : Unit {
if (i == 0) {
if (M(qs[0]) == One){
// apply the X gate to the second qubit
X(qs[1]);
}
} else {
if (M(qs[0]) == Zero){
// apply the X gate to the second qubit only
X(qs[1]);
}
}
}

// Exercise 8. State preparation using partial measurements
operation PostSelection_Reference ( qs : Qubit[] ): Unit {
// Initialize the extra qubit
use anc = Qubit();
// Using the repeat-until-success pattern to prepare the right state
repeat {
ApplyToEach(H, qs);
Controlled X(qs, anc);
let res = MResetZ(anc);
}
until (res == Zero)
fixup {
ResetAll(qs);
}
}

// Exercise 9. Two qubit parity Measurement
operation ParityMeasurement_Reference(qs : Qubit[]) : Int {
return Measure([PauliZ, PauliZ], qs) == Zero ? 0 | 1;
}
}
42 changes: 42 additions & 0 deletions tutorials/MultiQubitSystemMeasurements/Tasks.qs
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT license.

//////////////////////////////////////////////////////////////////
// This file is a back end for the tasks in the tutorial.
// We strongly recommend to use the Notebook version of the tutorial
// to enjoy the full experience.
//////////////////////////////////////////////////////////////////

namespace Quantum.Kata.MultiQubitSystemMeasurements {
open Microsoft.Quantum.Intrinsic;
open Microsoft.Quantum.Math;

// Exercise 3. Identify computational basis states
operation BasisStateMeasurement(qs : Qubit[]) : Int {
// ...
return 0;
}

// Exercise 5. Distinguish orthogonal states
operation IsPlusPlusMinus(qs : Qubit[]) : Int {
// ...
return 0;
}

// Exercise 7. State selection using partial measurements
operation StateSelction(qs : Qubit[], i : Int) : Unit {
// ...
}

// Exercise 8. State preparation using partial measurements
operation PostSelection( qs : Qubit[] ): Unit {
// ...
}

// Exercise 9. Two qubit parity Measurement
operation ParityMeasurement(qs : Qubit[]) : Int{
// ...
return 1;
}
}

Loading

0 comments on commit 0cad7c5

Please sign in to comment.