Home Reference Source

Function

Static Public Summary
public

C(gate: BasicGate, n: number): *

Return n-controlled version of the provided gate.

public

CRz(angle: *): *

public

Compute(engine: *, func: *)

Start a compute-section.

public

Control(engine: BasicEngine, qubits: Array<BasicQubit>, func: function)

Condition an entire code block on the value of qubits being 1.

public

CustomUncompute(engine: *, func: *)

Start a custom uncompute-section.

public

Dagger(engine: BasicEngine, func: function)

Invert an entire code block.

public

Loop(engine: *, num: *, func: *)

Loop n times over an entire code block.

public

create copy of object, with same class

public

Qureg(args: ...*): *

public

Subtract a constant from a quantum number represented by a quantum register, stored from low- to high-bit.

public

Subtract a constant from a quantum number represented by a quantum register modulo N.

public

Uncompute(engine: *)

Uncompute automatically.

public

add(key: *, value: *)

public

add_constant(eng: *, c: *, quint: *)

Adds a classical constant c to the quantum integer (qureg) quint using Draper addition.

public

add_constant_modN(eng: *, c: *, N: *, quint: *)

Adds a classical constant c to a quantum integer (qureg) quint modulo N using Draper addition and the construction from https://arxiv.org/abs/quant-ph/0205095.

public

arrayEqual(a1: Array, a2: Array, itemCompareFunc: function): boolean

test if two array(a1, a2) are equal, support instance of classes in this library

public

arrayFromRange(start: number, end: number, step: number): number[]

create an array filled by number in range, active like python does

public

check if an array is tuple

public

return class hierachy of cls

public

complexVectorDot(a1: Complex[], a2: Complex[]): Complex

return dot product of two complex vector(a1, a2)

public
public

Removes an engine from the singly-linked list of engines.

public

expmod(base: number, exp: number, mod: number): number

return (base ^ exp) % mod, it's fast and support big number

public

return item * n string like python does.

public

get(key: *): *

public

getEngineList(one_qubit_gates: string | Array<BasicGate>, two_qubit_gates: string | Array<BasicGate>, other_gates: string | Array<BasicGate>): Array

Returns an engine list to compile to a restricted gate set.

public
public

getEngineList(num_rows: number, num_columns: number, one_qubit_gates: string | Array<BasicGate>, two_qubit_gates: string | Array<BasicGate>): undefined[]

Returns an engine list to compile to a 2-D grid of qubits.

public
public
public

getEngineList(num_qubits: number, cyclic: boolean, one_qubit_gates: string | Array<BasicGate>, two_qubit_gates: string | Array<BasicGate>): Array

Returns an engine list to compile to a linear chain of qubits.

public

getInverse(gate: BasicGate): *

Return the inverse of a gate.

public

high_level_gates(eng: *, cmd: *): boolean

Remove any MathGates

public

insertEngine(prevEngine: BasicEngine, engineToInsert: BasicEngine)

Inserts an engine into the singly-linked list of engines.

public

instanceOf(inst: any, cls: function): boolean

check if inst is instance of cls, specialized for some class

public

intersection(s1: Set, s2: Set): Set

return intersection of s1 & s2

public

check if value is complex number

public

isKindclassOf(cls: function, superClass: function): boolean

check if cls is kind of superClass, will return true if cls is superClass

public

check if value is number or complex number

public

isSubclassOf(cls: function, superClass: function): boolean

check if cls is subclass of superClass, will return false if cls is superClass

public

len(v: any): number

return length of v, act like python

public

markTuple(value: *)

force mark a value as tuple, internal usage only

public

matrixDot(matrix: math.matrix, vector: number[]): math.matrix

dot product of matrix & vector

public

matrixGetRow(matrix: math.matrix, index: number): number[]

return a row of matrix

public

matrixRangeAssign(matrix: math.matrix, indices: number[], vector: number[])

assign value in vector into matrix by index in indices

public

matrixRangeIndicesAssign(matrix: *, mstart: *, mend: *, vector: *, vstart: *)

public

mul_by_constant_modN(eng: *, c: *, N: *, quint_in: *)

Multiplies a quantum integer by a classical number a modulo N, i.e.,

public

narray(item: Function | any, count: number): Array

return n-length Array filled by item

public

phase(c: *): *

public

