Skip to content
This repository has been archived by the owner on Sep 13, 2019. It is now read-only.

Commit

Permalink
Multiple engine support: ANU, JS
Browse files Browse the repository at this point in the history
  • Loading branch information
jesusprubio committed Jun 4, 2018
1 parent c7d514c commit 409fbc0
Show file tree
Hide file tree
Showing 29 changed files with 1,197 additions and 21 deletions.
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,12 @@ All notable changes to this project will be documented in this file.
The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/)
and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.html).

## [Unreleased-private]

### Added

* Multiple engine support to "qiskit-algos" package.

## [Unreleased]

### Changed
Expand Down
4 changes: 4 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,10 @@
"dep-check":
"depcheck --ignore-dirs=dist --ignores='brfs,brfs-babel,browserify-banner,mocha,nsp,husky' && lerna run dep-check",
"dep-sec": "lerna run dep-sec",
"test-algos": "lerna run test --scope @qiskit/algos",
"test-algos-js": "lerna run test --scope @qiskit/algos-js",
"test-algos-ibm": "lerna run test --scope @qiskit/algos-ibm",
"test-algos-anu": "lerna run test --scope @qiskit/algos-anu",
"test-qasm": "lerna run test --scope @qiskit/qasm",
"test-cloud": "lerna run test --scope @qiskit/cloud",
"test-sdk": "lerna run test --scope @qiskit/sdk",
Expand Down
31 changes: 31 additions & 0 deletions packages/qiskit-algos-anu/.npmignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
*.html
*.png
*.csv
*.dat
*.iml
*.log
*.out
*.pid
*.seed
*.sublime-*
*.swo
*.swp
*.tgz
*.xml
.DS_Store
.idea
.project
.strong-pm
coverage
*.lock
.vscode

# Node.js
node_modules
npm-debug.log
.jshintrc
.jslintrc
.editorconfig

# Project stuff
test
29 changes: 29 additions & 0 deletions packages/qiskit-algos-anu/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
# QISKit.js algorithms (ANU)

