Giter Site home page Giter Site logo

rustqip's Introduction

RustQIP

Quantum Computing library leveraging graph building to build efficient quantum circuit simulations.

qip on crates.io qip docs

See all the examples in the examples directory of the Github repository.

Example (CSWAP)

Here's an example of a small circuit where two groups of qubits are swapped conditioned on a third. This circuit is very small, only three operations plus a measurement, so the boilerplate can look quite large in comparison, but that setup provides the ability to construct circuits easily and safely when they do get larger. Furthermore there are tools in the library which can clean up this code significantly. See the docs.

use qip::*;

// Setup inputs
let mut b = OpBuilder::new();
let q = b.qubit();
let ra = b.register(3)?;
let rb = b.register(3)?;

// We will want to feed in some inputs later.
let ha = ra.handle();
let hb = rb.handle();

// Define circuit
let q = b.hadamard(q);

let (q, _, _) = b.cswap(q, ra, rb)?;
let q = b.hadamard(q);

let (q, m1) = b.measure(q);

// Print circuit diagram
qip::run_debug(&q)?;

// Initialize ra to |0> and rb to |1> using their handles.
// Make an initial state: |0,000,001>
let initial_state = [ha.make_init_from_index(0)?,
                     hb.make_init_from_index(1)?];

// Run circuit
let (_, measured) = run_local_with_init::<f64>(&q, &initial_state)?;

println!("{:?}", measured.get_measurement(&m1));

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.