Q# 是一种用于量子计算的编程语言,主要用于编写量子算法。
1. 环境配置
安装vscode2017以上
QDK下载地址:Azure Quantum Development Kit (QDK) - Visual Studio Marketplace
将下载好的QDK作为拓展配置到vscode里面。
2.代码
import Microsoft.Quantum.Diagnostics.*;
operation Main() : (Result, Result) {
// Allocate two qubits, q1 and q2, in the 0 state.
use (q1, q2) = (Qubit(), Qubit());
// Put q1 into an even superposition.
// It now has a 50% chance of being measured as 0 or 1.
H(q1);
// Entangle q1 and q2, making q2 depend on q1.
CNOT(q1, q2);
// Show the entangled state of the qubits.
DumpMachine();
// Measure q1 and q2 and store the results in m1 and m2.
let (m1, m2) = (M(q1), M(q2));
// Reset q1 and q2 to the 0 state.
Reset(q1);
Reset(q2);
// Return the measurement results.
return (m1, m2);
}
3. 运行结果