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/OpenQASM/BellPair.qasm

31lines · modecode

1// OpenQASM Bell Pair sample
2//
3// Bell pairs are specific quantum states of two qubits that represent
4// the simplest (and maximal) examples of quantum entanglement. This sample
5// prepares |Φ⁺⟩ = (|00⟩+|11⟩)/√2.
6//
7// See [Bell state](https://en.wikipedia.org/wiki/Bell_state)
8
9OPENQASM 3;
10include "stdgates.inc";
11
12// Declares use of qubits `q1` and `q2`.
13qubit q1;
14qubit q2;
15
16// Qubits are initially in an undefined state.
17// Reset is used here to initialize qubits to |0⟩ state.
18reset q1;
19reset q2;
20
21// Set qubit `q1` in superposition of |0⟩ and |1⟩ by applying a Hadamard gate.
22h q1;
23// Entangle the two qubits `q1` and `q2` using the `cx` gate.
24cx q1, q2;
25
26// Measure the two qubits and store results in classical variables `r1` and `r2`.
27bit r1 = measure q1;
28bit r2 = measure q2;
29
30// Note, that the reported result (r1, r2)
31// will always be either (Zero, Zero) or (One, One).