Skip to content

Commit

Permalink
Updating Katas to QDK 0.6 (#111)
Browse files Browse the repository at this point in the history
* Update the katas to use QDK 0.6.1905.301.
* Add mechanism to verify that the reference solutions actually solve all tasks of a Notebook correctly.

Co-Authored-By: Bettina Heim <34236215+bettinaheim@users.noreply.github.com>
Co-Authored-By: Andres Paz <anpaz@microsoft.com>
  • Loading branch information
2 people authored and tcNickolas committed May 3, 2019
1 parent df491c9 commit 7519eb3
Show file tree
Hide file tree
Showing 77 changed files with 1,630 additions and 1,846 deletions.
1 change: 1 addition & 0 deletions .gitignore
Expand Up @@ -17,6 +17,7 @@ Tests/build
# test outputs
TestResults/
*.qxe
Check.ipynb

# Random VS files
*.suo
Expand Down
6 changes: 3 additions & 3 deletions BasicGates/BasicGates.csproj
Expand Up @@ -7,9 +7,9 @@
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Microsoft.Quantum.Canon" Version="0.5.1904.1302" />
<PackageReference Include="Microsoft.Quantum.Development.Kit" Version="0.5.1904.1302" />
<PackageReference Include="Microsoft.Quantum.Xunit" Version="0.5.1904.1302" />
<PackageReference Include="Microsoft.Quantum.Standard" Version="0.6.1905.301" />
<PackageReference Include="Microsoft.Quantum.Development.Kit" Version="0.6.1905.301" />
<PackageReference Include="Microsoft.Quantum.Xunit" Version="0.6.1905.301" />
<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" />
Expand Down
94 changes: 26 additions & 68 deletions BasicGates/BasicGates.ipynb
Expand Up @@ -36,7 +36,7 @@
"metadata": {},
"outputs": [],
"source": [
"%package Microsoft.Quantum.Katas::0.5.1904.1302"
"%package Microsoft.Quantum.Katas::0.6.1905.301"
]
},
{
Expand All @@ -46,13 +46,13 @@
"> The package versions in the output of the cell above should always match. If you are running the Notebooks locally and the versions do not match, please install the IQ# version that matches the version of the `Microsoft.Quantum.Katas` package.\n",
"> <details>\n",
"> <summary><u>How to install the right IQ# version</u></summary>\n",
"> For example, if the version of `Microsoft.Quantum.Katas` package above is 0.5.1904.1302, the installation steps are as follows:\n",
"> For example, if the version of `Microsoft.Quantum.Katas` package above is 0.6.1905.301, the installation steps are as follows:\n",
">\n",
"> 1. Stop the kernel.\n",
"> 2. Uninstall the existing version of IQ#:\n",
"> dotnet tool uninstall microsoft.quantum.iqsharp -g\n",
"> 3. Install the matching version:\n",
"> dotnet tool install microsoft.quantum.iqsharp -g --version 0.5.1904.1302\n",
"> dotnet tool install microsoft.quantum.iqsharp -g --version 0.6.1905.301\n",
"> 4. Reinstall the kernel:\n",
"> dotnet iqsharp install\n",
"> 5. Restart the Notebook.\n",
Expand Down Expand Up @@ -94,17 +94,12 @@
"source": [
"%kata T11_StateFlip_Test \n",
"\n",
"operation StateFlip (q : Qubit) : Unit {\n",
"operation StateFlip (q : Qubit) : Unit is Adj {\n",
" // The Pauli X gate will change the |0⟩ state to the |1⟩ state and vice versa.\n",
" // Type X(q);\n",
" // Then run the cell using Ctrl/⌘+Enter.\n",
"\n",
" body (...) {\n",
" // The Pauli X gate will change the |0⟩ state to the |1⟩ state and vice versa.\n",
" // Type X(q);\n",
" // Then run the cell using Ctrl/⌘+Enter.\n",
"\n",
" // ...\n",
" }\n",
"\n",
" adjoint self;\n",
" // ...\n",
"}"
]
},
Expand Down Expand Up @@ -134,13 +129,8 @@
"source": [
"%kata T12_BasisChange_Test \n",
"\n",
"operation BasisChange (q : Qubit) : Unit {\n",
" \n",
" body (...) {\n",
" // ...\n",
" }\n",
"\n",
" adjoint self;\n",
"operation BasisChange (q : Qubit) : Unit is Adj {\n",
" // ...\n",
"}"
]
},
Expand All @@ -163,13 +153,8 @@
"source": [
"%kata T13_SignFlip_Test \n",
"\n",
"operation SignFlip (q : Qubit) : Unit {\n",
"\n",
" body (...) {\n",
" // ...\n",
" }\n",
"\n",
" adjoint self;\n",
"operation SignFlip (q : Qubit) : Unit is Adj {\n",
" // ...\n",
"}"
]
},
Expand All @@ -190,7 +175,7 @@
"- If the qubit is in superposition, change its state according to the effect on basis vectors.\n",
"\n",
"> This is the first operation in this kata that is not self-adjoint, i.e., applying it for a second time\n",
"> does not return the qubit to the original state. `adjoint invert` means that Q# can compute the operation \n",
"> does not return the qubit to the original state. `is Adj` means that Q# can compute the operation \n",
"> that returns the qubit to the original state automatically."
]
},
Expand All @@ -202,13 +187,8 @@
"source": [
"%kata T14_AmplitudeChange_Test\n",
"\n",
"operation AmplitudeChange (q : Qubit, α : Double) : Unit {\n",
"\n",
" body (...) {\n",
" // ...\n",
" }\n",
"\n",
" adjoint invert;\n",
"operation AmplitudeChange (q : Qubit, α : Double) : Unit is Adj {\n",
" // ...\n",
"}\n"
]
},
Expand All @@ -231,13 +211,8 @@
"source": [
"%kata T15_PhaseFlip_Test\n",
"\n",
"operation PhaseFlip (q : Qubit) : Unit {\n",
" \n",
" body (...) {\n",
" // ...\n",
" }\n",
" \n",
" adjoint invert;\n",
"operation PhaseFlip (q : Qubit) : Unit is Adj { \n",
" // ...\n",
"}\n",
"\n"
]
Expand Down Expand Up @@ -267,13 +242,8 @@
"source": [
"%kata T16_PhaseChange_Test\n",
"\n",
"operation PhaseChange (q : Qubit, α : Double) : Unit {\n",
" \n",
" body (...) {\n",
" // ...\n",
" }\n",
" \n",
" adjoint invert;\n",
"operation PhaseChange (q : Qubit, α : Double) : Unit is Adj {\n",
" // ...\n",
"}\n"
]
},
Expand All @@ -296,13 +266,9 @@
"source": [
"%kata T17_BellStateChange1_Test\n",
"\n",
"operation BellStateChange1 (qs : Qubit[]) : Unit {\n",
" \n",
" body (...) {\n",
" // ...\n",
" }\n",
"operation BellStateChange1 (qs : Qubit[]) : Unit is Adj {\n",
" \n",
" adjoint invert;\n",
" // ...\n",
"}\n"
]
},
Expand All @@ -325,13 +291,9 @@
"source": [
"%kata T18_BellStateChange2_Test\n",
"\n",
"operation BellStateChange2 (qs : Qubit[]) : Unit {\n",
"operation BellStateChange2 (qs : Qubit[]) : Unit is Adj {\n",
" \n",
" body (...) {\n",
" // ...\n",
" }\n",
" \n",
" adjoint invert;\n",
" // ...\n",
"}\n"
]
},
Expand All @@ -354,13 +316,9 @@
"source": [
"%kata T19_BellStateChange3_Test\n",
"\n",
"operation BellStateChange3 (qs : Qubit[]) : Unit {\n",
" \n",
" body (...) {\n",
" // ...\n",
" }\n",
"operation BellStateChange3 (qs : Qubit[]) : Unit is Adj {\n",
" \n",
" adjoint invert;\n",
" // ...\n",
"}\n"
]
},
Expand Down Expand Up @@ -451,7 +409,7 @@
"\n",
"**Goal:** Change the two-qubit state to $\\alpha |00\\rangle + \\color{red}\\gamma |01\\rangle + \\color{red}\\beta |10\\rangle + \\delta |11\\rangle$.\n",
"\n",
"> This task can be solved using one primitive gate; as an exercise, try to express the solution using several (possibly controlled) Pauli gates."
"> This task can be solved using one intrinsic gate; as an exercise, try to express the solution using several (possibly controlled) Pauli gates."
]
},
{
Expand Down
68 changes: 22 additions & 46 deletions BasicGates/ReferenceImplementation.qs
Expand Up @@ -10,7 +10,7 @@

namespace Quantum.Kata.BasicGates {

open Microsoft.Quantum.Primitive;
open Microsoft.Quantum.Intrinsic;
open Microsoft.Quantum.Canon;


Expand Down Expand Up @@ -72,27 +72,19 @@ namespace Quantum.Kata.BasicGates {
// If the qubit is in state |0⟩, change its state to cos(alpha)*|0⟩ + sin(alpha)*|1⟩.
// If the qubit is in state |1⟩, change its state to -sin(alpha)*|0⟩ + cos(alpha)*|1⟩.
// If the qubit is in superposition, change its state according to the effect on basis vectors.
operation AmplitudeChange_Reference (q : Qubit, alpha : Double) : Unit {

body (...) {
Ry(2.0 * alpha, q);
}

adjoint invert;
operation AmplitudeChange_Reference (q : Qubit, alpha : Double) : Unit
is Adj {
Ry(2.0 * alpha, q);
}


// Task 1.5. Phase flip
// Input: A qubit in state |ψ⟩ = α |0⟩ + β |1⟩.
// Goal: Change the qubit state to α |0⟩ + iβ |1⟩ (flip the phase of |1⟩ component of the superposition).
operation PhaseFlip_Reference (q : Qubit) : Unit {

body (...) {
S(q);
// alternatively Rz(0.5 * PI(), q);
}

adjoint invert;
operation PhaseFlip_Reference (q : Qubit) : Unit
is Adj {
S(q);
// alternatively Rz(0.5 * PI(), q);
}


Expand All @@ -104,54 +96,38 @@ namespace Quantum.Kata.BasicGates {
// If the qubit is in state |0⟩, don't change its state.
// If the qubit is in state |1⟩, change its state to exp(i*alpha)|1⟩.
// If the qubit is in superposition, change its state according to the effect on basis vectors.
operation PhaseChange_Reference (q : Qubit, alpha : Double) : Unit {

body (...) {
Rz(alpha, q);
}

adjoint invert;
operation PhaseChange_Reference (q : Qubit, alpha : Double) : Unit
is Adj {
Rz(alpha, q);
}


// Task 1.7. Bell state change - 1
// Input: Two entangled qubits in Bell state |Φ⁺⟩ = (|00⟩ + |11⟩) / sqrt(2).
// Goal: Change the two-qubit state to |Φ⁻⟩ = (|00⟩ - |11⟩) / sqrt(2).
operation BellStateChange1_Reference (qs : Qubit[]) : Unit {

body (...) {
Z(qs[0]);
// alternatively Z(qs[1]);
}

adjoint invert;
operation BellStateChange1_Reference (qs : Qubit[]) : Unit
is Adj {
Z(qs[0]);
// alternatively Z(qs[1]);
}


// Task 1.8. Bell state change - 2
// Input: Two entangled qubits in Bell state |Φ⁺⟩ = (|00⟩ + |11⟩) / sqrt(2).
// Goal: Change the two-qubit state to |Ψ⁺⟩ = (|01⟩ + |10⟩) / sqrt(2).
operation BellStateChange2_Reference (qs : Qubit[]) : Unit {

body (...) {
X(qs[0]);
// alternatively X(qs[1]);
}

adjoint invert;
operation BellStateChange2_Reference (qs : Qubit[]) : Unit
is Adj {
X(qs[0]);
// alternatively X(qs[1]);
}


// Task 1.9. Bell state change - 3
// Input: Two entangled qubits in Bell state |Φ⁺⟩ = (|00⟩ + |11⟩) / sqrt(2).
// Goal: Change the two-qubit state to |Ψ⁻⟩ = (|01⟩ - |10⟩) / sqrt(2).
operation BellStateChange3_Reference (qs : Qubit[]) : Unit {

body (...) {
Y(qs[0]);
}

adjoint invert;
operation BellStateChange3_Reference (qs : Qubit[]) : Unit
is Adj {
Y(qs[0]);
}


Expand Down

0 comments on commit 7519eb3

Please sign in to comment.