Coder Social home page Coder Social logo

valvy / miniqubit Goto Github PK

View Code? Open in Web Editor NEW
27.0 4.0 1.0 999 KB

Quantum emulator of the IBM Quantum experience

License: MIT License

CMake 7.14% C++ 88.36% Python 1.28% Java 3.23%
quantum-computing ibm-quantum-experience qubit entanglement ibm ibm-research quantum-mechanics quantum-computer-simulator quantum emulator

miniqubit's Introduction

Miniqbt, a runtime for the IBM Quantum experience

Build Status License: MIT

Introduction

IBM research released a quantum computer accessable in the cloud. MiniQbt is a emulator for the IBM quantum experience, with a generic amount of qubits and classical bits. To contribute to MiniQbt please refer to contributing

installation

The best way of installation is to compile the program from source. For this you need to install the following dependencies. Please consult the individual tools for help.

  1. Eigen3 (Compile from source at the website since some linux distros only have an old version in the repositories)
  2. CMake
  3. Git
  4. Please use for Windows, Visual studio 2015 or later.

For the Python wrapper your need:

  1. Python development libraries
  2. Boost-Python

For the Java wrapper you need:

  1. Java 8

When done create a new build folder and let Cmake unpack everything there. MiniQbt comes with the following options:

Build Option Effect
ENABLE_EMSCRIPTEN Instead of compiling to native code, use Webassembly (Requires emc++ )
ENABLE_TESTS Execute Unit tests
ENABLE_JAVA Build the Java wrapper
ENABLE_PYTHON Build the Python Wrapper

Building in GNU/Linux

# Clone the project.
git clone [email protected]:valvy/miniqubit.git
cd miniqubit
# Create a build directory.
mkdir build
cd build
# Build with only unit tests.
cmake .. -DENABLE_EMSCRIPTEN=OFF -DENABLE_TESTS=ON -DENABLE_JAVA=OFF -DENABLE_PYTHON=OFF
make

Library usage

C++ Sample code

#include <miniqbt/MiniQbt.hpp>
#include <iostream>
#include <vector>

int main(int argc, char** argv){
    using namespace MiniQbt;
    const char* src = 
    "OPENQASM 2.0;              \n"
    "include \"qelib1.inc\";    \n"
    "qreg q[1]; creg c[1];      \n"
    "h q[0];                    \n"
    "measure q[0] -> c[0];      \n";

    QasmAsyncInterpreter interpreter;
    interpreter.interpret(std::string(src));
    while(interpreter.hasErrors()){
        std::cout << interpreter.getError() << "\n";
    }

    QuantumResult result = interpreter.readClassicResult("c");


    std::cout << "result of the algorithm: " << result.dataToString();

    std::cout << "\n";
}

Python Sample code

from PyMiniQbt import QasmAsyncInterpreter

source = "OPENQASM 2.0; include \"qelib1.inc\";  qreg q[1]; creg c[1]; h q[0]; measure q[0] -> c[0];"
interpreter = QasmAsyncInterpreter()
interpreter.interpret(source)
result = interpreter.readClassicResult("c")
while interpreter.hasErrors():
    print(interpreter.getError())
print("result of the algorithm: ")
print(result.dataToString())

JavaScript sample code

"use strict";
const miniqbt = require('./MiniQbt')
// Make sure MiniQbt is properly loaded.
setTimeout(() => {
    console.log("Using : " + miniqbt.NAME + " version "+ miniqbt.VERSION)
    let vm = new miniqbt.QasmAsyncInterpreter()
    vm.interpret("creg cregister[5]; qreg qregister[5];")
    vm.interpret("h qregister;")
    vm.interpret("measure qregister -> cregister;")
    const result = vm.readClassicResult('cregister')
    console.log(result.getName() + " resulted in " + result.dataToString() )

},1000)

Java Sample code

import nl.hvanderheijden.miniqbt.Globals;
import nl.hvanderheijden.miniqbt.QasmAsyncInterpreter;

public class Main {
    public static void main(String[] args) {
        System.out.println(
                String.format("%s version %s",
                        Globals.getName(),
                        Globals.getVersion()
                )
        );
        QasmAsyncInterpreter interpreter = new QasmAsyncInterpreter();
        interpreter.interpret("qreg a[5];");
        interpreter.interpret("creg b[5];");
        interpreter.interpret("h a;");
        interpreter.interpret("measure a -> b;");
        while(interpreter.hasErrors()) {
            System.out.println(interpreter.getError());
        }
        for (String i : interpreter.getRegisters()) {
            QuantumResult result = interpreter.readClassicResult(i);
            System.out.println(result.dataToString());
        }
    }
}

miniqubit's People

Contributors

valvy avatar

Stargazers

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

Watchers

 avatar  avatar  avatar  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.