productLoop(p1: Array, p2: Array, func: function)

product loop on two Arrays p1 & p2

public

productLoop3(p1: Array, p2: Array, p3: Array, func: function)

product loop on three Arrays p1 & p2 & p3

public

randomSample(array: any[], count: number): any[]

return a random sample from array which length is count

public

Returns the circuit depth to execute these swaps.

public

setDifference(s1: *, s2: *): *

public

setEqual(s1: Set, s2: Set): boolean

check if s1 is equal to s2

public

create a Set contains numbers in range from 0 to n

public

setIsSuperSet(superset: Set, s: Set): boolean

check if superset is the super set of s

public

stringToArray(key: *): *

public

parse string contains 1/0 into bit array

public

symmetricDifference(s1: Set, s2: Set): Set<*>

return symmetric difference of s1 & s2

public

tuple(args: *): Array

create tuple from arguments

public

unionSet(s1: Set, s2: Set): Set<any>

return union set of s1 & s2

public

generate a n-Length Array filled by 0

Static Private Summary
private

_decompose_CnU(cmd: *)

Decompose a multi-controlled gate U into a single-controlled U.

private
private

_decompose_ry(cmd: *)

private

Given a 2x2 unitary matrix, find the parameters a, b/2, c/2, and d/2 such that matrix == [[exp(j(a-b/2-d/2))cos(c/2), -exp(j(a-b/2+d/2))sin(c/2)], [exp(j(a+b/2-d/2))sin(c/2), exp(j(a+b/2+d/2))cos(c/2)]]

private

Recognize an arbitrary gate which has n>=2 control qubits, except a Toffoli gate.

private
private
private

Recognize an arbitrary one qubit gate which has a matrix property.

private
private
private

_recognize_cnot(cmd: *)

private

Recognizes a matrix which can be written in the following form:

Static Public

public C(gate: BasicGate, n: number): * source

Return n-controlled version of the provided gate.

Params:

NameTypeAttributeDescription
gate BasicGate

Gate to turn into its controlled version

n number

Number of controls (default: 1)

Return:

*

Example:


    

public CRz(angle: *): * source

import {CRz} from 'projectq/src/ops/shortcuts.js'

Params:

NameTypeAttributeDescription
angle *

Return:

*

public Compute(engine: *, func: *) source

import {Compute} from 'projectq/src/meta/compute.js'

Start a compute-section.

Params:

NameTypeAttributeDescription
engine *
func *

Example:


    

public Control(engine: BasicEngine, qubits: Array<BasicQubit>, func: function) source

import {Control} from 'projectq/src/meta/control.js'

Condition an entire code block on the value of qubits being 1.

Params:

NameTypeAttributeDescription
engine BasicEngine

Engine which handles the commands (usually MainEngine)

qubits Array<BasicQubit>

Qubits to condition on

func function

Enter the section using a with-statement

Example:


    

public CustomUncompute(engine: *, func: *) source

import {CustomUncompute} from 'projectq/src/meta/compute.js'

Start a custom uncompute-section.

Params:

NameTypeAttributeDescription
engine *
func *

Throw:

QubitManagementError

If qubits are allocated within Compute or within CustomUncompute context but are not deallocated.

Example:


    

public Dagger(engine: BasicEngine, func: function) source

import {Dagger} from 'projectq/src/meta/dagger.js'

Invert an entire code block.

Use it with a with-statement, i.e.,

Params:

NameTypeAttributeDescription
engine BasicEngine

Engine which handles the commands (usually MainEngine)

func function

public Loop(engine: *, num: *, func: *) source

import {Loop} from 'projectq/src/meta/loop.js'

Loop n times over an entire code block.

Params:

NameTypeAttributeDescription
engine *
num *
func *

Example:


    

public ObjectCopy(obj: Object): Object source

import {ObjectCopy} from 'projectq/src/libs/util.js'

create copy of object, with same class

Params:

NameTypeAttributeDescription
obj Object

Return:

Object

public Qureg(args: ...*): * source

import {Qureg} from 'projectq/src/types/qubit.js'

Params:

NameTypeAttributeDescription
args ...*

Return:

*

public SubConstant(a: number): * source

import {SubConstant} from 'projectq/src/libs/math/gates.js'

Subtract a constant from a quantum number represented by a quantum register, stored from low- to high-bit.

Params:

