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
Automatically Visualize any dataset, any size with a single line of code. Created by Ram Seshadri. Collaborators Welcome. Permission Granted upon Request.

AutoViz Automatically Visualize any dataset, any size with a single line of code. AutoViz performs automatic visualization of any dataset with one lin

AutoViz and Auto_ViML 1k Jan 02, 2023
ICS-Visualizer is an interactive Industrial Control Systems (ICS) network graph that contains up-to-date ICS metadata

ICS-Visualizer is an interactive Industrial Control Systems (ICS) network graph that contains up-to-date ICS metadata (Name, company, port, user manua

QeeqBox 2 Dec 13, 2021
Write python locally, execute SQL in your data warehouse

RasgoQL Write python locally, execute SQL in your data warehouse ≪ Read the Docs · Join Our Slack » RasgoQL is a Python package that enables you to ea

Rasgo 265 Nov 21, 2022
Keir&'s Visualizing Data on Life Expectancy

Keir's Visualizing Data on Life Expectancy Below is information on life expectancy in the United States from 1900-2017. You will also find information

9 Jun 06, 2022
a plottling library for python, based on D3

Hello August 2013 Hello! Maybe you're looking for a nice Python interface to build interactive, javascript based plots that look as nice as all those

Mike Dewar 1.4k Dec 28, 2022
A script written in Python that generate output custom color (HEX or RGB input to x1b hexadecimal)

ColorShell ─ 1.5 Planned for v2: setup.sh for setup alias This script converts HEX and RGB code to x1b x1b is code for colorize outputs, works on ou

Riley 4 Oct 31, 2021
Statistics and Visualization of acceptance rate, main keyword of CVPR 2021 accepted papers for the main Computer Vision conference (CVPR)

Statistics and Visualization of acceptance rate, main keyword of CVPR 2021 accepted papers for the main Computer Vision conference (CVPR)

Hoseong Lee 78 Aug 23, 2022
flask extension for integration with the awesome pydantic package

Flask-Pydantic Flask extension for integration of the awesome pydantic package with Flask. Installation python3 -m pip install Flask-Pydantic Basics v

249 Jan 06, 2023
Visualize tensors in a plain Python REPL using Sparklines

Visualize tensors in a plain Python REPL using Sparklines

Shawn Presser 43 Sep 03, 2022
Rockstar - Makes you a Rockstar C++ Programmer in 2 minutes

Rockstar Rockstar is one amazing library, which will make you a Rockstar Programmer in just 2 minutes. In last decade, people learned C++ in 21 days.

4k Jan 05, 2023
This is a place where I'm playing around with pandas to analyze data in a csv/excel file.

pandas-csv-excel-analysis This is a place where I'm playing around with pandas to analyze data in a csv/excel file. 0-start A very simple cheat sheet

Chuqin 3 Oct 05, 2022
trade bot connected to binance API/ websocket.,, include dashboard in plotly dash to visualize trades and balances

Crypto trade bot 1. What it is Trading bot connected to Binance API. This project made for fun. So ... Do not use to trade live before you have backte

G 3 Oct 07, 2022
Example Code Notebooks for Data Visualization in Python

This repository contains sample code scripts for creating awesome data visualizations from scratch using different python libraries (such as matplotli

Javed Ali 27 Jan 04, 2023
Open-questions - Open questions for Bellingcat technical contributors

Open questions for Bellingcat technical contributors These are difficult, long-term projects that would contribute to open source investigations at Be

Bellingcat 234 Dec 31, 2022
Fast visualization of radar_scenes based on oleschum/radar_scenes

RadarScenes Tools About This python package provides fast visualization for the RadarScenes dataset. The Open GL based visualizer is smoother than ole

Henrik Söderlund 2 Dec 09, 2021
Shaded 😎 quantile plots

shadyquant 😎 This python package allows you to quantile and plot lines where you have multiple samples, typically for visualizing uncertainty. Your d

Mehrad Ansari 13 Sep 29, 2022
cqMore is a CadQuery plugin based on CadQuery 2.1.

cqMore (under construction) cqMore is a CadQuery plugin based on CadQuery 2.1. Installation Please use conda to install CadQuery and its dependencies

Justin Lin 36 Dec 21, 2022
Python library that makes it easy for data scientists to create charts.

Chartify Chartify is a Python library that makes it easy for data scientists to create charts. Why use Chartify? Consistent input data format: Spend l

Spotify 3.2k Jan 04, 2023
Altair extension for saving charts in a variety of formats.

Altair Saver This packge provides extensions to Altair for saving charts to a variety of output types. Supported output formats are: .json/.vl.json: V

Altair 85 Dec 09, 2022
Minimalistic tool to visualize how the routes to a given target domain change over time, feat. Python 3.10 & mermaid.js

Minimalistic tool to visualize how the routes to a given target domain change over time, feat. Python 3.10 & mermaid.js

Péter Ferenc Gyarmati 1 Jan 17, 2022