Mapomatic - Automatic mapping of compiled circuits to low-noise sub-graphs

Overview

mapomatic

Automatic mapping of compiled circuits to low-noise sub-graphs

Overview

One of the main painpoints in executing circuits on IBM Quantum hardware is finding the best qubit mapping. For a given circuit, one typically tries to pick the best initial_layout for a given target system, and then SWAP maps using that set of qubits as the starting point. However there are a couple of issues with that execution model. First, an initial_layout seletected, for example with respect to the noise characteristics of the system, need not be optimal for the SWAP mapping. In practice this leads to either low-noise layouts with extra SWAP gates inserted in the circuit, or optimally SWAP mapped circuits on (possibly) lousy qubits. Second, there is no way to know if the system you targeted in the compilation is actually the best one to execute the compiled circuit on. With 20+ quantum systems, it is hard to determine which device is actually ideal for a given problem.

mapomatic tries to tackle these issues in a different way. mapomatic is a post-compilation routine that finds the best low noise sub-graph on which to run a circuit given one or more quantum systems as target devices. Once compiled, a circuit has been rewritten so that its two-qubit gate structure matches that of a given sub-graph on the target system. mapomatic then searches for matching sub-graphs using the VF2 mapper in Qiskit (retworkx actually), and uses a heuristic to rank them based on error rates determined by the current calibration data. That is to say that given a single target system, mapomatic will return the best set of qubits on which to execute the compiled circuit. Or, given a list of systems, it will find the best system and set of qubits on which to run your circuit. Given the current size of quantum hardware, and the excellent performance of the VF2 mapper, this whole process is actually very fast.

Usage

To begin we first import what we need and load our IBM Quantum account.

import numpy as np
from qiskit import *
import mapomatic as mm

IBMQ.load_account()

Second we will select a provider that has one or more systems of interest in it:

provider = IBMQ.get_provider(group='deployed')

We then go through the usual step of making a circuit and calling transpile on a given backend:

qc = QuantumCircuit(5)
qc.h(0)
qc.cx(0,1)
qc.cx(0,2)
qc.cx(0,3)
qc.cx(0,4)
qc.measure_all()

Here we use optimization_level=3 as it is the best overall. It is also not noise-aware though, and thus can select lousy qubits on which to do a good SWAP mapping

trans_qc = transpile(qc, provider.get_backend('ibm_auckland'),optimization_level=3)

Now, a call to transpile inflates the circuit to the number of qubits in the target system. For small problems like the example here, this prevents us from finding the smaller sub-graphs. Thus we need to deflate the circuit down to just the number of active qubits:

small_qc = mm.deflate_circuit(trans_qc)

This deflated circuit, along with one or more backends can now be used to find the ideal system and mapping. Here we will look over all systems in the provider:

backends = provider.backends()

mm.best_mapping(small_qc, backends)

that returns a tuple with the target layout, system, and the computed error score:

([2, 1, 3, 5, 8], 'ibm_auckland', 0.09518597703355036)

You can then use the best layout in a new call to transpile which will then do the desired mapping for you. Alternatively, we can ask for the best mapping on all systems, yielding a list sorted in order from best to worse:

mm.best_mapping(small_qc, backends, successors=True)
[([2, 1, 3, 5, 8], 'ibm_auckland', 0.09518597703355036),
 ([7, 10, 4, 1, 0], 'ibm_hanoi', 0.11217956761629977),
 ([5, 6, 3, 1, 2], 'ibm_lagos', 0.1123755285308975),
 ([7, 6, 10, 12, 15], 'ibmq_mumbai', 0.13708593236124922),
 ([3, 2, 5, 8, 9], 'ibmq_montreal', 0.13762962991865924),
 ([2, 1, 3, 5, 8], 'ibm_cairo', 0.1423752001642351),
 ([1, 2, 3, 5, 6], 'ibmq_casablanca', 0.15623594190953083),
 ([4, 3, 5, 6, 7], 'ibmq_brooklyn', 0.16468576058762707),
 ([7, 6, 10, 12, 15], 'ibmq_guadalupe', 0.17186581811649904),
 ([5, 3, 8, 11, 14], 'ibmq_toronto', 0.1735555283027388),
 ([5, 4, 3, 1, 0], 'ibmq_jakarta', 0.1792325518776976),
 ([2, 3, 1, 0, 14], 'ibm_washington', 0.2078576175452339),
 ([1, 0, 2, 3, 4], 'ibmq_bogota', 0.23973220166838316),
 ([1, 2, 3, 5, 6], 'ibm_perth', 0.31268969778002176),
 ([3, 4, 2, 1, 0], 'ibmq_manila', 0.3182338194159915),
 ([1, 0, 2, 3, 4], 'ibmq_santiago', 1.0)]

