Function
Static Public Summary | ||
public |
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: BasicEngine, num: number, func: function) |
|
public |
SubConstant(a: number): * Subtract a constant from a quantum number represented by a quantum register, stored from low- to high-bit. |
|
public |
SubConstantModN(a: number, N: number): * Subtract a constant from a quantum number represented by a quantum register modulo N. |
|
public |
Uncompute(engine: *) Uncompute automatically. |
|
public |
classHierachy(cls: function): function[] return class hierachy of |
|
public |
dropEngineAfter(engine: BasicEngine): BasicEngine Removes an engine from the singly-linked list of engines. |
|
public |
getEngineList(num_qubits: number, cyclic: boolean, one_qubit_gates: string | Array<BasicGate>, two_qubit_gates: string | Array<BasicGate>): Array<BasicEngine> Returns an engine list to compile to a linear chain of qubits. |
|
public |
getEngineList(): BasicEngine[] |
|
public |
getEngineList(one_qubit_gates: string | Array<BasicGate>, two_qubit_gates: string | Array<BasicGate>, other_gates: string | Array<BasicGate>): Array<BasicEngine> Returns an engine list to compile to a restricted gate set. |
|
public |
getEngineList(): undefined[] |
|
public |
getEngineList(): BasicEngine[] |
|
public |
getEngineList(num_rows: number, num_columns: number, one_qubit_gates: string | Array<BasicGate>, two_qubit_gates: string | Array<BasicGate>): Array<BasicEngine> Returns an engine list to compile to a 2-D grid of qubits. |
|
public |
getInverse(gate: BasicGate): * Return the inverse of a gate. |
|
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 |
|
public |
isKindclassOf(cls: function, superClass: function): boolean check if |
|
public |
isSubclassOf(cls: function, superClass: function): boolean check if |
|
public |
return |
|
public |
stringToArray(key: *): * |
|
public |
create |
Static Public
public C(gate: BasicGate, n: number): * source
import {C} from 'projectq/src/ops/metagates.js'
Return n-controlled version of the provided gate.
Return:
* |
Example:
C(NOT) | (c, q) # equivalent to CNOT | (c, q)
public CRz(angle: *): * source
import {CRz} from 'projectq/src/ops/shortcuts.js'
Params:
Name | Type | Attribute | Description |
angle | * |
Return:
* |
public Compute(engine: *, func: *) source
import {Compute} from 'projectq/src/meta/compute.js'
Start a compute-section.
Params:
Name | Type | Attribute | Description |
engine | * | ||
func | * |
Example:
Compute(eng, () => {
do_something(qubits)
action(qubits)
})
Uncompute(eng) // runs inverse of the compute section
Warning:
If qubits are allocated within the compute section, they must either be
uncomputed and deallocated within that section or, alternatively,
uncomputed and deallocated in the following uncompute section.
This means that the following examples are valid:
Compute(eng, () => {
anc = eng.allocateQubit()
do_something_with_ancilla(anc)
})
...
uncompute_ancilla(anc)
anc.deallocate()
do_something_else(qubits)
Uncompute(eng) // will allocate a new ancilla (with a different id)
// and then deallocate it again
Compute(eng, () => {
anc = eng.allocateQubit()
do_something_with_ancilla(anc)
...
})
do_something_else(qubits)
Uncompute(eng) // will deallocate the ancilla!
After the uncompute section, ancilla qubits allocated within the
compute section will be invalid (and deallocated). The same holds when
using CustomUncompute.
Failure to comply with these rules results in an exception being thrown.
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:
Name | Type | Attribute | Description |
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:
with Control(eng, ctrlqubits)
do_something(otherqubits)
Enter a controlled section.
Control(eng, ctrlqubits, () => ...)
public CustomUncompute(engine: *, func: *) source
import {CustomUncompute} from 'projectq/src/meta/compute.js'
Start a custom uncompute-section.
Params:
Name | Type | Attribute | Description |
engine | * | ||
func | * |
Throw:
If qubits are allocated within Compute or within CustomUncompute context but are not deallocated. |
Example:
Compute(eng, () => {
do_something(qubits)
})
action(qubits)
CustomUncompute(eng, () => {
do_something_inverse(qubits)
})
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:
Name | Type | Attribute | Description |
engine | BasicEngine | Engine which handles the commands (usually MainEngine) |
|
func | function |
Example:
Dagger(eng, () => [code to invert])
Warning:
If the code to invert contains allocation of qubits, those qubits have
to be deleted prior to exiting the 'with Dagger()' context.
This code is **NOT VALID**:
Dagger(eng, () => {
qb = eng.allocateQubit()
H.or(qb) // qb is still available!!!
})
The **correct way** of handling qubit (de-)allocation is as follows:
Dagger(eng, () => {
qb = eng.allocateQubit()
...
qb.deallocate() // sends deallocate gate (which becomes an allocate)
})
public Loop(engine: BasicEngine, num: number, func: function) source
import {Loop} from 'projectq/src/meta/loop.js'
Params:
Name | Type | Attribute | Description |
engine | BasicEngine | ||
num | number | ||
func | function | Loop n times over an entire code block. |
Example:
Loop(eng, 4, () => { })
// [quantum gates to be executed 4 times]
Warning:
If the code in the loop contains allocation of qubits, those qubits
have to be deleted prior to exiting the 'Loop()' context.
This code is **NOT VALID**:
Loop(eng, 4, () => {
qb = eng.allocateQubit()
H.or(qb) // qb is still available!!!
})
The **correct way** of handling qubit (de-)allocation is as follows:
Loop(eng, 4, () => {
qb = eng.allocateQubit()
...
qb.deallocate() // sends deallocate gate
})
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:
Name | Type | Attribute | Description |
a | number | Constant to subtract |
Return:
* |
Example:
qunum = eng.allocateQureg(5) # 5-qubit number
X | qunum[2] # qunum is now equal to 4
SubConstant(3) | qunum # qunum is now equal to 1
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.
Return:
* |
Example:
qunum = eng.allocateQureg(3) # 3-qubit number
X | qunum[1] # qunum is now equal to 2
SubConstantModN(4,5) | qunum # qunum is now -2 = 6 = 1 (mod 5)
public Uncompute(engine: *) source
import {Uncompute} from 'projectq/src/meta/compute.js'
Uncompute automatically.
Params:
Name | Type | Attribute | Description |
engine | * |
Example:
Compute(eng, () => {
do_something(qubits)
})
action(qubits)
Uncompute(eng) // runs inverse of the compute section
public classHierachy(cls: function): function[] source
import {classHierachy} from 'projectq/src/libs/util.js'
return class hierachy of cls
Params:
Name | Type | Attribute | Description |
cls | function |
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:
Name | Type | Attribute | Description |
engine | BasicEngine | The engine just before the engine to drop. |
public getEngineList(num_qubits: number, cyclic: boolean, one_qubit_gates: string | Array<BasicGate>, two_qubit_gates: string | Array<BasicGate>): Array<BasicEngine> 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:
Name | Type | Attribute | Description |
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). |
Throw:
If input is for the gates is not "any" or a tuple. |
Example:
getEngineList(10, false, tuple(Rz, Ry, Rx, H), tuple(CNOT))
public getEngineList(): BasicEngine[] source
import {getEngineList} from 'projectq/src/setups/ibm.js'
public getEngineList(one_qubit_gates: string | Array<BasicGate>, two_qubit_gates: string | Array<BasicGate>, other_gates: string | Array<BasicGate>): Array<BasicEngine> 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:
Name | Type | Attribute | Description |
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. |
Throw:
If input is for the gates is not "any" or a tuple. |
Example:
getEngineList(tuple(Rz, Ry, Rx, H), tuple(CNOT), tuple(TimeEvolution))
public getEngineList(): undefined[] source
import {getEngineList} from 'projectq/src/setups/ibm16.js'
public getEngineList(): BasicEngine[] source
import {getEngineList} from 'projectq/src/setups/index.js'
public getEngineList(num_rows: number, num_columns: number, one_qubit_gates: string | Array<BasicGate>, two_qubit_gates: string | Array<BasicGate>): Array<BasicEngine> 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.
Params:
Name | Type | Attribute | Description |
num_rows | number | Number of rows in the grid |
|
num_columns | number | Number of columns in the grid. |
|
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). |
Throw:
If input is for the gates is not "any" or a tuple. |
Example:
getEngineList(2, 3, tuple(Rz, Ry, Rx, H), tuple(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:
Name | Type | Attribute | Description |
gate | BasicGate | Gate of which to get the inverse |
Return:
* |
Example:
getInverse(H) // returns a Hadamard gate (HGate object)
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:
Name | Type | Attribute | Description |
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:
Name | Type | Attribute | Description |
inst | any | ||
cls | function |
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
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
public len(v: any): number source
import {len} from 'projectq/src/libs/polyfill.js'
return length
of v, act like python
Params:
Name | Type | Attribute | Description |
v | any |
public stringToArray(key: *): * source
import {stringToArray} from 'projectq/src/ops/qubitoperator.js'
Params:
Name | Type | Attribute | Description |
key | * |
Return:
* |
public tuple(args: *): Array source
import {tuple} from 'projectq/src/libs/util.js'
create tuple
from arguments
Params:
Name | Type | Attribute | Description |
args | * |