Simulator
NodeJS implementation of a quantum computer simulator.
This Simulator can be used as a backup if compiling the c++ simulator is not an option (for some reason). It has the same features but is much slower, so please consider building the c++ version for larger experiments.
Constructor Summary
Public Constructor | ||
public |
|
Method Summary
Public Methods | ||
public |
allocateQubit(ID: number) Allocate a qubit. |
|
public |
Applies the k-qubit gate matrix m to the qubits with indices ids, using ctrlids as control qubits. |
|
public |
applyQubitOperator(termsArray: Array<Array>, IDs: number[]) Apply a (possibly non-unitary) qubit operator to qubits. |
|
public |
Applies a QubitOperator term to the state vector. |
|
public |
Return the qubit index to bit location map and the corresponding state vector. |
|
public |
collapseWavefunction(ids: number[], values: boolean[]) Collapse a quantum register onto a classical basis state. |
|
public |
deallocateQubit(ID: number) Deallocate a qubit (if it has been measured / uncomputed). |
|
public |
emulateMath(f: function, qubitIDs: Array<number[]>, ctrlQubitIDs: number[]) Emulate a math function (e.g., BasicMathGate). |
|
public |
Applies exp(-itimeH) to the wave function, i.e., evolves under the Hamiltonian H for a given time. |
|
public |
getAmplitude(bitString: boolean[] | number[], IDs: number[]): * Return the probability amplitude of the supplied |
|
public |
getClassicalValue(ID: number, tolerance: number): * Return the classical value of a classical bit (i.e., a qubit which has been measured / uncomputed). |
|
public |
getControlMask(ctrlids: *): number Get control mask from list of control qubit IDs. |
|
public |
getExpectationValue(termsArray: Array<Array>, IDs: number[]): * Return the expectation value of a qubit operator w.r.t. |
|
public |
getProbability(bitString: boolean[] | number[], IDs: number[]): * Return the probability of the outcome |
|
public |
measureQubits(ids: number[]): boolean[] Measure the qubits with IDs ids and return a list of measurement outcomes (true/false). |
|
public |
run() leave it empty to keep same API with cpp simulator |
|
public |
setWavefunction(wavefunction: Complex[], ordering: Array) Set wavefunction and qubit ordering. |
Private Methods | ||
private |
_multiQubitGate(m: Array<number[]>, pos: number[], mask: number) Applies the k-qubit gate matrix m to the qubits at |
|
private |
Applies the single qubit gate matrix m to the qubit at position |
Public Constructors
public constructor() source
Public Methods
public allocateQubit(ID: number) source
Allocate a qubit.
Params:
Name | Type | Attribute | Description |
ID | number | ID of the qubit which is being allocated. |
public applyControlledGate(m: Array<Array<number>>, ids: number[], ctrlids: number[]) source
Applies the k-qubit gate matrix m to the qubits with indices ids, using ctrlids as control qubits.
public applyQubitOperator(termsArray: Array<Array>, IDs: number[]) source
Apply a (possibly non-unitary) qubit operator to qubits.
public applyTerm(term: Array, ids: number[], controlIDs: number[]) source
Applies a QubitOperator term to the state vector. (Helper function for time evolution & expectation)
public cheat(): Array source
Return the qubit index to bit location map and the corresponding state vector.
This function can be used to measure expectation values more efficiently (emulation).
Return:
Array | A tuple where the first entry is a dictionary mapping qubit indices to bit-locations and the second entry is the corresponding state vector |
public collapseWavefunction(ids: number[], values: boolean[]) source
Collapse a quantum register onto a classical basis state.
Throw:
If probability of outcome is ~0 or unknown qubits are provided. |
public deallocateQubit(ID: number) source
Deallocate a qubit (if it has been measured / uncomputed).
Params:
Name | Type | Attribute | Description |
ID | number | ID of the qubit to deallocate. |
Throw:
If the qubit is in a superposition, i.e., has not been measured / uncomputed. |
public emulateMath(f: function, qubitIDs: Array<number[]>, ctrlQubitIDs: number[]) source
Emulate a math function (e.g., BasicMathGate).
Params:
Name | Type | Attribute | Description |
f | function | Function executing the operation to emulate. |
|
qubitIDs | Array<number[]> | List of lists of qubit IDs to which the gate is being applied. Every gate is applied to a tuple of quantum registers, which corresponds to this 'list of lists'. |
|
ctrlQubitIDs | number[] | List of control qubit ids. |
public emulateTimeEvolution(terms_dict: Array<Array>, time: number, ids: number[], ctrlids: number[]) source
Applies exp(-itimeH) to the wave function, i.e., evolves under the Hamiltonian H for a given time. The terms in the Hamiltonian are not required to commute.
This function computes the action of the matrix exponential using ideas from Al-Mohy and Higham, 2011. TODO: Implement better estimates for s.
public getAmplitude(bitString: boolean[] | number[], IDs: number[]): * source
Return the probability amplitude of the supplied bit_string
.
The ordering is given by the list of qubit ids.
Return:
* | Probability amplitude of the provided bit string. |
Throw:
if the second argument is not a permutation of all allocated qubits. |
public getClassicalValue(ID: number, tolerance: number): * source
Return the classical value of a classical bit (i.e., a qubit which has been measured / uncomputed).
Return:
* |
Throw:
If the qubit is in a superposition, i.e., has not been measured / uncomputed. |
public getControlMask(ctrlids: *): number source
Get control mask from list of control qubit IDs.
Params:
Name | Type | Attribute | Description |
ctrlids | * |
public getExpectationValue(termsArray: Array<Array>, IDs: number[]): * source
Return the expectation value of a qubit operator w.r.t. qubit ids.
Return:
* | Expectation value |
public getProbability(bitString: boolean[] | number[], IDs: number[]): * source
Return the probability of the outcome bit_string
when measuring
the qubits given by the list of ids.
Return:
* | Probability of measuring the provided bit string. |
Throw:
if an unknown qubit id was provided. |
public measureQubits(ids: number[]): boolean[] source
Measure the qubits with IDs ids and return a list of measurement outcomes (true/false).
Params:
Name | Type | Attribute | Description |
ids | number[] | List of qubit IDs to measure. |
public setWavefunction(wavefunction: Complex[], ordering: Array) source
Set wavefunction and qubit ordering.
Params:
Name | Type | Attribute | Description |
wavefunction | Complex[] | Array of complex amplitudes describing the wavefunction (must be normalized). |
|
ordering | Array | List of ids describing the new ordering of qubits (i.e., the ordering of the provided wavefunction). |
Private Methods
private _multiQubitGate(m: Array<number[]>, pos: number[], mask: number) source
Applies the k-qubit gate matrix m to the qubits at pos
using mask
to identify control qubits.
Params:
Name | Type | Attribute | Description |
m | Array<number[]> | 2^k x 2^k complex matrix describing the k-qubit gate. |
|
pos | number[] | List of bit-positions of the qubits. |
|
mask | number | Bit-mask where set bits indicate control qubits. see follows the description in https://arxiv.org/abs/1704.01127 |