0.9.0 • Published 5 years ago

@qiskit/sim v0.9.0

Weekly downloads
2
License
Apache-2.0
Repository
github
Last release
5 years ago

Qiskit.js simulator

:atom_symbol: Quantum Information Science Kit simulator in pure JavaScript. As a first feature it includes an unitary one, with specific support for OpenQASM circuits representation.

Please visit the main repository to know more about the rest of the project tools.

Install

:coffee: Install lastest Node.js stable version (or LTS) and then:

npm i @qiskit/sim

Use

:pencil: You can visit more complete examples in the tests.

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

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 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
0.9.0

5 years ago

0.8.0

5 years ago

0.7.1

5 years ago

0.7.0

5 years ago

0.6.3

5 years ago

0.6.2

5 years ago

0.6.1

5 years ago

0.6.0

5 years ago

0.5.0

6 years ago

0.4.0

6 years ago

0.3.0

6 years ago

0.2.0

6 years ago

0.1.9

6 years ago

0.1.7

6 years ago

0.1.6

6 years ago

0.1.5

6 years ago

0.1.3

6 years ago

0.1.2

6 years ago