Git Product home page Git Product logo

q1tsim's Introduction

Build Status License crates.io Released API docs

A simple, efficient, quantum computer simulator.

Overview

q1tsim is a simulator library for a quantum computer, written in Rust. Its goal is to be an easy to use, efficient simulator for the development and testing of quantum algorithms.

Features

  • Easy implementation and simulation of quantum circuits
  • Supports the creation of arbitrary quantum gates
  • Most common quantum gates already included
  • Measurement in X, Y, or Z basis
  • Possibility of measurement without affecting the quantum state
  • Creation of histograms of measurement results over multiple runs
  • Operations conditional on classical values
  • Export of circuits to Open QASM and c-QASM for running your programs on other computers or simulators
  • Export of circuits to LaTeX, for drawing pictures of your circuit
  • Efficient simulation of stabilizer circuits

Usage

To use q1tsim in your Rust application, add the following to your Cargo.toml file:

[dependencies]
q1tsim = "0.5"

As an example, here is a 3-qubit quantum Fourier transform of the |000⟩ quantum state:

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);
    }
}

The result should be a more or less equal distribution over the eight possible states (000, 001, ..., 111).

Read the complete API documentation on docs.rs.

q1tsim's People

Contributors

geq1t avatar

Watchers

James Cloos avatar

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.