microsoft/qdk
Publicmirrored from https://github.com/microsoft/qdkAvailable
samples/qasm/sample_001.qasm
25lines · modecode
| 1 | OPENQASM 3; |
| 2 | include "stdgates.inc"; |
| 3 | |
| 4 | gate hgate q { h q; } |
| 5 | gate xgate q { x q; } |
| 6 | |
| 7 | const int[32] N = 4; |
| 8 | |
| 9 | qubit[4] q; |
| 10 | qubit ancilla; |
| 11 | |
| 12 | def deutsch_jozsa(qubit[N] q_func, qubit ancilla_q) { |
| 13 | for int i in [0:N-1] { hgate q_func[i]; } |
| 14 | hgate ancilla_q; |
| 15 | for int i in [0:N-1] { cx q_func[i], ancilla_q; } |
| 16 | for int i in [0:N-1] { hgate q_func[i]; } |
| 17 | } |
| 18 | |
| 19 | deutsch_jozsa(q, ancilla); |
| 20 | |
| 21 | output bit[4] result; |
| 22 | result[0] = measure q[0]; |
| 23 | result[1] = measure q[1]; |
| 24 | result[2] = measure q[2]; |
| 25 | result[3] = measure q[3]; |