microsoft/qdk

Public

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

CodeCommitsIssuesPull requestsActionsInsightsSecurity
20c2fb1c118e553b69d042c5289d61dda9c55e76

Branches

Tags

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

Clone

HTTPS

Download ZIP

samples/getting_started/Entanglement.qs

29lines · modecode

1/// # Summary
2/// Entanglement sample
3///
4/// # Description
5/// This Q# program entangles two qubits and measures them.
6///
7/// # Remarks
8/// Qubits are said to be entangled when the state of each one of them
9/// cannot be described independently from the state of the others.
10operation Main() : Result[] {
11 // Allocate the two qubits that will be entangled.
12 use q1 = Qubit();
13 use q2 = Qubit();
14
15 // Set the first qubit in superposition by calling the `H` operation,
16 // which applies a Hadamard transformation to the qubit.
17 H(q1);
18 // Entangle the two qubits using the `CNOT` operation.
19 CNOT(q1, q2);
20
21 // Show the entangled state using the `DumpMachine` function.
22 // Note that the state is a superposition of |00〉 and |11〉,
23 // but not |01〉 and |10〉.
24 Std.Diagnostics.DumpMachine();
25
26 // Create an array (register) out of the two qubits, measure each qubit,
27 // reset each qubit, return the array of measurement results.
28 MResetEachZ([q1, q2])
29}
30