BasicEngine
Direct Subclass:
Indirect Subclass:
Basic compiler engine: All compiler engines are derived from this class. It provides basic functionality such as qubit allocation/deallocation and functions that provide information about the engine's position (e.g., next engine).
This information is provided by the MainEngine, which initializes all further engines.
Attributes: next_engine (BasicEngine): Next compiler engine (or the back-end). main_engine (MainEngine): Reference to the main compiler engine. is_last_engine (bool): true for the last engine, which is the back-end.
Constructor Summary
Public Constructor | ||
public |
|
Member Summary
Public Members | ||
public |
|
Method Summary
Public Methods | ||
public |
allocateQubit(dirty: boolean): Qureg Return a new qubit as a list containing 1 qubit object (quantum register of size 1). |
|
public |
allocateQureg(n: number): Qureg Allocate n qubits and return them as a quantum register, which is a list of qubit objects. |
|
public |
deallocateQubit(qubit: BasicQubit) Deallocate a qubit (and sends the deallocation command down the pipeline). |
|
public |
isAvailable(cmd: Command): boolean Default implementation of isAvailable: Ask the next engine whether a command is available, i.e., whether it can be executed by the next engine(s). |
|
public |
isMetaTagSupported(metaTag: function): boolean Check if there is a compiler engine handling the meta tag |
|
public |
receive() |
|
public |
Forward the list of commands to the next engine in the pipeline. |
Public Constructors
public constructor() source
Public Methods
public allocateQubit(dirty: boolean): Qureg source
Return a new qubit as a list containing 1 qubit object (quantum register of size 1).
Allocates a new qubit by getting a (new) qubit id from the MainEngine, creating the qubit object, and then sending an AllocateQubit command down the pipeline. If dirty=true, the fresh qubit can be replaced by a pre-allocated one (in an unknown, dirty, initial state). Dirty qubits must be returned to their initial states before they are deallocated / freed.
All allocated qubits are added to the MainEngine's set of active qubits as weak references. This allows proper clean-up at the end of the JavaScript program (using atexit), deallocating all qubits which are still alive. Qubit ids of dirty qubits are registered in MainEngine's dirty_qubits set.
Params:
Name | Type | Attribute | Description |
dirty | boolean | If true, indicates that the allocated qubit may be dirty (i.e., in an arbitrary initial state). |
public allocateQureg(n: number): Qureg source
Allocate n qubits and return them as a quantum register, which is a list of qubit objects.
Params:
Name | Type | Attribute | Description |
n | number | Number of qubits to allocate |
public deallocateQubit(qubit: BasicQubit) source
Deallocate a qubit (and sends the deallocation command down the pipeline). If the qubit was allocated as a dirty qubit, add DirtyQubitTag() to Deallocate command.
Params:
Name | Type | Attribute | Description |
qubit | BasicQubit | Qubit to deallocate. |
Throw:
Qubit already deallocated. Caller likely has a bug. |
public isAvailable(cmd: Command): boolean source
Default implementation of isAvailable: Ask the next engine whether a command is available, i.e., whether it can be executed by the next engine(s).
Params:
Name | Type | Attribute | Description |
cmd | Command | Command for which to check availability. |
Throw:
If is_last_engine is true but isAvailable is not implemented. |
public isMetaTagSupported(metaTag: function): boolean source
Check if there is a compiler engine handling the meta tag
Params:
Name | Type | Attribute | Description |
metaTag | function | Meta tag class for which to check support |
Return:
boolean | true if one of the further compiler engines is a meta tag handler, i.e., engine.is_meta_tag_handler(meta_tag) returns true. |