microsoft/qdk

Public

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

CodeCommitsIssuesPull requestsActionsInsightsSecurity
logo

Branches

Tags

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

Clone

HTTPS

Download ZIP

samples/getting_started/Entanglement.qs

29lines · modeblame

c97c05a1DmitryVasilevsky1 years ago1/// # 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.
12use q1 = Qubit();
13use q2 = Qubit();
14
15// Set the first qubit in superposition by calling the `H` operation,
16// which applies a Hadamard transformation to the qubit.
17H(q1);
18// Entangle the two qubits using the `CNOT` operation.
19CNOT(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〉.
24Std.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.
28MResetEachZ([q1, q2])
29}