Home Reference Source
import {BasicEngine} from 'projectq/src/cengines/basics.js'
public class | source

BasicEngine

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

Return a new qubit as a list containing 1 qubit object (quantum register of size 1).

public

Allocate n qubits and return them as a quantum register, which is a list of qubit objects.

public

Deallocate a qubit (and sends the deallocation command down the pipeline).

public

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

Check if there is a compiler engine handling the meta tag

public
public

send(commandList: Command[])

Forward the list of commands to the next engine in the pipeline.

Public Constructors

public constructor() source

Public Members

public isLastEngine: boolean 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:

NameTypeAttributeDescription
dirty boolean

If true, indicates that the allocated qubit may be dirty (i.e., in an arbitrary initial state).

Return:

Qureg

Qureg of length 1, where the first entry is the allocated qubit.

public allocateQureg(n: number): Qureg source

Allocate n qubits and return them as a quantum register, which is a list of qubit objects.

Params:

NameTypeAttributeDescription
n number

Number of qubits to allocate

Return:

Qureg

Qureg of length n, a list of n newly allocated qubits.

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:

NameTypeAttributeDescription
qubit BasicQubit

Qubit to deallocate.

Throw:

Error

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:

NameTypeAttributeDescription
cmd Command

Command for which to check availability.

Return:

boolean

true if the command can be executed.

Throw:

LastEngineError

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:

NameTypeAttributeDescription
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.

public receive() source

public send(commandList: Command[]) source

Forward the list of commands to the next engine in the pipeline.

Params:

NameTypeAttributeDescription
commandList Command[]