Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@qiskit/devs

Package Overview
Dependencies
Maintainers
5
Versions
11
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@qiskit/devs - npm Package Compare versions

Comparing version 0.3.0 to 0.4.0

19

cfg.json
{
"backends": {
"simulator": {
"nQubits": 5
},
"ibmqx2": {
"nQubits": 5
},
"ibmqx4": {
"nQubits": 5
},
"ibmqx5": {
"nQubits": 16
},
"qs1_1": {
"nQubits": 20
}
"engines": {
"supported": ["js", "anu", "ibm"],
"default": "js"
}
}
/**
* @license
*
* Copyright (c) 2017-present, IBM Research.
* Copyright (c) 2017, IBM.
*
* This source code is licensed under the Apache license found in the
* LICENSE.txt file in the root directory of this source tree.
* This source code is licensed under the Apache License, Version 2.0 found in
* the LICENSE.txt file in the root directory of this source tree.
*/

@@ -12,120 +12,34 @@

const Cloud = require('@qiskit/cloud');
const engineJs = require('@qiskit/devs-js');
const engineAnu = require('@qiskit/devs-anu');
const engineIbm = require('@qiskit/devs-ibm');
const utils = require('./lib/utils');
const genBin = require('./lib/genBin');
const { version } = require('./package');
const { backends } = require('./cfg');
const cfg = require('./cfg');
const backendNames = Object.keys(backends);
const dbg = utils.dbg(__filename);
const enginesList = cfg.engines.supported;
const engines = {
js: engineJs,
anu: engineAnu,
ibm: engineIbm,
};
module.exports.version = version;
module.exports.random = async (token, userId, opts = {}) => {
module.exports.random = async (opts = {}) => {
dbg('Passed opts:', opts);
if (!token || typeof token !== 'string') {
throw new TypeError('The "token" parameter is mandatory (string)');
}
const engine = opts.engine || cfg.engines.default;
if (!userId || typeof userId !== 'string') {
throw new TypeError('The "userId" parameter is mandatory (string)');
if (!utils.includes(enginesList, engine)) {
throw new TypeError(`Bad engine, supported: ${engines}`);
}
if (opts.length) {
if (typeof opts.length !== 'number') {
throw new TypeError('A number expected in "length" option');
}
}
const length = opts.length || 16;
if (opts.shots) {
if (typeof opts.shots !== 'number') {
throw new TypeError('A number expected in "shots" option');
}
}
const shots = opts.shots || 1;
if (opts.maxCredits) {
if (typeof opts.maxCredits !== 'number') {
throw new TypeError('A number expected in "shots" option');
}
}
const maxCredits = opts.maxCredits || null;
if (opts.backend) {
if (typeof opts.backend !== 'string') {
throw new TypeError('A string expected in "backend" option');
}
if (!utils.includes(backendNames, opts.backend.toLowerCase())) {
throw new Error(`Not valid "backend", allowed: ${backendNames}`);
}
}
const backend = opts.backend || 'simulator';
dbg('Parsed opts:', { length, shots, backend });
return genBin(token, userId, {
length,
backend,
shots,
maxCredits,
});
return engines[engine].random(opts);
};
module.exports.result = async (token, userId, jobId) => {
const cloud = new Cloud();
module.exports.result = engines.ibm.result;
cloud.token = token;
cloud.userId = token;
if (!token || typeof token !== 'string') {
throw new TypeError('The "token" parameter is mandatory (string)');
}
if (!userId || typeof userId !== 'string') {
throw new TypeError('The "userId" parameter is mandatory (string)');
}
if (!jobId || typeof jobId !== 'string') {
throw new TypeError('The "jobId" parameter is mandatory (string)');
}
const res = await cloud.job(jobId);
const result = { status: res.status.toLowerCase() };
if (result.status !== 'completed') {
return result;
}
const binaryArray = utils.map(res.circuits, resCircuit => {
if (
!resCircuit.result ||
!resCircuit.result.data ||
!resCircuit.result.data.counts ||
typeof resCircuit.result.data.counts !== 'object'
) {
throw new Error(`Parsing the circuits result: ${JSON.stringify(res)}`);
}
return Object.keys(resCircuit.result.data.counts)[0];
});
dbg('Generated partial number (binary-array):', {
binaryArray,
len: binaryArray.length,
});
const binary = binaryArray.join('');
dbg('Generated partial number (binary):', { binary });
const decimal = utils.ayb.parseInt(binary, 2, 10);
dbg('Generated number (decimal):', { decimal });
// To return a value between 0 and 1 (similar to "Math.floor").
result.data = decimal / 10 ** decimal.toString().length;
return result;
};
module.exports.factor = engines.js.factor;

6

lib/utils.js
/**
* @license
*
* Copyright (c) 2017-present, IBM Research.
* Copyright (c) 2017, IBM.
*
* This source code is licensed under the Apache license found in the
* LICENSE.txt file in the root directory of this source tree.
* This source code is licensed under the Apache License, Version 2.0 found in
* the LICENSE.txt file in the root directory of this source tree.
*/

@@ -9,0 +9,0 @@

{
"name": "@qiskit/devs",
"version": "0.3.0",
"version": "0.4.0",
"description": "Quantum Information algorithms for developers",

@@ -9,13 +9,13 @@ "author": {

},
"homepage": "https://github.com/QISKit/qiskit-sdk-js",
"homepage": "https://github.com/Qiskit/qiskit-js",
"contributors": [
"https://github.com/QISKit/qiskit-sdk-js/graphs/contributors"
"https://github.com/Qiskit/qiskit-js/graphs/contributors"
],
"repository": {
"type": "git",
"url": "https://github.com/QISKit/qiskit-sdk-js"
"url": "https://github.com/Qiskit/qiskit-js"
},
"scripts": {
"dep-check": "depcheck",
"test": "mocha --recursive test --timeout 20000"
"test": "mocha --recursive test --timeout 20000 --color"
},

@@ -34,7 +34,9 @@ "keywords": [

"bugs": {
"url": "https://github.com/QISKit/qiskit-sdk-js/issues"
"url": "https://github.com/Qiskit/qiskit-js/issues"
},
"dependencies": {
"@qiskit/cloud": "^0.3.0",
"@qiskit/utils": "^0.3.0"
"@qiskit/devs-anu": "^0.4.0",
"@qiskit/devs-ibm": "^0.4.0",
"@qiskit/devs-js": "^0.4.0",
"@qiskit/utils": "^0.4.0"
},

@@ -41,0 +43,0 @@ "engines": {

@@ -1,6 +0,6 @@

# QISKit for developers
# Qiskit for developers
:atom_symbol: Quantum Information Software Kit Quantum Information algorithms for developers. The idea is t
:atom_symbol: Quantum Information Science Kit algorithms for developers. The idea is to hide all quantum mechanics complexity exposing only the upper layer.
Please visit the [main repository](https://github.com/QISKit/qiskit-sdk-js) of the project to know about the rest of the tools.
Please visit the [main repository](https://github.com/Qiskit/qiskit-js) of the project to know about the rest of the tools.

@@ -41,3 +41,3 @@ ## Install

* `version` (string) - Version number.
- `version` (string) - Version number.

@@ -48,30 +48,27 @@ ### `async random(opts) -> rand | jobId`

* `opts` (object) - Optional parameters:
* `engine` (string) - Where to run the operation. Please visit the [packages](https://github.ibm.com/jesusper/qiskit-sdk-js-next/tree/master/packages) to see the supported ones. The number of digits depends on the selected engine. (default: "js")
* `length` (number) - Number of random hex characters to ask for to the engine. As you can see in the doc referenced before each engine has different limit, they will throw in it's overpassed. (default: 16)
* `format` (string) - To ask for the result in a different format, supported ("hex").
* `token` (string) - Some engines need an access token (visit each specific doc).
* `rand` (number) - Generated random number in the desired format if the operation doesn't involves a background job.
* `jobId` (string) - Identifier for the generated background job (see next method).
- `opts` (object) - Optional parameters:
- `engine` (string) - Where to run the operation. Please visit the [packages](https://github.ibm.com/jesusper/qiskit-js-next/tree/master/packages) to see the supported ones. The number of digits depends on the selected engine. (default: "js")
- `length` (number) - Number of random hex characters to ask for to the engine. As you can see in the doc referenced before each engine has different limit, they will throw in it's overpassed. (default: 16)
- `format` (string) - To ask for the result in a different format, supported ("hex").
- `custom` (string/object) - Custom stuff (API key, inited connector instance, etc) needed for some backends (visit each specific doc).
- `rand` (number) - Generated random number in the desired format if the operation doesn't involves a background job.
- `jobId` (string) - Identifier for the generated background job (see next method).
### `async result(jobId, opts) -> result`
Get the result of a background job generated by an algorithm method.
Get the result of a background job generated by an algorithm method. The engine is not ommited for now because IBM Q is the unique which uses background jobs for now.
* `jobId` (string) - Job identifier got as initial response.
* `opts`(object) - Optional parameters:
* `token`
* `result` (?) - Depending on the used agorithm:
* "random": (object) - With nex fields:
* `status` (string) - To know if the job has finished correctly. Supported: "running", "completed", TODO.
* `data` (number) - Generated random number. Only present if "status" is "completed".
- `jobId` (string) - Job identifier got as initial response.
- `opts`(object) - Optional parameters:
- `custom`
- `result` (?) - Depending on the used agorithm:
- "random": (object) - With nex fields:
- `status` (string) - To know if the job has finished correctly. Supported: "running", "completed", TODO.
- `data` (number) - Generated random number. Only present if "status" is "completed".
### `async factor(number, opts) -> prime`
Integer factorization in prime numbers using [Shor's algorithm](https://en.wikipedia.org/wiki/Shor%27s_algorithm). **Only supported in the local simulator for now**. Should be run multiple times until get all primes and if the result is invalid.
Integer factorization in prime numbers using [Shor's algorithm](https://en.wikipedia.org/wiki/Shor%27s_algorithm). **Only supported in the local simulator for now**, so the engine is also ommited here for now. The result can be invalid, retry in this clase.
* `number` (number/string) - Number to factorize, can also be an string (hexadecimal).
* `opts`
* `engine`
* `token`
* `prime` (number) - Prime factor of the passed one.
- `number` (number/string) - Number to factorize, an integer for now.
- `prime` (number) - Prime factor of the passed one.
SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc