diff --git a/docs/mindquantum/docs/source_zh_cn/beginner/chip_tutorial.ipynb b/docs/mindquantum/docs/source_zh_cn/beginner/chip_tutorial.ipynb new file mode 100644 index 0000000000000000000000000000000000000000..5ca3fef55cda6f00c2cb6768aedb650cdc8f25b7 --- /dev/null +++ b/docs/mindquantum/docs/source_zh_cn/beginner/chip_tutorial.ipynb @@ -0,0 +1,377 @@ +{ + "cells": [ + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "# MindQuantum编程实践\n", + "\n", + "## 量子计算机中的量子比特" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [ + "from mindquantum.device import Quafu\n", + "\n", + "token = 'NhlRrlzXU`3e{9[CTD.ZGWyq44dZiV7lfwQpK.HnVRr/:WEOzJ{O1hkM4R{O6FkN3J{OypkJxiY[jxjJ4BkP6JkP4FEJ1FUM5BUM1JENzJjPjRYZqKDMj13ck6zN3FER6lUewinflWnbjpkJzW3d2Kzf'\n", + "quafu = Quafu('Baihua', token=token)\n", + "\n", + "# 查看当前各个芯片的任务队列情况\n", + "quafu.get_supported_chip()" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [ + "# 查看Baihua芯片的信息\n", + "print(quafu.get_chip_info('Baihua'))\n", + "\n", + "# 绘制量子比特的T1数据\n", + "# print(quafu.get_chip_info('Baihua', draw='T1'))" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## 在量子计算机上运行量子线路" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [ + "from mindquantum.core.gates import Measure, H, X, Y\n", + "from mindquantum.core.circuit import Circuit\n", + "from mindquantum.device import Quafu\n", + "\n", + "circ = Circuit()\n", + "circ += H.on(0)\n", + "circ += Y.on(0)\n", + "circ += X.on(1)\n", + "\n", + "circ += Measure().on(0)\n", + "circ += Measure().on(1)\n", + "\n", + "circ.svg()" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [ + "quafu = Quafu('Baihua')\n", + "res = quafu.sampling(circ, shots=1024, wait=True)\n", + "res" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## Pauli-X门" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [ + "from mindquantum.core.gates import X\n", + "from mindquantum.core.circuit import Circuit\n", + "from mindquantum.device import Quafu\n", + "\n", + "circ = Circuit()\n", + "for i in range(4):\n", + " circ += X.on(i)\n", + "circ.measure_all()\n", + "\n", + "circ.svg()" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [ + "quafu = Quafu('Baihua')\n", + "res = quafu.sampling(circ, shots=1024, wait=True)\n", + "res" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## Pauli-Z门" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [ + "from mindquantum.core.gates import X, Z\n", + "from mindquantum.core.circuit import Circuit\n", + "from mindquantum.device import Quafu\n", + "\n", + "circ = Circuit()\n", + "for i in range(4):\n", + " circ += X.on(i)\n", + "circ += Z.on(0)\n", + "circ.measure_all()\n", + "\n", + "circ.svg()" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [ + "quafu = Quafu('Baihua')\n", + "res = quafu.sampling(circ, shots=1024, wait=True)\n", + "res" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## Pauli-Y门" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [ + "from mindquantum.core.gates import X\n", + "from mindquantum.core.circuit import Circuit\n", + "from mindquantum.device import Quafu\n", + "\n", + "circ = Circuit()\n", + "for i in range(4):\n", + " circ += X.on(i)\n", + "circ += Y.on(0)\n", + "circ.measure_all()\n", + "\n", + "circ.svg()" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [ + "quafu = Quafu('Baihua')\n", + "res = quafu.sampling(circ, shots=1024, wait=True)\n", + "res" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## Hadamard门" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [ + "from mindquantum.core.gates import H\n", + "from mindquantum.core.circuit import Circuit\n", + "from mindquantum.device import Quafu\n", + "\n", + "circ = Circuit()\n", + "circ += H.on(0)\n", + "circ.measure_all()\n", + "\n", + "circ.svg()" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [ + "quafu = Quafu('Baihua')\n", + "res = quafu.sampling(circ, shots=1024, wait=True)\n", + "res" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## 参数化量子门:旋转门" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [ + "from mindquantum.core.gates import RX\n", + "from mindquantum.core.circuit import Circuit\n", + "from mindquantum.device import Quafu\n", + "import numpy as np\n", + "\n", + "circ = Circuit()\n", + "circ += RX(np.pi / 2).on(0)\n", + "circ.measure_all()\n", + "\n", + "circ.svg()" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [ + "quafu = Quafu('Baihua')\n", + "res = quafu.sampling(circ, shots=1024, wait=True)\n", + "res" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## 两比特量子门:CNOT门" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [ + "from mindquantum.core.gates import X\n", + "from mindquantum.core.circuit import Circuit\n", + "from mindquantum.device import Quafu\n", + "\n", + "circ = Circuit()\n", + "circ += X.on(0)\n", + "circ += X.on(1, 0)\n", + "circ.measure_all()\n", + "\n", + "circ.svg()" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [ + "quafu = Quafu('Baihua')\n", + "res = quafu.sampling(circ, shots=1024, wait=True)\n", + "res" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## 研讨环节" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [ + "from mindquantum.core.gates import X, H\n", + "from mindquantum.core.circuit import Circuit\n", + "from mindquantum.device import Quafu\n", + "\n", + "# 请搭建你设计的量子线路\n", + "circ = Circuit()\n", + "circ += ...\n", + "\n", + "\n", + "circ.svg()" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [ + "quafu = Quafu('Baihua')\n", + "res = quafu.sampling(circ, shots=8192, wait=True)\n", + "res" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## 量子模拟器\n", + "\n", + "若量子计算真机不可用,可将前面的相应代码进行替换:" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [ + "from mindquantum.simulator import Simulator\n", + "\n", + "# 选择'mqvector'模拟器,量子比特数为4\n", + "sim = Simulator('mqvector', 4)\n", + "res = sim.sampling(circ, shots=1024)\n", + "res" + ] + } + ], + "metadata": { + "kernelspec": { + "display_name": "py310", + "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.14" + } + }, + "nbformat": 4, + "nbformat_minor": 4 +}