NameTypeAttributeDescription
a number

Constant to subtract

Return:

*

Example:


    

public SubConstantModN(a: number, N: number): * source

import {SubConstantModN} from 'projectq/src/libs/math/gates.js'

Subtract a constant from a quantum number represented by a quantum register modulo N.

The number is stored from low- to high-bit, i.e., qunum[0] is the LSB.

Params:

NameTypeAttributeDescription
a number

Constant to add

N number

Constant modulo which the addition of a should be carried out.

Return:

*

Example:


    

public Uncompute(engine: *) source

import {Uncompute} from 'projectq/src/meta/compute.js'

Uncompute automatically.

Params:

NameTypeAttributeDescription
engine *

Example:


    

public add(key: *, value: *) source

import {add} from 'projectq/src/ops/_cycle.js'

Params:

NameTypeAttributeDescription
key *
value *

public add_constant(eng: *, c: *, quint: *) source

import {add_constant} from 'projectq/src/libs/math/constantmath.js'

Adds a classical constant c to the quantum integer (qureg) quint using Draper addition. Note: Uses the Fourier-transform adder from https://arxiv.org/abs/quant-ph/0008033.

Params:

NameTypeAttributeDescription
eng *
c *
quint *

public add_constant_modN(eng: *, c: *, N: *, quint: *) source

import {add_constant_modN} from 'projectq/src/libs/math/constantmath.js'

Adds a classical constant c to a quantum integer (qureg) quint modulo N using Draper addition and the construction from https://arxiv.org/abs/quant-ph/0205095.

Params:

NameTypeAttributeDescription
eng *
c *
N *
quint *

public arrayEqual(a1: Array, a2: Array, itemCompareFunc: function): boolean source

import {arrayEqual} from 'projectq/src/libs/polyfill.js'

test if two array(a1, a2) are equal, support instance of classes in this library

Params:

NameTypeAttributeDescription
a1 Array
a2 Array
itemCompareFunc function

Return:

boolean

public arrayFromRange(start: number, end: number, step: number): number[] source

import {arrayFromRange} from 'projectq/src/libs/polyfill.js'

create an array filled by number in range, active like python does

Params:

NameTypeAttributeDescription
start number
end number
step number

Return:

number[]

public arrayIsTuple(value: Array): boolean source

import {arrayIsTuple} from 'projectq/src/libs/util.js'

check if an array is tuple

Params:

NameTypeAttributeDescription
value Array

Return:

boolean

public classHierachy(cls: function): function[] source

import {classHierachy} from 'projectq/src/libs/util.js'

return class hierachy of cls

Params:

NameTypeAttributeDescription
cls function

Return:

function[]

public complexVectorDot(a1: Complex[], a2: Complex[]): Complex source

import {complexVectorDot} from 'projectq/src/libs/polyfill.js'

return dot product of two complex vector(a1, a2)

Params:

NameTypeAttributeDescription
a1 Complex[]
a2 Complex[]

Return:

Complex

public create_test_matrices(): * source

Return:

*

public dropEngineAfter(engine: BasicEngine): BasicEngine source

import {dropEngineAfter} from 'projectq/src/meta/util.js'

Removes an engine from the singly-linked list of engines.

Params:

NameTypeAttributeDescription
engine BasicEngine

The engine just before the engine to drop.

Return:

BasicEngine

The dropped engine.

public expmod(base: number, exp: number, mod: number): number source

import {expmod} from 'projectq/src/libs/polyfill.js'

return (base ^ exp) % mod, it's fast and support big number

Params:

NameTypeAttributeDescription
base number
exp number
mod number

Return:

number

public genString(item: string, n: number): string source

import {genString} from 'projectq/src/libs/util.js'

return item * n string like python does.

Params:

NameTypeAttributeDescription
item string
n number

Return:

string

public get(key: *): * source

import {get} from 'projectq/src/ops/_cycle.js'

Params:

NameTypeAttributeDescription
key *

Return:

*

public getEngineList(one_qubit_gates: string | Array<BasicGate>, two_qubit_gates: string | Array<BasicGate>, other_gates: string | Array<BasicGate>): Array source

import {getEngineList} from 'projectq/src/setups/restrictedgateset.js'

Returns an engine list to compile to a restricted gate set.

