Home Reference Source
import LinearMapper from 'projectq/src/cengines/linearmapper.js'
public class | source

LinearMapper

Extends:

BasicEngineBasicMapperEngine → LinearMapper

Static Method Summary

Static Public Methods
public static

returnNewMapping(num_qubits: number, cyclic: boolean, currently_allocated_ids: Set<Number>, stored_commands: Command[], current_mapping: Object): Object

Static Private Methods
private static

_processTwoQubitGate(num_qubits: number, cyclic: boolean, qubit0: number, qubit1: number, active_qubits: Set<Number>, segments: Array, neighbour_ids: Object)

Processes a two qubit gate.

private static

_returnNewMappingFromSegments(num_qubits: number, segments: Array, allocated_qubits: Object, current_mapping: Object): *

Constructor Summary

Public Constructor
public

constructor(num_qubits: number, cyclic: boolean, storage: number)

Member Summary

Public Members
public
public

cyclic: *

public
public
public
public
public

storage: *

Private Members
private
private

Method Summary

Public Methods
public

isAvailable(cmd: *): *

public

receive(command_list: Command[])

Receives a command list and, for each command, stores it until we do a mapping (FlushGate or Cache of stored commands is full).

Private Methods
private

_oddEvenTranspositionSortSwaps(old_mapping: Object, new_mapping: Object): Array

Returns the swap operation for an odd-even transposition sort.

private

_run()

Creates a new mapping and executes possible gates.

private

Sends the stored commands possible without changing the mapping.

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.

From class BasicMapperEngine
public get
public set
private
public

Send this Command using the mapped qubit ids of this.current_mapping.

Static Public Methods

public static returnNewMapping(num_qubits: number, cyclic: boolean, currently_allocated_ids: Set<Number>, stored_commands: Command[], current_mapping: Object): Object source

Params:

NameTypeAttributeDescription
num_qubits number

Total number of qubits in the linear chain

cyclic boolean

If linear chain is a cycle.

currently_allocated_ids Set<Number>

Logical qubit ids for which the Allocate gate has already been processed and sent to the next engine but which are not yet deallocated and hence need to be included in the new mapping.

stored_commands Command[]

Future commands which should be applied next.

current_mapping Object

A current mapping as a dict. key is logical qubit id, value is placement id. If there are different possible maps, this current mapping is used to minimize the swaps to go to the new mapping by a heuristic.

Return:

Object

A new mapping as a dict. key is logical qubit id, value is placement id

Static Private Methods

private static _processTwoQubitGate(num_qubits: number, cyclic: boolean, qubit0: number, qubit1: number, active_qubits: Set<Number>, segments: Array, neighbour_ids: Object) source

Processes a two qubit gate.

It either removes the two qubits from active_qubits if the gate is not possible or updates the segements such that the gate is possible.

Params:

NameTypeAttributeDescription
num_qubits number

Total number of qubits in the chain

cyclic boolean

If linear chain is a cycle

qubit0 number

qubit.id of one of the qubits

qubit1 number

qubit.id of the other qubit

active_qubits Set<Number>

contains all qubit ids which for which gates can be applied in this cycle before the swaps

segments Array

List of segments. A segment is a list of neighbouring qubits.

neighbour_ids Object

Key: qubit.id Value: qubit.id of neighbours

private static _returnNewMappingFromSegments(num_qubits: number, segments: Array, allocated_qubits: Object, current_mapping: Object): * source

Params:

NameTypeAttributeDescription
num_qubits number

Total number of qubits in the linear chain

segments Array

List of segments. A segment is a list of qubit ids which should be nearest neighbour in the new map. Individual qubits are in allocated_qubits but not in any segment

allocated_qubits Object

A set of all qubit ids which need to be present in the new map

current_mapping Object

A current mapping as a dict. key is logical qubit id, value is placement id. If there are different possible maps, this current mapping is used to minimize the swaps to go to the new mapping by a heuristic.

Return:

*

A new mapping as a dict. key is logical qubit id, value is placement id

Public Constructors

public constructor(num_qubits: number, cyclic: boolean, storage: number) source

Override:

BasicMapperEngine#constructor

Params:

NameTypeAttributeDescription
num_qubits number

Number of physical qubits in the linear chain

cyclic boolean

If 1D chain is a cycle. Default is false.

storage number

Number of gates to temporarily store, default is 1000

Public Members

public currentMapping: {} source

Override:

BasicMapperEngine#currentMapping

public cyclic: * source

public depth_of_swaps: {} source

public num_mappings: number source

public num_of_swaps_per_mapping: {} source

public num_qubits: * source

public storage: * source

Private Members

private _currently_allocated_ids: * source

private _stored_commands: *[] source

Public Methods

public isAvailable(cmd: *): * 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).

Override:

BasicEngine#isAvailable

Params:

NameTypeAttributeDescription
cmd *

Return:

*

public receive(command_list: Command[]) source

Receives a command list and, for each command, stores it until we do a mapping (FlushGate or Cache of stored commands is full).

Override:

BasicEngine#receive

Params:

NameTypeAttributeDescription
command_list Command[]

list of commands to receive.

Private Methods

private _oddEvenTranspositionSortSwaps(old_mapping: Object, new_mapping: Object): Array source

Returns the swap operation for an odd-even transposition sort.

See https://en.wikipedia.org/wiki/Odd-even_sort for more info.

Params:

NameTypeAttributeDescription
old_mapping Object

keys are logical ids and values are mapped qubit ids

new_mapping Object

dict: keys are logical ids and values are mapped qubit ids

Return:

Array

List of tuples. Each tuple is a swap operation which needs to be applied. Tuple contains the two MappedQubit ids for the Swap.

private _run() source

Creates a new mapping and executes possible gates.

It first allocates all 0, ..., this.num_qubits-1 mapped qubit ids, if they are not already used because we might need them all for the swaps. Then it creates a new map, swaps all the qubits to the new map, executes all possible gates, and finally deallocates mapped qubit ids which don't store any information.

private _sendPossibleCommands() source

Sends the stored commands possible without changing the mapping.

Note: this.currentMapping must exist already