From 182756f869c15cd0cb24c1784249aae00ba389ae Mon Sep 17 00:00:00 2001 From: Sarah Schneider Date: Tue, 21 Mar 2023 16:12:05 +0100 Subject: [PATCH 1/7] Added Ipynb for Limiting Search Space --- docs/source/LimitingSearchSpace.ipynb | 102 ++++++++++++++++++++++++++ 1 file changed, 102 insertions(+) create mode 100644 docs/source/LimitingSearchSpace.ipynb diff --git a/docs/source/LimitingSearchSpace.ipynb b/docs/source/LimitingSearchSpace.ipynb new file mode 100644 index 000000000..31590485e --- /dev/null +++ b/docs/source/LimitingSearchSpace.ipynb @@ -0,0 +1,102 @@ +{ + "cells": [ + { + "attachments": {}, + "cell_type": "markdown", + "metadata": {}, + "source": [ + "# Limiting the Search Space\n", + "\n", + "Many quantum computing architectures limit the pairs of qubits that two-qubit operations can be applied to.\n", + "This is commonly described by a device's *coupling map*.\n", + "To further speed up the mapping process, there are several ways to limit the pairs of qubits that need to be considered, in ways of limiting the whole search space for the exact mapping problem.\n", + "\n", + "Consider the following circuit." + ] + }, + { + "cell_type": "code", + "execution_count": 1, + "metadata": {}, + "outputs": [], + "source": [ + "from qiskit import QuantumCircuit\n", + "\n", + "qc = QuantumCircuit(4)\n", + "qc.h(0)\n", + "qc.cx(0, 1)\n", + "qc.cx(0, 2)\n", + "qc.cx(0, 3)\n", + "\n", + "qc.barrier()\n", + "\n", + "qc.t(0)\n", + "qc.t(1)\n", + "qc.t(2)\n", + "qc.t(3)\n", + "\n", + "qc.barrier()\n", + "\n", + "qc.cx(0, 3)\n", + "qc.cx(0, 2)\n", + "qc.cx(0, 1)\n", + "\n", + "qc.measure_all()\n", + "\n", + "qc.draw(output=\"mpl\")" + ] + }, + { + "attachments": {}, + "cell_type": "markdown", + "metadata": {}, + "source": [ + "Now assume this circuit shall be mapped to a $4$-qubit architecture defined by the following coupling map:\n", + "\n", + "![Linear 4-qubit Architecture](images/linear_arch.svg)\n", + "\n", + "In *QMAP* this architecture can be manually defined as described in the Mapping section.\n", + "\n", + "Instead we look now at the cayley graph, especially the reduced cayley graph that can be generated from the series of swaps possible on an architecture.\n", + "\n", + "![Reduced Cayley graph](images/cayley.png)\n", + "\n", + "Instead of considering all possible SWAP-configurations in the Cayley, only those that are not greyed out need to be considered. \n", + "\n", + "Using the search space limitations is as simple as:" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [ + "qc_mapped, res = qmap.compile(qc, arch, method=\"exact\", post_mapping_optimizations=False, swap_reduction=\"coupling_limit\")\n", + "\n", + "qc_mapped.draw(output=\"mpl\")" + ] + } + ], + "metadata": { + "kernelspec": { + "display_name": "Python 3", + "language": "python", + "name": "python3" + }, + "language_info": { + "codemirror_mode": { + "name": "ipython", + "version": 3 + }, + "file_extension": ".py", + "mimetype": "text/x-python", + "name": "python", + "nbconvert_exporter": "python", + "pygments_lexer": "ipython3", + "version": "3.10.4" + } + }, + "nbformat": 4, + "nbformat_minor": 0 +} From fd8cefc3c1dcf0f01b09eb7b18a7374f26b2659a Mon Sep 17 00:00:00 2001 From: Sarah Schneider Date: Sat, 25 Mar 2023 08:45:05 +0100 Subject: [PATCH 2/7] Added Ipynb for Limiting Search Space --- docs/source/LimitingSearchSpace.ipynb | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/docs/source/LimitingSearchSpace.ipynb b/docs/source/LimitingSearchSpace.ipynb index 31590485e..197dd030a 100644 --- a/docs/source/LimitingSearchSpace.ipynb +++ b/docs/source/LimitingSearchSpace.ipynb @@ -76,6 +76,16 @@ "\n", "qc_mapped.draw(output=\"mpl\")" ] + }, + { + "attachments": {}, + "cell_type": "markdown", + "metadata": {}, + "source": [ + "This limits the number of SWAPs based on the selected subgraph of the architecture.\n", + "\n", + "Check out the [reference documentation](library/Mapping.rst) for more information." + ] } ], "metadata": { From b9ec2b8ce84daa890062fa934226bcbdfbf13571 Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Sat, 25 Mar 2023 07:46:43 +0000 Subject: [PATCH 3/7] =?UTF-8?q?=F0=9F=8E=A8=20pre-commit=20fixes?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- docs/source/LimitingSearchSpace.ipynb | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/docs/source/LimitingSearchSpace.ipynb b/docs/source/LimitingSearchSpace.ipynb index 197dd030a..0a6b0468a 100644 --- a/docs/source/LimitingSearchSpace.ipynb +++ b/docs/source/LimitingSearchSpace.ipynb @@ -16,7 +16,7 @@ }, { "cell_type": "code", - "execution_count": 1, + "execution_count": null, "metadata": {}, "outputs": [], "source": [ @@ -72,7 +72,9 @@ "metadata": {}, "outputs": [], "source": [ - "qc_mapped, res = qmap.compile(qc, arch, method=\"exact\", post_mapping_optimizations=False, swap_reduction=\"coupling_limit\")\n", + "qc_mapped, res = qmap.compile(\n", + " qc, arch, method=\"exact\", post_mapping_optimizations=False, swap_reduction=\"coupling_limit\"\n", + ")\n", "\n", "qc_mapped.draw(output=\"mpl\")" ] @@ -103,8 +105,7 @@ "mimetype": "text/x-python", "name": "python", "nbconvert_exporter": "python", - "pygments_lexer": "ipython3", - "version": "3.10.4" + "pygments_lexer": "ipython3" } }, "nbformat": 4, From 27efb4f6adb547da62637a71595aad8428cb590d Mon Sep 17 00:00:00 2001 From: Sarah Schneider Date: Mon, 27 Mar 2023 11:45:26 +0200 Subject: [PATCH 4/7] Fixed missing import --- docs/source/LimitingSearchSpace.ipynb | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/docs/source/LimitingSearchSpace.ipynb b/docs/source/LimitingSearchSpace.ipynb index 0a6b0468a..0966454a7 100644 --- a/docs/source/LimitingSearchSpace.ipynb +++ b/docs/source/LimitingSearchSpace.ipynb @@ -72,6 +72,19 @@ "metadata": {}, "outputs": [], "source": [ + "from mqt import qmap\n", + "\n", + "arch = qmap.Architecture(\n", + " 4,\n", + " {\n", + " (0, 1),\n", + " (1, 0),\n", + " (1, 2),\n", + " (2, 1),\n", + " (2, 3),\n", + " (3, 2),\n", + " },\n", + ")" "qc_mapped, res = qmap.compile(\n", " qc, arch, method=\"exact\", post_mapping_optimizations=False, swap_reduction=\"coupling_limit\"\n", ")\n", From d6522fca2b4cfbeb005f8c55383f922b2f93606e Mon Sep 17 00:00:00 2001 From: Sarah Schneider Date: Mon, 27 Mar 2023 12:49:59 +0200 Subject: [PATCH 5/7] Fixed missing comma --- docs/source/LimitingSearchSpace.ipynb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/source/LimitingSearchSpace.ipynb b/docs/source/LimitingSearchSpace.ipynb index 0966454a7..46f6921be 100644 --- a/docs/source/LimitingSearchSpace.ipynb +++ b/docs/source/LimitingSearchSpace.ipynb @@ -84,7 +84,7 @@ " (2, 3),\n", " (3, 2),\n", " },\n", - ")" + ")", "qc_mapped, res = qmap.compile(\n", " qc, arch, method=\"exact\", post_mapping_optimizations=False, swap_reduction=\"coupling_limit\"\n", ")\n", From 269d44fc96b10d2b12cf5dc4aa598c0ca0c273d5 Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Mon, 27 Mar 2023 10:50:28 +0000 Subject: [PATCH 6/7] =?UTF-8?q?=F0=9F=8E=A8=20pre-commit=20fixes?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- docs/source/LimitingSearchSpace.ipynb | 27 +++++++++++++-------------- 1 file changed, 13 insertions(+), 14 deletions(-) diff --git a/docs/source/LimitingSearchSpace.ipynb b/docs/source/LimitingSearchSpace.ipynb index 46f6921be..68e9afaa0 100644 --- a/docs/source/LimitingSearchSpace.ipynb +++ b/docs/source/LimitingSearchSpace.ipynb @@ -72,20 +72,19 @@ "metadata": {}, "outputs": [], "source": [ - "from mqt import qmap\n", - "\n", - "arch = qmap.Architecture(\n", - " 4,\n", - " {\n", - " (0, 1),\n", - " (1, 0),\n", - " (1, 2),\n", - " (2, 1),\n", - " (2, 3),\n", - " (3, 2),\n", - " },\n", - ")", - "qc_mapped, res = qmap.compile(\n", + "from mqt import qmap\n", + "\n", + "arch = qmap.Architecture(\n", + " 4,\n", + " {\n", + " (0, 1),\n", + " (1, 0),\n", + " (1, 2),\n", + " (2, 1),\n", + " (2, 3),\n", + " (3, 2),\n", + " },\n", + ")qc_mapped, res = qmap.compile(\n", " qc, arch, method=\"exact\", post_mapping_optimizations=False, swap_reduction=\"coupling_limit\"\n", ")\n", "\n", From be1c98bfecff8b5522ab5181f469eb366b049e51 Mon Sep 17 00:00:00 2001 From: Sarah Schneider Date: Mon, 27 Mar 2023 13:13:40 +0200 Subject: [PATCH 7/7] Fixed missing newline --- docs/source/LimitingSearchSpace.ipynb | 26 +++++++++++++------------- 1 file changed, 13 insertions(+), 13 deletions(-) diff --git a/docs/source/LimitingSearchSpace.ipynb b/docs/source/LimitingSearchSpace.ipynb index 46f6921be..94b0750ed 100644 --- a/docs/source/LimitingSearchSpace.ipynb +++ b/docs/source/LimitingSearchSpace.ipynb @@ -72,19 +72,19 @@ "metadata": {}, "outputs": [], "source": [ - "from mqt import qmap\n", - "\n", - "arch = qmap.Architecture(\n", - " 4,\n", - " {\n", - " (0, 1),\n", - " (1, 0),\n", - " (1, 2),\n", - " (2, 1),\n", - " (2, 3),\n", - " (3, 2),\n", - " },\n", - ")", + "from mqt import qmap\n", + "\n", + "arch = qmap.Architecture(\n", + " 4,\n", + " {\n", + " (0, 1),\n", + " (1, 0),\n", + " (1, 2),\n", + " (2, 1),\n", + " (2, 3),\n", + " (3, 2),\n", + " },\n", + ")\n", "qc_mapped, res = qmap.compile(\n", " qc, arch, method=\"exact\", post_mapping_optimizations=False, swap_reduction=\"coupling_limit\"\n", ")\n",