Home Reference Source
import {LoopEngine} from 'projectq/src/meta/loop.js'
public class | source

LoopEngine

Extends:

BasicEngine → LoopEngine

Stores all commands and, when done, executes them num times if no loop tag handler engine is available. If there is one, it adds a loop_tag to the commands and sends them on.

Constructor Summary

Public Constructor
public

Member Summary

Private Members
private
private

_cmdList: *[]

private
private
private
private

_tag: *

Method Summary

Public Methods
public

receive(commandList: Command[])

Receive (and potentially temporarily store) all commands.

public

run()

Apply the loop statements to all stored commands.

Inherited Summary

From class BasicEngine
public
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(num: number) source

Override:

BasicEngine#constructor

Params:

NameTypeAttributeDescription
num number

Number of loop iterations.

Private Members

private _allocatedQubitIDs: * source

private _cmdList: *[] source

private _deallocatedQubitIDs: * source

private _nextEnginesSupportLoopTag: boolean source

private _refsToLocalQB: {} source

private _tag: * source

Public Methods

public receive(commandList: Command[]) source

Receive (and potentially temporarily store) all commands.

Add LoopTag to all receiving commands and send to the next engine if a further engine is a LoopTag-handling engine. Otherwise store all commands (to later unroll them). Check that within the loop body, all allocated qubits have also been deallocated. If loop needs to be unrolled and ancilla qubits have been allocated within the loop body, then store a reference all these qubit ids (to change them when unrolling the loop)

Override:

BasicEngine#receive

Params:

NameTypeAttributeDescription
commandList Command[]

List of commands to store and later unroll or, if there is a LoopTag-handling engine, add the LoopTag.

public run() source

Apply the loop statements to all stored commands. Unrolls the loop if LoopTag is not supported by any of the following engines, i.e., if

Example:

is_meta_tag_supported(next_engine, LoopTag) == false