Code Monkey home page Code Monkey logo

strange's Introduction

strange Build Status

Quantum Computing API for Java

This project defines a Java API that can be used to create Quantum Programs. A Quantum Program, defined by org.redfx.strange.Program can be executed on an implementation of the org.redfx.strange.QuantumExecutionEnvironment.

You can read more about Java and QuantumComputing in Quantum Computing for Java Developers Quantum Computing for Developers

Getting Started

Strange is distributed via the traditional Java distribution channels (e.g. maven central and jcenter) and can thus easily be used leveraging maven or gradle build software.

Using maven

A typical pom.xml file looks as follows:

<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
  <modelVersion>4.0.0</modelVersion>
  <groupId>org.redfx.javaqc</groupId>
  <artifactId>simplestrangedemo</artifactId>
  <packaging>jar</packaging>
  <version>1.0-SNAPSHOT</version>
  <name>SimpleStrangeDemo</name>
  <url>http://maven.apache.org</url>

  <dependencies>
    <dependency>
      <groupId>org.redfx</groupId>
      <artifactId>strange</artifactId>
      <version>0.1.1</version>
    </dependency>
  </dependencies>
  <build> 
    <plugins>
      <plugin>
        <groupId>org.openjfx</groupId>
        <artifactId>javafx-maven-plugin</artifactId>
        <version>0.0.6</version>
        <configuration>
          <mainClass>SimpleStrangeDemo</mainClass>
        </configuration>
      </plugin>
    </plugins>
  </build>
</project>

Using gradle

A typical build.gradle file looks as follows:

plugins {
    id 'application'
}

repositories {
    mavenCentral()
}

dependencies {
    implementation 'org.redfx:strange:0.1.1'
}

mainClassName = 'SimpleStrangeDemo'

The sample application contains a single Java file:

import org.redfx.strange.*;
import org.redfx.strange.gate.*;
import org.redfx.strange.local.SimpleQuantumExecutionEnvironment;
import java.util.Arrays;

public class SimpleStrangeDemo {

    public static void main(String[] args) {
        Program p = new Program(2);
        Gate xGate1 = new X(0); 
        Step step1 = new Step();
        step1.addGate(xGate1);
        p.addStep(step1);
        Gate hGate2 = new Hadamard(0);
        Gate xGate2 = new X(1);
        Step step2 = new Step();
        step2.addGates(hGate2, xGate2);
        p.addStep(step2);
        SimpleQuantumExecutionEnvironment sqee = new SimpleQuantumExecutionEnvironment();
        Result res = sqee.runProgram(p);
        Qubit[] qubits = res.getQubits();
        Arrays.asList(qubits).forEach(q -> System.out.println("qubit with probability on 1 = "+q.getProbability()+", measured it gives "+ q.measure()));
    }

}

This sample create a Program that requires 2 qubits. It will create 2 steps (s and t). The first step adds a Paul-X (NOT) Gate to the first qubit. The second steps adds a Hadamard Gate to the first qubit, and a NOT gate to the second qubit. Both steps are added to the Program.

In order to "run" this program, we need a QuantumExecutionEnvironment. Strange comes with a SimpleQuantumExecutionEnvironment which contains a very simple, non-optimized quantum computer simulator.

After running the program on this simulator, we inspect the state of the Qubits. As expected, there is a 50% chance the first qubit (which had an X and an H gate) will be in the 0 state, and a 50% chance it will be in the 1 state. The second qubit will always be in the 1 state.

Running this application a number of times will consistently give the same probabilities, and different measurements.

Visualization

The Strange API's allow creating and simulate quantum programs. A companion project, StrangeFX , allows visualising programs, and create them with a simple drag and drop interface. The sample program above rendered via StrangeFX looks as follows: StrangeFX rendering

More samples

You can find more samples at https://github.com/johanvos/quantumjava

strange's People

Contributors

abhinayagarwal avatar aitan75 avatar eugener avatar johanvos avatar melix avatar ramazansakin avatar shathor avatar tiainen 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.