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

GridMapper

Extends:

BasicEngineBasicMapperEngine → GridMapper

Constructor Summary

Public Constructor
public

constructor(args: {num_rows: number, num_columns: number, mapped_ids_to_backend_ids: Object, storage: number, optimization_function: function, num_optimization_steps: number})

Member Summary

Public Members
public set
public get
public
public
public
public
public
public
public
public
public

storage: *

Private Members
private
private
private
private
private
private
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 || Cache of stored commands is full).

public

Returns a new mapping of the qubits.

public

returnSwaps(old_mapping: Object, new_mapping: Object, permutation: Array<number[]>): Array<number[]>

Returns the swap operation to change mapping

Private Methods
private

_compareAndSwap(element0: *, element1: *, key: *): *

private

_run()

Creates a new mapping and executes possible gates.

private

Sends the stored commands possible without changing the mapping.

private

_sortWithinColumns(final_positions: *, key: *): *

private

_sortWithinRows(final_positions: *, key: *): *

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.

Public Constructors

public constructor(args: {num_rows: number, num_columns: number, mapped_ids_to_backend_ids: Object, storage: number, optimization_function: function, num_optimization_steps: number}) source

Override:

BasicMapperEngine#constructor

Params:

NameTypeAttributeDescription
args {num_rows: number, num_columns: number, mapped_ids_to_backend_ids: Object, storage: number, optimization_function: function, num_optimization_steps: number}

num_rows(int): Number of rows in the grid num_columns(int): Number of columns in the grid. mapped_ids_to_backend_ids(dict): Stores a mapping from mapped ids which are 0,...,this.num_qubits-1 in row-major order on the grid to the corresponding qubit ids of the backend. Key: mapped id. Value: corresponding backend id. Default is None which means backend ids are identical to mapped ids. storage: Number of gates to temporarily store optimization_function: Function which takes a list of swaps and returns a cost value. Mapper chooses a permutation which minimizes this cost. Default optimizes for circuit depth. num_optimization_steps(int): Number of different permutations to of the matching to try and minimize the cost.

Throw:

Error

if incorrect mapped_ids_to_backend_ids parameter

Public Members

public set currentMapping source

Override:

BasicMapperEngine#currentMapping

public get currentMapping: * source

Override:

BasicMapperEngine#currentMapping

public depth_of_swaps: {} source

public num_columns: * source

public num_mappings: number source

public num_of_swaps_per_mapping: {} source

public num_optimization_steps: * source

public num_qubits: * source

public num_rows: * source

public optimization_function: * source

public storage: * source

Private Members

private _backend_ids_to_mapped_ids: {} source

private _currentMapping: * source

Override:

BasicMapperEngine#_currentMapping

private _current_row_major_mapping: * source

private _currently_allocated_ids: * source

private _map_1d_to_2d: {} source

private _map_2d_to_1d: {} source

private _mapped_ids_to_backend_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 || Cache of stored commands is full).

Override:

BasicEngine#receive

Params:

NameTypeAttributeDescription
command_list Command[]

list of commands to receive.

public returnNewMapping(): Object source

Returns a new mapping of the qubits.

It goes through this._saved_commands and tries to find a mapping to apply these gates on a first come first served basis. It reuses the function of a 1D mapper and creates a mapping for a 1D linear chain and then wraps it like a snake onto the square grid.

One might create better mappings by specializing this function for a square grid.

Return:

Object

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

public returnSwaps(old_mapping: Object, new_mapping: Object, permutation: Array<number[]>): Array<number[]> source

Returns the swap operation to change mapping

Params:

NameTypeAttributeDescription
old_mapping Object

dict keys are logical ids and values are mapped qubit ids

new_mapping Object

dict keys are logical ids and values are mapped qubit ids

permutation Array<number[]>

list of int from 0, 1, ..., this.num_rows-1. It is used to permute the found perfect matchings. Default is None which keeps the original order.

Return:

Array<number[]>

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

Private Methods

private _compareAndSwap(element0: *, element1: *, key: *): * source

Params:

NameTypeAttributeDescription
element0 *
element1 *
key *

Return:

*

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._current_row_major_mapping (hence also this.currentMapping) must exist already

private _sortWithinColumns(final_positions: *, key: *): * source

Params:

NameTypeAttributeDescription
final_positions *
key *

Return:

*

private _sortWithinRows(final_positions: *, key: *): * source

Params:

NameTypeAttributeDescription
final_positions *
key *

Return:

*