Skip to content

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

License

Notifications You must be signed in to change notification settings

mapmeld/quantum-peep

Repository files navigation

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

About

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

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published