microsoft/qdk

Public

mirrored from https://github.com/microsoft/qdkAvailable

CodeCommitsIssuesPull requestsActionsInsightsSecurity
dmitryv/select-updated

Branches

Tags

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

Clone

HTTPS

Download ZIP

katas/content/multi_qubit_systems/examples/MultiQubitSystems.qs

44lines · modecode

1namespace Kata {
2 open Microsoft.Quantum.Diagnostics;
3
4 @EntryPoint()
5 operation MultiQubitSystemsDemo () : Unit {
6 // This allocates an array of 2 qubits, each of them in state |0⟩.
7 // The overall state of the system is |00⟩
8 use qs = Qubit[2];
9 // X gate changes the first qubit into state |1⟩
10 // The entire system is now in state |10⟩
11 X(qs[0]);
12
13 Message("System in state |10⟩:");
14 DumpMachine();
15
16 // This changes the second qubit into state |+⟩ = (1/sqrt(2))(|0⟩ + |1⟩).
17 // The entire system is now in state (1/sqrt(2))(|10⟩ + |11⟩)
18 H(qs[1]);
19
20 Message("System in state (1/sqrt(2))(|10⟩ + |11⟩):");
21 DumpMachine();
22
23 // This changes the first qubit into state |-⟩ = (1/sqrt(2))(|0⟩ - |1⟩)
24 // The entire system is now in state 0.5(|00⟩ + |01⟩ - |10⟩ - |11⟩)
25 H(qs[0]);
26
27 Message("System in state 0.5(|00⟩ + |01⟩ - |10⟩ - |11⟩):");
28 DumpMachine();
29
30 // The next lines entangle the qubits.
31 // Don't worry about what exactly they do for now
32 H(qs[1]);
33 CNOT(qs[0], qs[1]);
34
35 Message("Entangled state 0.5(|00⟩ - |11⟩):");
36 DumpMachine();
37
38 // Since the states of entangled qubits are inseparable,
39 // it makes no sense to examine only one of them
40
41 // This returns the system into state |00⟩
42 ResetAll(qs);
43 }
44}