Add first QC experiments.

Bell states in the Microsoft Quantum SDK and Rigetti's pyQuil.
This commit is contained in:
2018-06-11 09:41:09 -07:00
parent 6ad979d28f
commit c633b08cbd
6 changed files with 132 additions and 0 deletions

14
qc/msqdk/Bell/Bell.csproj Normal file
View File

@@ -0,0 +1,14 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>netcoreapp2.0</TargetFramework>
<PlatformTarget>x64</PlatformTarget>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Microsoft.Quantum.Canon" Version="0.2.1802.1603-preview" />
<PackageReference Include="Microsoft.Quantum.Development.Kit" Version="0.2.1802.1603-preview" />
</ItemGroup>
</Project>

52
qc/msqdk/Bell/Bell.qs Normal file
View File

@@ -0,0 +1,52 @@
namespace Quantum.Bell
{
open Microsoft.Quantum.Canon;
open Microsoft.Quantum.Primitive;
operation Set (desired: Result, q1: Qubit) : ()
{
body
{
let current = M(q1);
if (desired != current) {
X(q1);
}
}
}
operation BellTest (count: Int, initial: Result) : (Int, Int, Int)
{
body {
mutable numOnes = 0; // by default in Q#, variables are immutable.
// Q# doesn't require type annotations for variables.
mutable agree = 0;
// using allocates an array of qubits for use in a block of code.
// all qubits are dynamically allocated and released.
using (qubits = Qubit[2])
{
for (test in 1..count) {
Set(initial, qubits[0]);
Set(Zero, qubits[1]);
H(qubits[0]);
CNOT(qubits[0], qubits[1]);
let res = M(qubits[0]);
if (res == M(qubits[1])) {
set agree = agree + 1;
}
// Count the number of ones we've seen.
if (res == One) {
set numOnes = numOnes + 1;
}
Set(Zero, qubits[0]);
Set(Zero, qubits[1]);
}
}
return (count-numOnes, numOnes, agree);
}
}
}

23
qc/msqdk/Bell/Driver.cs Normal file
View File

@@ -0,0 +1,23 @@
using Microsoft.Quantum.Simulation.Core;
using Microsoft.Quantum.Simulation.Simulators;
namespace Quantum.Bell
{
class Driver
{
static void Main(string[] args)
{
using (var sim = new QuantumSimulator()) {
// Try initial values.
Result[] initials = new Result[] { Result.Zero, Result.One };
foreach (Result initial in initials) {
var res = BellTest.Run(sim, 1000, initial).Result;
var (numZeroes, numOnes, agree) = res;
System.Console.WriteLine($"Init:{initial,-4} |0>={numZeroes,-4}, |1>={numOnes,-4}, agree={agree,-4}");
}
}
System.Console.WriteLine("Press any key to continue.");
System.Console.ReadKey();
}
}
}