microsoft/qdk

Public

mirrored fromhttps://github.com/microsoft/qdkAvailable

CodeCommitsIssuesPull requestsActionsInsightsSecurity
v1.1.1

Branches

Tags

  • No tags available.
0Branches0Tags
Go to file
Add file
Code

Clone

HTTPS

Download ZIP

samples/algorithms/BellState.qs

66lines · modecode

1/// # Sample
2/// Bell States
3///
4/// # Description
5/// Bell states or EPR pairs are specific quantum states of two qubits
6/// that represent the simplest (and maximal) examples of quantum entanglement.
7///
8/// This Q# program implements the four different Bell states.
9namespace Sample {
10 open Microsoft.Quantum.Diagnostics;
11 open Microsoft.Quantum.Measurement;
12
13 @EntryPoint()
14 operation BellStates() : (Result, Result)[] {
15 // Allocate the two qubits that will be used to create a Bell state.
16 use register = Qubit[2];
17
18 // This array contains a label and a preparation operation for each one
19 // of the four Bell states.
20 let bellStateTuples = [
21 ("|Φ+〉", PreparePhiPlus),
22 ("|Φ-〉", PreparePhiMinus),
23 ("|Ψ+〉", PreparePsiPlus),
24 ("|Ψ-〉", PreparePsiMinus)
25 ];
26
27 // Prepare all Bell states, show them using the `DumpMachine` operation
28 // and measure the Bell state qubits.
29 mutable measurements = [];
30 for (label, prepare) in bellStateTuples {
31 prepare(register);
32 Message($"Bell state {label}:");
33 DumpMachine();
34 set measurements += [(MResetZ(register[0]), MResetZ(register[1]))];
35 }
36 return measurements;
37 }
38
39 operation PreparePhiPlus(register : Qubit[]) : Unit {
40 ResetAll(register); // |00〉
41 H(register[0]); // |+0〉
42 CNOT(register[0], register[1]); // 1/sqrt(2)(|00〉 + |11〉)
43 }
44
45 operation PreparePhiMinus(register : Qubit[]) : Unit {
46 ResetAll(register); // |00〉
47 H(register[0]); // |+0〉
48 Z(register[0]); // |-0〉
49 CNOT(register[0], register[1]); // 1/sqrt(2)(|00〉 - |11〉)
50 }
51
52 operation PreparePsiPlus(register : Qubit[]) : Unit {
53 ResetAll(register); // |00〉
54 H(register[0]); // |+0〉
55 X(register[1]); // |+1〉
56 CNOT(register[0], register[1]); // 1/sqrt(2)(|01〉 + |10〉)
57 }
58
59 operation PreparePsiMinus(register : Qubit[]) : Unit {
60 ResetAll(register); // |00〉
61 H(register[0]); // |+0〉
62 Z(register[0]); // |-0〉
63 X(register[1]); // |-1〉
64 CNOT(register[0], register[1]); // 1/sqrt(2)(|01〉 - |10〉)
65 }
66}
67