Giter Site home page Giter Site logo

sueannioanis / quantum-peep Goto Github PK

View Code? Open in Web Editor NEW

This project forked from mapmeld/quantum-peep

1.0 2.0 0.0 681 KB

Multi-platform quantum programming library, written in TypeScript, good for JS/NodeJS

Home Page: http://QuantumPeep.com

License: MIT License

TypeScript 100.00%

quantum-peep's Introduction

Quantum-Peep

Greenkeeper badge

Work in progress - build quantum programs that are platform-agnostic - compile for IBM's Qobj and QASM, Rigetti's Quil, Microsoft's Q#, or Google's Cirq.

Example code

import { Gates, Program, RigettiProcessor, IBMProcessor } from 'quantum-peep';

// write your quantum gates and measurements into a program
let p = new Program();
p.add(Gates.X(1));
p.measure(1, 2);

// get Microsoft's Q# code
p.code('q#');

// get Python code for Google Cirq
p.code('cirq');

// run on Rigetti QVM Docker container
// For actual QPUs, register for Rigetti Forest and use their endpoint, api_key, and user_id
let q = new RigettiProcessor({
  endpoint: URL_of_Rigetti_qvm_docker,
  api_key: 'aaa',
  user_id: 'uuu'
});
let runTimes = 10;
q.run(p, runTimes, (body) => {
  console.log(JSON.parse(body));
});

// fetch device options + status from https://forest-server.qcs.rigetti.com/devices
q.devices((deviceInfo) => {
  // { "Aspen-4": { "is_online": false, ... }, "Aspen-3": { ... } }
});

// run on IBM quantum chip
// setting backend: in node_modules/@qiskit/cloud/cfg.json, set URI to https://api.quantum-computing.ibm.com/api
// getting the login: go to https://quantum-computing.ibm.com
// -- go to your profile
// getting the token: inspect your browser's requests to headers on Backends
let q2 = new IBMProcessor({
  login: secrets.ibm.login,
  token: secrets.ibm.token,
  processor: 'ibmq_qobj_simulator'
});
// fetch device options + status from https://api.quantum-computing.ibm.com/api/Backends
// uses given processor type
q2.devices((deviceInfo) => {
  // [
  //   { "name": "ibmq_ourense", "status": "on", "specificConfiguration": { ... }, ... }
  // ]
});
q2.run(p, runTimes, (body) => {
  console.log(JSON.parse(body));
});

More complex gates

// gate names from different platforms are equivalent
Gates.CNOT(control, target);
Gates.CX(control, target);

// swap operations
Gates.SWAP(qubit1, qubit2);
Gates.CSWAP(conditional, qubit1, qubit2);
// ISWAP and PSWAP are only one-step operations in Quil? Advice welcome

// phase gates: phase is a radian value
// use this shorthand to express on several different platforms

import { pi_multipled_by, pi_divided_by } from 'quantum-peep';
Gates.RX(pi_multiplied_by(0.45), qubit1);
Gates.RY(pi_divided_by(2), qubit2);

Bonus features

Output a circuit diagram with this library ported from QISKit Python: https://github.com/mapmeld/quantum-circuit-viz

import { textViz } from 'quantum-circuit-viz';
...
program.add(Gates.X(1));
program.measure(1, 2);
textViz(program);
        ┌───┐┌─┐
q_1: |0>┤ X ├┤M├
        └───┘└╥┘
 c_2: 0 ══════╩═

Goals

  • work with experimental results from APIs
  • more complex conditional / GOTO output in assembly languages
  • async/queue support: for newer APIs which put programs in a queue
  • browser JS distribution: easier use in web apps

Language references

IBM's QISkit (for Python and JS) compile to Qobj and OpenQASM: https://github.com/Qiskit/openqasm

Rigetti's pyQuil (and the previous jsQuil project) compile to Quil: http://docs.rigetti.com/en/stable/compiler.html

Microsoft Q# https://docs.microsoft.com/en-us/quantum/language/?view=qsharp-preview

Google Cirq https://github.com/quantumlib/Cirq

License

Open source, MIT license

quantum-peep's People

Contributors

greenkeeper[bot] avatar mapmeld avatar

Stargazers

 avatar

Watchers

 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.