microsoft/qdk

Public

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

CodeCommitsIssuesPull requestsActionsInsightsSecurity
alex/callable-generic

Branches

Tags

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

Clone

HTTPS

Download ZIP

samples/algorithms/Entanglement.qs

29lines · modecode

1/// # Sample
2/// Entanglement
3///
4/// # Description
5/// Qubits are said to be entangled when the state of each one of them cannot be
6/// described independently from the state of the others.
7///
8/// This Q# program entangles two qubits.
9import Std.Diagnostics.*;
10
11operation Main() : (Result, Result) {
12 // Allocate the two qubits that will be entangled.
13 use (q1, q2) = (Qubit(), Qubit());
14
15 // Set the first qubit in superposition by calling the `H` operation,
16 // which applies a Hadamard transformation to the qubit.
17 // Then, entangle the two qubits using the `CNOT` operation.
18 H(q1);
19 CNOT(q1, q2);
20
21 // Show the entangled state using the `DumpMachine` function.
22 DumpMachine();
23
24 // Measurements of entangled qubits are always correlated.
25 let (m1, m2) = (M(q1), M(q2));
26 Reset(q1);
27 Reset(q2);
28 return (m1, m2);
29}
30