Science Workflow

量子计算

通过线性类型建模量子态

Back to Science Hub

使用Sounio进行量子计算

Sounio在编译时强制执行量子力学的无克隆定理,通过线性类型:Qubit是一种线性资源,必须恰好使用一次。尝试复制它会产生编译错误。

量子态的线性类型

// Qubit不能被克隆。
// 标准量子门(H, X, Y, Z, CNOT)消耗并返回Qubit。

fn apply_hadamard(q: Qubit) -> Qubit {
    // 应用H门 ...
}

struct QubitPair { fst: Qubit, snd: Qubit }

fn apply_cnot_pair(control: Qubit, target: Qubit) -> QubitPair {
    // 应用CNOT门 ...
}

fn bell_state() -> QubitPair {
    let q1 = allocate_qubit()
    let q2 = allocate_qubit()

    let h1 = apply_hadamard(q1)
    let pair = apply_cnot_pair(h1, q2)

    pair
}