GridMapper
Extends:
Mapper to a 2-D grid graph.
Mapped qubits on the grid are numbered in row-major order. E.g. for 3 rows and 2 columns:
0 - 1
|   |
2 - 3
|   |
4 - 5
The numbers are the mapped qubit ids. The backend might number the qubits on the grid differently (e.g. not row-major), we call these backend qubit ids. If the backend qubit ids are not row-major, one can pass a dictionary translating from our row-major mapped ids to these backend ids.
Note: The algorithm sorts twice inside each column and once inside each row.
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 | 
       depth_of_swaps: {}  | 
    |
| public | 
       num_columns: *  | 
    |
| public | 
      
       Statistics  | 
    |
| public | 
      
       | 
    |
| public | 
      
       | 
    |
| public | 
       num_qubits: *  | 
    |
| public | 
       num_rows: *  | 
    |
| public | 
      
       | 
    |
| public | 
       storage: *  | 
    |
| Private Members | ||
| private | 
      
       | 
    |
| private | 
      
       | 
    |
| private | 
      
       | 
    |
| private | 
      
       Logical qubit ids for which the Allocate gate has already been processed and sent to the next engine but which are not yet deallocated:  | 
    |
| private | 
       _map_1d_to_2d: {}  | 
    |
| private | 
       _map_2d_to_1d: {} Change between 2D and 1D mappings (2D is a snake like 1D chain) Note it translates to our mapped ids in row major order and not backend ids which might be different.  | 
    |
| private | 
      
       | 
    |
| private | 
       _stored_commands: *[] Storing commands  | 
    |
Method Summary
| Public Methods | ||
| public | 
       isAvailable(cmd: *): *  | 
    |
| public | 
      
       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: Position, element1: Position, key: function(arg: Position): number): Array<number> | undefined If swapped (inplace), then return swap operation so that   | 
    |
| private | 
       _run() Creates a new mapping and executes possible gates.  | 
    |
| private | 
      
       Sends the stored commands possible without changing the mapping.  | 
    |
| private | 
       _sortWithinColumns(final_positions: Array<Position[]>, key: function(arg: Position): number): Array<number[]>  | 
    |
| private | 
       _sortWithinRows(final_positions: Array<Position[]>, key: function(arg: Position): number): Array<number[]>  | 
    |
Inherited Summary
| From class BasicEngine | ||
| public | 
      
       | 
    |
| 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.  | 
    |
| From class BasicMapperEngine | ||
| public get | 
      
       | 
    |
| public set | 
      
       | 
    |
| private | 
      
       | 
    |
| public | 
       sendCMDWithMappedIDs(cmd: Command) Send this Command using the mapped qubit ids of this.current_mapping.  | 
    |
Public Constructors
Public Members
public depth_of_swaps: {} source
public num_columns: * source
public num_of_swaps_per_mapping: {} source
public num_optimization_steps: * source
public num_qubits: * source
public num_rows: * source
Properties:
| Name | Type | Attribute | Description | 
| this.num_rows | number | Number of rows in the grid  | 
    |
| this.num_columns | number | Number of columns in the grid.  | 
    |
| this.num_qubits | number | ||
| this._mapped_ids_to_backend_ids | Object<number, number> | ||
| this._backend_ids_to_mapped_ids | Object<number, number> | 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.  | 
    |
| this._current_row_major_mapping | Object<number, number> | ||
| this.storage | number | Number of gates to temporarily store  | 
    |
| this.optimization_function | 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.  | 
    |
| this.num_optimization_steps | number | Number of different permutations to of the matching to try and minimize the cost.  | 
    |
| this.num_mappings | number | ||
| this.depth_of_swaps | Object<number, number> | ||
| this.num_of_swaps_per_mapping | Object<number, number> | 
public optimization_function: * source
public storage: * source
Private Members
private _backend_ids_to_mapped_ids: {} source
private _current_row_major_mapping: * source
private _currently_allocated_ids: * source
Logical qubit ids for which the Allocate gate has already been processed and sent to the next engine but which are not yet deallocated:
private _map_1d_to_2d: {} source
private _map_2d_to_1d: {} source
Change between 2D and 1D mappings (2D is a snake like 1D chain) Note it translates to our mapped ids in row major order and not backend ids which might be different.
private _mapped_ids_to_backend_ids: * 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#isAvailableParams:
| Name | Type | Attribute | Description | 
| 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#receiveParams:
| Name | Type | Attribute | Description | 
| 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.
public returnSwaps(old_mapping: Object, new_mapping: Object, permutation: Array<number[]>): Array<number[]> source
Returns the swap operation to change mapping
Params:
| Name | Type | Attribute | Description | 
| 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.  | 
    
Private Methods
private _compareAndSwap(element0: Position, element1: Position, key: function(arg: Position): number): Array<number> | undefined source
If swapped (inplace), then return swap operation so that key(element0) < key(element1)
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