Skip to content

Commit

Permalink
Merge pull request #43 from aryashah2k/CHSH
Browse files Browse the repository at this point in the history
Add CHSH Implementation + Documentation
  • Loading branch information
born-2learn authored Feb 25, 2021
2 parents 5da08d3 + 0b1b7d2 commit 0172b69
Show file tree
Hide file tree
Showing 2 changed files with 129 additions and 0 deletions.
114 changes: 114 additions & 0 deletions qsharp/CHSH Implementation/CHSH Implementation.qs
Original file line number Diff line number Diff line change
@@ -0,0 +1,114 @@
namespace chsh {
open Microsoft.Quantum.Canon;
open Microsoft.Quantum.Intrinsic;
open Microsoft.Quantum.Convert;
open Microsoft.Quantum.Math;
open Microsoft.Quantum.Measurement;

@EntryPoint()
operation SayHello() : Unit
{
Message(" CHSH ");
Message("------");

let numberOfGames = 10000;
mutable classicalWinCount = 0;
mutable quantumWinCount = 0;

for( i in 1..numberOfGames )
{
let bitForAlice = GetRandomBit();
let bitForBob = GetRandomBit();

let (classicalXorA, classicalXorB) = PlayClassic(bitForAlice, bitForBob);
let (quantumXorA, quantumXorB) = PlayQuantum(bitForAlice, bitForBob);

let bitProduct = BoolArrayAsInt([bitForAlice]) * BoolArrayAsInt([bitForBob]);

let bitXorClassic = ModulusI(classicalXorA + classicalXorB, 2);
if( bitProduct == bitXorClassic )
{
set classicalWinCount += 1;
}

let bitXorQuantum = ModulusI(quantumXorA + quantumXorB, 2);
if( bitProduct == bitXorQuantum )
{
set quantumWinCount += 1;
}
}

Message($"Classical win percentage: {(IntAsDouble(classicalWinCount) / IntAsDouble(numberOfGames))}");
Message($"Quantum win percentage: {IntAsDouble(quantumWinCount) / IntAsDouble(numberOfGames)}");
}

operation GetRandomBit() : Bool
{
using( q = Qubit() )
{
H(q);
let bit = MResetZ(q);
return bit == One;
}
}

operation PlayClassic( bitForAlice : Bool, bitForBob : Bool ) : (Int, Int)
{
if( GetRandomBit() )
{
return (0, 0);
}
else
{
return (1, 1);
}
}

operation PlayQuantum( bitForAlice : Bool, bitForBob : Bool ) : (Int, Int)
{
using( (qubitForAlice, qubitForBob) = (Qubit(), Qubit()) )
{
H(qubitForAlice);
CNOT(qubitForAlice, qubitForBob);

if( GetRandomBit() )
{
let measuredForAlice = MeasureQubitForAlice(bitForAlice, qubitForAlice) == One ? 1 | 0;
let measuredForBob = MeasureQubitForBob(bitForBob, qubitForBob) == One ? 1 | 0;
return (measuredForAlice, measuredForBob);
}
else
{
let measuredForBob = MeasureQubitForBob(bitForBob, qubitForBob) == One ? 1 | 0;
let measuredForAlice = MeasureQubitForAlice(bitForAlice, qubitForAlice) == One ? 1 | 0;
return (measuredForAlice, measuredForBob);
}
}
}

operation MeasureQubitForAlice( bit : Bool, qubit : Qubit) : Result
{
if( bit )
{
return MResetX(qubit);
}
else
{
return MResetZ(qubit);
}
}

operation MeasureQubitForBob( bit : Bool, qubit : Qubit) : Result
{
if( bit )
{
Ry(2.0 * PI() / 8.0, qubit);
}
else
{
Ry(-2.0 * PI() / 8.0, qubit);
}

return MResetZ(qubit);
}
}
15 changes: 15 additions & 0 deletions qsharp/CHSH Implementation/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
In physics, the CHSH inequality can be used in the proof of Bell's theorem, which states that certain consequences of entanglement in quantum mechanics cannot be reproduced by local hidden variable theories. Experimental verification of violation of the inequalities is seen as experimental confirmation that nature cannot be described by local hidden variables theories. CHSH stands for John Clauser, Michael Horne, Abner Shimony, and Richard Holt, who described it in a much-cited paper published in 1969 (Clauser et al., 1969). They derived the CHSH inequality, which, as with John Bell's original inequality (Bell, 1964), is a constraint on the statistics of "coincidences" in a Bell test experiment which is necessarily true if there exist underlying local hidden variables (local realism). This constraint can, on the other hand, be infringed by quantum mechanics.

In 1935, when Einstein authored his EPR Paradox paper in conjunction with Podolsky and Rosen (hence the appellation EPR) he was essentially stating that Quantum Entanglement -Spooky action at a distance which he was later to call it- did not exist.

Einstein postulated that there was nothing ‘spooky’ going on and that it was just like saying if you separated a pair of boots and revealed that the boot in front of you was left, then you immediately knew that the distant one was a right boot! Essentially, Einstein said that there was a ‘Hidden Variable’ within every particle that science had just not discovered at that time. The science community happily accepted Einstein’s explanation as it was nowhere near understanding this perplexing phenomenon.

But Einstein was wrong!

It took 30 years and a Northern Irish professor -John Bell- to, mathematically, prove Einstein wrong. His proof has come to be known as ‘Bell’s Inequality’ and the CHSH Game is an intuitive way to understand the inequality.

The CHSH game looks like a magic trick for which there is no explanation yet it works every time!

In this presentation, Eamonn Darcy the Founder/Operator of QUECWA -The Quantum Education Centre of Western Australia provides a description of the CHSH game -a hypothetical Bell test experiment. The players of this game can use either classical strategies (corresponding to local hidden variable theories) or quantum strategies, which involve measurements of a shared entangled bit.

No matter what strategy you come up with, classically, the chances of you winning the game can never be greater than 75% whereas exploiting the enigmatic, spooky force of quantum entanglement you will regularly win 85% of the time.

0 comments on commit 0172b69

Please sign in to comment.