Created
May 15, 2020 03:45
-
-
Save billchenxi/3a9543f81ec206f7619be97db21e6e72 to your computer and use it in GitHub Desktop.
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
namespace Q_Entanglement { | |
open Microsoft.Quantum.Canon; | |
open Microsoft.Quantum.Intrinsic; | |
operation Entanglement() : (Result, Result) { | |
mutable Q1_state = Zero; | |
mutable Q2_state = Zero; | |
using ((Q1, Q2) = (Qubit(), Qubit())) { | |
H(Q1); | |
CNOT(Q1, Q2); // short for Controled NOT | |
set Q1_state = M(Q1); | |
set Q2_state = M(Q2); | |
Reset(Q1); | |
Reset(Q2); | |
} | |
return (Q1_state, Q2_state); | |
} | |
operation QuantumSimulator(count : Int) : (Int, Int) { | |
mutable Q1_state = Zero; | |
mutable Q2_state = Zero; | |
mutable ones = 0; | |
mutable equal = 0; | |
for (indx in 1..count) { | |
set (Q1_state, Q2_state) = Entanglement(); | |
if (Q1_state == One) { | |
set ones += 1; | |
} | |
if (Q1_state == Q2_state) { | |
set equal += 1; | |
} | |
} | |
return (ones, equal); | |
} | |
@EntryPoint() | |
operation Driver_Code() : Unit { | |
let (ones, equal) = QuantumSimulator(1000); | |
let zeros = 1000-ones; | |
Message($"Entanglement result: "); | |
Message($" One: {ones}"); | |
Message($" Zero: {zeros}"); | |
Message($" Equal: {equal}"); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment