Giter Site home page Giter Site logo

qiskit-js's Introduction

Qiskit.js

Build Status stability-experimental lerna code style: prettier Downloads

โš›๏ธ Quantum Information Science Kit for JavaScript, I was born as a clone of my big brother.

logo

๐ŸŽ Follow us on Twitter if you like this project

Alpha: Until v1 breaking changes could be included.

Philosophy

๐Ÿ“™ The basic concept of our quantum program is an array of quantum circuits. The program workflow consists of three stages: Build, Compile, and Run. Build allows you to make different quantum circuits that represent the problem you are solving. Compile allows you to rewrite them to run on different backends (simulators/real chips of different quantum volumes, sizes, fidelity, etc); and Run launches the jobs. After the jobs have been run, the data is collected. There are methods for putting this data together, depending on the program. This either gives you the answer you wanted or allows you to make a better program for the next instance.

If you want to learn more about Quantum Computing, you're invited to visit our Quamtum Experience project.

Structure

๐Ÿ‘œ The components of this repository are exposed as these libraries:

Qiskit for the browser

๐Ÿ“ฅ All components are compatible with browserify.

Install

โ˜• Install lastest Node.js stable version (or LTS) and then:

npm i -g qiskit

Use

CLI

๐Ÿš€ The command line client allows to play with the circuits without having to use any programming language API.

qiskitjs --help
qiskitjs <command>

Commands:
  backend [name] - Get latest calibration stats for a backend  [aliases: b]
  backends [onlySims] - Get latest calibration stats for a backend  [aliases: bs]
  calibration [backend] - Get latest calibration stats for a backend  [aliases: c]
  circuit <circuit> [backend] [shots] [name] [seed] [maxCredits] - Send the circuit to be run in the Quantum
  	Experience (https://quantumexperience.ng.bluemix.net)  [aliases: ci]
  credits - Information about your credits  [aliases: cr]
  factor <number> - Calculate a factor of a number  [aliases: f]
  job <id> - Get the info of a specific job  [aliases: j]
  jobs [limit] [offset] - Get all your jobs. Ordered by creation date  [aliases: js]
  login [printToken] - Use an API key to get a token to make requests  [aliases: l]
  params [backend] - Get latest parameter stats for a backend  [aliases: p]
  parse <circuit> - Parse the circuit to our IR (intermediate representation - JSON format)  [aliases: p]
  queue [backend] - Get the status of a backend queue  [aliases: q]
  random [engine] [length] [format] [backend] - Generate a true random number among 0 and 1  [aliases: r]
  result <jobId> - Get the result of a background job generated by an algorithm method. The engine is ommited
  	because IBM Q is the unique which uses background jobs for now  [aliases: re]

Options:
  --help     Show help                                                 [boolean]
  --version  Show version number                                       [boolean]

Programatically

๐Ÿ“ As you can see in the next section, we have to use it like in the rest of independent modules. The only difference is we need to select the proper field of the main object before.

const qiskit = require('qiskit');

console.log('True random numbers\n');

qiskit.algo.random().then(rand => console.log(`JavaScript: ${rand}`));

const cloud = new qiskit.Cloud();
cloud.login('YOUR_PERSONAL_TOKEN_HERE').then(() => {
  cloud.backends().then(data => {
    console.log('(IBM Backends');
    console.log(data);
  });

  qiskit.algo.random({
    engine: 'ibm',
    custom: cloud,
    // default: simulator
    // engine: "ibmqx4"
  }).then(rand => console.log(`IBM Cloud: ${rand}`))
});

qiskit.algo.random({
  engine: 'anu',
  length: 8,
}).then(rand => console.log(`ANU Server: ${rand}`));

API

๐Ÿ‘€ Full specification.

version

The actual version of the library.

  • version (string) - Version number.

qasm

A wrapper for the qiskit-qasm project.

  • qasm (object) - The same object provided in the original library.

sim

A wrapper for the qiskit-sim project.

  • sim (object) - The same object provided in the original library.

Cloud

A wrapper for the qiskit-cloud project.

  • Cloud (object) - The same constructor provided in the original library.

utils

A wrapper for the qiskit-utils project.

  • utils (object) - The same object provided in the original library.

algo

A wrapper for the qiskit-algo project.

  • algo (object) - The same object provided in the original library.

Authors

๐Ÿ‘ฝ https://github.com/Qiskit/qiskit-js/graphs/contributors

Original code (Python) authors here.

Other Qiskit projects

๐ŸŽ’

License

๐Ÿง Qiskit is released under the Apache license, v2.0.

Do you want to help?

๐Ÿ˜Ž If you'd like to help please take a look to our contribution guidelines.

qiskit-js's People

Contributors

abdonrd avatar cbjuan avatar danbev avatar jelcaf avatar jesusprubio avatar omarcostahamido 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  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  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  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar

qiskit-js's Issues

not able to run test file

Environment (please complete the following information):

  • Qiskit.js version:
    0.8.0 (actually also a direct copy of the github folder structure)
  • Node.js version:
    10.15.3
  • Operating system:
    mojave

What is the current behavior?

How am I supposed to be able to run the test files?
this is what happens when I try to run qiskit-qasm/test/functional/parser.test.js

terminal

$ node parser.test.js 
internal/modules/cjs/loader.js:584
    throw err;
    ^

Error: Cannot find module 'jison'
    at Function.Module._resolveFilename (internal/modules/cjs/loader.js:582:15)
    at Function.Module._load (internal/modules/cjs/loader.js:508:25)
    at Module.require (internal/modules/cjs/loader.js:637:17)
    at require (internal/modules/cjs/helpers.js:22:18)
    at Object.<anonymous> (/Users/omar/Documents/RESEARCH/Experiments/qiskit-js-master(2019-05-04)/packages/qiskit-qasm/lib/Parser.js:12:15)
    at Module._compile (internal/modules/cjs/loader.js:701:30)
    at Object.Module._extensions..js (internal/modules/cjs/loader.js:712:10)
    at Module.load (internal/modules/cjs/loader.js:600:32)
    at tryModuleLoad (internal/modules/cjs/loader.js:539:12)
    at Function.Module._load (internal/modules/cjs/loader.js:531:3)

Steps to reproduce the problem

copied github structure and then run js file.

What is the expected behavior?

not an error (?)

Suggested solutions

webpack example issues

What is the expected behavior?

I'm receiving this if I try to run the example on a copy of the webpack folder by itself:

terminal
Omars-MBP:Downloads omar$  cd webpack
Omars-MBP:webpack omar$  npm i

> [email protected] install /Users/omar/Downloads/webpack/node_modules/fsevents
> node install

node-pre-gyp WARN Using needle for node-pre-gyp https download 
[fsevents] Success: "/Users/omar/Downloads/webpack/node_modules/fsevents/lib/binding/Release/node-v64-darwin-x64/fse.node" is installed via remote
added 649 packages from 374 contributors and audited 7089 packages in 10.044s
found 0 vulnerabilities

Omars-MBP:webpack omar$  npm run init

> [email protected] init /Users/omar/Downloads/webpack
> mkdir node_modules/@qiskit/qasm/core ; cp ../../packages/qiskit-qasm/core/qelib1.inc node_modules/@qiskit/qasm/core

cp: ../../packages/qiskit-qasm/core/qelib1.inc: No such file or directory
npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! [email protected] init: `mkdir node_modules/@qiskit/qasm/core ; cp ../../packages/qiskit-qasm/core/qelib1.inc node_modules/@qiskit/qasm/core`
npm ERR! Exit status 1
npm ERR! 
npm ERR! Failed at the [email protected] init script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.

npm ERR! A complete log of this run can be found in:
npm ERR!     /Users/omar/.npm/_logs/2019-08-30T23_27_03_547Z-debug.log
log
0 info it worked if it ends with ok
1 verbose cli [ '/usr/local/bin/node',
1 verbose cli   '/Users/omar/.npm-global/bin/npm',
1 verbose cli   'run',
1 verbose cli   'init' ]
2 info using [email protected]
3 info using [email protected]
4 verbose run-script [ 'preinit', 'init', 'postinit' ]
5 info lifecycle [email protected]~preinit: [email protected]
6 info lifecycle [email protected]~init: [email protected]
7 verbose lifecycle [email protected]~init: unsafe-perm in lifecycle true
8 verbose lifecycle [email protected]~init: PATH: /Users/omar/.npm-global/lib/node_modules/npm/node_modules/npm-lifecycle/node-gyp-bin:/Users/omar/Downloads/webpack/node_modules/.bin:/Library/Frameworks/Python.framework/Versions/3.7/bin:~/.npm-global/bin:/Library/Frameworks/Python.framework/Versions/3.5/bin:~/.npm-global/bin:/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin:/usr/local/share/dotnet:~/.dotnet/tools
9 verbose lifecycle [email protected]~init: CWD: /Users/omar/Downloads/webpack
10 silly lifecycle [email protected]~init: Args: [ '-c',
10 silly lifecycle   'mkdir node_modules/@qiskit/qasm/core ; cp ../../packages/qiskit-qasm/core/qelib1.inc node_modules/@qiskit/qasm/core' ]
11 silly lifecycle [email protected]~init: Returned: code: 1  signal: null
12 info lifecycle [email protected]~init: Failed to exec init script
13 verbose stack Error: [email protected] init: `mkdir node_modules/@qiskit/qasm/core ; cp ../../packages/qiskit-qasm/core/qelib1.inc node_modules/@qiskit/qasm/core`
13 verbose stack Exit status 1
13 verbose stack     at EventEmitter.<anonymous> (/Users/omar/.npm-global/lib/node_modules/npm/node_modules/npm-lifecycle/index.js:301:16)
13 verbose stack     at EventEmitter.emit (events.js:189:13)
13 verbose stack     at ChildProcess.<anonymous> (/Users/omar/.npm-global/lib/node_modules/npm/node_modules/npm-lifecycle/lib/spawn.js:55:14)
13 verbose stack     at ChildProcess.emit (events.js:189:13)
13 verbose stack     at maybeClose (internal/child_process.js:970:16)
13 verbose stack     at Process.ChildProcess._handle.onexit (internal/child_process.js:259:5)
14 verbose pkgid [email protected]
15 verbose cwd /Users/omar/Downloads/webpack
16 verbose Darwin 18.7.0
17 verbose argv "/usr/local/bin/node" "/Users/omar/.npm-global/bin/npm" "run" "init"
18 verbose node v10.15.3
19 verbose npm  v6.9.0
20 error code ELIFECYCLE
21 error errno 1
22 error [email protected] init: `mkdir node_modules/@qiskit/qasm/core ; cp ../../packages/qiskit-qasm/core/qelib1.inc node_modules/@qiskit/qasm/core`
22 error Exit status 1
23 error Failed at the [email protected] init script.
23 error This is probably not a problem with npm. There is likely additional logging output above.
24 verbose exit [ 1, true ]

could you make so that it doesn't need to change/access files from the main repo and work independently?

qiskit-sim not working

Environment (please complete the following information):

  • Qiskit.js version:
    0.7.1
  • Node.js version:
    10.15.3
  • Operating system:
    mac os mojave

What is the current behavior?

the first time I run it

Input randomized (as string):
0:|0>
1:|0>

Input randomized:
[ false, false ]

Running the circuit now ...

Done, internal state:
[ { re: 0.7071067811865475, im: 0 },
  { re: 0, im: 0 },
  { re: 0, im: 0 },
  { re: 0.7071067811865475, im: 0 } ]

Internal state (as string):
0.70710678+0i|00>50%
0+0i|01>0%
0+0i|10>0%
0.70710678+0i|11>50%

Saved IR:
{ nQubits: 2,
  gates:
   [ [ { id: 'nu8FAAIALbxRuQMn5K',
         name: 'h',
         connector: 0,
         wires: [ 0 ] },
       { id: 'hwUglvXbpfqqMwPJ0r',
         name: 'cx',
         connector: 0,
         wires: [ 0, 1 ] } ],
     [ null,
       { id: 'hwUglvXbpfqqMwPJ0r',
         name: 'cx',
         connector: 1,
         wires: [ 0, 1 ] } ] ],
  customGates: {} }

the second time I run it

Input randomized (as string):
0:|1>
1:|0>

Input randomized:
[ true, false ]

Running the circuit now ...
/Users/omar/Documents/RESEARCH/Experiments/[email protected]/node_modules/@qiskit/sim/lib/Circuit.js:237
    const gate = gates.get(gateName.toLowerCase());
                                    ^

TypeError: gateName.toLowerCase is not a function
    at Circuit.applyGate (/Users/omar/Documents/RESEARCH/Experiments/[email protected]/node_modules/@qiskit/sim/lib/Circuit.js:237:37)
    at Circuit.run (/Users/omar/Documents/RESEARCH/Experiments/[email protected]/node_modules/@qiskit/sim/lib/Circuit.js:298:16)
    at Object.<anonymous> (/Users/omar/Documents/RESEARCH/Experiments/[email protected]/app_02.js:30:9)
    at Module._compile (internal/modules/cjs/loader.js:701:30)
    at Object.Module._extensions..js (internal/modules/cjs/loader.js:712:10)
    at Module.load (internal/modules/cjs/loader.js:600:32)
    at tryModuleLoad (internal/modules/cjs/loader.js:539:12)
    at Function.Module._load (internal/modules/cjs/loader.js:531:3)
    at Function.Module.runMain (internal/modules/cjs/loader.js:754:12)
    at startup (internal/bootstrap/node.js:283:19)

it always gives me this error unless I get lucky enough for the input randomized to be [false, false].
Seems like it is not the way it is supposed to work, right?

Steps to reproduce the problem

I'm running the first bell state example that appears both on the readme page of qiskit-sim and the example folder.

What is the expected behavior?

not throw this error.

Suggested solutions

sim.Circuit is not a constructor

Environment:

  • Qiskit-js 0.3.0:
  • Node 10.7.0:
  • macOS High Sierra 10.13.6:

What is the current behavior?

TypeError: sim.Circuit is not a constructor thrown

TypeError: sim.Circuit is not a constructor
at Object. (/Users/ericmay/Development/work/simulator_test.js:18:17)
at Module._compile (internal/modules/cjs/loader.js:689:30)
at Object.Module._extensions..js (internal/modules/cjs/loader.js:700:10)
at Module.load (internal/modules/cjs/loader.js:599:32)
at tryModuleLoad (internal/modules/cjs/loader.js:538:12)
at Function.Module._load (internal/modules/cjs/loader.js:530:3)
at Function.Module.runMain (internal/modules/cjs/loader.js:742:12)
at startup (internal/bootstrap/node.js:266:19)
at bootstrapNodeJSCore (internal/bootstrap/node.js:596:3)

Steps to reproduce the problem

Run the example program on the Readme page after installing qiskit-js/sim

What is the expected behavior?

The sample program should execute without the TypeError.
https://github.com/Qiskit/qiskit-js/tree/master/packages/qiskit-sim

Suggested solutions

TY!

C++ simulator thanks to WASM

The idea is to compile to include the C++ simulator provided in the regular Qiskit distribution. The plan is to start with Node.js support, some related resources:

Once it works, we would like to explore the idea of compiling it to WASM to get it running into the browser. It would be awesome because maybe (it doesn't depends on me) it could be used in the Quantum Experience website. We explored different options but it was a long time ago, probably a re-research would be needed.

About the actual simulator, I don't work in Qiskit anymore. Now it has its own repo: https://github.com/Qiskit/qiskit-aer

Please ask any doubt, @atilag can help us :).

Improve the command line client outputs

Some of the new commands output is not readable, we should print in chunks (ie: as in the cloud-backs one).

Moreover we should make this "chunked" output as an option, we should add another parameter in the affected commands.

qiskit-sim for dummies

What is the expected behavior?

I wanted to be able to just run a couple circuits with the qiskit-sim, but I am not able to completely understand how to work with it. I can see that we can query the state of the circuit which is fine - i.e. it gives us the equivalent to the aggregated results from IBM QX.
However, if I want to run this circuit for a different number of shots, how can I do it?
Also, and actually more importantly, how can I add a measurement gate? Is there an equivalent classical register here?
I am sorry if these questions sound very basic. I am really enjoying learning this!

Best,
OCH

require qiskit-js TypeError: fs.readFileSync is not a function

[email protected] [email protected]

TypeError: fs.readFileSync is not a function
(anonymous function)
D:/mytest/node_modules/@qiskit/qasm/lib/Parser.js:23
20 | const dbg = utils.dbg(__filename); // const QasmError = require('./QasmError');
21 | // TODO: Do async?
22 |

23 | const bnf = fs.readFileSync(path.resolve(__dirname, 'grammar.jison'), 'utf8');
24 | let parser;
25 |
26 | class Parser {
View compiled
./node_modules/@qiskit/qasm/lib/Parser.js
http://localhost:3000/static/js/1.chunk.js:1683:30
webpack_require
D:/mytest/webpack/bootstrap:781
778 | };
779 |
780 | // Execute the module function
781 | modules[moduleId].call(module.exports, module, module.exports, hotCreateRequire(moduleId));
| ^ 782 |
783 | // Flag the module as loaded
784 | module.l = true;
View compiled

dead link on readme

on the readme file, the very first link (Quantum Information Science Kit) is dead.

Environment (please complete the following information):

  • Qiskit.js version:
  • Node.js version:
  • Operating system:

What is the current behavior?

Steps to reproduce the problem

What is the expected behavior?

Suggested solutions

Quantum State Visualization (with ECharts & ECharts-GL)

I am not sure if proving quantum state visualization is already in the roadmap but, one way or another, I think it might be worthy to comment here how I added this functionality to qiskit-sdk-swift.

On the contrary to the python repo where the visualization is based on matplotlib, there were nothing equivalent for Swift (that was also available on macOS, iOS & Linux); so I ended up using the following JavaScript libraries to display the graphs embedded in web views:

These libraries provided (out of the box) all I needed to plot the quantum states, also without any other dependency. They are under Apache license and behind them is a big company: Baidu, so I think we can assume they will be maintained for a while.

I hope the javascript code I wrote might serve as an example.

What is the expected behavior?

The code I mention above is located in:

Swift & JavaScript code are mixed in the same files but I think it is quite readable.

To end, any suggestion about how to improve the existing javascript code is welcome, in fact it would be very appreciated :)

can't run --help

Environment (please complete the following information):

I try to run: qiskitjs --help
and get:

module.js:540
    throw err;
    ^

Error: Cannot find module 'jsqubits/lib/jsqubits'
    at Function.Module._resolveFilename (module.js:538:15)
    at Function.Module._load (module.js:468:25)
    at Module.require (module.js:587:17)
    at require (internal/module.js:11:18)
    at Object.<anonymous> (C:\Users\Omar\AppData\Roaming\npm\node_modules\@qiskit\sdk\node_modules\@qiskit\devs-js\lib\factor.js:17:18)
    at Module._compile (module.js:643:30)
    at Object.Module._extensions..js (module.js:654:10)
    at Module.load (module.js:556:32)
    at tryModuleLoad (module.js:499:12)
    at Function.Module._load (module.js:491:3)
  • Qiskit.js version: 0.5.0
  • Node.js version:8.9.4
  • Operating system:Win 10 x64 updated 17134

What is the current behavior?

Steps to reproduce the problem

What is the expected behavior?

Suggested solutions

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.