Q#使用教程

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. 运行结果

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值