Note: If you choose a new gate set for which the compiler does not yet have standard rules, it raises an NoGateDecompositionError or a RuntimeError: maximum recursion depth exceeded.... Also note that even the gate sets which work might not yet be optimized. So make sure to double check and potentially extend the decomposition rules. This implemention currently requires that the one qubit gates must contain Rz and at least one of {Ry(best), Rx, H} and the two qubit gate must contain CNOT (recommended) or CZ.

Note: Classical instructions gates such as e.g. Flush and Measure are automatically allowed.

Params:

NameTypeAttributeDescription
one_qubit_gates string | Array<BasicGate>

"any" allows any one qubit gate, otherwise provide a tuple of the allowed gates. If the gates are instances of a class (e.g. X), it allows all gates which are equal to it. If the gate is a class (Rz), it allows all instances of this class. Default is "any"

two_qubit_gates string | Array<BasicGate>

"any" allows any two qubit gate, otherwise provide a tuple of the allowed gates. If the gates are instances of a class (e.g. CNOT), it allows all gates which are equal to it. If the gate is a class, it allows all instances of this class. Default is (CNOT,).

other_gates string | Array<BasicGate>

A tuple of the allowed gates. If the gates are instances of a class (e.g. QFT), it allows all gates which are equal to it. If the gate is a class, it allows all instances of this class.

Return:

Array

A list of suitable compiler engines.

Throw:

Error

If input is for the gates is not "any" or a tuple.

Example:

get_engine_list(one_qubit_gates=(Rz, Ry, Rx, H),
two_qubit_gates=(CNOT,),
other_gates=(TimeEvolution,))

public getEngineList(): undefined[] source

import {getEngineList} from 'projectq/src/setups/ibm.js'

Return:

undefined[]

public getEngineList(num_rows: number, num_columns: number, one_qubit_gates: string | Array<BasicGate>, two_qubit_gates: string | Array<BasicGate>): undefined[] source

import {getEngineList} from 'projectq/src/setups/grid.js'

Returns an engine list to compile to a 2-D grid of qubits.

Note: If you choose a new gate set for which the compiler does not yet have standard rules, it raises an NoGateDecompositionError or a RuntimeError: maximum recursion depth exceeded.... Also note that even the gate sets which work might not yet be optimized. So make sure to double check and potentially extend the decomposition rules. This implemention currently requires that the one qubit gates must contain Rz and at least one of {Ry(best), Rx, H} and the two qubit gate must contain CNOT (recommended) or CZ.

Note: Classical instructions gates such as e.g. Flush and Measure are automatically allowed.

Example: get_engine_list(num_rows=2, num_columns=3, one_qubit_gates=(Rz, Ry, Rx, H), two_qubit_gates=(CNOT,))

Args: num_rows(int): Number of rows in the grid num_columns(int): Number of columns in the grid. one_qubit_gates: "any" allows any one qubit gate, otherwise provide a tuple of the allowed gates. If the gates are instances of a class (e.g. X), it allows all gates which are equal to it. If the gate is a class (Rz), it allows all instances of this class. Default is "any" two_qubit_gates: "any" allows any two qubit gate, otherwise provide a tuple of the allowed gates. If the gates are instances of a class (e.g. CNOT), it allows all gates which are equal to it. If the gate is a class, it allows all instances of this class. Default is (CNOT, Swap). Raises: TypeError: If input is for the gates is not "any" or a tuple.

Returns: A list of suitable compiler engines.

Params:

NameTypeAttributeDescription
num_rows number
num_columns number
one_qubit_gates string | Array<BasicGate>
two_qubit_gates string | Array<BasicGate>

Return:

undefined[]

public getEngineList(): undefined[] source

import {getEngineList} from 'projectq/src/setups/index.js'

Return:

undefined[]

public getEngineList(): undefined[] source

import {getEngineList} from 'projectq/src/setups/ibm16.js'

Return:

undefined[]

public getEngineList(num_qubits: number, cyclic: boolean, one_qubit_gates: string | Array<BasicGate>, two_qubit_gates: string | Array<BasicGate>): Array source

import {getEngineList} from 'projectq/src/setups/linear.js'

Returns an engine list to compile to a linear chain of qubits.

