# @qiskit/sim

> Quantum Information Science Kit simulator

Latest version **0.9.0** (published 2019-05-13) · Apache-2.0 license · 0 weekly downloads

> **Deprecated.** This package is deprecated.

## Install

```sh
npm install @qiskit/sim
pnpm add @qiskit/sim
yarn add @qiskit/sim
bun add @qiskit/sim
```

## Health

**Score 10/100 (F)** — status: deprecated.

Negative: deprecated.

## Facts

| | |
|---|---|
| Version | 0.9.0 |
| Published | 2019-05-13 |
| First published | 2017-11-28 |
| Weekly downloads | 0 |
| License | Apache-2.0 |
| TypeScript types | none |
| Module format | CommonJS |
| Node | >=10 |
| Dependencies | 3 |
| Unpacked size | 33.1 KB |
| Known vulnerabilities | 0 (+1 in 1 direct dependencies) |
| Install scripts | no |
| GitHub stars | 116 |
| Author | IBM RESEARCH |
| Maintainers | abdonrd, atilag, jelcaf, jesusprubio, qiskit-team |
| Keywords | quantum, computing, information, qasm, openqasm, simulator, emulator, compiler, unroller, qiskit, IBM |

## Links

- npm: https://www.npmjs.com/package/@qiskit/sim
- Repository: https://github.com/Qiskit/qiskit-js
- Issues: https://github.com/Qiskit/qiskit-js/issues
- npm.io page: https://npm.io/package/@qiskit/sim

## Dependencies (3)

- [mathjs](https://npm.io/package/mathjs.md) ^5.10.0
- [@qiskit/qasm](https://npm.io/package/@qiskit/qasm.md) ^0.9.0
- [@qiskit/utils](https://npm.io/package/@qiskit/utils.md) ^0.9.0

## Alternatives

- [@openai/codex-sdk](https://npm.io/package/@openai/codex-sdk.md) — 731.4K weekly downloads
- [babel-plugin-transform-react-jsx](https://npm.io/package/babel-plugin-transform-react-jsx.md) — 565.0K weekly downloads
- [babel-helper-remove-or-void](https://npm.io/package/babel-helper-remove-or-void.md) — 508.5K weekly downloads
- [@pnpm/store-controller-types](https://npm.io/package/@pnpm/store-controller-types.md) — 186.9K weekly downloads
- [react-native-signature-canvas](https://npm.io/package/react-native-signature-canvas.md) — 155.6K weekly downloads

## Recent versions

- 0.9.0 (latest) — 2019-05-13
- 0.8.0 — 2019-04-25
- 0.7.1 — 2019-04-23
- 0.7.0 — 2019-04-12
- 0.6.3 — 2019-04-12
- 0.6.2 — 2019-03-13
- 0.6.1 — 2019-03-11
- 0.6.0 — 2019-03-11
- 0.5.0 — 2018-10-20
- 0.4.0 — 2018-08-02
- 0.3.0 — 2018-06-07
- 0.2.0 — 2018-05-24
- 0.1.9 — 2018-04-27
- 0.1.7 — 2018-04-24
- 0.1.6 — 2018-04-24
- … 3 more at https://npm.io/package/@qiskit/sim/versions

## README

# Qiskit.js simulator

:atom_symbol: [Quantum Information Science Kit](https://developer.ibm.com/open/openprojects/qiskit) simulator in pure JavaScript. As a first feature it includes an unitary one, with specific support for [OpenQASM](https://github.com/Qiskit/openqasm) circuits representation.

Please visit the [main repository](https://github.com/Qiskit/qiskit-js) to know more about the rest of the project tools.

## Install

:coffee: Install lastest [Node.js](https://nodejs.org/download) stable version (or LTS) and then:

```sh
npm i @qiskit/sim
```

## Use

:pencil: You can visit more complete examples [in the tests](./test).

```js
const util = require('util');

const { Circuit, Gate } = require('@qiskit/sim');

function randomizeInput(nQubits) {
  const input = [];

  for (let i = 0; i < nQubits; i += 1) {
    const x = !!Math.round(Math.random());
    input.push(x);

    console.log(`${i}:${x ? '|1>' : '|0>'}`);
  }

  return input;
}

const circuit = Circuit.createCircuit(2);

circuit.add(Gate.h, 0, 0);
circuit.add(Gate.cx, 1, [0, 1]);
circuit.print();

console.log('\nInput randomized (as string):');
const input = randomizeInput(circuit.nQubits);

console.log('\nInput randomized:');
console.log(input);

console.log('\nRunning the circuit now ...');
circuit.run(input);

console.log('\nDone, internal state:');
console.log(circuit.state);

console.log('\nInternal state (as string):');
console.log(circuit.stateToString());

const circuitIr = circuit.save();
console.log('\nSaved IR:');
console.log(util.inspect(circuitIr, { showHidden: false, depth: null }));
```

## API

:eyes: Full specification.

### `version`

The actual version of the library.

* `version` (string) - Version number.

### `gates`

Gates definition.

* `gates` (object) - Supported gates definition.

### `Circuit(opts) -> circuit`

* `opts` (object) -The constructor accepts next options:
  * `nQubits` (number) - Number of qubits needed to run the circuit. It will be automatically updated by the `addGate` method if needed.
* `circuit` (object) - New instance.

### `circuit.state`

* `state` (object, [Math.js matrix](http://mathjs.org/docs/datatypes/matrices.html)) - Internal state of the simulation.

### `circuit.stateToString() -> stateStr`

* `stateStr` (string) - Human friendly representation of the internal state.

### `circuit.addGate(gate, column, wires)`

Add a gate to the circuit.

* `gate` (Gate|string) - Gate instance or name of the gate, from `gates` field.
* `column` (number) - Qubit to connect the gate.
* `wires` (number / [number]) - Gate connections. An array is used for multi-gates.

### `circuit.add(gate, column, wires)`

Add a gate to the circuit. This function is identical to `addGate` but only
accepts `Gate` instances.

* `gate` (Gate) - Gate instance to add to the circuit.
* `column` (number) - Qubit to connect the gate.
* `wires` (number / [number]) - Gate connections. An array is used for multi-gates.

### `circuit.print([writable])`

Prints a visual representation of the circuit to standard out (by default).

* `writable` (object) - Optional [Writable](https://nodejs.org/api/stream.html#stream_writable_streams)
object which will be written to. Defaults to process.stdout.

### `circuit.run(input)`

Make the simulation.

* `input` ([boolean]) - Initial state of each qubit.

### `circuit.save() -> circuitIr`

Export the circuit setup for a future reuse.

* `circuitIr` (object) - Simulator internal representation of the circuit (JSON).

### `circuit.load(circuitIr)`

Import a circuit setup.

* `circuitIr`

---
_Source: https://npm.io/package/@qiskit/sim · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
