forked from microsoft/QuantumKatas
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add Multi Qubit Systems Measurements tutorial (microsoft#601)
- Loading branch information
1 parent
adeaa8c
commit 0cad7c5
Showing
11 changed files
with
1,797 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
{"dump.basisStateLabelingConvention":"Bitstring"} |
20 changes: 20 additions & 0 deletions
20
tutorials/MultiQubitSystemMeasurements/MultiQubitSystemMeasurements.csproj
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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> | ||
|
789 changes: 789 additions & 0 deletions
789
tutorials/MultiQubitSystemMeasurements/MultiQubitSystemMeasurements.ipynb
Large diffs are not rendered by default.
Oops, something went wrong.
25 changes: 25 additions & 0 deletions
25
tutorials/MultiQubitSystemMeasurements/MultiQubitSystemMeasurements.sln
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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
64
tutorials/MultiQubitSystemMeasurements/ReferenceImplementation.qs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} | ||
} | ||
|
Oops, something went wrong.