Note: If you choose a new gate set for which the compiler does not yet have standard rules, it raises an NoGateDecompositionError or a RuntimeError: maximum recursion depth exceeded.... Also note that even the gate sets which work might not yet be optimized. So make sure to double check and potentially extend the decomposition rules. This implemention currently requires that the one qubit gates must contain Rz and at least one of {Ry(best), Rx, H} and the two qubit gate must contain CNOT (recommended) or CZ.

Note: Classical instructions gates such as e.g. Flush and Measure are automatically allowed.

Params:

NameTypeAttributeDescription
num_qubits number

Number of qubits in the chain

cyclic boolean

If a circle or not. Default is false

one_qubit_gates string | Array<BasicGate>

"any" allows any one qubit gate, otherwise provide a tuple of the allowed gates. If the gates are instances of a class (e.g. X), it allows all gates which are equal to it. If the gate is a class (Rz), it allows all instances of this class. Default is "any"

two_qubit_gates string | Array<BasicGate>

"any" allows any two qubit gate, otherwise provide a tuple of the allowed gates. If the gates are instances of a class (e.g. CNOT), it allows all gates which are equal to it. If the gate is a class, it allows all instances of this class. Default is (CNOT, Swap).

Return:

Array

A list of suitable compiler engines.

Throw:

Error

If input is for the gates is not "any" or a tuple.

Example:

get_engine_list(num_qubits=10, cyclic=false,
one_qubit_gates=(Rz, Ry, Rx, H),
two_qubit_gates=(CNOT,))

public getInverse(gate: BasicGate): * source

import {getInverse} from 'projectq/src/ops/_cycle.js'

Return the inverse of a gate.

Tries to call gate.getInverse and, upon failure, creates a DaggeredGate instead.

Params:

NameTypeAttributeDescription
gate BasicGate

Gate of which to get the inverse

Return:

*

Example:


    

public high_level_gates(eng: *, cmd: *): boolean source

import {high_level_gates} from 'projectq/src/setups/grid.js'

Remove any MathGates

Params:

NameTypeAttributeDescription
eng *
cmd *

Return:

boolean

public insertEngine(prevEngine: BasicEngine, engineToInsert: BasicEngine) source

import {insertEngine} from 'projectq/src/meta/util.js'

Inserts an engine into the singly-linked list of engines. It also sets the correct main_engine for engine_to_insert.

Params:

NameTypeAttributeDescription
prevEngine BasicEngine

The engine just before the insertion point.

engineToInsert BasicEngine

The engine to insert at the insertion point.

public instanceOf(inst: any, cls: function): boolean source

import {instanceOf} from 'projectq/src/libs/util.js'

check if inst is instance of cls, specialized for some class

Params:

NameTypeAttributeDescription
inst any
cls function

Return:

boolean

public intersection(s1: Set, s2: Set): Set source

import {intersection} from 'projectq/src/libs/polyfill.js'

return intersection of s1 & s2

Params:

NameTypeAttributeDescription
s1 Set
s2 Set

Return:

Set

public isComplex(value: Object): boolean source

import {isComplex} from 'projectq/src/libs/polyfill.js'

check if value is complex number

Params:

NameTypeAttributeDescription
value Object

Return:

boolean

public isKindclassOf(cls: function, superClass: function): boolean source

import {isKindclassOf} from 'projectq/src/libs/util.js'

check if cls is kind of superClass, will return true if cls is superClass

Params:

NameTypeAttributeDescription
cls function
superClass function

Return:

boolean

public isNumeric(value: Object): boolean source

import {isNumeric} from 'projectq/src/libs/polyfill.js'

check if value is number or complex number

Params:

NameTypeAttributeDescription
value Object

Return:

boolean

public isSubclassOf(cls: function, superClass: function): boolean source

import {isSubclassOf} from 'projectq/src/libs/util.js'

check if cls is subclass of superClass, will return false if cls is superClass

Params:

NameTypeAttributeDescription
cls function
superClass function

Return:

boolean

public len(v: any): number source

import {len} from 'projectq/src/libs/polyfill.js'

return length of v, act like python

Params:

NameTypeAttributeDescription
v any

Return:

number

public markTuple(value: *) source

import {markTuple} from 'projectq/src/libs/util.js'

force mark a value as tuple, internal usage only

Params:

NameTypeAttributeDescription
value *

public matrixDot(matrix: math.matrix, vector: number[]): math.matrix source

import {matrixDot} from 'projectq/src/libs/util.js'