The [Australian National University](http://www.anu.edu.au) [Quantum Random Numbers Server](https://qrng.anu.edu.au) engine (chip) for the [QISKit algorithms package](https://github.com/QISKit/qiskit-sdk-js/tree/master/packages/qiskit-algos).

## Install

:coffee: Install [Node.js](https://nodejs.org/download) v8 and then:

```sh
npm i @qiskit/algos-anu
```

## Use

:pencil: You can visit the complete example [in this test](./test/functional/index.js).

```js
const algos = require('@qiskit/algos-anu');

console.log('Version');
console.log(algos.version);
```

## API

:eyes: Please check the [main doc](../../README.md#API). The methods signature is the same but:

* As expected, the `engine` parameter is omitted here.
* Only the `random` method is supported.
19 changes: 19 additions & 0 deletions packages/qiskit-algos-anu/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
/**
* @license
*
* Copyright (c) 2017-present, IBM Research.
*
* This source code is licensed under the Apache license found in the
* LICENSE.txt file in the root directory of this source tree.
*/

'use strict';

const utils = require('@qiskit/utils');

const genHex = require('./lib/genHex');
const { version } = require('./package');

module.exports.version = version;

module.exports.random = async opts => utils.genRandom(genHex, opts);
36 changes: 36 additions & 0 deletions packages/qiskit-algos-anu/lib/genHex.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
/**
* @license
*
* Copyright (c) 2017-present, IBM Research.
*
* This source code is licensed under the Apache license found in the
* LICENSE.txt file in the root directory of this source tree.
*/

'use strict';

const util = require('util');

const utils = require('@qiskit/utils');
const qrand = util.promisify(require('qrand').getRandomHexOctets);

const { name } = require('../package');

const dbg = utils.debug(name);

module.exports = async (len = 16) => {
// "/2" The library expecst the number of octects and we ask for number of
// hexadecimal digits (8 octets = 16 hex chars).

const octects = await qrand(len / 2);
dbg('Generated number (octects):', { octects, len: octects.length });

if (!octects || !utils.isArray(octects)) {
throw new Error('Parsing the result (octects)');
}

const strHex = octects.join('');
dbg('Random string (hex):', { strHex });

return strHex;
};
45 changes: 45 additions & 0 deletions packages/qiskit-algos-anu/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
{
"name": "@qiskit/algos-anu",
"version": "0.2.0",
"description": "Australia National University engine for QISKit algorithms",
"author": {
"name": "IBM RESEARCH",
"url": "http://research.ibm.com"
},
"homepage": "https://github.com/QISKit/qiskit-sdk-js",
"contributors": [
"https://github.com/QISKit/qiskit-sdk-js/graphs/contributors"
],
"repository": {
"type": "git",
"url": "https://github.com/QISKit/qiskit-sdk-js"
},
"scripts": {
"dep-check": "depcheck",
"test": "mocha --recursive test --timeout 20000"
},
"keywords": [
"quantum",
"computing",
"information",
"algorithms",
"random",
"shor",
"Australian National University"
],
"bugs": {
"url": "https://github.com/QISKit/qiskit-sdk-js/issues"
},
"dependencies": {
"qrand": "^0.1.3",
"@qiskit/utils": "^0.2.0"
},
"engines": {
"node": ">=8",
"npm": ">=5"
},
"license": "Apache-2.0",
"publishConfig": {
"access": "public"
}
}
62 changes: 62 additions & 0 deletions packages/qiskit-algos-anu/test/functional.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
/**
* @license
*
* Copyright (c) 2017-present, IBM Research.
*
* This source code is licensed under the Apache license found in the
* LICENSE.txt file in the root directory of this source tree.
*/

'use strict';

const assert = require('assert');

const utils = require('@qiskit/utils');

const algos = require('..');
const { name, version } = require('../package');
const genHex = require('../lib/genHex');

const dbg = utils.debug(`${name}:test`);

describe('api', () => {
it('should include all documented items', () => {
assert.equal(
utils.difference(['version', 'random'], Object.keys(algos)),
0,
);
});
});

describe('version', () => {
it('should be included', () => assert.equal(algos.version, version));
});

describe('random', () => {
it('should return a number between 0 and 1 without options', async () => {
const res = await algos.random();
dbg('Result', res);

assert.ok(res >= 0);
assert.ok(res <= 1);
});
});

describe('genHex', () => {
it('should return a hex string of the default length without options', async () => {
const res = await genHex();
dbg('Result', res);

assert.ok(typeof res === 'string');
assert.ok(res.length === 16);
});

it('should return a hex string of the desired length if passed', async () => {
const len = 8;
const res = await genHex(len);
dbg('Result', res);

assert.ok(typeof res === 'string');
assert.ok(res.length === len);
});
});
31 changes: 31 additions & 0 deletions packages/qiskit-algos-ibm/.npmignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
*.html
*.png
*.csv
*.dat
*.iml
*.log
*.out
*.pid
*.seed
*.sublime-*
*.swo
*.swp
*.tgz
*.xml
.DS_Store
.idea
.project
.strong-pm
coverage
*.lock
.vscode

# Node.js
node_modules
npm-debug.log
.jshintrc
.jslintrc
.editorconfig

# Project stuff
test
31 changes: 31 additions & 0 deletions packages/qiskit-algos-ibm/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
# QISKit.js algorithms (IBM Q)

[IBM Q](https://www.research.ibm.com/ibm-q) engine (chip and remote simulator) for the [QISKit algorithms package](https://github.com/QISKit/qiskit-sdk-js/tree/master/packages/qiskit-algos).

## Install

:coffee: Install [Node.js](https://nodejs.org/download) v8 and then:

```sh
npm i @qiskit/algos-ibm
```

## Use

:pencil: You can visit the complete example [in this test](./test/functional/index.js).

```js
const algos = require('@qiskit/algos-ibm');

console.log('Version');
console.log(algos.version);
```

## API

:eyes: Please check the [main doc](../../README.md#API). The method signature is the same but:

* As expected, the `engine` parameter is omitted here.
* All algorithms need a background job, so a `jobId` is returned.
* The `token` parameter is mandatory. Provided by the `login` method of the [qiskit-cloud](../qiskit-cloud) package.
* An extra one `userId` is also needed, same that for the last option.
19 changes: 19 additions & 0 deletions packages/qiskit-algos-ibm/cfg.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
{
"backends": {
"simulator": {
"nQubits": 5
},
"ibmqx2": {
"nQubits": 5
},
"ibmqx4": {
"nQubits": 5
},
"ibmqx5": {
"nQubits": 16
},
"qs1_1": {
"nQubits": 20
}
}
}
Loading

0 comments on commit 409fbc0

Please sign in to comment.