- URL: https://github.com/MikeMcl/decimal.js/
- Description: The decimal.js library. This is used to perform more accurate floating point operations.
- Implements:
Decimal
- Description: This implements basic math functions like complex numbers and complex matrices.
- Source Tree:
Complex(real, imaginary)- Type:
Object - Description: This implements complex numbers and complex number operations.
- Arguments:
real- Either a JavaScript floating point number or a
Decimalobject. This represents the real component of the complex number.
- Either a JavaScript floating point number or a
imaginary- Either a JavaScript floating point number or a
Decimalobject. This represents the imaginary component of the complex number.
- Either a JavaScript floating point number or a
Complex.Real- Type:
Property - Description: A
Decimalobject that represents the real component of the complex number.
- Type:
Complex.Imaginary- Type:
Property - Description: A
Decimalobject that represents the imaginary component of the complex number.
- Type:
Complex.Sub(comp)Complex.Add(comp)Complex.Mult(comp)Complex.Inverse()Complex.Negate()Complex.Div(comp)Complex.Abs()Complex.toString()- Type:
Method - Description: Creates a string representation of the current
Complex. - Returns: A new
Stringwhich holds a representation of the currentComplex.
- Type:
Complex.Sqr()Complex.Clone()- Type:
Method - Description: Creates a clone of the current
Complex. - Returns: A new
Complexwhich is a clone of the currentComplex.
- Type:
- Type:
Matrix(width, height, opt = true)- Type:
Object - Description: A
Objectthat represents a matrix in memory. ThisObjectalso implements operations on matrices. - Arguments:
width- An
Intthat represents thewidthof theMatrix.
- An
height- An
Intthat represents theheightof theMatrix.
- An
opt- A
Booleanthat enables theMatrixto be stored differently depending on thewidthandheight. This speeds upMatrixoperations andStateVectoroperations.
- A
Matrix.Width- Type:
Property - Description: An
Intthat represents thewidthof theMatrix.
- Type:
Matrix.Height- Type:
Property - Description: An
Intthat represents theheightof theMatrix.
- Type:
Matrix.Rotated- Type:
Property - Description: A
Booleanthat represents whether theMatrixrepresentation has been flipped in memory for optimization reasons.
- Type:
Matrix.Vals- Type:
Property - Description: A representation of the
Matrixin memory.
- Type:
Matrix.Set(i, j, v)Matrix.Get(i, j)Matrix.Mult(mat)Matrix.Rotate90()Matrix.CounterRotate90()Matrix.VerticleFlatten()Matrix.toString()- Type:
Method - Description: Creates a
Stringthat represents theMatrix. - Returns: A
Stringthat represents theMatrix.
- Type:
Matrix.FlatFromArr(arr, horiz = false)- Type:
Method - Description: Creates either a vector or a vector flipped on its side from an
ArrayofComplexobjects. - Arguments:
arr- A one dimensional
ArrayofComplexobjects.
- A one dimensional
horiz- A
Booleanwhich if set tofalsecreates a vector and if set totruecreates a vector that is flipped on its side.
- A
- Returns: A vector or a vector flipped on its side from an
ArrayofComplexobjects. Both in aMatrixObject.
- Type:
Matrix.From2dArr(arr2d)- Type:
Method - Description: Creates a new
MatrixObjectfrom a two dimensionalArrayofComplexobjects. Still implemented for compatibility reasons. UseMatrix.From2dComplexArr(arr2d)instead. - Arguments:
arr2d- A two dimensional
ArrayofComplexobjects.
- A two dimensional
- Returns: A new
Matrixthat is functionally equivalent to the input two dimensionalArray.
- Type:
Matrix.From2dRealArr(arr2d)- Type:
Method - Description: Creates a new
MatrixObjectfrom a two dimensionalArrayof JavaScriptFloatobjects. - Arguments:
arr2d- A two dimensional
Arrayof JavaScriptFloatobjects.
- A two dimensional
- Returns: A new
Matrixthat is filled withComplexobjects with theRealcomponent set to the inputarr2d.
- Type:
Matrix.From2dComplexArr(arr2d)- Type:
Method - Description: Creates a new
MatrixObjectfrom a two dimensionalArrayofComplexobjects. - Arguments:
arr2d- A two dimensional
ArrayofComplexobjects.
- A two dimensional
- Returns: A new
Matrixthat is functionally equivalent to the input two dimensionalArray.
- Type:
Matrix.Scalar(a)- Type:
Method - Description: Multiplies every element of the matrix by the argument
a. - Arguments:
a- A
Complexthat will be multiplied every element of theMatrix.
- A
- Returns: A new
Matrixwhere every element has been multiplied bya.
- Type:
- Type:
- Description: A module that allows the demo to estimate how many qubits the host computer can process in a reasonable amount of time.
- Source Tree:
PerformanceEval()- Type:
Method - Description: provides an estimate of how many qubits a host computer can work with in a reasonable amount of time.
- Type:
- Description: A module that provides an interpreting service to interpret the quantum programming language.
- Source Tree:
qEvaluator- Type:
Object - Description: A
Objectthat provides the quantum language interpreter.qEvaluator.sim- Type:
Property - Description: An instance of the
QVMObjectto actually preform the simulation of the quantum operations.
- Type:
qEvaluator.measureObj- Type:
Property - Description: An
Arraywhich represents the measured state vector. If no measurement operation has been performed, this will remainUndefined.
- Type:
qEvaluator.readLine(x)- Type:
Method - Description: A method to feed a line of data into the language interpreter.
- Arguments:
x- A
Stringthat represents a line of a quantum program.
- A
- Type:
- Type:
- Description: A module that contains all quantum gate definitions in matrix form. All the gates are contained in the
ObjectqGates.
- Description: Implements the actual quantum computer simulator.
- Source Tree:
StateVector(nBit)- Type:
Object - Description: A
Objectthat stores a quantum state for a quantum computer withnBitnumber of bits. - Arguments:
nBit- A JavaScript
Intthat stores the number of bits represented by the state vector.
- A JavaScript
StateVector.UnitVec- Type:
Property - Description: A
Matrixthat hold the vector that represents the state of the quantum computer.
- Type:
StateVector.SetBinUnitVector(states)StateVector.ZeroBinUnitVector()StateVector.Flatten()- Type:
Method - Description: Creates a one dimensional
ArrayofComplexobjects that represents theUnitVec. - Returns: A one dimensional
ArrayofComplexobjects that represents theUnitVec.
- Type:
StateVector.GetProbDist()- Type:
Method - Description: Calculates the probabilities of each possible state of the quantum computer.
- Returns: A new one dimensional
ArrayofDecimalobjects that represents all the possible probabilities of each state.
- Type:
- Type:
QVM(nBit)- Type:
Object - Description: A simple
Objectwhich allows quantum computations. - Arguments:
nBit- A JavaScript
Intthat represents the amount of qubits in the simulated quantum computer.
- A JavaScript
QVM.Gates- Type:
Property - Description: An
ArrayofqGatesobjects which represent all the quantum operations in order.
- Type:
QVM.qBitSels- Type:
Property - Description: An
ArrayofIntArraythat represents the qubits to be operated on. The length ofQVM.qBitSelsshould matchQVM.Gates.
- Type:
QVM.State- Type:
Property - Description: An
StateVectorthat represents the current state of the quantum computer simulator.
- Type:
QVM.Reset()- Type:
Method - Description: Resets
QVM.Stateby callingQVM.State.ZeroBinUnitVector().
- Type:
QVM.Run(trackStates = true)- Type:
Method - Description: Runs the simulation of the quantum computer.
- Arguments:
trackStates- A
Booleanthat if set totruewill log every intermediateStateVector.
- A
- Result: An
Arrayof intermediateStateVector.
- Type:
QVM.MeasureBits(selBits)- Type:
Method - Description: Calculates the probabilities of each possible state of the quantum computer when measured.
- Arguments:
selBits- An
Arrayof JavaScriptIntthat represents the qubits that are measured.
- An
- Type:
- Type:
-
Description: A module that implements algorithms for processing multiple qubits that are entangled.
-
Source Tree:
-
incArr(len) -
baseArrToN(baseArr, base = 2)- Type:
Method - Description: From an
Arrayof JavaScriptIntconverts from basebaseto N. - Arguments:
baseArr- An
ArrayofIntwhich represents the value of the places.
- An
base- A JavaScript
Intthat represents the base of thebaseArr
- A JavaScript
- Returns: A JavaScript
Intthat is the base 10 representation ofbaseArrin the basebase.
- Type:
-
nToBaseArr(n, base = 2)- Type:
Method - Description: Converts a JavaScript
Intnto a base array with the basebase. - Arguments:
n- A JavaScript
Intto convert into basebase.
- A JavaScript
base- The base to use for the conversion.
- Returns: An
Arrayof JavaScriptIntthat represent the numbernin the basebase.
- Type:
-
padRight0(bitArr, n)- Type:
Method - Description: Appends 0s to
bitArr. - Arguments:
bitArr- The
Arrayto append to.
- The
n- A JavaScript
Intthat represents the number of 0s to append to the array.
- A JavaScript
- Returns: The original
Arraywithnextra 0s appended to it.
- Type:
-
xorArrs(arr1, arr2)- Type:
Method - Description: Creates a new
Arraythat holds every element ofarr1XORed witharr2. - Arguments:
arr1- A bit
Arrayto be XORed.
- A bit
- `arr2
- A bit
Arrayto be XORed.
- A bit
- Returns: A new
Arraywith every element ofarr1XORed witharr2.
- Type:
-
removeFromArray(original, remove)- Type:
Method - Description: Creates a new
Arraythat holds every element oforiginalthat is not inremove. - Arguments:
original- A generic
Array.
- A generic
remove- A generic
Array.
- A generic
- Returns: A new
Arraythat holds every element oforiginalthat is not inremove.
- Type:
-
orBitSelArray(arr, bitSel)- Type:
Method - Description: ORs all
arr[bitSel]. - Arguments:
arr- A binary
Arrayto OR.
- A binary
bitSel- A JavaScript
IntArraythat contains the indexes to OR.
- A JavaScript
- Returns: The indexes,
bitSelofArrayarrORed.
- Type:
-
orArray(arr) -
Type:
Method -
Description: ORs all the elements of
arr -
Arguments:
arr- A binary
Arrayto OR.
- A binary
-
Returns: All the elements of
arrORed. -
mapArr(orig, map, preserve = false)- Type:
Method - Description: Returns a new
Arrayoforig[map]. - Arguments:
orig- The
Arraythat will be used as the source.
- The
map- A JavaScript
Arraythat is anArrayof indexes to return fromorig
- A JavaScript
- Returns: A new
Arrayoforig[map].
- Type:
-
generateGroupMap(len, selBits)- Type:
Method - Description: An algorithm that creates a map of quantum states to perform single qubit operations on a pair of two or more entangled qubits.
- Arguments:
len- A JavaScript
Intthat represents the length of theStateVector.
- A JavaScript
selBits- A JavaScript
ArrayofIntthat represents the index of the qubits that should be operated on.
- A JavaScript
- Returns: A map of quantum states to perform single qubit operations on a pair of two or more entangled qubits.
- Type:
-
applyGroupMap(map, vec)- Type:
Method - Description: Applies the result of
generateGroupMap(len, selBits)to aStateVector. - Arguments:
map- A group map generated by
generateGroupMap(len, selBits)
- A group map generated by
vec- A
StateVectorto apply the group map to.
- A
- Returns: Groups of pairs of qubit
StateVectorsto be operated on.
- Type:
-
removeGroupMap(map, pairs)- Type:
Method - Description: After performing the operation, the pairs must be ‘glued back together’ or combined back into a
StateVector. Meaning that:removeGroupMap(map, applyGroupMap(map, vec)) == vec. - Arguments:
map- A group map generated by
generateGroupMap(len, selBits).
- A group map generated by
pairs- An
Arrayof pairs generated byapplyGroupMap(map, vec).
- An
- Returns: Reverses the result of
applyGroupMap(map, vec).
- Type:
-
generateCombinationMap(len, selBits)-
Type:
Method -
Description: Generates a map to combine probabilities of a
StateVectorto create the illusion of measuring individual qubits. Used for theMcommand (read the Readme). -
Arguments:
-
len- A JavaScript
Intthat represents the length of theStateVector.
- A JavaScript
-
selBits- A JavaScript
ArrayofIntthat represents the index of the qubits that should be operated on.
- A JavaScript
-
-
Returns: A map to combine probabilities of a
StateVector.
-
-
ApplyCombinationMap(map, arr, pad = true)- Type:
Method - Description: Applies a map generated by
generateCombinationMap(len, selBits)to probability vector. - Arguments:
map- A group map generated by
generateCombinationMap(len, selBits).
- A group map generated by
arr- A probability vector to apply the group map to.
pad- A
Booleanthat if set totruewill preserve the original probability vector length.
- A
- Returns a probability map as if the quantum computer only measured the qubits defined in
generateCombinationMap(len, selBits)asselBits.
- Type:
-
-
The QVM project contains:
827lines of JavaScript.