dot product of matrix & vector

Params:

NameTypeAttributeDescription
matrix math.matrix
vector number[]

Return:

math.matrix

public matrixGetRow(matrix: math.matrix, index: number): number[] source

import {matrixGetRow} from 'projectq/src/libs/util.js'

return a row of matrix

Params:

NameTypeAttributeDescription
matrix math.matrix
index number

Return:

number[]

public matrixRangeAssign(matrix: math.matrix, indices: number[], vector: number[]) source

import {matrixRangeAssign} from 'projectq/src/libs/util.js'

assign value in vector into matrix by index in indices

Params:

NameTypeAttributeDescription
matrix math.matrix
indices number[]
vector number[]

public matrixRangeIndicesAssign(matrix: *, mstart: *, mend: *, vector: *, vstart: *) source

import {matrixRangeIndicesAssign} from 'projectq/src/libs/util.js'

Params:

NameTypeAttributeDescription
matrix *
mstart *
mend *
vector *
vstart *

public mul_by_constant_modN(eng: *, c: *, N: *, quint_in: *) source

import {mul_by_constant_modN} from 'projectq/src/libs/math/constantmath.js'

Multiplies a quantum integer by a classical number a modulo N, i.e.,

|x> -> |a*x mod N>

(only works if a and N are relative primes, otherwise the modular inverse does not exist).

Params:

NameTypeAttributeDescription
eng *
c *
N *
quint_in *

public narray(item: Function | any, count: number): Array source

import {narray} from 'projectq/src/libs/polyfill.js'

return n-length Array filled by item

Params:

NameTypeAttributeDescription
item Function | any
count number

Return:

Array

public phase(c: *): * source

Params:

NameTypeAttributeDescription
c *

Return:

*

public productLoop(p1: Array, p2: Array, func: function) source

import {productLoop} from 'projectq/src/libs/polyfill.js'

product loop on two Arrays p1 & p2

Params:

NameTypeAttributeDescription
p1 Array
p2 Array
func function

public productLoop3(p1: Array, p2: Array, p3: Array, func: function) source

import {productLoop3} from 'projectq/src/libs/polyfill.js'

product loop on three Arrays p1 & p2 & p3

Params:

NameTypeAttributeDescription
p1 Array
p2 Array
p3 Array
func function

public randomSample(array: any[], count: number): any[] source

import {randomSample} from 'projectq/src/libs/polyfill.js'

return a random sample from array which length is count

Params:

NameTypeAttributeDescription
array any[]
count number

Return:

any[]

public return_swap_depth(swaps: Array<Array>): number source

import {return_swap_depth} from 'projectq/src/cengines/linearmapper.js'

Returns the circuit depth to execute these swaps.

Params:

NameTypeAttributeDescription
swaps Array<Array>

Each tuple contains two integers representing the two IDs of the qubits involved in the Swap operation

Return:

number

Circuit depth to execute these swaps.

public setDifference(s1: *, s2: *): * source

import {setDifference} from 'projectq/src/libs/polyfill.js'

Params:

NameTypeAttributeDescription
s1 *
s2 *

Return:

*

public setEqual(s1: Set, s2: Set): boolean source

import {setEqual} from 'projectq/src/libs/polyfill.js'

check if s1 is equal to s2

Params:

NameTypeAttributeDescription
s1 Set
s2 Set

Return:

boolean

public setFromRange(n: number): Set<number> source

import {setFromRange} from 'projectq/src/libs/polyfill.js'

create a Set contains numbers in range from 0 to n

Params:

NameTypeAttributeDescription
n number

Return:

Set<number>

public setIsSuperSet(superset: Set, s: Set): boolean source

import {setIsSuperSet} from 'projectq/src/libs/polyfill.js'

check if superset is the super set of s

Params:

NameTypeAttributeDescription
superset Set
s Set

Return:

boolean

public stringToArray(key: *): * source

import {stringToArray} from 'projectq/src/ops/qubitoperator.js'

Params:

NameTypeAttributeDescription
key *

Return:

*

public stringToBitArray(str: string): boolean[] source

import {stringToBitArray} from 'projectq/src/libs/polyfill.js'

parse string contains 1/0 into bit array

Params:

NameTypeAttributeDescription
str string

Return:

boolean[]

public symmetricDifference(s1: Set, s2: Set): Set<*> source

