{ "cells": [ { "attachments": {}, "cell_type": "markdown", "metadata": {}, "source": [ "# 比特映射\n", "\n", "[](https://mindspore-website.obs.cn-north-4.myhuaweicloud.com/notebook/r2.5.0/mindquantum/zh_cn/middle_level/mindspore_qubit_mapping.ipynb) \n", "[](https://mindspore-website.obs.cn-north-4.myhuaweicloud.com/notebook/r2.5.0/mindquantum/zh_cn/middle_level/mindspore_qubit_mapping.py) \n", "[](https://gitee.com/mindspore/docs/blob/r2.5.0/docs/mindquantum/docs/source_zh_cn/middle_level/qubit_mapping.ipynb)\n", "\n", "用户在设计量子线路时往往是根据自己的算法需求来进行设计,但是现阶段的量子芯片难以实现所有比特之间都有耦合。因此,在量子计算硬件上执行量子线路时,我们需要通过一定的算法来将量子算法中所用到的比特进行重新排列,或者引入一些 [SWAP](https://www.mindspore.cn/mindquantum/docs/zh-CN/r0.10/core/gates/mindquantum.core.gates.SWAPGate.html) 门,来将本来不能耦合的比特耦合起来。这也就是比特映射算法。\n", "\n", "在这篇教程中,我们将首先介绍构成量子芯片中的量子节点对象 [QubitNode](https://mindspore.cn/mindquantum/docs/zh-CN/r0.10/device/mindquantum.device.QubitNode.html#mindquantum.device.QubitNode) 和量子拓扑图对象 [QubitsTopology](https://mindspore.cn/mindquantum/docs/zh-CN/r0.10/device/mindquantum.device.QubitsTopology.html#mindquantum.device.QubitsTopology),然后将介绍如何利用比特映射算法来实现量子线路的编译。\n", "\n", "## Qubit Node\n", "\n", "[QubitNode](https://mindspore.cn/mindquantum/docs/zh-CN/r0.10/device/mindquantum.device.QubitNode.html#mindquantum.device.QubitNode)表示量子芯片中的比特,当前,主要包含四个属性:\n", "\n", "- qubit_id:量子比特的唯一识别码\n", "- color:在绘制拓扑结构图时,量子比特的颜色, 默认为 #000000\n", "- poi_x:在绘制拓扑结构图时,量子比特的 x 位置,默认为 0.0\n", "- poi_y:在绘制拓扑结构图时,量子比特的 y 位置,默认为 0.0\n", "\n", "下面,我们申明一个量子比特:" ] }, { "cell_type": "code", "execution_count": 1, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "qubit id: 0, with color: #121212, and position (0, 0)\n" ] } ], "source": [ "from mindquantum.device import QubitNode\n", "\n", "q0 = QubitNode(0, '#121212', 0, 0)\n", "\n", "print(f\"qubit id: {q0.qubit_id}, with color: {q0.color}, and position ({q0.poi_x}, {q0.poi_y})\")" ] }, { "attachments": {}, "cell_type": "markdown", "metadata": {}, "source": [ "量子比特之间可以通过运算符 `>>` 和 `<<` 来将两个比特连接起来,也可以同过 `>` 和 `<` 取消连接。不同方向的连接或者取消连接算符会有不同的返回值。\n", "\n", "|lhs|op|rhs|效果|返回值|\n", "| --|--|-- |-- |--|\n", "|q0 |`>>`|q1 |连接两个比特|q1|\n", "|q0 |`<<`|q1 |连接两个比特|q0|\n", "|q0 |`>`|q1 |取消连接两个比特|q1|\n", "|q0 |`<`|q1 |取消连接两个比特|q0|\n", "\n", "通过如上定义的操作,我们可以快速连接不同的比特,如:" ] }, { "cell_type": "code", "execution_count": 2, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "<mindquantum.device.topology.QubitNode at 0x7f0c83e76fa0>" ] }, "execution_count": 2, "metadata": {}, "output_type": "execute_result" } ], "source": [ "q0, q1, q2 = QubitNode(0), QubitNode(1), QubitNode(2)\n", "\n", "q0 >> q1 >> q2" ] }, { "attachments": {}, "cell_type": "markdown", "metadata": {}, "source": [ "在上述代码中 `q0 >> q1` 会将 `q0` 和 `q1` 比特连接起来,并返回 `q1` 比特,而后再通过 `>> q2` 就可以将 `q1` 和 `q2` 连接起来。" ] }, { "attachments": {}, "cell_type": "markdown", "metadata": {}, "source": [ "### QubitsTopology\n", "\n", "[QubitsTopology](https://mindspore.cn/mindquantum/docs/zh-CN/r0.10/device/mindquantum.device.QubitsTopology.html#mindquantum.device.QubitsTopology) 类是量子比特的容器,可以有效地组织和操控量子比特,例如当我们想要构建一个一维链的量子比特时,我们可以如下操作:" ] }, { "cell_type": "code", "execution_count": 3, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "<mindquantum.device.topology.QubitsTopology object at 0x7f0cd07808b0>\n" ] } ], "source": [ "from mindquantum.device import QubitsTopology, QubitNode\n", "\n", "n = 5\n", "\n", "topology = QubitsTopology([QubitNode(i, poi_x=i) for i in range(n)])\n", "print(topology)" ] }, { "attachments": {}, "cell_type": "markdown", "metadata": {}, "source": [ "MindQuantum 中自带了绘制量子比特拓扑结构图的接口,接口如下:" ] }, { "cell_type": "code", "execution_count": 4, "metadata": {}, "outputs": [ { "data": { "image/svg+xml": [ "<svg xmlns=\"http://www.w3.org/2000/svg\" width=\"264\" height=\"24.0\" xmlns:xlink=\"http://www.w3.org/1999/xlink\"><rect x=\"0\" y=\"0\" width=\"264\" height=\"24.0\" fill=\"#ffffff\" /><circle cx=\"12.0\" cy=\"12.0\" r=\"12\" fill=\"#000000\" /><text x=\"12.0\" y=\"12.0\" font-size=\"18px\" dominant-baseline=\"middle\" text-anchor=\"middle\" fill=\"#ffffff\" >0 </text><circle cx=\"72.0\" cy=\"12.0\" r=\"12\" fill=\"#000000\" /><text x=\"72.0\" y=\"12.0\" font-size=\"18px\" dominant-baseline=\"middle\" text-anchor=\"middle\" fill=\"#ffffff\" >1 </text><circle cx=\"132.0\" cy=\"12.0\" r=\"12\" fill=\"#000000\" /><text x=\"132.0\" y=\"12.0\" font-size=\"18px\" dominant-baseline=\"middle\" text-anchor=\"middle\" fill=\"#ffffff\" >2 </text><circle cx=\"192.0\" cy=\"12.0\" r=\"12\" fill=\"#000000\" /><text x=\"192.0\" y=\"12.0\" font-size=\"18px\" dominant-baseline=\"middle\" text-anchor=\"middle\" fill=\"#ffffff\" >3 </text><circle cx=\"252.0\" cy=\"12.0\" r=\"12\" fill=\"#000000\" /><text x=\"252.0\" y=\"12.0\" font-size=\"18px\" dominant-baseline=\"middle\" text-anchor=\"middle\" fill=\"#ffffff\" >4 </text></svg>" ], "text/plain": [ "<mindquantum.io.display.circuit_svg_drawer.SVGContainer at 0x7f0c83e1d370>" ] }, "execution_count": 4, "metadata": {}, "output_type": "execute_result" } ], "source": [ "from mindquantum.io.display import draw_topology\n", "\n", "draw_topology(topology)" ] }, { "attachments": {}, "cell_type": "markdown", "metadata": {}, "source": [ "由上我们可以发现,我们成功产生了 5 个量子比特,但是还没有将其连接起来,下面我们就来将其进行耦合。" ] }, { "cell_type": "code", "execution_count": 5, "metadata": {}, "outputs": [ { "data": { "image/svg+xml": [ "<svg xmlns=\"http://www.w3.org/2000/svg\" width=\"264\" height=\"24.0\" xmlns:xlink=\"http://www.w3.org/1999/xlink\"><rect x=\"0\" y=\"0\" width=\"264\" height=\"24.0\" fill=\"#ffffff\" /><line x1=\"12.0\" x2=\"72.0\" y1=\"12.0\" y2=\"12.0\" stroke=\"#ababab\" stroke-width=\"8\" /><line x1=\"12.0\" x2=\"132.0\" y1=\"12.0\" y2=\"12.0\" stroke=\"#ababab\" stroke-width=\"8\" /><line x1=\"12.0\" x2=\"192.0\" y1=\"12.0\" y2=\"12.0\" stroke=\"#ababab\" stroke-width=\"8\" /><line x1=\"12.0\" x2=\"252.0\" y1=\"12.0\" y2=\"12.0\" stroke=\"#ababab\" stroke-width=\"8\" /><circle cx=\"12.0\" cy=\"12.0\" r=\"12\" fill=\"#000000\" /><text x=\"12.0\" y=\"12.0\" font-size=\"18px\" dominant-baseline=\"middle\" text-anchor=\"middle\" fill=\"#ffffff\" >0 </text><circle cx=\"72.0\" cy=\"12.0\" r=\"12\" fill=\"#000000\" /><text x=\"72.0\" y=\"12.0\" font-size=\"18px\" dominant-baseline=\"middle\" text-anchor=\"middle\" fill=\"#ffffff\" >1 </text><circle cx=\"132.0\" cy=\"12.0\" r=\"12\" fill=\"#000000\" /><text x=\"132.0\" y=\"12.0\" font-size=\"18px\" dominant-baseline=\"middle\" text-anchor=\"middle\" fill=\"#ffffff\" >2 </text><circle cx=\"192.0\" cy=\"12.0\" r=\"12\" fill=\"#000000\" /><text x=\"192.0\" y=\"12.0\" font-size=\"18px\" dominant-baseline=\"middle\" text-anchor=\"middle\" fill=\"#ffffff\" >3 </text><circle cx=\"252.0\" cy=\"12.0\" r=\"12\" fill=\"#000000\" /><text x=\"252.0\" y=\"12.0\" font-size=\"18px\" dominant-baseline=\"middle\" text-anchor=\"middle\" fill=\"#ffffff\" >4 </text></svg>" ], "text/plain": [ "<mindquantum.io.display.circuit_svg_drawer.SVGContainer at 0x7f0c83e1df10>" ] }, "execution_count": 5, "metadata": {}, "output_type": "execute_result" } ], "source": [ "left_node = topology[0]\n", "for i in range(1, n):\n", " left_node = left_node << topology[i]\n", "\n", "draw_topology(topology)" ] }, { "attachments": {}, "cell_type": "markdown", "metadata": {}, "source": [ "在上述代码中,我们通过取值运算符 `[]`,获取对应 qubit_id 的量子比特,然后我们利用 `<<` 运算符进行比特之间的连接。\n", "\n", "在 MindQuantum 中,我们已经集成了多种结构,如这里提到的[一维链结构](https://mindspore.cn/mindquantum/docs/zh-CN/r0.10/device/mindquantum.device.LinearQubits.html#mindquantum.device.LinearQubits),和[方格子结构](https://mindspore.cn/mindquantum/docs/zh-CN/r0.10/device/mindquantum.device.GridQubits.html):" ] }, { "cell_type": "code", "execution_count": 6, "metadata": {}, "outputs": [ { "data": { "image/svg+xml": [ "<svg xmlns=\"http://www.w3.org/2000/svg\" width=\"144\" height=\"24.0\" xmlns:xlink=\"http://www.w3.org/1999/xlink\"><rect x=\"0\" y=\"0\" width=\"144\" height=\"24.0\" fill=\"#ffffff\" /><line x1=\"12.0\" x2=\"72.0\" y1=\"12.0\" y2=\"12.0\" stroke=\"#ababab\" stroke-width=\"8\" /><line x1=\"72.0\" x2=\"132.0\" y1=\"12.0\" y2=\"12.0\" stroke=\"#ababab\" stroke-width=\"8\" /><circle cx=\"12.0\" cy=\"12.0\" r=\"12\" fill=\"#000000\" /><text x=\"12.0\" y=\"12.0\" font-size=\"18px\" dominant-baseline=\"middle\" text-anchor=\"middle\" fill=\"#ffffff\" >0 </text><circle cx=\"72.0\" cy=\"12.0\" r=\"12\" fill=\"#000000\" /><text x=\"72.0\" y=\"12.0\" font-size=\"18px\" dominant-baseline=\"middle\" text-anchor=\"middle\" fill=\"#ffffff\" >1 </text><circle cx=\"132.0\" cy=\"12.0\" r=\"12\" fill=\"#000000\" /><text x=\"132.0\" y=\"12.0\" font-size=\"18px\" dominant-baseline=\"middle\" text-anchor=\"middle\" fill=\"#ffffff\" >2 </text></svg>" ] }, "metadata": {}, "output_type": "display_data" }, { "data": { "image/svg+xml": [ "<svg xmlns=\"http://www.w3.org/2000/svg\" width=\"264\" height=\"204\" xmlns:xlink=\"http://www.w3.org/1999/xlink\"><rect x=\"0\" y=\"0\" width=\"264\" height=\"204\" fill=\"#ffffff\" /><line x1=\"192.0\" x2=\"252.0\" y1=\"12.0\" y2=\"12.0\" stroke=\"#ababab\" stroke-width=\"8\" /><line x1=\"252.0\" x2=\"252.0\" y1=\"12.0\" y2=\"72.0\" stroke=\"#ababab\" stroke-width=\"8\" /><line x1=\"72.0\" x2=\"132.0\" y1=\"192.0\" y2=\"192.0\" stroke=\"#ababab\" stroke-width=\"8\" /><line x1=\"132.0\" x2=\"192.0\" y1=\"132.0\" y2=\"132.0\" stroke=\"#ababab\" stroke-width=\"8\" /><line x1=\"12.0\" x2=\"12.0\" y1=\"72.0\" y2=\"132.0\" stroke=\"#ababab\" stroke-width=\"8\" /><line x1=\"192.0\" x2=\"252.0\" y1=\"72.0\" y2=\"72.0\" stroke=\"#ababab\" stroke-width=\"8\" /><line x1=\"252.0\" x2=\"252.0\" y1=\"132.0\" y2=\"192.0\" stroke=\"#ababab\" stroke-width=\"8\" /><line x1=\"12.0\" x2=\"12.0\" y1=\"12.0\" y2=\"72.0\" stroke=\"#ababab\" stroke-width=\"8\" /><line x1=\"252.0\" x2=\"252.0\" y1=\"72.0\" y2=\"132.0\" stroke=\"#ababab\" stroke-width=\"8\" /><line x1=\"72.0\" x2=\"72.0\" y1=\"12.0\" y2=\"72.0\" stroke=\"#ababab\" stroke-width=\"8\" /><line x1=\"132.0\" x2=\"192.0\" y1=\"192.0\" y2=\"192.0\" stroke=\"#ababab\" stroke-width=\"8\" /><line x1=\"12.0\" x2=\"12.0\" y1=\"132.0\" y2=\"192.0\" stroke=\"#ababab\" stroke-width=\"8\" /><line x1=\"192.0\" x2=\"252.0\" y1=\"132.0\" y2=\"132.0\" stroke=\"#ababab\" stroke-width=\"8\" /><line x1=\"72.0\" x2=\"72.0\" y1=\"72.0\" y2=\"132.0\" stroke=\"#ababab\" stroke-width=\"8\" /><line x1=\"192.0\" x2=\"252.0\" y1=\"192.0\" y2=\"192.0\" stroke=\"#ababab\" stroke-width=\"8\" /><line x1=\"12.0\" x2=\"72.0\" y1=\"72.0\" y2=\"72.0\" stroke=\"#ababab\" stroke-width=\"8\" /><line x1=\"12.0\" x2=\"72.0\" y1=\"12.0\" y2=\"12.0\" stroke=\"#ababab\" stroke-width=\"8\" /><line x1=\"72.0\" x2=\"132.0\" y1=\"12.0\" y2=\"12.0\" stroke=\"#ababab\" stroke-width=\"8\" /><line x1=\"12.0\" x2=\"72.0\" y1=\"132.0\" y2=\"132.0\" stroke=\"#ababab\" stroke-width=\"8\" /><line x1=\"132.0\" x2=\"132.0\" y1=\"12.0\" y2=\"72.0\" stroke=\"#ababab\" stroke-width=\"8\" /><line x1=\"72.0\" x2=\"72.0\" y1=\"132.0\" y2=\"192.0\" stroke=\"#ababab\" stroke-width=\"8\" /><line x1=\"72.0\" x2=\"132.0\" y1=\"72.0\" y2=\"72.0\" stroke=\"#ababab\" stroke-width=\"8\" /><line x1=\"12.0\" x2=\"72.0\" y1=\"192.0\" y2=\"192.0\" stroke=\"#ababab\" stroke-width=\"8\" /><line x1=\"132.0\" x2=\"132.0\" y1=\"72.0\" y2=\"132.0\" stroke=\"#ababab\" stroke-width=\"8\" /><line x1=\"192.0\" x2=\"192.0\" y1=\"12.0\" y2=\"72.0\" stroke=\"#ababab\" stroke-width=\"8\" /><line x1=\"132.0\" x2=\"132.0\" y1=\"132.0\" y2=\"192.0\" stroke=\"#ababab\" stroke-width=\"8\" /><line x1=\"132.0\" x2=\"192.0\" y1=\"12.0\" y2=\"12.0\" stroke=\"#ababab\" stroke-width=\"8\" /><line x1=\"192.0\" x2=\"192.0\" y1=\"72.0\" y2=\"132.0\" stroke=\"#ababab\" stroke-width=\"8\" /><line x1=\"72.0\" x2=\"132.0\" y1=\"132.0\" y2=\"132.0\" stroke=\"#ababab\" stroke-width=\"8\" /><line x1=\"192.0\" x2=\"192.0\" y1=\"132.0\" y2=\"192.0\" stroke=\"#ababab\" stroke-width=\"8\" /><line x1=\"132.0\" x2=\"192.0\" y1=\"72.0\" y2=\"72.0\" stroke=\"#ababab\" stroke-width=\"8\" /><circle cx=\"12.0\" cy=\"12.0\" r=\"12\" fill=\"#000000\" /><text x=\"12.0\" y=\"12.0\" font-size=\"18px\" dominant-baseline=\"middle\" text-anchor=\"middle\" fill=\"#ffffff\" >0 </text><circle cx=\"72.0\" cy=\"12.0\" r=\"12\" fill=\"#000000\" /><text x=\"72.0\" y=\"12.0\" font-size=\"18px\" dominant-baseline=\"middle\" text-anchor=\"middle\" fill=\"#ffffff\" >1 </text><circle cx=\"132.0\" cy=\"12.0\" r=\"12\" fill=\"#000000\" /><text x=\"132.0\" y=\"12.0\" font-size=\"18px\" dominant-baseline=\"middle\" text-anchor=\"middle\" fill=\"#ffffff\" >2 </text><circle cx=\"192.0\" cy=\"12.0\" r=\"12\" fill=\"#000000\" /><text x=\"192.0\" y=\"12.0\" font-size=\"18px\" dominant-baseline=\"middle\" text-anchor=\"middle\" fill=\"#ffffff\" >3 </text><circle cx=\"252.0\" cy=\"12.0\" r=\"12\" fill=\"#000000\" /><text x=\"252.0\" y=\"12.0\" font-size=\"18px\" dominant-baseline=\"middle\" text-anchor=\"middle\" fill=\"#ffffff\" >4 </text><circle cx=\"12.0\" cy=\"72.0\" r=\"12\" fill=\"#000000\" /><text x=\"12.0\" y=\"72.0\" font-size=\"18px\" dominant-baseline=\"middle\" text-anchor=\"middle\" fill=\"#ffffff\" >5 </text><circle cx=\"72.0\" cy=\"72.0\" r=\"12\" fill=\"#000000\" /><text x=\"72.0\" y=\"72.0\" font-size=\"18px\" dominant-baseline=\"middle\" text-anchor=\"middle\" fill=\"#ffffff\" >6 </text><circle cx=\"132.0\" cy=\"72.0\" r=\"12\" fill=\"#000000\" /><text x=\"132.0\" y=\"72.0\" font-size=\"18px\" dominant-baseline=\"middle\" text-anchor=\"middle\" fill=\"#ffffff\" >7 </text><circle cx=\"192.0\" cy=\"72.0\" r=\"12\" fill=\"#000000\" /><text x=\"192.0\" y=\"72.0\" font-size=\"18px\" dominant-baseline=\"middle\" text-anchor=\"middle\" fill=\"#ffffff\" >8 </text><circle cx=\"252.0\" cy=\"72.0\" r=\"12\" fill=\"#000000\" /><text x=\"252.0\" y=\"72.0\" font-size=\"18px\" dominant-baseline=\"middle\" text-anchor=\"middle\" fill=\"#ffffff\" >9 </text><circle cx=\"12.0\" cy=\"132.0\" r=\"12\" fill=\"#000000\" /><text x=\"12.0\" y=\"132.0\" font-size=\"18px\" dominant-baseline=\"middle\" text-anchor=\"middle\" fill=\"#ffffff\" >10 </text><circle cx=\"72.0\" cy=\"132.0\" r=\"12\" fill=\"#000000\" /><text x=\"72.0\" y=\"132.0\" font-size=\"18px\" dominant-baseline=\"middle\" text-anchor=\"middle\" fill=\"#ffffff\" >11 </text><circle cx=\"132.0\" cy=\"132.0\" r=\"12\" fill=\"#000000\" /><text x=\"132.0\" y=\"132.0\" font-size=\"18px\" dominant-baseline=\"middle\" text-anchor=\"middle\" fill=\"#ffffff\" >12 </text><circle cx=\"192.0\" cy=\"132.0\" r=\"12\" fill=\"#000000\" /><text x=\"192.0\" y=\"132.0\" font-size=\"18px\" dominant-baseline=\"middle\" text-anchor=\"middle\" fill=\"#ffffff\" >13 </text><circle cx=\"252.0\" cy=\"132.0\" r=\"12\" fill=\"#000000\" /><text x=\"252.0\" y=\"132.0\" font-size=\"18px\" dominant-baseline=\"middle\" text-anchor=\"middle\" fill=\"#ffffff\" >14 </text><circle cx=\"12.0\" cy=\"192.0\" r=\"12\" fill=\"#000000\" /><text x=\"12.0\" y=\"192.0\" font-size=\"18px\" dominant-baseline=\"middle\" text-anchor=\"middle\" fill=\"#ffffff\" >15 </text><circle cx=\"72.0\" cy=\"192.0\" r=\"12\" fill=\"#000000\" /><text x=\"72.0\" y=\"192.0\" font-size=\"18px\" dominant-baseline=\"middle\" text-anchor=\"middle\" fill=\"#ffffff\" >16 </text><circle cx=\"132.0\" cy=\"192.0\" r=\"12\" fill=\"#000000\" /><text x=\"132.0\" y=\"192.0\" font-size=\"18px\" dominant-baseline=\"middle\" text-anchor=\"middle\" fill=\"#ffffff\" >17 </text><circle cx=\"192.0\" cy=\"192.0\" r=\"12\" fill=\"#000000\" /><text x=\"192.0\" y=\"192.0\" font-size=\"18px\" dominant-baseline=\"middle\" text-anchor=\"middle\" fill=\"#ffffff\" >18 </text><circle cx=\"252.0\" cy=\"192.0\" r=\"12\" fill=\"#000000\" /><text x=\"252.0\" y=\"192.0\" font-size=\"18px\" dominant-baseline=\"middle\" text-anchor=\"middle\" fill=\"#ffffff\" >19 </text></svg>" ] }, "metadata": {}, "output_type": "display_data" } ], "source": [ "from mindquantum.device import LinearQubits, GridQubits\n", "from IPython.display import display_svg\n", "\n", "t1 = LinearQubits(3)\n", "t2 = GridQubits(4, 5)\n", "\n", "display_svg(draw_topology(t1))\n", "display_svg(draw_topology(t2))" ] }, { "attachments": {}, "cell_type": "markdown", "metadata": {}, "source": [ "我们还可以对拓扑结构图进行更多的操作,如删除某个节点:" ] }, { "cell_type": "code", "execution_count": 7, "metadata": {}, "outputs": [ { "data": { "image/svg+xml": [ "<svg xmlns=\"http://www.w3.org/2000/svg\" width=\"264\" height=\"204\" xmlns:xlink=\"http://www.w3.org/1999/xlink\"><rect x=\"0\" y=\"0\" width=\"264\" height=\"204\" fill=\"#ffffff\" /><line x1=\"192.0\" x2=\"252.0\" y1=\"12.0\" y2=\"12.0\" stroke=\"#ababab\" stroke-width=\"8\" /><line x1=\"252.0\" x2=\"252.0\" y1=\"12.0\" y2=\"72.0\" stroke=\"#ababab\" stroke-width=\"8\" /><line x1=\"72.0\" x2=\"132.0\" y1=\"192.0\" y2=\"192.0\" stroke=\"#ababab\" stroke-width=\"8\" /><line x1=\"132.0\" x2=\"192.0\" y1=\"132.0\" y2=\"132.0\" stroke=\"#ababab\" stroke-width=\"8\" /><line x1=\"12.0\" x2=\"12.0\" y1=\"72.0\" y2=\"132.0\" stroke=\"#ababab\" stroke-width=\"8\" /><line x1=\"192.0\" x2=\"252.0\" y1=\"72.0\" y2=\"72.0\" stroke=\"#ababab\" stroke-width=\"8\" /><line x1=\"252.0\" x2=\"252.0\" y1=\"132.0\" y2=\"192.0\" stroke=\"#ababab\" stroke-width=\"8\" /><line x1=\"12.0\" x2=\"12.0\" y1=\"12.0\" y2=\"72.0\" stroke=\"#ababab\" stroke-width=\"8\" /><line x1=\"252.0\" x2=\"252.0\" y1=\"72.0\" y2=\"132.0\" stroke=\"#ababab\" stroke-width=\"8\" /><line x1=\"132.0\" x2=\"192.0\" y1=\"192.0\" y2=\"192.0\" stroke=\"#ababab\" stroke-width=\"8\" /><line x1=\"12.0\" x2=\"12.0\" y1=\"132.0\" y2=\"192.0\" stroke=\"#ababab\" stroke-width=\"8\" /><line x1=\"192.0\" x2=\"252.0\" y1=\"132.0\" y2=\"132.0\" stroke=\"#ababab\" stroke-width=\"8\" /><line x1=\"192.0\" x2=\"252.0\" y1=\"192.0\" y2=\"192.0\" stroke=\"#ababab\" stroke-width=\"8\" /><line x1=\"12.0\" x2=\"72.0\" y1=\"12.0\" y2=\"12.0\" stroke=\"#ababab\" stroke-width=\"8\" /><line x1=\"72.0\" x2=\"132.0\" y1=\"12.0\" y2=\"12.0\" stroke=\"#ababab\" stroke-width=\"8\" /><line x1=\"12.0\" x2=\"72.0\" y1=\"132.0\" y2=\"132.0\" stroke=\"#ababab\" stroke-width=\"8\" /><line x1=\"132.0\" x2=\"132.0\" y1=\"12.0\" y2=\"72.0\" stroke=\"#ababab\" stroke-width=\"8\" /><line x1=\"72.0\" x2=\"72.0\" y1=\"132.0\" y2=\"192.0\" stroke=\"#ababab\" stroke-width=\"8\" /><line x1=\"12.0\" x2=\"72.0\" y1=\"192.0\" y2=\"192.0\" stroke=\"#ababab\" stroke-width=\"8\" /><line x1=\"132.0\" x2=\"132.0\" y1=\"72.0\" y2=\"132.0\" stroke=\"#ababab\" stroke-width=\"8\" /><line x1=\"192.0\" x2=\"192.0\" y1=\"12.0\" y2=\"72.0\" stroke=\"#ababab\" stroke-width=\"8\" /><line x1=\"132.0\" x2=\"132.0\" y1=\"132.0\" y2=\"192.0\" stroke=\"#ababab\" stroke-width=\"8\" /><line x1=\"132.0\" x2=\"192.0\" y1=\"12.0\" y2=\"12.0\" stroke=\"#ababab\" stroke-width=\"8\" /><line x1=\"192.0\" x2=\"192.0\" y1=\"72.0\" y2=\"132.0\" stroke=\"#ababab\" stroke-width=\"8\" /><line x1=\"72.0\" x2=\"132.0\" y1=\"132.0\" y2=\"132.0\" stroke=\"#ababab\" stroke-width=\"8\" /><line x1=\"192.0\" x2=\"192.0\" y1=\"132.0\" y2=\"192.0\" stroke=\"#ababab\" stroke-width=\"8\" /><line x1=\"132.0\" x2=\"192.0\" y1=\"72.0\" y2=\"72.0\" stroke=\"#ababab\" stroke-width=\"8\" /><circle cx=\"12.0\" cy=\"12.0\" r=\"12\" fill=\"#000000\" /><text x=\"12.0\" y=\"12.0\" font-size=\"18px\" dominant-baseline=\"middle\" text-anchor=\"middle\" fill=\"#ffffff\" >0 </text><circle cx=\"72.0\" cy=\"12.0\" r=\"12\" fill=\"#000000\" /><text x=\"72.0\" y=\"12.0\" font-size=\"18px\" dominant-baseline=\"middle\" text-anchor=\"middle\" fill=\"#ffffff\" >1 </text><circle cx=\"132.0\" cy=\"12.0\" r=\"12\" fill=\"#000000\" /><text x=\"132.0\" y=\"12.0\" font-size=\"18px\" dominant-baseline=\"middle\" text-anchor=\"middle\" fill=\"#ffffff\" >2 </text><circle cx=\"192.0\" cy=\"12.0\" r=\"12\" fill=\"#000000\" /><text x=\"192.0\" y=\"12.0\" font-size=\"18px\" dominant-baseline=\"middle\" text-anchor=\"middle\" fill=\"#ffffff\" >3 </text><circle cx=\"252.0\" cy=\"12.0\" r=\"12\" fill=\"#000000\" /><text x=\"252.0\" y=\"12.0\" font-size=\"18px\" dominant-baseline=\"middle\" text-anchor=\"middle\" fill=\"#ffffff\" >4 </text><circle cx=\"12.0\" cy=\"72.0\" r=\"12\" fill=\"#000000\" /><text x=\"12.0\" y=\"72.0\" font-size=\"18px\" dominant-baseline=\"middle\" text-anchor=\"middle\" fill=\"#ffffff\" >5 </text><circle cx=\"132.0\" cy=\"72.0\" r=\"12\" fill=\"#000000\" /><text x=\"132.0\" y=\"72.0\" font-size=\"18px\" dominant-baseline=\"middle\" text-anchor=\"middle\" fill=\"#ffffff\" >7 </text><circle cx=\"192.0\" cy=\"72.0\" r=\"12\" fill=\"#000000\" /><text x=\"192.0\" y=\"72.0\" font-size=\"18px\" dominant-baseline=\"middle\" text-anchor=\"middle\" fill=\"#ffffff\" >8 </text><circle cx=\"252.0\" cy=\"72.0\" r=\"12\" fill=\"#000000\" /><text x=\"252.0\" y=\"72.0\" font-size=\"18px\" dominant-baseline=\"middle\" text-anchor=\"middle\" fill=\"#ffffff\" >9 </text><circle cx=\"12.0\" cy=\"132.0\" r=\"12\" fill=\"#000000\" /><text x=\"12.0\" y=\"132.0\" font-size=\"18px\" dominant-baseline=\"middle\" text-anchor=\"middle\" fill=\"#ffffff\" >10 </text><circle cx=\"72.0\" cy=\"132.0\" r=\"12\" fill=\"#000000\" /><text x=\"72.0\" y=\"132.0\" font-size=\"18px\" dominant-baseline=\"middle\" text-anchor=\"middle\" fill=\"#ffffff\" >11 </text><circle cx=\"132.0\" cy=\"132.0\" r=\"12\" fill=\"#000000\" /><text x=\"132.0\" y=\"132.0\" font-size=\"18px\" dominant-baseline=\"middle\" text-anchor=\"middle\" fill=\"#ffffff\" >12 </text><circle cx=\"192.0\" cy=\"132.0\" r=\"12\" fill=\"#000000\" /><text x=\"192.0\" y=\"132.0\" font-size=\"18px\" dominant-baseline=\"middle\" text-anchor=\"middle\" fill=\"#ffffff\" >13 </text><circle cx=\"252.0\" cy=\"132.0\" r=\"12\" fill=\"#000000\" /><text x=\"252.0\" y=\"132.0\" font-size=\"18px\" dominant-baseline=\"middle\" text-anchor=\"middle\" fill=\"#ffffff\" >14 </text><circle cx=\"12.0\" cy=\"192.0\" r=\"12\" fill=\"#000000\" /><text x=\"12.0\" y=\"192.0\" font-size=\"18px\" dominant-baseline=\"middle\" text-anchor=\"middle\" fill=\"#ffffff\" >15 </text><circle cx=\"72.0\" cy=\"192.0\" r=\"12\" fill=\"#000000\" /><text x=\"72.0\" y=\"192.0\" font-size=\"18px\" dominant-baseline=\"middle\" text-anchor=\"middle\" fill=\"#ffffff\" >16 </text><circle cx=\"132.0\" cy=\"192.0\" r=\"12\" fill=\"#000000\" /><text x=\"132.0\" y=\"192.0\" font-size=\"18px\" dominant-baseline=\"middle\" text-anchor=\"middle\" fill=\"#ffffff\" >17 </text><circle cx=\"192.0\" cy=\"192.0\" r=\"12\" fill=\"#000000\" /><text x=\"192.0\" y=\"192.0\" font-size=\"18px\" dominant-baseline=\"middle\" text-anchor=\"middle\" fill=\"#ffffff\" >18 </text><circle cx=\"252.0\" cy=\"192.0\" r=\"12\" fill=\"#000000\" /><text x=\"252.0\" y=\"192.0\" font-size=\"18px\" dominant-baseline=\"middle\" text-anchor=\"middle\" fill=\"#ffffff\" >19 </text></svg>" ], "text/plain": [ "<mindquantum.io.display.circuit_svg_drawer.SVGContainer at 0x7f0c83e3a340>" ] }, "execution_count": 7, "metadata": {}, "output_type": "execute_result" } ], "source": [ "t2.remove_qubit_node(6)\n", "\n", "draw_topology(t2)" ] }, { "attachments": {}, "cell_type": "markdown", "metadata": {}, "source": [ "孤立某个节点:" ] }, { "cell_type": "code", "execution_count": 8, "metadata": {}, "outputs": [ { "data": { "image/svg+xml": [ "<svg xmlns=\"http://www.w3.org/2000/svg\" width=\"264\" height=\"204\" xmlns:xlink=\"http://www.w3.org/1999/xlink\"><rect x=\"0\" y=\"0\" width=\"264\" height=\"204\" fill=\"#ffffff\" /><line x1=\"192.0\" x2=\"252.0\" y1=\"12.0\" y2=\"12.0\" stroke=\"#ababab\" stroke-width=\"8\" /><line x1=\"252.0\" x2=\"252.0\" y1=\"12.0\" y2=\"72.0\" stroke=\"#ababab\" stroke-width=\"8\" /><line x1=\"72.0\" x2=\"132.0\" y1=\"192.0\" y2=\"192.0\" stroke=\"#ababab\" stroke-width=\"8\" /><line x1=\"12.0\" x2=\"12.0\" y1=\"72.0\" y2=\"132.0\" stroke=\"#ababab\" stroke-width=\"8\" /><line x1=\"192.0\" x2=\"252.0\" y1=\"72.0\" y2=\"72.0\" stroke=\"#ababab\" stroke-width=\"8\" /><line x1=\"252.0\" x2=\"252.0\" y1=\"132.0\" y2=\"192.0\" stroke=\"#ababab\" stroke-width=\"8\" /><line x1=\"12.0\" x2=\"12.0\" y1=\"12.0\" y2=\"72.0\" stroke=\"#ababab\" stroke-width=\"8\" /><line x1=\"252.0\" x2=\"252.0\" y1=\"72.0\" y2=\"132.0\" stroke=\"#ababab\" stroke-width=\"8\" /><line x1=\"132.0\" x2=\"192.0\" y1=\"192.0\" y2=\"192.0\" stroke=\"#ababab\" stroke-width=\"8\" /><line x1=\"12.0\" x2=\"12.0\" y1=\"132.0\" y2=\"192.0\" stroke=\"#ababab\" stroke-width=\"8\" /><line x1=\"192.0\" x2=\"252.0\" y1=\"192.0\" y2=\"192.0\" stroke=\"#ababab\" stroke-width=\"8\" /><line x1=\"12.0\" x2=\"72.0\" y1=\"12.0\" y2=\"12.0\" stroke=\"#ababab\" stroke-width=\"8\" /><line x1=\"72.0\" x2=\"132.0\" y1=\"12.0\" y2=\"12.0\" stroke=\"#ababab\" stroke-width=\"8\" /><line x1=\"12.0\" x2=\"72.0\" y1=\"132.0\" y2=\"132.0\" stroke=\"#ababab\" stroke-width=\"8\" /><line x1=\"132.0\" x2=\"132.0\" y1=\"12.0\" y2=\"72.0\" stroke=\"#ababab\" stroke-width=\"8\" /><line x1=\"72.0\" x2=\"72.0\" y1=\"132.0\" y2=\"192.0\" stroke=\"#ababab\" stroke-width=\"8\" /><line x1=\"12.0\" x2=\"72.0\" y1=\"192.0\" y2=\"192.0\" stroke=\"#ababab\" stroke-width=\"8\" /><line x1=\"132.0\" x2=\"132.0\" y1=\"72.0\" y2=\"132.0\" stroke=\"#ababab\" stroke-width=\"8\" /><line x1=\"192.0\" x2=\"192.0\" y1=\"12.0\" y2=\"72.0\" stroke=\"#ababab\" stroke-width=\"8\" /><line x1=\"132.0\" x2=\"132.0\" y1=\"132.0\" y2=\"192.0\" stroke=\"#ababab\" stroke-width=\"8\" /><line x1=\"132.0\" x2=\"192.0\" y1=\"12.0\" y2=\"12.0\" stroke=\"#ababab\" stroke-width=\"8\" /><line x1=\"72.0\" x2=\"132.0\" y1=\"132.0\" y2=\"132.0\" stroke=\"#ababab\" stroke-width=\"8\" /><line x1=\"132.0\" x2=\"192.0\" y1=\"72.0\" y2=\"72.0\" stroke=\"#ababab\" stroke-width=\"8\" /><circle cx=\"12.0\" cy=\"12.0\" r=\"12\" fill=\"#000000\" /><text x=\"12.0\" y=\"12.0\" font-size=\"18px\" dominant-baseline=\"middle\" text-anchor=\"middle\" fill=\"#ffffff\" >0 </text><circle cx=\"72.0\" cy=\"12.0\" r=\"12\" fill=\"#000000\" /><text x=\"72.0\" y=\"12.0\" font-size=\"18px\" dominant-baseline=\"middle\" text-anchor=\"middle\" fill=\"#ffffff\" >1 </text><circle cx=\"132.0\" cy=\"12.0\" r=\"12\" fill=\"#000000\" /><text x=\"132.0\" y=\"12.0\" font-size=\"18px\" dominant-baseline=\"middle\" text-anchor=\"middle\" fill=\"#ffffff\" >2 </text><circle cx=\"192.0\" cy=\"12.0\" r=\"12\" fill=\"#000000\" /><text x=\"192.0\" y=\"12.0\" font-size=\"18px\" dominant-baseline=\"middle\" text-anchor=\"middle\" fill=\"#ffffff\" >3 </text><circle cx=\"252.0\" cy=\"12.0\" r=\"12\" fill=\"#000000\" /><text x=\"252.0\" y=\"12.0\" font-size=\"18px\" dominant-baseline=\"middle\" text-anchor=\"middle\" fill=\"#ffffff\" >4 </text><circle cx=\"12.0\" cy=\"72.0\" r=\"12\" fill=\"#000000\" /><text x=\"12.0\" y=\"72.0\" font-size=\"18px\" dominant-baseline=\"middle\" text-anchor=\"middle\" fill=\"#ffffff\" >5 </text><circle cx=\"132.0\" cy=\"72.0\" r=\"12\" fill=\"#000000\" /><text x=\"132.0\" y=\"72.0\" font-size=\"18px\" dominant-baseline=\"middle\" text-anchor=\"middle\" fill=\"#ffffff\" >7 </text><circle cx=\"192.0\" cy=\"72.0\" r=\"12\" fill=\"#000000\" /><text x=\"192.0\" y=\"72.0\" font-size=\"18px\" dominant-baseline=\"middle\" text-anchor=\"middle\" fill=\"#ffffff\" >8 </text><circle cx=\"252.0\" cy=\"72.0\" r=\"12\" fill=\"#000000\" /><text x=\"252.0\" y=\"72.0\" font-size=\"18px\" dominant-baseline=\"middle\" text-anchor=\"middle\" fill=\"#ffffff\" >9 </text><circle cx=\"12.0\" cy=\"132.0\" r=\"12\" fill=\"#000000\" /><text x=\"12.0\" y=\"132.0\" font-size=\"18px\" dominant-baseline=\"middle\" text-anchor=\"middle\" fill=\"#ffffff\" >10 </text><circle cx=\"72.0\" cy=\"132.0\" r=\"12\" fill=\"#000000\" /><text x=\"72.0\" y=\"132.0\" font-size=\"18px\" dominant-baseline=\"middle\" text-anchor=\"middle\" fill=\"#ffffff\" >11 </text><circle cx=\"132.0\" cy=\"132.0\" r=\"12\" fill=\"#000000\" /><text x=\"132.0\" y=\"132.0\" font-size=\"18px\" dominant-baseline=\"middle\" text-anchor=\"middle\" fill=\"#ffffff\" >12 </text><circle cx=\"192.0\" cy=\"132.0\" r=\"12\" fill=\"#000000\" /><text x=\"192.0\" y=\"132.0\" font-size=\"18px\" dominant-baseline=\"middle\" text-anchor=\"middle\" fill=\"#ffffff\" >13 </text><circle cx=\"252.0\" cy=\"132.0\" r=\"12\" fill=\"#000000\" /><text x=\"252.0\" y=\"132.0\" font-size=\"18px\" dominant-baseline=\"middle\" text-anchor=\"middle\" fill=\"#ffffff\" >14 </text><circle cx=\"12.0\" cy=\"192.0\" r=\"12\" fill=\"#000000\" /><text x=\"12.0\" y=\"192.0\" font-size=\"18px\" dominant-baseline=\"middle\" text-anchor=\"middle\" fill=\"#ffffff\" >15 </text><circle cx=\"72.0\" cy=\"192.0\" r=\"12\" fill=\"#000000\" /><text x=\"72.0\" y=\"192.0\" font-size=\"18px\" dominant-baseline=\"middle\" text-anchor=\"middle\" fill=\"#ffffff\" >16 </text><circle cx=\"132.0\" cy=\"192.0\" r=\"12\" fill=\"#000000\" /><text x=\"132.0\" y=\"192.0\" font-size=\"18px\" dominant-baseline=\"middle\" text-anchor=\"middle\" fill=\"#ffffff\" >17 </text><circle cx=\"192.0\" cy=\"192.0\" r=\"12\" fill=\"#000000\" /><text x=\"192.0\" y=\"192.0\" font-size=\"18px\" dominant-baseline=\"middle\" text-anchor=\"middle\" fill=\"#ffffff\" >18 </text><circle cx=\"252.0\" cy=\"192.0\" r=\"12\" fill=\"#000000\" /><text x=\"252.0\" y=\"192.0\" font-size=\"18px\" dominant-baseline=\"middle\" text-anchor=\"middle\" fill=\"#ffffff\" >19 </text></svg>" ], "text/plain": [ "<mindquantum.io.display.circuit_svg_drawer.SVGContainer at 0x7f0c83dc0f70>" ] }, "execution_count": 8, "metadata": {}, "output_type": "execute_result" } ], "source": [ "t2.isolate_with_near(13)\n", "\n", "draw_topology(t2)" ] }, { "attachments": {}, "cell_type": "markdown", "metadata": {}, "source": [ "修改节点颜色:" ] }, { "cell_type": "code", "execution_count": 9, "metadata": {}, "outputs": [ { "data": { "image/svg+xml": [ "<svg xmlns=\"http://www.w3.org/2000/svg\" width=\"264\" height=\"204\" xmlns:xlink=\"http://www.w3.org/1999/xlink\"><rect x=\"0\" y=\"0\" width=\"264\" height=\"204\" fill=\"#ffffff\" /><line x1=\"192.0\" x2=\"252.0\" y1=\"12.0\" y2=\"12.0\" stroke=\"#ababab\" stroke-width=\"8\" /><line x1=\"252.0\" x2=\"252.0\" y1=\"12.0\" y2=\"72.0\" stroke=\"#ababab\" stroke-width=\"8\" /><line x1=\"72.0\" x2=\"132.0\" y1=\"192.0\" y2=\"192.0\" stroke=\"#ababab\" stroke-width=\"8\" /><line x1=\"12.0\" x2=\"12.0\" y1=\"72.0\" y2=\"132.0\" stroke=\"#ababab\" stroke-width=\"8\" /><line x1=\"192.0\" x2=\"252.0\" y1=\"72.0\" y2=\"72.0\" stroke=\"#ababab\" stroke-width=\"8\" /><line x1=\"252.0\" x2=\"252.0\" y1=\"132.0\" y2=\"192.0\" stroke=\"#ababab\" stroke-width=\"8\" /><line x1=\"12.0\" x2=\"12.0\" y1=\"12.0\" y2=\"72.0\" stroke=\"#ababab\" stroke-width=\"8\" /><line x1=\"252.0\" x2=\"252.0\" y1=\"72.0\" y2=\"132.0\" stroke=\"#ababab\" stroke-width=\"8\" /><line x1=\"132.0\" x2=\"192.0\" y1=\"192.0\" y2=\"192.0\" stroke=\"#ababab\" stroke-width=\"8\" /><line x1=\"12.0\" x2=\"12.0\" y1=\"132.0\" y2=\"192.0\" stroke=\"#ababab\" stroke-width=\"8\" /><line x1=\"192.0\" x2=\"252.0\" y1=\"192.0\" y2=\"192.0\" stroke=\"#ababab\" stroke-width=\"8\" /><line x1=\"12.0\" x2=\"72.0\" y1=\"12.0\" y2=\"12.0\" stroke=\"#ababab\" stroke-width=\"8\" /><line x1=\"72.0\" x2=\"132.0\" y1=\"12.0\" y2=\"12.0\" stroke=\"#ababab\" stroke-width=\"8\" /><line x1=\"12.0\" x2=\"72.0\" y1=\"132.0\" y2=\"132.0\" stroke=\"#ababab\" stroke-width=\"8\" /><line x1=\"132.0\" x2=\"132.0\" y1=\"12.0\" y2=\"72.0\" stroke=\"#ababab\" stroke-width=\"8\" /><line x1=\"72.0\" x2=\"72.0\" y1=\"132.0\" y2=\"192.0\" stroke=\"#ababab\" stroke-width=\"8\" /><line x1=\"12.0\" x2=\"72.0\" y1=\"192.0\" y2=\"192.0\" stroke=\"#ababab\" stroke-width=\"8\" /><line x1=\"132.0\" x2=\"132.0\" y1=\"72.0\" y2=\"132.0\" stroke=\"#ababab\" stroke-width=\"8\" /><line x1=\"192.0\" x2=\"192.0\" y1=\"12.0\" y2=\"72.0\" stroke=\"#ababab\" stroke-width=\"8\" /><line x1=\"132.0\" x2=\"132.0\" y1=\"132.0\" y2=\"192.0\" stroke=\"#ababab\" stroke-width=\"8\" /><line x1=\"132.0\" x2=\"192.0\" y1=\"12.0\" y2=\"12.0\" stroke=\"#ababab\" stroke-width=\"8\" /><line x1=\"72.0\" x2=\"132.0\" y1=\"132.0\" y2=\"132.0\" stroke=\"#ababab\" stroke-width=\"8\" /><line x1=\"132.0\" x2=\"192.0\" y1=\"72.0\" y2=\"72.0\" stroke=\"#ababab\" stroke-width=\"8\" /><circle cx=\"12.0\" cy=\"12.0\" r=\"12\" fill=\"#000000\" /><text x=\"12.0\" y=\"12.0\" font-size=\"18px\" dominant-baseline=\"middle\" text-anchor=\"middle\" fill=\"#ffffff\" >0 </text><circle cx=\"72.0\" cy=\"12.0\" r=\"12\" fill=\"#000000\" /><text x=\"72.0\" y=\"12.0\" font-size=\"18px\" dominant-baseline=\"middle\" text-anchor=\"middle\" fill=\"#ffffff\" >1 </text><circle cx=\"132.0\" cy=\"12.0\" r=\"12\" fill=\"#000000\" /><text x=\"132.0\" y=\"12.0\" font-size=\"18px\" dominant-baseline=\"middle\" text-anchor=\"middle\" fill=\"#ffffff\" >2 </text><circle cx=\"192.0\" cy=\"12.0\" r=\"12\" fill=\"#000000\" /><text x=\"192.0\" y=\"12.0\" font-size=\"18px\" dominant-baseline=\"middle\" text-anchor=\"middle\" fill=\"#ffffff\" >3 </text><circle cx=\"252.0\" cy=\"12.0\" r=\"12\" fill=\"#000000\" /><text x=\"252.0\" y=\"12.0\" font-size=\"18px\" dominant-baseline=\"middle\" text-anchor=\"middle\" fill=\"#ffffff\" >4 </text><circle cx=\"12.0\" cy=\"72.0\" r=\"12\" fill=\"#000000\" /><text x=\"12.0\" y=\"72.0\" font-size=\"18px\" dominant-baseline=\"middle\" text-anchor=\"middle\" fill=\"#ffffff\" >5 </text><circle cx=\"132.0\" cy=\"72.0\" r=\"12\" fill=\"#ff0000\" /><text x=\"132.0\" y=\"72.0\" font-size=\"18px\" dominant-baseline=\"middle\" text-anchor=\"middle\" fill=\"#ffffff\" >7 </text><circle cx=\"192.0\" cy=\"72.0\" r=\"12\" fill=\"#000000\" /><text x=\"192.0\" y=\"72.0\" font-size=\"18px\" dominant-baseline=\"middle\" text-anchor=\"middle\" fill=\"#ffffff\" >8 </text><circle cx=\"252.0\" cy=\"72.0\" r=\"12\" fill=\"#000000\" /><text x=\"252.0\" y=\"72.0\" font-size=\"18px\" dominant-baseline=\"middle\" text-anchor=\"middle\" fill=\"#ffffff\" >9 </text><circle cx=\"12.0\" cy=\"132.0\" r=\"12\" fill=\"#000000\" /><text x=\"12.0\" y=\"132.0\" font-size=\"18px\" dominant-baseline=\"middle\" text-anchor=\"middle\" fill=\"#ffffff\" >10 </text><circle cx=\"72.0\" cy=\"132.0\" r=\"12\" fill=\"#000000\" /><text x=\"72.0\" y=\"132.0\" font-size=\"18px\" dominant-baseline=\"middle\" text-anchor=\"middle\" fill=\"#ffffff\" >11 </text><circle cx=\"132.0\" cy=\"132.0\" r=\"12\" fill=\"#000000\" /><text x=\"132.0\" y=\"132.0\" font-size=\"18px\" dominant-baseline=\"middle\" text-anchor=\"middle\" fill=\"#ffffff\" >12 </text><circle cx=\"192.0\" cy=\"132.0\" r=\"12\" fill=\"#000000\" /><text x=\"192.0\" y=\"132.0\" font-size=\"18px\" dominant-baseline=\"middle\" text-anchor=\"middle\" fill=\"#ffffff\" >13 </text><circle cx=\"252.0\" cy=\"132.0\" r=\"12\" fill=\"#000000\" /><text x=\"252.0\" y=\"132.0\" font-size=\"18px\" dominant-baseline=\"middle\" text-anchor=\"middle\" fill=\"#ffffff\" >14 </text><circle cx=\"12.0\" cy=\"192.0\" r=\"12\" fill=\"#000000\" /><text x=\"12.0\" y=\"192.0\" font-size=\"18px\" dominant-baseline=\"middle\" text-anchor=\"middle\" fill=\"#ffffff\" >15 </text><circle cx=\"72.0\" cy=\"192.0\" r=\"12\" fill=\"#000000\" /><text x=\"72.0\" y=\"192.0\" font-size=\"18px\" dominant-baseline=\"middle\" text-anchor=\"middle\" fill=\"#ffffff\" >16 </text><circle cx=\"132.0\" cy=\"192.0\" r=\"12\" fill=\"#000000\" /><text x=\"132.0\" y=\"192.0\" font-size=\"18px\" dominant-baseline=\"middle\" text-anchor=\"middle\" fill=\"#ffffff\" >17 </text><circle cx=\"192.0\" cy=\"192.0\" r=\"12\" fill=\"#000000\" /><text x=\"192.0\" y=\"192.0\" font-size=\"18px\" dominant-baseline=\"middle\" text-anchor=\"middle\" fill=\"#ffffff\" >18 </text><circle cx=\"252.0\" cy=\"192.0\" r=\"12\" fill=\"#000000\" /><text x=\"252.0\" y=\"192.0\" font-size=\"18px\" dominant-baseline=\"middle\" text-anchor=\"middle\" fill=\"#ffffff\" >19 </text></svg>" ], "text/plain": [ "<mindquantum.io.display.circuit_svg_drawer.SVGContainer at 0x7f0c83dd0bb0>" ] }, "execution_count": 9, "metadata": {}, "output_type": "execute_result" } ], "source": [ "t2.set_color(7, '#ff0000')\n", "\n", "draw_topology(t2)" ] }, { "attachments": {}, "cell_type": "markdown", "metadata": {}, "source": [ "修改节点位置:" ] }, { "cell_type": "code", "execution_count": 10, "metadata": {}, "outputs": [ { "data": { "image/svg+xml": [ "<svg xmlns=\"http://www.w3.org/2000/svg\" width=\"324.0\" height=\"204\" xmlns:xlink=\"http://www.w3.org/1999/xlink\"><rect x=\"0\" y=\"0\" width=\"324.0\" height=\"204\" fill=\"#ffffff\" /><line x1=\"192.0\" x2=\"312.0\" y1=\"12.0\" y2=\"42.0\" stroke=\"#ababab\" stroke-width=\"8\" /><line x1=\"312.0\" x2=\"252.0\" y1=\"42.0\" y2=\"72.0\" stroke=\"#ababab\" stroke-width=\"8\" /><line x1=\"72.0\" x2=\"132.0\" y1=\"192.0\" y2=\"192.0\" stroke=\"#ababab\" stroke-width=\"8\" /><line x1=\"12.0\" x2=\"12.0\" y1=\"72.0\" y2=\"132.0\" stroke=\"#ababab\" stroke-width=\"8\" /><line x1=\"192.0\" x2=\"252.0\" y1=\"72.0\" y2=\"72.0\" stroke=\"#ababab\" stroke-width=\"8\" /><line x1=\"252.0\" x2=\"252.0\" y1=\"132.0\" y2=\"192.0\" stroke=\"#ababab\" stroke-width=\"8\" /><line x1=\"12.0\" x2=\"12.0\" y1=\"12.0\" y2=\"72.0\" stroke=\"#ababab\" stroke-width=\"8\" /><line x1=\"252.0\" x2=\"252.0\" y1=\"72.0\" y2=\"132.0\" stroke=\"#ababab\" stroke-width=\"8\" /><line x1=\"132.0\" x2=\"192.0\" y1=\"192.0\" y2=\"192.0\" stroke=\"#ababab\" stroke-width=\"8\" /><line x1=\"12.0\" x2=\"12.0\" y1=\"132.0\" y2=\"192.0\" stroke=\"#ababab\" stroke-width=\"8\" /><line x1=\"192.0\" x2=\"252.0\" y1=\"192.0\" y2=\"192.0\" stroke=\"#ababab\" stroke-width=\"8\" /><line x1=\"12.0\" x2=\"72.0\" y1=\"12.0\" y2=\"12.0\" stroke=\"#ababab\" stroke-width=\"8\" /><line x1=\"72.0\" x2=\"132.0\" y1=\"12.0\" y2=\"12.0\" stroke=\"#ababab\" stroke-width=\"8\" /><line x1=\"12.0\" x2=\"72.0\" y1=\"132.0\" y2=\"132.0\" stroke=\"#ababab\" stroke-width=\"8\" /><line x1=\"132.0\" x2=\"132.0\" y1=\"12.0\" y2=\"72.0\" stroke=\"#ababab\" stroke-width=\"8\" /><line x1=\"72.0\" x2=\"72.0\" y1=\"132.0\" y2=\"192.0\" stroke=\"#ababab\" stroke-width=\"8\" /><line x1=\"12.0\" x2=\"72.0\" y1=\"192.0\" y2=\"192.0\" stroke=\"#ababab\" stroke-width=\"8\" /><line x1=\"132.0\" x2=\"132.0\" y1=\"72.0\" y2=\"132.0\" stroke=\"#ababab\" stroke-width=\"8\" /><line x1=\"192.0\" x2=\"192.0\" y1=\"12.0\" y2=\"72.0\" stroke=\"#ababab\" stroke-width=\"8\" /><line x1=\"132.0\" x2=\"132.0\" y1=\"132.0\" y2=\"192.0\" stroke=\"#ababab\" stroke-width=\"8\" /><line x1=\"132.0\" x2=\"192.0\" y1=\"12.0\" y2=\"12.0\" stroke=\"#ababab\" stroke-width=\"8\" /><line x1=\"72.0\" x2=\"132.0\" y1=\"132.0\" y2=\"132.0\" stroke=\"#ababab\" stroke-width=\"8\" /><line x1=\"132.0\" x2=\"192.0\" y1=\"72.0\" y2=\"72.0\" stroke=\"#ababab\" stroke-width=\"8\" /><circle cx=\"12.0\" cy=\"12.0\" r=\"12\" fill=\"#000000\" /><text x=\"12.0\" y=\"12.0\" font-size=\"18px\" dominant-baseline=\"middle\" text-anchor=\"middle\" fill=\"#ffffff\" >0 </text><circle cx=\"72.0\" cy=\"12.0\" r=\"12\" fill=\"#000000\" /><text x=\"72.0\" y=\"12.0\" font-size=\"18px\" dominant-baseline=\"middle\" text-anchor=\"middle\" fill=\"#ffffff\" >1 </text><circle cx=\"132.0\" cy=\"12.0\" r=\"12\" fill=\"#000000\" /><text x=\"132.0\" y=\"12.0\" font-size=\"18px\" dominant-baseline=\"middle\" text-anchor=\"middle\" fill=\"#ffffff\" >2 </text><circle cx=\"192.0\" cy=\"12.0\" r=\"12\" fill=\"#000000\" /><text x=\"192.0\" y=\"12.0\" font-size=\"18px\" dominant-baseline=\"middle\" text-anchor=\"middle\" fill=\"#ffffff\" >3 </text><circle cx=\"312.0\" cy=\"42.0\" r=\"12\" fill=\"#000000\" /><text x=\"312.0\" y=\"42.0\" font-size=\"18px\" dominant-baseline=\"middle\" text-anchor=\"middle\" fill=\"#ffffff\" >4 </text><circle cx=\"12.0\" cy=\"72.0\" r=\"12\" fill=\"#000000\" /><text x=\"12.0\" y=\"72.0\" font-size=\"18px\" dominant-baseline=\"middle\" text-anchor=\"middle\" fill=\"#ffffff\" >5 </text><circle cx=\"132.0\" cy=\"72.0\" r=\"12\" fill=\"#ff0000\" /><text x=\"132.0\" y=\"72.0\" font-size=\"18px\" dominant-baseline=\"middle\" text-anchor=\"middle\" fill=\"#ffffff\" >7 </text><circle cx=\"192.0\" cy=\"72.0\" r=\"12\" fill=\"#000000\" /><text x=\"192.0\" y=\"72.0\" font-size=\"18px\" dominant-baseline=\"middle\" text-anchor=\"middle\" fill=\"#ffffff\" >8 </text><circle cx=\"252.0\" cy=\"72.0\" r=\"12\" fill=\"#000000\" /><text x=\"252.0\" y=\"72.0\" font-size=\"18px\" dominant-baseline=\"middle\" text-anchor=\"middle\" fill=\"#ffffff\" >9 </text><circle cx=\"12.0\" cy=\"132.0\" r=\"12\" fill=\"#000000\" /><text x=\"12.0\" y=\"132.0\" font-size=\"18px\" dominant-baseline=\"middle\" text-anchor=\"middle\" fill=\"#ffffff\" >10 </text><circle cx=\"72.0\" cy=\"132.0\" r=\"12\" fill=\"#000000\" /><text x=\"72.0\" y=\"132.0\" font-size=\"18px\" dominant-baseline=\"middle\" text-anchor=\"middle\" fill=\"#ffffff\" >11 </text><circle cx=\"132.0\" cy=\"132.0\" r=\"12\" fill=\"#000000\" /><text x=\"132.0\" y=\"132.0\" font-size=\"18px\" dominant-baseline=\"middle\" text-anchor=\"middle\" fill=\"#ffffff\" >12 </text><circle cx=\"192.0\" cy=\"132.0\" r=\"12\" fill=\"#000000\" /><text x=\"192.0\" y=\"132.0\" font-size=\"18px\" dominant-baseline=\"middle\" text-anchor=\"middle\" fill=\"#ffffff\" >13 </text><circle cx=\"252.0\" cy=\"132.0\" r=\"12\" fill=\"#000000\" /><text x=\"252.0\" y=\"132.0\" font-size=\"18px\" dominant-baseline=\"middle\" text-anchor=\"middle\" fill=\"#ffffff\" >14 </text><circle cx=\"12.0\" cy=\"192.0\" r=\"12\" fill=\"#000000\" /><text x=\"12.0\" y=\"192.0\" font-size=\"18px\" dominant-baseline=\"middle\" text-anchor=\"middle\" fill=\"#ffffff\" >15 </text><circle cx=\"72.0\" cy=\"192.0\" r=\"12\" fill=\"#000000\" /><text x=\"72.0\" y=\"192.0\" font-size=\"18px\" dominant-baseline=\"middle\" text-anchor=\"middle\" fill=\"#ffffff\" >16 </text><circle cx=\"132.0\" cy=\"192.0\" r=\"12\" fill=\"#000000\" /><text x=\"132.0\" y=\"192.0\" font-size=\"18px\" dominant-baseline=\"middle\" text-anchor=\"middle\" fill=\"#ffffff\" >17 </text><circle cx=\"192.0\" cy=\"192.0\" r=\"12\" fill=\"#000000\" /><text x=\"192.0\" y=\"192.0\" font-size=\"18px\" dominant-baseline=\"middle\" text-anchor=\"middle\" fill=\"#ffffff\" >18 </text><circle cx=\"252.0\" cy=\"192.0\" r=\"12\" fill=\"#000000\" /><text x=\"252.0\" y=\"192.0\" font-size=\"18px\" dominant-baseline=\"middle\" text-anchor=\"middle\" fill=\"#ffffff\" >19 </text></svg>" ], "text/plain": [ "<mindquantum.io.display.circuit_svg_drawer.SVGContainer at 0x7f0c83ddd8b0>" ] }, "execution_count": 10, "metadata": {}, "output_type": "execute_result" } ], "source": [ "t2.set_position(4, 5.0, 0.5)\n", "\n", "draw_topology(t2)" ] }, { "attachments": {}, "cell_type": "markdown", "metadata": {}, "source": [ "重新耦合比特:" ] }, { "cell_type": "code", "execution_count": 11, "metadata": {}, "outputs": [ { "data": { "image/svg+xml": [ "<svg xmlns=\"http://www.w3.org/2000/svg\" width=\"324.0\" height=\"204\" xmlns:xlink=\"http://www.w3.org/1999/xlink\"><rect x=\"0\" y=\"0\" width=\"324.0\" height=\"204\" fill=\"#ffffff\" /><line x1=\"192.0\" x2=\"312.0\" y1=\"12.0\" y2=\"42.0\" stroke=\"#ababab\" stroke-width=\"8\" /><line x1=\"312.0\" x2=\"252.0\" y1=\"42.0\" y2=\"72.0\" stroke=\"#ababab\" stroke-width=\"8\" /><line x1=\"72.0\" x2=\"132.0\" y1=\"192.0\" y2=\"192.0\" stroke=\"#ababab\" stroke-width=\"8\" /><line x1=\"12.0\" x2=\"12.0\" y1=\"72.0\" y2=\"132.0\" stroke=\"#ababab\" stroke-width=\"8\" /><line x1=\"192.0\" x2=\"252.0\" y1=\"72.0\" y2=\"72.0\" stroke=\"#ababab\" stroke-width=\"8\" /><line x1=\"252.0\" x2=\"252.0\" y1=\"132.0\" y2=\"192.0\" stroke=\"#ababab\" stroke-width=\"8\" /><line x1=\"12.0\" x2=\"12.0\" y1=\"12.0\" y2=\"72.0\" stroke=\"#ababab\" stroke-width=\"8\" /><line x1=\"252.0\" x2=\"252.0\" y1=\"72.0\" y2=\"132.0\" stroke=\"#ababab\" stroke-width=\"8\" /><line x1=\"132.0\" x2=\"192.0\" y1=\"192.0\" y2=\"192.0\" stroke=\"#ababab\" stroke-width=\"8\" /><line x1=\"12.0\" x2=\"12.0\" y1=\"132.0\" y2=\"192.0\" stroke=\"#ababab\" stroke-width=\"8\" /><line x1=\"192.0\" x2=\"252.0\" y1=\"192.0\" y2=\"192.0\" stroke=\"#ababab\" stroke-width=\"8\" /><line x1=\"312.0\" x2=\"252.0\" y1=\"42.0\" y2=\"132.0\" stroke=\"#ababab\" stroke-width=\"8\" /><line x1=\"12.0\" x2=\"72.0\" y1=\"12.0\" y2=\"12.0\" stroke=\"#ababab\" stroke-width=\"8\" /><line x1=\"72.0\" x2=\"132.0\" y1=\"12.0\" y2=\"12.0\" stroke=\"#ababab\" stroke-width=\"8\" /><line x1=\"12.0\" x2=\"72.0\" y1=\"132.0\" y2=\"132.0\" stroke=\"#ababab\" stroke-width=\"8\" /><line x1=\"132.0\" x2=\"132.0\" y1=\"12.0\" y2=\"72.0\" stroke=\"#ababab\" stroke-width=\"8\" /><line x1=\"72.0\" x2=\"72.0\" y1=\"132.0\" y2=\"192.0\" stroke=\"#ababab\" stroke-width=\"8\" /><line x1=\"12.0\" x2=\"72.0\" y1=\"192.0\" y2=\"192.0\" stroke=\"#ababab\" stroke-width=\"8\" /><line x1=\"132.0\" x2=\"132.0\" y1=\"72.0\" y2=\"132.0\" stroke=\"#ababab\" stroke-width=\"8\" /><line x1=\"192.0\" x2=\"192.0\" y1=\"12.0\" y2=\"72.0\" stroke=\"#ababab\" stroke-width=\"8\" /><line x1=\"132.0\" x2=\"132.0\" y1=\"132.0\" y2=\"192.0\" stroke=\"#ababab\" stroke-width=\"8\" /><line x1=\"132.0\" x2=\"192.0\" y1=\"12.0\" y2=\"12.0\" stroke=\"#ababab\" stroke-width=\"8\" /><line x1=\"72.0\" x2=\"132.0\" y1=\"132.0\" y2=\"132.0\" stroke=\"#ababab\" stroke-width=\"8\" /><line x1=\"132.0\" x2=\"192.0\" y1=\"72.0\" y2=\"72.0\" stroke=\"#ababab\" stroke-width=\"8\" /><circle cx=\"12.0\" cy=\"12.0\" r=\"12\" fill=\"#000000\" /><text x=\"12.0\" y=\"12.0\" font-size=\"18px\" dominant-baseline=\"middle\" text-anchor=\"middle\" fill=\"#ffffff\" >0 </text><circle cx=\"72.0\" cy=\"12.0\" r=\"12\" fill=\"#000000\" /><text x=\"72.0\" y=\"12.0\" font-size=\"18px\" dominant-baseline=\"middle\" text-anchor=\"middle\" fill=\"#ffffff\" >1 </text><circle cx=\"132.0\" cy=\"12.0\" r=\"12\" fill=\"#000000\" /><text x=\"132.0\" y=\"12.0\" font-size=\"18px\" dominant-baseline=\"middle\" text-anchor=\"middle\" fill=\"#ffffff\" >2 </text><circle cx=\"192.0\" cy=\"12.0\" r=\"12\" fill=\"#000000\" /><text x=\"192.0\" y=\"12.0\" font-size=\"18px\" dominant-baseline=\"middle\" text-anchor=\"middle\" fill=\"#ffffff\" >3 </text><circle cx=\"312.0\" cy=\"42.0\" r=\"12\" fill=\"#000000\" /><text x=\"312.0\" y=\"42.0\" font-size=\"18px\" dominant-baseline=\"middle\" text-anchor=\"middle\" fill=\"#ffffff\" >4 </text><circle cx=\"12.0\" cy=\"72.0\" r=\"12\" fill=\"#000000\" /><text x=\"12.0\" y=\"72.0\" font-size=\"18px\" dominant-baseline=\"middle\" text-anchor=\"middle\" fill=\"#ffffff\" >5 </text><circle cx=\"132.0\" cy=\"72.0\" r=\"12\" fill=\"#ff0000\" /><text x=\"132.0\" y=\"72.0\" font-size=\"18px\" dominant-baseline=\"middle\" text-anchor=\"middle\" fill=\"#ffffff\" >7 </text><circle cx=\"192.0\" cy=\"72.0\" r=\"12\" fill=\"#000000\" /><text x=\"192.0\" y=\"72.0\" font-size=\"18px\" dominant-baseline=\"middle\" text-anchor=\"middle\" fill=\"#ffffff\" >8 </text><circle cx=\"252.0\" cy=\"72.0\" r=\"12\" fill=\"#000000\" /><text x=\"252.0\" y=\"72.0\" font-size=\"18px\" dominant-baseline=\"middle\" text-anchor=\"middle\" fill=\"#ffffff\" >9 </text><circle cx=\"12.0\" cy=\"132.0\" r=\"12\" fill=\"#000000\" /><text x=\"12.0\" y=\"132.0\" font-size=\"18px\" dominant-baseline=\"middle\" text-anchor=\"middle\" fill=\"#ffffff\" >10 </text><circle cx=\"72.0\" cy=\"132.0\" r=\"12\" fill=\"#000000\" /><text x=\"72.0\" y=\"132.0\" font-size=\"18px\" dominant-baseline=\"middle\" text-anchor=\"middle\" fill=\"#ffffff\" >11 </text><circle cx=\"132.0\" cy=\"132.0\" r=\"12\" fill=\"#000000\" /><text x=\"132.0\" y=\"132.0\" font-size=\"18px\" dominant-baseline=\"middle\" text-anchor=\"middle\" fill=\"#ffffff\" >12 </text><circle cx=\"192.0\" cy=\"132.0\" r=\"12\" fill=\"#000000\" /><text x=\"192.0\" y=\"132.0\" font-size=\"18px\" dominant-baseline=\"middle\" text-anchor=\"middle\" fill=\"#ffffff\" >13 </text><circle cx=\"252.0\" cy=\"132.0\" r=\"12\" fill=\"#000000\" /><text x=\"252.0\" y=\"132.0\" font-size=\"18px\" dominant-baseline=\"middle\" text-anchor=\"middle\" fill=\"#ffffff\" >14 </text><circle cx=\"12.0\" cy=\"192.0\" r=\"12\" fill=\"#000000\" /><text x=\"12.0\" y=\"192.0\" font-size=\"18px\" dominant-baseline=\"middle\" text-anchor=\"middle\" fill=\"#ffffff\" >15 </text><circle cx=\"72.0\" cy=\"192.0\" r=\"12\" fill=\"#000000\" /><text x=\"72.0\" y=\"192.0\" font-size=\"18px\" dominant-baseline=\"middle\" text-anchor=\"middle\" fill=\"#ffffff\" >16 </text><circle cx=\"132.0\" cy=\"192.0\" r=\"12\" fill=\"#000000\" /><text x=\"132.0\" y=\"192.0\" font-size=\"18px\" dominant-baseline=\"middle\" text-anchor=\"middle\" fill=\"#ffffff\" >17 </text><circle cx=\"192.0\" cy=\"192.0\" r=\"12\" fill=\"#000000\" /><text x=\"192.0\" y=\"192.0\" font-size=\"18px\" dominant-baseline=\"middle\" text-anchor=\"middle\" fill=\"#ffffff\" >18 </text><circle cx=\"252.0\" cy=\"192.0\" r=\"12\" fill=\"#000000\" /><text x=\"252.0\" y=\"192.0\" font-size=\"18px\" dominant-baseline=\"middle\" text-anchor=\"middle\" fill=\"#ffffff\" >19 </text></svg>" ], "text/plain": [ "<mindquantum.io.display.circuit_svg_drawer.SVGContainer at 0x7f0c83deb490>" ] }, "execution_count": 11, "metadata": {}, "output_type": "execute_result" } ], "source": [ "t2[4] << t2[14]\n", "\n", "draw_topology(t2)" ] }, { "attachments": {}, "cell_type": "markdown", "metadata": {}, "source": [ "我们还可以获取拓扑结构中所有的耦合边:" ] }, { "cell_type": "code", "execution_count": 12, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "{(0, 1),\n", " (0, 5),\n", " (1, 2),\n", " (2, 3),\n", " (2, 7),\n", " (3, 4),\n", " (3, 8),\n", " (4, 9),\n", " (4, 14),\n", " (5, 10),\n", " (7, 8),\n", " (7, 12),\n", " (8, 9),\n", " (9, 14),\n", " (10, 11),\n", " (10, 15),\n", " (11, 12),\n", " (11, 16),\n", " (12, 17),\n", " (14, 19),\n", " (15, 16),\n", " (16, 17),\n", " (17, 18),\n", " (18, 19)}" ] }, "execution_count": 12, "metadata": {}, "output_type": "execute_result" } ], "source": [ "t2.edges_with_id()" ] }, { "attachments": {}, "cell_type": "markdown", "metadata": {}, "source": [ "### Qubit Mapping\n", "\n", "当我们在真实量子硬件上运行量子线路时,我们往往不能直接运行,因为真实硬件中的比特拓扑关系和用户给定的量子线路结构并不一定匹配,这时比特映射技术就应运而生。我们可以通过对量子比特进行重新映射,或插入一下 [SWAP](https://mindspore.cn/mindquantum/docs/zh-CN/r0.10/core/mindquantum.core.gates.html#%E9%A2%84%E5%AE%9E%E4%BE%8B%E5%8C%96%E9%97%A8) 门,来使得线路能够成功运行。\n", "\n", "我们给定一个量子线路:" ] }, { "cell_type": "code", "execution_count": 13, "metadata": {}, "outputs": [ { "data": { "image/svg+xml": [ "<svg xmlns=\"http://www.w3.org/2000/svg\" width=\"336.8\" height=\"200.0\" xmlns:xlink=\"http://www.w3.org/1999/xlink\"><rect x=\"0\" y=\"0.0\" width=\"336.8\" height=\"200.0\" fill=\"#ffffff\" /><text x=\"20.0\" y=\"40.0\" font-size=\"16px\" dominant-baseline=\"middle\" text-anchor=\"start\" font-family=\"Arial\" font-weight=\"normal\" fill=\"#252b3a\" >q0: </text><text x=\"20.0\" y=\"100.0\" font-size=\"16px\" dominant-baseline=\"middle\" text-anchor=\"start\" font-family=\"Arial\" font-weight=\"normal\" fill=\"#252b3a\" >q1: </text><text x=\"20.0\" y=\"160.0\" font-size=\"16px\" dominant-baseline=\"middle\" text-anchor=\"start\" font-family=\"Arial\" font-weight=\"normal\" fill=\"#252b3a\" >q2: </text><line x1=\"48.8\" x2=\"316.8\" y1=\"40.0\" y2=\"40.0\" stroke=\"#adb0b8\" stroke-width=\"1\" /><line x1=\"48.8\" x2=\"316.8\" y1=\"100.0\" y2=\"100.0\" stroke=\"#adb0b8\" stroke-width=\"1\" /><line x1=\"48.8\" x2=\"316.8\" y1=\"160.0\" y2=\"160.0\" stroke=\"#adb0b8\" stroke-width=\"1\" /><rect x=\"72.8\" y=\"20.0\" width=\"40.0\" height=\"40\" rx=\"4\" ry=\"4\" stroke=\"#ffffff\" stroke-width=\"0\" fill=\"#fac209\" fill-opacity=\"1\" /><text x=\"92.8\" y=\"36.0\" font-size=\"20px\" dominant-baseline=\"middle\" text-anchor=\"middle\" font-family=\"Arial\" font-weight=\"normal\" fill=\"#ffffff\" >RX </text><text x=\"92.8\" y=\"52.0\" font-size=\"14.0px\" dominant-baseline=\"middle\" text-anchor=\"middle\" font-family=\"Arial\" font-weight=\"normal\" fill=\"#ffffff\" >a </text><rect x=\"72.8\" y=\"80.0\" width=\"40.0\" height=\"40\" rx=\"4\" ry=\"4\" stroke=\"#ffffff\" stroke-width=\"0\" fill=\"#fac209\" fill-opacity=\"1\" /><text x=\"92.8\" y=\"96.0\" font-size=\"20px\" dominant-baseline=\"middle\" text-anchor=\"middle\" font-family=\"Arial\" font-weight=\"normal\" fill=\"#ffffff\" >RX </text><text x=\"92.8\" y=\"112.0\" font-size=\"14.0px\" dominant-baseline=\"middle\" text-anchor=\"middle\" font-family=\"Arial\" font-weight=\"normal\" fill=\"#ffffff\" >b </text><rect x=\"72.8\" y=\"140.0\" width=\"40.0\" height=\"40\" rx=\"4\" ry=\"4\" stroke=\"#ffffff\" stroke-width=\"0\" fill=\"#fac209\" fill-opacity=\"1\" /><text x=\"92.8\" y=\"156.0\" font-size=\"20px\" dominant-baseline=\"middle\" text-anchor=\"middle\" font-family=\"Arial\" font-weight=\"normal\" fill=\"#ffffff\" >RX </text><text x=\"92.8\" y=\"172.0\" font-size=\"14.0px\" dominant-baseline=\"middle\" text-anchor=\"middle\" font-family=\"Arial\" font-weight=\"normal\" fill=\"#ffffff\" >c </text><circle cx=\"152.8\" cy=\"40.0\" r=\"4\" fill=\"#16acff\" /><line x1=\"152.8\" x2=\"152.8\" y1=\"40.0\" y2=\"100.0\" stroke=\"#16acff\" stroke-width=\"3\" /><rect x=\"132.8\" y=\"80.0\" width=\"40\" height=\"40\" rx=\"4\" ry=\"4\" stroke=\"#ffffff\" stroke-width=\"0\" fill=\"#16acff\" fill-opacity=\"1\" /><line x1=\"138.8\" x2=\"166.8\" y1=\"100.0\" y2=\"100.0\" stroke=\"#ffffff\" stroke-width=\"4\" /><line x1=\"152.8\" x2=\"152.8\" y1=\"86.0\" y2=\"114.0\" stroke=\"#ffffff\" stroke-width=\"4\" /><circle cx=\"212.8\" cy=\"100.0\" r=\"4\" fill=\"#16acff\" /><line x1=\"212.8\" x2=\"212.8\" y1=\"100.0\" y2=\"160.0\" stroke=\"#16acff\" stroke-width=\"3\" /><rect x=\"192.8\" y=\"140.0\" width=\"40\" height=\"40\" rx=\"4\" ry=\"4\" stroke=\"#ffffff\" stroke-width=\"0\" fill=\"#16acff\" fill-opacity=\"1\" /><line x1=\"198.8\" x2=\"226.8\" y1=\"160.0\" y2=\"160.0\" stroke=\"#ffffff\" stroke-width=\"4\" /><line x1=\"212.8\" x2=\"212.8\" y1=\"146.0\" y2=\"174.0\" stroke=\"#ffffff\" stroke-width=\"4\" /><circle cx=\"272.8\" cy=\"160.0\" r=\"4\" fill=\"#16acff\" /><line x1=\"272.8\" x2=\"272.8\" y1=\"40.0\" y2=\"160.0\" stroke=\"#16acff\" stroke-width=\"3\" /><rect x=\"252.8\" y=\"20.0\" width=\"40\" height=\"40\" rx=\"4\" ry=\"4\" stroke=\"#ffffff\" stroke-width=\"0\" fill=\"#16acff\" fill-opacity=\"1\" /><line x1=\"258.8\" x2=\"286.8\" y1=\"40.0\" y2=\"40.0\" stroke=\"#ffffff\" stroke-width=\"4\" /><line x1=\"272.8\" x2=\"272.8\" y1=\"26.0\" y2=\"54.0\" stroke=\"#ffffff\" stroke-width=\"4\" /></svg>" ], "text/plain": [ "<mindquantum.io.display.circuit_svg_drawer.SVGCircuit at 0x7f0c83debfa0>" ] }, "execution_count": 13, "metadata": {}, "output_type": "execute_result" } ], "source": [ "from mindquantum.core.circuit import Circuit\n", "\n", "circ = Circuit().rx('a', 0).rx('b', 1).rx('c', 2).x(1, 0).x(2, 1).x(0, 2)\n", "circ.svg()" ] }, { "attachments": {}, "cell_type": "markdown", "metadata": {}, "source": [ "再给定一个 2x2 的方格子量子拓扑结构:" ] }, { "cell_type": "code", "execution_count": 14, "metadata": {}, "outputs": [ { "data": { "image/svg+xml": [ "<svg xmlns=\"http://www.w3.org/2000/svg\" width=\"84\" height=\"84\" xmlns:xlink=\"http://www.w3.org/1999/xlink\"><rect x=\"0\" y=\"0\" width=\"84\" height=\"84\" fill=\"#ffffff\" /><line x1=\"12.0\" x2=\"72.0\" y1=\"12.0\" y2=\"12.0\" stroke=\"#ababab\" stroke-width=\"8\" /><line x1=\"12.0\" x2=\"12.0\" y1=\"12.0\" y2=\"72.0\" stroke=\"#ababab\" stroke-width=\"8\" /><line x1=\"12.0\" x2=\"72.0\" y1=\"72.0\" y2=\"72.0\" stroke=\"#ababab\" stroke-width=\"8\" /><line x1=\"72.0\" x2=\"72.0\" y1=\"12.0\" y2=\"72.0\" stroke=\"#ababab\" stroke-width=\"8\" /><circle cx=\"12.0\" cy=\"12.0\" r=\"12\" fill=\"#000000\" /><text x=\"12.0\" y=\"12.0\" font-size=\"18px\" dominant-baseline=\"middle\" text-anchor=\"middle\" fill=\"#ffffff\" >0 </text><circle cx=\"72.0\" cy=\"12.0\" r=\"12\" fill=\"#000000\" /><text x=\"72.0\" y=\"12.0\" font-size=\"18px\" dominant-baseline=\"middle\" text-anchor=\"middle\" fill=\"#ffffff\" >1 </text><circle cx=\"12.0\" cy=\"72.0\" r=\"12\" fill=\"#000000\" /><text x=\"12.0\" y=\"72.0\" font-size=\"18px\" dominant-baseline=\"middle\" text-anchor=\"middle\" fill=\"#ffffff\" >2 </text><circle cx=\"72.0\" cy=\"72.0\" r=\"12\" fill=\"#000000\" /><text x=\"72.0\" y=\"72.0\" font-size=\"18px\" dominant-baseline=\"middle\" text-anchor=\"middle\" fill=\"#ffffff\" >3 </text></svg>" ], "text/plain": [ "<mindquantum.io.display.circuit_svg_drawer.SVGContainer at 0x7f0c83e58850>" ] }, "execution_count": 14, "metadata": {}, "output_type": "execute_result" } ], "source": [ "t = GridQubits(2, 2)\n", "\n", "draw_topology(t)" ] }, { "attachments": {}, "cell_type": "markdown", "metadata": {}, "source": [ "由于上述量子线路中的量子比特两两都有相互作用,因此无法直接在上述的量子硬件中运行。我们引入 [SABER](https://mindspore.cn/mindquantum/docs/zh-CN/r0.10/algorithm/mapping/mindquantum.algorithm.mapping.SABRE.html#mindquantum.algorithm.mapping.SABRE) 算法解决该问题。更多算法细节,请参考论文:[Tackling the Qubit Mapping Problem for NISQ-Era Quantum Devices](https://arxiv.org/abs/1809.02573)。" ] }, { "cell_type": "code", "execution_count": 15, "metadata": {}, "outputs": [], "source": [ "from mindquantum.algorithm.mapping import SABRE\n", "\n", "solver = SABRE(circ, t)\n", "new_circ, init_mapping, final_mapping = solver.solve(5, 0.5, 0.3, 0.2)" ] }, { "attachments": {}, "cell_type": "markdown", "metadata": {}, "source": [ "我们可以看到新给出的量子线路为:" ] }, { "cell_type": "code", "execution_count": 16, "metadata": {}, "outputs": [ { "data": { "image/svg+xml": [ "<svg xmlns=\"http://www.w3.org/2000/svg\" width=\"396.8\" height=\"260.0\" xmlns:xlink=\"http://www.w3.org/1999/xlink\"><rect x=\"0\" y=\"0.0\" width=\"396.8\" height=\"260.0\" fill=\"#ffffff\" /><text x=\"20.0\" y=\"40.0\" font-size=\"16px\" dominant-baseline=\"middle\" text-anchor=\"start\" font-family=\"Arial\" font-weight=\"normal\" fill=\"#252b3a\" >q0: </text><text x=\"20.0\" y=\"100.0\" font-size=\"16px\" dominant-baseline=\"middle\" text-anchor=\"start\" font-family=\"Arial\" font-weight=\"normal\" fill=\"#252b3a\" >q1: </text><text x=\"20.0\" y=\"160.0\" font-size=\"16px\" dominant-baseline=\"middle\" text-anchor=\"start\" font-family=\"Arial\" font-weight=\"normal\" fill=\"#252b3a\" >q2: </text><text x=\"20.0\" y=\"220.0\" font-size=\"16px\" dominant-baseline=\"middle\" text-anchor=\"start\" font-family=\"Arial\" font-weight=\"normal\" fill=\"#252b3a\" >q3: </text><line x1=\"48.8\" x2=\"376.8\" y1=\"40.0\" y2=\"40.0\" stroke=\"#adb0b8\" stroke-width=\"1\" /><line x1=\"48.8\" x2=\"376.8\" y1=\"100.0\" y2=\"100.0\" stroke=\"#adb0b8\" stroke-width=\"1\" /><line x1=\"48.8\" x2=\"376.8\" y1=\"160.0\" y2=\"160.0\" stroke=\"#adb0b8\" stroke-width=\"1\" /><line x1=\"48.8\" x2=\"376.8\" y1=\"220.0\" y2=\"220.0\" stroke=\"#adb0b8\" stroke-width=\"1\" /><rect x=\"72.8\" y=\"200.0\" width=\"40.0\" height=\"40\" rx=\"4\" ry=\"4\" stroke=\"#ffffff\" stroke-width=\"0\" fill=\"#fac209\" fill-opacity=\"1\" /><text x=\"92.8\" y=\"216.0\" font-size=\"20px\" dominant-baseline=\"middle\" text-anchor=\"middle\" font-family=\"Arial\" font-weight=\"normal\" fill=\"#ffffff\" >RX </text><text x=\"92.8\" y=\"232.0\" font-size=\"14.0px\" dominant-baseline=\"middle\" text-anchor=\"middle\" font-family=\"Arial\" font-weight=\"normal\" fill=\"#ffffff\" >a </text><rect x=\"72.8\" y=\"140.0\" width=\"40.0\" height=\"40\" rx=\"4\" ry=\"4\" stroke=\"#ffffff\" stroke-width=\"0\" fill=\"#fac209\" fill-opacity=\"1\" /><text x=\"92.8\" y=\"156.0\" font-size=\"20px\" dominant-baseline=\"middle\" text-anchor=\"middle\" font-family=\"Arial\" font-weight=\"normal\" fill=\"#ffffff\" >RX </text><text x=\"92.8\" y=\"172.0\" font-size=\"14.0px\" dominant-baseline=\"middle\" text-anchor=\"middle\" font-family=\"Arial\" font-weight=\"normal\" fill=\"#ffffff\" >b </text><rect x=\"72.8\" y=\"20.0\" width=\"40.0\" height=\"40\" rx=\"4\" ry=\"4\" stroke=\"#ffffff\" stroke-width=\"0\" fill=\"#fac209\" fill-opacity=\"1\" /><text x=\"92.8\" y=\"36.0\" font-size=\"20px\" dominant-baseline=\"middle\" text-anchor=\"middle\" font-family=\"Arial\" font-weight=\"normal\" fill=\"#ffffff\" >RX </text><text x=\"92.8\" y=\"52.0\" font-size=\"14.0px\" dominant-baseline=\"middle\" text-anchor=\"middle\" font-family=\"Arial\" font-weight=\"normal\" fill=\"#ffffff\" >c </text><circle cx=\"152.8\" cy=\"220.0\" r=\"4\" fill=\"#16acff\" /><line x1=\"152.8\" x2=\"152.8\" y1=\"160.0\" y2=\"220.0\" stroke=\"#16acff\" stroke-width=\"3\" /><rect x=\"132.8\" y=\"140.0\" width=\"40\" height=\"40\" rx=\"4\" ry=\"4\" stroke=\"#ffffff\" stroke-width=\"0\" fill=\"#16acff\" fill-opacity=\"1\" /><line x1=\"138.8\" x2=\"166.8\" y1=\"160.0\" y2=\"160.0\" stroke=\"#ffffff\" stroke-width=\"4\" /><line x1=\"152.8\" x2=\"152.8\" y1=\"146.0\" y2=\"174.0\" stroke=\"#ffffff\" stroke-width=\"4\" /><circle cx=\"212.8\" cy=\"160.0\" r=\"4\" fill=\"#16acff\" /><line x1=\"212.8\" x2=\"212.8\" y1=\"40.0\" y2=\"160.0\" stroke=\"#16acff\" stroke-width=\"3\" /><rect x=\"192.8\" y=\"20.0\" width=\"40\" height=\"40\" rx=\"4\" ry=\"4\" stroke=\"#ffffff\" stroke-width=\"0\" fill=\"#16acff\" fill-opacity=\"1\" /><line x1=\"198.8\" x2=\"226.8\" y1=\"40.0\" y2=\"40.0\" stroke=\"#ffffff\" stroke-width=\"4\" /><line x1=\"212.8\" x2=\"212.8\" y1=\"26.0\" y2=\"54.0\" stroke=\"#ffffff\" stroke-width=\"4\" /><line x1=\"272.8\" x2=\"272.8\" y1=\"80.0\" y2=\"240.0\" stroke-width=\"3\" stroke=\"#16acff\" /><rect x=\"252.8\" y=\"80.0\" width=\"40\" height=\"40\" rx=\"4\" ry=\"4\" fill=\"#16acff\" fill-opacity=\"1\" stroke=\"#ffffff\" stroke-width=\"0\" /><path d=\"M 263.2 96.31384387633061 L 268.0 88.0 L 272.8 96.31384387633061 L 269.44 96.31384387633061 L 269.44 112.0 L 266.56 112.0 L 266.56 96.31384387633061 Z\" fill=\"#ffffff\" /><path d=\"M 282.4 103.68615612366939 L 277.6 112.0 L 272.8 103.68615612366939 L 276.16 103.68615612366939 L 276.16 88.0 L 279.04 88.0 L 279.04 103.68615612366939 Z\" fill=\"#ffffff\" /><rect x=\"252.8\" y=\"200.0\" width=\"40\" height=\"40\" rx=\"4\" ry=\"4\" fill=\"#16acff\" fill-opacity=\"1\" stroke=\"#ffffff\" stroke-width=\"0\" /><path d=\"M 263.2 216.31384387633062 L 268.0 208.0 L 272.8 216.31384387633062 L 269.44 216.31384387633062 L 269.44 232.0 L 266.56 232.0 L 266.56 216.31384387633062 Z\" fill=\"#ffffff\" /><path d=\"M 282.4 223.68615612366938 L 277.6 232.0 L 272.8 223.68615612366938 L 276.16 223.68615612366938 L 276.16 208.0 L 279.04 208.0 L 279.04 223.68615612366938 Z\" fill=\"#ffffff\" /><circle cx=\"332.8\" cy=\"40.0\" r=\"4\" fill=\"#16acff\" /><line x1=\"332.8\" x2=\"332.8\" y1=\"40.0\" y2=\"100.0\" stroke=\"#16acff\" stroke-width=\"3\" /><rect x=\"312.8\" y=\"80.0\" width=\"40\" height=\"40\" rx=\"4\" ry=\"4\" stroke=\"#ffffff\" stroke-width=\"0\" fill=\"#16acff\" fill-opacity=\"1\" /><line x1=\"318.8\" x2=\"346.8\" y1=\"100.0\" y2=\"100.0\" stroke=\"#ffffff\" stroke-width=\"4\" /><line x1=\"332.8\" x2=\"332.8\" y1=\"86.0\" y2=\"114.0\" stroke=\"#ffffff\" stroke-width=\"4\" /></svg>" ], "text/plain": [ "<mindquantum.io.display.circuit_svg_drawer.SVGCircuit at 0x7f0c83debb50>" ] }, "execution_count": 16, "metadata": {}, "output_type": "execute_result" } ], "source": [ "new_circ.svg()" ] }, { "attachments": {}, "cell_type": "markdown", "metadata": {}, "source": [ "通过对比旧的量子线路,我们得知,算法重新分配的比特编号,并在合适的位置加入了 [SWAP](https://mindspore.cn/mindquantum/docs/zh-CN/r0.10/core/mindquantum.core.gates.html#%E9%A2%84%E5%AE%9E%E4%BE%8B%E5%8C%96%E9%97%A8) 门,使得线路得以正常运行。" ] }, { "cell_type": "code", "execution_count": 17, "metadata": {}, "outputs": [ { "data": { "image/svg+xml": [ "<svg xmlns=\"http://www.w3.org/2000/svg\" width=\"336.8\" height=\"200.0\" xmlns:xlink=\"http://www.w3.org/1999/xlink\"><rect x=\"0\" y=\"0.0\" width=\"336.8\" height=\"200.0\" fill=\"#ffffff\" /><text x=\"20.0\" y=\"40.0\" font-size=\"16px\" dominant-baseline=\"middle\" text-anchor=\"start\" font-family=\"Arial\" font-weight=\"normal\" fill=\"#252b3a\" >q0: </text><text x=\"20.0\" y=\"100.0\" font-size=\"16px\" dominant-baseline=\"middle\" text-anchor=\"start\" font-family=\"Arial\" font-weight=\"normal\" fill=\"#252b3a\" >q1: </text><text x=\"20.0\" y=\"160.0\" font-size=\"16px\" dominant-baseline=\"middle\" text-anchor=\"start\" font-family=\"Arial\" font-weight=\"normal\" fill=\"#252b3a\" >q2: </text><line x1=\"48.8\" x2=\"316.8\" y1=\"40.0\" y2=\"40.0\" stroke=\"#adb0b8\" stroke-width=\"1\" /><line x1=\"48.8\" x2=\"316.8\" y1=\"100.0\" y2=\"100.0\" stroke=\"#adb0b8\" stroke-width=\"1\" /><line x1=\"48.8\" x2=\"316.8\" y1=\"160.0\" y2=\"160.0\" stroke=\"#adb0b8\" stroke-width=\"1\" /><rect x=\"72.8\" y=\"20.0\" width=\"40.0\" height=\"40\" rx=\"4\" ry=\"4\" stroke=\"#ffffff\" stroke-width=\"0\" fill=\"#fac209\" fill-opacity=\"1\" /><text x=\"92.8\" y=\"36.0\" font-size=\"20px\" dominant-baseline=\"middle\" text-anchor=\"middle\" font-family=\"Arial\" font-weight=\"normal\" fill=\"#ffffff\" >RX </text><text x=\"92.8\" y=\"52.0\" font-size=\"14.0px\" dominant-baseline=\"middle\" text-anchor=\"middle\" font-family=\"Arial\" font-weight=\"normal\" fill=\"#ffffff\" >a </text><rect x=\"72.8\" y=\"80.0\" width=\"40.0\" height=\"40\" rx=\"4\" ry=\"4\" stroke=\"#ffffff\" stroke-width=\"0\" fill=\"#fac209\" fill-opacity=\"1\" /><text x=\"92.8\" y=\"96.0\" font-size=\"20px\" dominant-baseline=\"middle\" text-anchor=\"middle\" font-family=\"Arial\" font-weight=\"normal\" fill=\"#ffffff\" >RX </text><text x=\"92.8\" y=\"112.0\" font-size=\"14.0px\" dominant-baseline=\"middle\" text-anchor=\"middle\" font-family=\"Arial\" font-weight=\"normal\" fill=\"#ffffff\" >b </text><rect x=\"72.8\" y=\"140.0\" width=\"40.0\" height=\"40\" rx=\"4\" ry=\"4\" stroke=\"#ffffff\" stroke-width=\"0\" fill=\"#fac209\" fill-opacity=\"1\" /><text x=\"92.8\" y=\"156.0\" font-size=\"20px\" dominant-baseline=\"middle\" text-anchor=\"middle\" font-family=\"Arial\" font-weight=\"normal\" fill=\"#ffffff\" >RX </text><text x=\"92.8\" y=\"172.0\" font-size=\"14.0px\" dominant-baseline=\"middle\" text-anchor=\"middle\" font-family=\"Arial\" font-weight=\"normal\" fill=\"#ffffff\" >c </text><circle cx=\"152.8\" cy=\"40.0\" r=\"4\" fill=\"#16acff\" /><line x1=\"152.8\" x2=\"152.8\" y1=\"40.0\" y2=\"100.0\" stroke=\"#16acff\" stroke-width=\"3\" /><rect x=\"132.8\" y=\"80.0\" width=\"40\" height=\"40\" rx=\"4\" ry=\"4\" stroke=\"#ffffff\" stroke-width=\"0\" fill=\"#16acff\" fill-opacity=\"1\" /><line x1=\"138.8\" x2=\"166.8\" y1=\"100.0\" y2=\"100.0\" stroke=\"#ffffff\" stroke-width=\"4\" /><line x1=\"152.8\" x2=\"152.8\" y1=\"86.0\" y2=\"114.0\" stroke=\"#ffffff\" stroke-width=\"4\" /><circle cx=\"212.8\" cy=\"100.0\" r=\"4\" fill=\"#16acff\" /><line x1=\"212.8\" x2=\"212.8\" y1=\"100.0\" y2=\"160.0\" stroke=\"#16acff\" stroke-width=\"3\" /><rect x=\"192.8\" y=\"140.0\" width=\"40\" height=\"40\" rx=\"4\" ry=\"4\" stroke=\"#ffffff\" stroke-width=\"0\" fill=\"#16acff\" fill-opacity=\"1\" /><line x1=\"198.8\" x2=\"226.8\" y1=\"160.0\" y2=\"160.0\" stroke=\"#ffffff\" stroke-width=\"4\" /><line x1=\"212.8\" x2=\"212.8\" y1=\"146.0\" y2=\"174.0\" stroke=\"#ffffff\" stroke-width=\"4\" /><circle cx=\"272.8\" cy=\"160.0\" r=\"4\" fill=\"#16acff\" /><line x1=\"272.8\" x2=\"272.8\" y1=\"40.0\" y2=\"160.0\" stroke=\"#16acff\" stroke-width=\"3\" /><rect x=\"252.8\" y=\"20.0\" width=\"40\" height=\"40\" rx=\"4\" ry=\"4\" stroke=\"#ffffff\" stroke-width=\"0\" fill=\"#16acff\" fill-opacity=\"1\" /><line x1=\"258.8\" x2=\"286.8\" y1=\"40.0\" y2=\"40.0\" stroke=\"#ffffff\" stroke-width=\"4\" /><line x1=\"272.8\" x2=\"272.8\" y1=\"26.0\" y2=\"54.0\" stroke=\"#ffffff\" stroke-width=\"4\" /></svg>" ], "text/plain": [ "<mindquantum.io.display.circuit_svg_drawer.SVGCircuit at 0x7f0c83d947c0>" ] }, "execution_count": 17, "metadata": {}, "output_type": "execute_result" } ], "source": [ "circ.svg()" ] }, { "attachments": {}, "cell_type": "markdown", "metadata": {}, "source": [ "这里 `init_mapping` 和 `final_mapping` 分别告诉我们,最开始量子线路应该如何作用在量子硬件上,以及运行完线路后,各量子比特与原始线路中量子比特的对应关系。" ] }, { "cell_type": "code", "execution_count": 18, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "initial mapping: [3, 2, 0, 1]\n", " final mapping: [1, 2, 0, 3]\n" ] } ], "source": [ "print(f\"initial mapping: {init_mapping}\")\n", "print(f\" final mapping: {final_mapping}\")" ] }, { "attachments": {}, "cell_type": "markdown", "metadata": {}, "source": [ "我们还可以通过 `draw_topology`,在量子拓扑图中绘制出新的量子线路用到了哪些量子比特以及其耦合的边。" ] }, { "cell_type": "code", "execution_count": 19, "metadata": {}, "outputs": [ { "data": { "image/svg+xml": [ "<svg xmlns=\"http://www.w3.org/2000/svg\" width=\"84\" height=\"84\" xmlns:xlink=\"http://www.w3.org/1999/xlink\"><rect x=\"0\" y=\"0\" width=\"84\" height=\"84\" fill=\"#ffffff\" /><line x1=\"12.0\" x2=\"72.0\" y1=\"12.0\" y2=\"12.0\" stroke=\"#ff0000\" stroke-width=\"8\" /><line x1=\"12.0\" x2=\"12.0\" y1=\"12.0\" y2=\"72.0\" stroke=\"#ff0000\" stroke-width=\"8\" /><line x1=\"12.0\" x2=\"72.0\" y1=\"72.0\" y2=\"72.0\" stroke=\"#ff0000\" stroke-width=\"8\" /><line x1=\"72.0\" x2=\"72.0\" y1=\"12.0\" y2=\"72.0\" stroke=\"#ff0000\" stroke-width=\"8\" /><circle cx=\"12.0\" cy=\"12.0\" r=\"12\" fill=\"#000000\" /><text x=\"12.0\" y=\"12.0\" font-size=\"18px\" dominant-baseline=\"middle\" text-anchor=\"middle\" fill=\"#ffffff\" >0 </text><circle cx=\"72.0\" cy=\"12.0\" r=\"12\" fill=\"#000000\" /><text x=\"72.0\" y=\"12.0\" font-size=\"18px\" dominant-baseline=\"middle\" text-anchor=\"middle\" fill=\"#ffffff\" >1 </text><circle cx=\"12.0\" cy=\"72.0\" r=\"12\" fill=\"#000000\" /><text x=\"12.0\" y=\"72.0\" font-size=\"18px\" dominant-baseline=\"middle\" text-anchor=\"middle\" fill=\"#ffffff\" >2 </text><circle cx=\"72.0\" cy=\"72.0\" r=\"12\" fill=\"#000000\" /><text x=\"72.0\" y=\"72.0\" font-size=\"18px\" dominant-baseline=\"middle\" text-anchor=\"middle\" fill=\"#ffffff\" >3 </text></svg>" ], "text/plain": [ "<mindquantum.io.display.circuit_svg_drawer.SVGContainer at 0x7f0c83da8580>" ] }, "execution_count": 19, "metadata": {}, "output_type": "execute_result" } ], "source": [ "draw_topology(t, new_circ)" ] }, { "attachments": {}, "cell_type": "markdown", "metadata": {}, "source": [ "我们发现,其中的4个量子比特和4条边全部都用上了。" ] }, { "cell_type": "code", "execution_count": 20, "metadata": {}, "outputs": [ { "data": { "text/html": [ "\n", "<table border=\"1\">\n", " <tr>\n", " <th>Software</th>\n", " <th>Version</th>\n", " </tr>\n", "<tr><td>mindquantum</td><td>0.9.11</td></tr>\n", "<tr><td>scipy</td><td>1.10.1</td></tr>\n", "<tr><td>numpy</td><td>1.24.4</td></tr>\n", "<tr>\n", " <th>System</th>\n", " <th>Info</th>\n", "</tr>\n", "<tr><td>Python</td><td>3.8.17</td></tr><tr><td>OS</td><td>Linux x86_64</td></tr><tr><td>Memory</td><td>16.62 GB</td></tr><tr><td>CPU Max Thread</td><td>16</td></tr><tr><td>Date</td><td>Tue Jan 2 16:54:34 2024</td></tr>\n", "</table>\n" ], "text/plain": [ "<mindquantum.utils.show_info.InfoTable at 0x7f0c83d8a730>" ] }, "execution_count": 20, "metadata": {}, "output_type": "execute_result" } ], "source": [ "from mindquantum.utils.show_info import InfoTable\n", "InfoTable('mindquantum', 'scipy', 'numpy')" ] } ], "metadata": { "kernelspec": { "display_name": "MindSpore", "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.8.17" }, "orig_nbformat": 4 }, "nbformat": 4, "nbformat_minor": 2 }