5 个版本 (breaking)

0.5.0 2019 年 9 月 13 日
0.4.0 2019 年 5 月 29 日
0.3.0 2019 年 4 月 10 日
0.2.0 2019 年 2 月 27 日
0.1.0 2019 年 1 月 30 日

#231 in 模拟


用于 q1tsim-logic-gates

Apache-2.0

540KB
13K SLoC

q1tsim

Build Status License Released API docs

一个简单、高效的量子计算机模拟器。

概述

q1tsim 是一个量子计算机的模拟库,用 Rust 编写。它的目标是成为一个易于使用、高效的模拟器,用于量子算法的开发和测试。

特性

  • 易于实现和模拟量子电路
  • 支持创建任意量子门
  • 已包含大多数常见的量子门
  • XYZ 基底进行测量
  • 可以进行不影响量子状态的测量
  • 创建多次运行测量结果的直方图
  • 基于经典值的条件操作
  • 将电路导出到 Open QASM 和 c-QASM,以便在其他计算机或模拟器上运行程序
  • 将电路导出到 LaTeX,以便绘制电路图
  • 高效模拟稳定电路

用法

要在 Rust 应用程序中使用 q1tsim,请将以下内容添加到您的 Cargo.toml 文件中

[dependencies]
q1tsim = "0.4"

例如,以下是一个 3 个量子比特的 |000⟩ 量子状态的量子傅里叶变换

extern crate q1tsim;

use q1tsim::{circuit, gates};

fn main()
{
    // The number of times this circuit is evaluated
    let nr_runs = 8192;

    // Create a quantum circuit with 3 quantum bits and 3 classical (measurement)
    // bits. The circuit starts by default with all quantum bits in the |0⟩ state,
    // so in this case |000⟩.
    let mut circuit = circuit::Circuit::new(3, 3);

    // Set up a 3-qubit quantum Fourier transform
    // There is no predefined method on Circuit that implements a controlled
    // `S` or `T` gate, so we use the `add_gate()` method for those.
    circuit.h(2);
    circuit.add_gate(gates::CS::new(), &[1, 2]);
    circuit.add_gate(gates::CT::new(), &[0, 2]);
    circuit.h(1);
    circuit.add_gate(gates::CS::new(), &[0, 1]);
    circuit.h(0);
    circuit.add_gate(gates::Swap::new(), &[0, 2]);

    // Measure all quantum bits in the Pauli `Z` basis
    circuit.measure_all(&[0, 1, 2]);

    // Actually calculate the resulting quantum state and perform the measurements,
    // averaging over `nr_runs` runs.
    circuit.execute(nr_runs);

    // And print the results.
    let hist = circuit.histogram_string().unwrap();
    for (bits, count) in hist
    {
        println!("{}: {}", bits, count);
    }
}

结果应该在八个可能的状态(000、001、...、111)之间大致均匀分布。

请参阅 docs.rs 上的完整 API 文档。

依赖关系

~7MB
~130K SLoC