ibm-quantum-js

A node.js module to interact with the IBM Quantum API.


Keywords
ibm, quantum, nodejs, promises, api, async
License
IPL-1.0
Install
npm install ibm-quantum-js@0.1.7

Documentation

IBM Quantum JS

David

GitHub code size in bytes

npm

NPM

GitHub contributors

This module provides a set of functions to help JavaScript Developers working on IBM Quantum Experience projects to authenticate and access API endpoints using Javascript promises.

Requirements (MacOS/Windows)

  • Node v12.x
  • npm v6.x
  • Standard account on IBM Quantum Experience portal

Note: Depending on your Windows setup windows-build-tools may need to be installed first. Also, for MacOS users, you should have xcode-select or entire Xcode App installed.

Install

$ npm install ibm-quantum-js

Uninstall

$ npm uninstall ibm-quantum-js

Change Log

  • 0.1.7

    • Fixed security vulnerabilities
  • 0.1.6

    • Fixed security vulnerability on ws
  • 0.1.5

    • Fixed security vulnerability on host-git-info, underscode, and lodash
  • 0.1.4

    • Fixed security vulnerability on lodash dependency
  • 0.1.3

    • First working module

Usage

Perform a login on IBM Q Experience API with API_TOKEN and get a valid auth token:

const quantum = require('ibm-quantum-js');

const token = await quantum.loginWithToken(API_TOKEN);

Note: API_TOKEN is created after you validate your IBM Q Experience user ID. You can find it under "My Account" in the IBM Q Experience web site.

Define a function to return user information from IBM Q:

const quantum = require('ibm-quantum-js');

const userInformation = function(token) {
  return quantum.getUserInfo(token).then(function(result){
    return result;
  }).catch(function(error){
    return error;
  });
};

Get IBM Q backends (processors):

const backends = await quantum.getIBMBackends(token);

Get IBM Q backend queue status:

const processor = backends[0].name || 'ibmq_qasm_simulator';

const queueStatus = await quantum.getIBMBackendQueue(processor);

Get user experiments from IBM Q:

const userExperiments = await quantum.getUserExperiments(token);

List user jobs in the IBM Q:

const userExperiments = await quantum.listUserJobs(token);

Cancel an user job in the IBM Q:

const userExperiments = await quantum.cancelUserJob(token, jobId);

Execute a new user job in the IBM Q:

const token = await quantum.loginWithToken(API_TOKEN);

const userExperiments = await quantum.postUserJob(token, jobInfo, jobQObject);

Note: jobQObject is JSON object resulted from a compiled QASM (Quantum Assembly) code. jobInfo indicates which backend/processor to use.

const JOB_INFO = {
  allowObjectStorage: true,
  backend: {
    name: 'ibmq_qasm_simulator'
  }
};

Show the results of a COMPLETED user job in the IBM Q:

const token = await quantum.loginWithToken(API_TOKEN);

const userExperiments = await quantum.showUserJobResults(token, jobId);

List of functions available

  • loginWithToken(API_TOKEN)
  • getIBMBackends(token)
  • getIBMBackendQueue(processor)
  • getUserInfo(token)
  • getUserExperiments(token)
  • cancelUserJob(token, jobId)
  • listUserJobs(token)
  • postUserJob(token, jobInfo, jobQObject)
  • showUserJobResults(token, jobId)

QObject versus QASM

  • Unfortunately there's no available API to compile a QASM into a QOBJ, however its JSON schema is published here.

Contributing

If you want to contribute to the module and make it better, your help is very welcome. You can do so submitting a Pull Request.

Authors

Written by Rod Anami rod.anami@kyndryl.com, May 2020. Contributor(s): Paco Martin paco@ibm.com

License

This project is licensed under the IBM Public License.