Command
Class used as a container to store commands. If a gate is applied to qubits, then the gate and qubits are saved in a command object. Qubits are copied into WeakQubitRefs in order to allow early deallocation (would be kept alive otherwise). WeakQubitRef qubits don't send deallocate gate when destructed.
Attributes: gate: The gate to execute qubits: Tuple of qubit lists (e.g. Quregs). Interchangeable qubits are stored in a unique order control_qubits: The Qureg of control qubits in a unique order engine: The engine (usually: MainEngine) tags: The list of tag objects associated with this command (e.g., ComputeTag, UncomputeTag, LoopTag, ...). tag objects need to support ==, != (eq and ne) for comparison as used in e.g. TagRemover. New tags should always be added to the end of the list. This means that if there are e.g. two LoopTags in a command, tag[0] is from the inner scope while tag[1] is from the other scope as the other scope receives the command after the inner scope LoopEngine and hence adds its LoopTag to the end. all_qubits: A tuple of control_qubits + qubits
Constructor Summary
Public Constructor | ||
public |
constructor(engine: BasicEngine, gate: BasicGate, qubits: Array<Qureg>, controls: Qureg | Array<Qubit>, tags: any[]) |
Member Summary
Public Members | ||
public get |
allQubits: * Get all qubits (gate and control qubits). |
|
public get |
controlCount: * |
|
public get |
|
|
public set |
controlQubits(nq: Qureg) Set control_qubits to qubits |
|
public get |
engine: * |
|
public set |
engine(ng: BasicEngine) Set / Change engine of all qubits to engine. |
|
public |
gate: * |
|
public get |
Return nested list of qubit indices which are interchangeable. |
|
public set |
|
|
public get |
qubits: * |
|
public |
tags: * |
Private Members | ||
private |
|
|
private |
_engine: * |
|
private |
_qubits: * |
Method Summary
Public Methods | ||
public |
addControlQubits(qubits: Array<Qubit>) Add (additional) control qubits to this command object. |
|
public |
apply() Apply a command. |
|
public |
return the copy of current command |
|
public |
|
|
public |
getInverse(): * Get the command object corresponding to the inverse of this command. |
|
public |
Merge this command with another one and return the merged command object. |
|
public |
|
|
public |
orderQubits(qubits: Array<Qubit>): Array<Qubit> Order the given qubits according to their IDs (for unique comparison of commands). |
|
public |
|
Public Constructors
public constructor(engine: BasicEngine, gate: BasicGate, qubits: Array<Qureg>, controls: Qureg | Array<Qubit>, tags: any[]) source
Params:
Name | Type | Attribute | Description |
engine | BasicEngine | engine which created the qubit (mostly the MainEngine) |
|
gate | BasicGate | Gate to be executed |
|
qubits | Array<Qureg> | Array of quantum registers (to which the gate is applied) |
|
controls | Qureg | Array<Qubit> | Qubits that condition the command. |
|
tags | any[] | Tags associated with the command. |
Public Members
public get allQubits: * source
Get all qubits (gate and control qubits).
Returns a tuple T where T[0] is a quantum register (a list of WeakQubitRef objects) containing the control qubits and T[1:] contains the quantum registers to which the gate is applied.
public get controlCount: * source
public get controlQubits: * source
public get engine: * source
public gate: * source
public get interchangeableQubitIndices: * source
Return nested list of qubit indices which are interchangeable.
Certain qubits can be interchanged (e.g., the qubit order for a Swap gate). To ensure that only those are sorted when determining the ordering (see _order_qubits), this.interchangeable_qubit_indices is used.
Example:
If we can interchange qubits 0,1 and qubits 3,4,5,
then this function returns [[0,1],[3,4,5]]
public set qubits source
public get qubits: * source
public tags: * source
Private Members
private _controlQubits: * source
private _engine: * source
private _qubits: * source
Public Methods
public addControlQubits(qubits: Array<Qubit>) source
Add (additional) control qubits to this command object.
They are sorted to ensure a canonical order. Also Qubit objects are converted to WeakQubitRef objects to allow garbage collection and thus early deallocation of qubits.
public apply() source
Apply a command.
Extracts the qubits-owning (target) engine from the Command object and sends the Command to it.
public getInverse(): * source
Get the command object corresponding to the inverse of this command. Inverts the gate (if possible) and creates a new command object from the result.
Return:
* |
Throw:
NotInvertible |
If the gate does not provide an inverse (see BasicGate.getInverse) |
public getMerged(other: Command): * source
Merge this command with another one and return the merged command object.
Params:
Name | Type | Attribute | Description |
other | Command | Other command to merge with this one (self) |
Return:
* |
Throw:
* |
NotMergeable if the gates don't supply a get_merged()-function or can't be merged for other reasons. |