Because of the stochastic nature of the SWAP mapping, the optimal sub-graph may change over repeated compilations.

Getting optimal results

Because the SWAP mappers in Qiskit are stochastic, the number of inserted SWAP gates can vary with each run. The spread in this number can be quite large, and can impact the performance of your circuit. It is thus beneficial to transpile many instances of a circuit and take the best one. For example:

trans_qc_list = transpile([qc]*20, provider.get_backend('ibm_auckland'), optimization_level=3)

best_cx_count = [circ.count_ops()['cx'] for circ in trans_qc_list]
best_cx_count
[10, 13, 10, 7, 7, 10, 10, 7, 10, 7, 10, 10, 10, 10, 5, 7, 6, 13, 7, 10]

We obviously want the one with minimum CNOT gates here:

best_idx = np.where(best_cx_count == np.min(best_cx_count))[0][0]
best_qc = trans_qc_list[best_idx] 

We can then use this best mapped circuit to find the ideal qubit candidates via mapomatic.

best_small_qc = mm.deflate_circuit(best_qc)
mm.best_mapping(best_small_qc, backends, successors=True)
[([11, 13, 14, 16, 19], 'ibm_auckland', 0.07634155667667142),
 ([2, 0, 1, 4, 7], 'ibm_hanoi', 0.0799012562006044),
 ([4, 6, 5, 3, 1], 'ibm_lagos', 0.09374259142721897),
 ([10, 15, 12, 13, 14], 'ibm_cairo', 0.0938958618334792),
 ([5, 9, 8, 11, 14], 'ibmq_montreal', 0.09663069814643488),
 ([10, 6, 7, 4, 1], 'ibmq_mumbai', 0.10253149958591112),
 ([10, 15, 12, 13, 14], 'ibmq_guadalupe', 0.11075230351892806),
 ([11, 5, 4, 3, 2], 'ibmq_brooklyn', 0.13179514610612808),
 ([0, 2, 1, 3, 5], 'ibm_perth', 0.13309987649094324),
 ([4, 6, 5, 3, 1], 'ibmq_casablanca', 0.13570907147053013),
 ([2, 0, 1, 3, 5], 'ibmq_jakarta', 0.14449169384159954),
 ([5, 9, 8, 11, 14], 'ibmq_toronto', 0.1495199193756318),
 ([2, 0, 1, 3, 4], 'ibmq_quito', 0.16858894163955718),
 ([0, 2, 1, 3, 4], 'ibmq_belem', 0.1783430267967986),
 ([0, 2, 1, 3, 4], 'ibmq_lima', 0.20380730100751476),
 ([23, 25, 24, 34, 43], 'ibm_washington', 0.23527393065514557)]
Owner
Qiskit Partners
Qiskit Partners
Rubrix is a free and open-source tool for exploring and iterating on data for artificial intelligence projects.

Open-source tool for exploring, labeling, and monitoring data for AI projects

Recognai 1.5k Jan 07, 2023
PanGraphViewer -- show panenome graph in an easy way

PanGraphViewer -- show panenome graph in an easy way Table of Contents Versions and dependences Desktop-based panGraphViewer Library installation for

16 Dec 17, 2022
An open-source tool for visual and modular block programing in python

PyFlow PyFlow is an open-source tool for modular visual programing in python ! Although for now the tool is in Beta and features are coming in bit by

1.1k Jan 06, 2023
https://there.oughta.be/a/macro-keyboard

inkkeys Details and instructions can be found on https://there.oughta.be/a/macro-keyboard In contrast to most of my other projects, I decided to put t

