Giter VIP home page Giter VIP logo

rusq's Introduction

Rusq

crates.io docs.rs Build Status

Quantum computing simulator in Rust

Overview

Rusq is a library to simulate a gate-type quantum computer written purely in Rust.

The Rusq design is highly inspired by Q#. Basically, only "physically safe" operation is implemented - no non-physical information like the amplitude of a wavefunction can be obtained by default.

Feature

  • Measurement and projection
  • Basic quantum gates
    • $X, Y, Z$, Hadamard, identity, CNOT, CCNOT

How to use

First, add the following to Cargo.toml

[dependencies]
rusq = "0.1"

For example codes, check out the following section.

Examples

For instance, you can make EPR pair like this:

extern crate rusq;

use rusq::prelude::*;

fn set(sim: &mut QuantumSimulator, qubit: &Qubit, r: MeasuredResult) {
    if sim.measure(qubit) != r {
        sim.X(qubit);
    }
}

fn main() {
    let mut sim = QuantumSimulator::new(2);
    let qubits = sim.get_qubits();
    let measure_count = 10000;

    for _ in 0..measure_count {
        set(&mut sim, &qubits[0], MeasuredResult::Zero);
        set(&mut sim, &qubits[1], MeasuredResult::Zero);

        sim.H(&qubits[0]);
        sim.CNOT(&qubits[0], &qubits[1]);

        assert_eq!(sim.measure(&qubits[0]), sim.measure(&qubits[1]));
    }
}

For other kinds of examples, check tests directory. Pull requests to implement another examples of quantum computation is welcome.

License

MIT

rusq's People

Contributors

hajifkd avatar itchyny avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

Forkers

cainthebest

rusq's Issues

`unphysical` feature?

Shall we enable some "unphysical" functions like showing wavefunction itself with, say, unphysical feature?

Add CNOT21 gate

This is a suggestion for adding inverse CNOT gate (or CNOT_21). What do you think?

Macro for truth table

First, it looks too ad hoc :(
At least, tests for classical states can be more systematic.

Second, some tests do not exploit "quantum" features although I have no idea what to be done for this.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.