import {symmetricDifference} from 'projectq/src/libs/polyfill.js'

return symmetric difference of s1 & s2

Params:

NameTypeAttributeDescription
s1 Set
s2 Set

Return:

Set<*>

public tuple(args: *): Array source

import {tuple} from 'projectq/src/libs/util.js'

create tuple from arguments

Params:

NameTypeAttributeDescription
args *

Return:

Array

public unionSet(s1: Set, s2: Set): Set<any> source

import {unionSet} from 'projectq/src/libs/polyfill.js'

return union set of s1 & s2

Params:

NameTypeAttributeDescription
s1 Set
s2 Set

Return:

Set<any>

public zeros(n: number): number[] source

import {zeros} from 'projectq/src/libs/util.js'

generate a n-Length Array filled by 0

Params:

NameTypeAttributeDescription
n number

Return:

number[]

Static Private

private _decompose_CnU(cmd: *) source

Decompose a multi-controlled gate U into a single-controlled U. It uses (n-1) work qubits and 2 * (n-1) Toffoli gates.

Params:

NameTypeAttributeDescription
cmd *

private _decompose_barrier(cmd: *) source

import {_decompose_barrier} from 'projectq/src/setups/decompositions/barrier.js'

Params:

NameTypeAttributeDescription
cmd *

private _decompose_ry(cmd: *) source

import {_decompose_ry} from 'projectq/src/setups/decompositions/ry2rz.js'

Params:

NameTypeAttributeDescription
cmd *

private _find_parameters(matrix: Array<number[]>): number[] source

Given a 2x2 unitary matrix, find the parameters a, b/2, c/2, and d/2 such that matrix == [[exp(j(a-b/2-d/2))cos(c/2), -exp(j(a-b/2+d/2))sin(c/2)], [exp(j(a+b/2-d/2))sin(c/2), exp(j(a+b/2+d/2))cos(c/2)]]

Note: If the matrix is element of SU(2) (determinant == 1), then we can choose a = 0.

Params:

NameTypeAttributeDescription
matrix Array<number[]>

2x2 unitary matrix

Return:

number[]

parameters of the matrix: (a, b/2, c/2, d/2)

private _recognize_CnU(cmd: *): boolean source

Recognize an arbitrary gate which has n>=2 control qubits, except a Toffoli gate.

Params:

NameTypeAttributeDescription
cmd *

Return:

boolean

private _recognize_RxNoCtrl(cmd: *) source

import {_recognize_RxNoCtrl} from 'projectq/src/setups/decompositions/rx2rz.js'

Params:

NameTypeAttributeDescription
cmd *

private _recognize_RyNoCtrl(cmd: *) source

import {_recognize_RyNoCtrl} from 'projectq/src/setups/decompositions/ry2rz.js'

Params:

NameTypeAttributeDescription
cmd *

private _recognize_arb1qubit(cmd: Command): boolean source

import {_recognize_arb1qubit} from 'projectq/src/setups/decompositions/arb1qubit2rzandry.js'

Recognize an arbitrary one qubit gate which has a matrix property.

It does not allow gates which have control qubits as otherwise the AutoReplacer might go into an infinite loop. Use carb1qubit2cnotrzandry instead.

Params:

NameTypeAttributeDescription
cmd Command

Return:

boolean

private _recognize_barrier(cmd: *): boolean source

import {_recognize_barrier} from 'projectq/src/setups/decompositions/barrier.js'

Params:

NameTypeAttributeDescription
cmd *

Return:

boolean

private _recognize_carb1qubit(cmd: *): boolean source

Params:

NameTypeAttributeDescription
cmd *

Return:

boolean

private _recognize_cnot(cmd: *) source

import {_recognize_cnot} from 'projectq/src/setups/decompositions/cnot2cz.js'

Params:

NameTypeAttributeDescription
cmd *

private _recognize_v(matrix: Array<number[]>): boolean source

Recognizes a matrix which can be written in the following form:

V = [[-sin(c/2) exp(ja), exp(j(a-b)) cos(c/2)], [exp(j(a+b)) cos(c/2), exp(ja) sin(c/2)]]

Params:

NameTypeAttributeDescription
matrix Array<number[]>

2x2 matrix

Return:

boolean

false if it is not possible otherwise (a, b, c/2)