Sebastian Staacks 209 Dec 21, 2022
University of Missouri - Kansas City: CS451R: Capstone

CS451RC University of Missouri - Kansas City: CS451R: Capstone Installation cd git clone https://github.com/ala2q6/CS451RC.git cd CS451RC pip3 instal

Alex Arbuckle 1 Nov 17, 2021
Displaying plot of death rates from past years in Poland. Data source from these years is in readme

Average-Death-Rate Displaying plot of death rates from past years in Poland The goal collect the data from a CSV file count the ADR (Average Death Rat

Oliwier Szymański 0 Sep 12, 2021
Simple spectra visualization tool for astronomers

SpecViewer A simple visualization tool for astronomers. Dependencies Python = 3.7.4 PyQt5 = 5.15.4 pyqtgraph == 0.10.0 numpy = 1.19.4 How to use py

5 Oct 07, 2021
This is a sorting visualizer made with Tkinter.

Sorting-Visualizer This is a sorting visualizer made with Tkinter. Make sure you've installed tkinter in your system to use this visualizer pip instal

Vishal Choubey 7 Jul 06, 2022
Flexitext is a Python library that makes it easier to draw text with multiple styles in Matplotlib

Flexitext is a Python library that makes it easier to draw text with multiple styles in Matplotlib

Tomás Capretto 93 Dec 28, 2022
Visualization Website by using Dash and Heroku

Visualization Website by using Dash and Heroku You can visit the website https://payroll-expense-analysis.herokuapp.com/ In this project, I am interes

YF Liu 1 Jan 14, 2022
Curvipy - The Python package for visualizing curves and linear transformations in a super simple way

Curvipy - The Python package for visualizing curves and linear transformations in a super simple way

Dylan Tintenfich 55 Dec 28, 2022
Jupyter Notebook extension leveraging pandas DataFrames by integrating DataTables and ChartJS.

Jupyter DataTables Jupyter Notebook extension to leverage pandas DataFrames by integrating DataTables JS. About Data scientists and in fact many devel

Marek Čermák 142 Dec 28, 2022
DrawBot lets you draw images taken from the internet on Skribbl.io, Gartic Phone and Paint

DrawBot You don't speak french? No worries, english translation is over here. C'est quoi ? DrawBot est un logiciel codé par V2F qui va prendre possess

V2F 205 Jan 01, 2023
A high performance implementation of HDBSCAN clustering. http://hdbscan.readthedocs.io/en/latest/

HDBSCAN Now a part of scikit-learn-contrib HDBSCAN - Hierarchical Density-Based Spatial Clustering of Applications with Noise. Performs DBSCAN over va

Leland McInnes 91 Dec 29, 2022
又一个云探针

ServerStatus-Murasame 感谢ServerStatus-Hotaru,又一个云探针诞生了(大雾 本项目在ServerStatus-Hotaru的基础上使用fastapi重构了服务端,部分修改了客户端与前端 项目还在非常原始的阶段,可能存在严重的问题 演示站:https://stat

6 Oct 19, 2021
python partial dependence plot toolbox

PDPbox python partial dependence plot toolbox Motivation This repository is inspired by ICEbox. The goal is to visualize the impact of certain feature

Li Jiangchun 723 Jan 07, 2023
An interactive GUI for WhiteboxTools in a Jupyter-based environment

whiteboxgui An interactive GUI for WhiteboxTools in a Jupyter-based environment GitHub repo: https://github.com/giswqs/whiteboxgui Documentation: http

Qiusheng Wu 105 Dec 15, 2022
Epagneul is a tool to visualize and investigate windows event logs

epagneul Epagneul is a tool to visualize and investigate windows event logs. Dep

jurelou 190 Dec 13, 2022
Personal IMDB Graphs with Bokeh

Personal IMDB Graphs with Bokeh Do you like watching movies and also rate all of them in IMDB? Would you like to look at your IMDB stats based on your

2 Dec 15, 2021
Param: Make your Python code clearer and more reliable by declaring Parameters

Param Param is a library providing Parameters: Python attributes extended to have features such as type and range checking, dynamically generated valu

HoloViz 304 Jan 07, 2023