4 releases

0.0.0-pre5 Jul 14, 2022
0.0.0-pre4 Jul 13, 2022
0.0.0-pre3 Jun 28, 2022
0.0.0-pre1 Jun 17, 2022

#358 in WebAssembly

MIT and GPL-3.0 licenses

4.5K SLoC

Npm Crates License: MIT CI Latest Stable Latest Release

Qukit - Quantum Simulation Toolkit

Qukit is an open source quantum circuit simulator implemented in rust and compiled for wasm. Qukit is capable of running 20+ q-bit simulations in browser or at the server (rust and node.js). You can use it in your javascript program to run quantum simulations.


  • Rust API
  • JS API (Wasm)
  • Algorithm creation and simulation
  • Execute an algoritm step wise
  • Convert all supported gates into rotation to enable partial simulation
  • Python API
  • QASM Export
  • SVG Export
  • State Visulisations
  • Quiskit Export
  • QASM Import



npm install qukit

You should be able to import Qukit directly into Node, as normal, or into a browser using any bundler that supports ES modules & webassembly (e.g. Webpack v4 or v5).

The browser build supports both sync (v4 or v5 syncWebAssembly mode) and async (v5 asyncWebAssembly) builds. When imported in a browser build the module always exports a promise, not a fixed value, as this is a requirement for synchronous builds, and you will need to await this after import.

We also provide a parallel version via the Web Workers API, the implementation uses wasm-bindgen-rayon, for further information on setup visit the wasm-bindgen-rayon github page.


First of all, add this crate as a dependency to your Cargo.toml:

qukit = "0.0.0-pre4"

To use this crate u need to use the nighty toolchain, since it heavily uses the latest nightly const fn features.

Feature Flags

  • std Links against std
  • parallel enables rayon usage



const builder: GateBuilder = new GateBuilder();
const qbits: QBit[] = builder.qbits(hidden.length);
const bits: Bit[] = builder.bits(hidden.length);
const target: QBit = builder.qbit();



hidden.forEach((active, index) => {
    if (active) {
        cPauliX(qbits[index], target);


measurement(qbits, bits);

builder.intoAlgorithm().run(); // -> Executes the Algorithm


let algorithm = Algorithm::new(|gate_builder| {
    let a = gate_builder.qbit();
    let b = gate_builder.qbit();
    let c_a = gate_builder.bit();
    let c_b = gate_builder.bit();

    controlled_pauli_x(a, b);

    measurement(a, c_a);
    measurement(b, c_b);


algorithm.run() // -> Executes the Algorithm

Wasm Limitations

In wasm you are limited to 2GB/4GB of memory, thus your are only able to simulate up to 25 q-bits with this library. For a 25 q-bit system we need to keep track of 2^26 states. A state is described by a complex value, which is composed of 2 f64 values, which equates to 2 x 8 = 16 Bytes. This equates to a state vector of 2^26 x 16 = 1073731824 Bytes ≈ 1.07 GB. For each transformation we need one source and one target vector, this leads to a memory usage of 2.14 GB. With a future stabilisation of wasm64 we can simulate large vectors.


~56K SLoC