Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
{
"cells": [
{
"cell_type": "markdown",
"metadata": {},
"source": [
"# `Gate` の削除"
]
},
{
"cell_type": "code",
"execution_count": 1,
"metadata": {},
"outputs": [],
"source": [
"import matplotlib.pyplot as plt\n",
"%matplotlib inline\n",
"import numpy as np\n",
"from qiskit import QuantumCircuit, ClassicalRegister, QuantumRegister, execute"
]
},
{
"cell_type": "code",
"execution_count": 2,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"[(<qiskit.extensions.standard.x.XGate at 0x27bc5572f08>,\n",
" [Qubit(QuantumRegister(1, 'q'), 0)],\n",
" []),\n",
" (<qiskit.extensions.standard.h.HGate at 0x27bc55744c8>,\n",
" [Qubit(QuantumRegister(1, 'q'), 0)],\n",
" []),\n",
" (<qiskit.circuit.measure.Measure at 0x27bc5574408>,\n",
" [Qubit(QuantumRegister(1, 'q'), 0)],\n",
" [Clbit(ClassicalRegister(1, 'c'), 0)])]"
]
},
"execution_count": 2,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"Circ = QuantumCircuit(1, 1)\n",
"Circ.x(0)\n",
"Circ.h(0)\n",
"Circ.measure(0, 0)\n",
"Circ.data"
]
},
{
"cell_type": "code",
"execution_count": 3,
"metadata": {},
"outputs": [
{
"data": {
"image/png": "iVBORw0KGgoAAAANSUhEUgAAAOwAAAB7CAYAAAB3sGzvAAAABHNCSVQICAgIfAhkiAAAAAlwSFlzAAALEgAACxIB0t1+/AAAADh0RVh0U29mdHdhcmUAbWF0cGxvdGxpYiB2ZXJzaW9uMy4xLjEsIGh0dHA6Ly9tYXRwbG90bGliLm9yZy8QZhcZAAAKVElEQVR4nO3df0zU9x3H8dfdgaiglt9EfhU5rXIRVJi1tq65kU7W2apolbLwRyt2Jy6CbTZrUze7rSJg1hldzRWJaaK2+AP0j3Zxo+05O9b0tOHg0FZRlB9hgJu02IpV7vYHle5E4KB3fu4dXo+EP/h+78eb6PM+3/utcTqdThCRCFrVAx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wmCJBGGwRIIwWCJBGCyRIAyWSBAGSyQIgyUShMESCcJgiQRhsESCMFgiQRgskSAMlkgQBkskCIMlEoTBEgnCYIkE+R+1cdv8JF6S6wAAAABJRU5ErkJggg==\n",
"text/plain": [
"<Figure size 293.776x144.48 with 1 Axes>"
]
},
"execution_count": 3,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"Circ.draw(output=\"mpl\")"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"`measure` を削除する"
]
},
{
"cell_type": "code",
"execution_count": 4,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"[(<qiskit.extensions.standard.x.XGate at 0x27bc5572f08>,\n",
" [Qubit(QuantumRegister(1, 'q'), 0)],\n",
" []),\n",
" (<qiskit.extensions.standard.h.HGate at 0x27bc55744c8>,\n",
" [Qubit(QuantumRegister(1, 'q'), 0)],\n",
" [])]"
]
},
"execution_count": 4,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"Circ.data.pop()\n",
"Circ.data"
]
},
{
"cell_type": "code",
"execution_count": 5,
"metadata": {},
"outputs": [
{
"data": {
"image/png": "iVBORw0KGgoAAAANSUhEUgAAAL4AAAB7CAYAAADKUTqaAAAABHNCSVQICAgIfAhkiAAAAAlwSFlzAAALEgAACxIB0t1+/AAAADh0RVh0U29mdHdhcmUAbWF0cGxvdGxpYiB2ZXJzaW9uMy4xLjEsIGh0dHA6Ly9tYXRwbG90bGliLm9yZy8QZhcZAAAGZElEQVR4nO3df0zUdRzH8df37hAQRH51sIRQxFwwjk3NtpI5/ygvRd0iIU3bdAGabOFcpX9ULgsMKP2j1mj1h5s/BrJj94/MYg3CaPOYE4WcFzsa2ghycQ4MUO6+/aHRLkuOH8fn4P16bPzzOe6+b+C5D9/vjeM0Xdd1EAljUD0AkQoMn0Ri+CQSwyeRGD6JxPBJJIZPIjF8Eonhk0gMn0Ri+CQSwyeRGD6JxPBJJIZPIjF8Eonhk0gMn0Ri+CQSwyeRGD6JxPBJJIZPIj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DrciBhydMwGH33wZ7OH+fkaQ4AaPpEf5fPkJ07d6KtrQ1XrlxRPQpfejgBfOnhFLW2ts6q0xyaXYIy/MHBQTidzoBf2JJcyi9u/0tkZCQ8Ho/qMWgOC8odnyjQGD6JxPBJJIZPIjF8Eonhk0gMn0QK2j9ZIAok7vgkEsMnkRg+icTwSSSGTyIxfBKJ4ZNIDJ9EYvgkEsMnkRg+icTwSSSGTyIxfBKJ4ZNIDJ9EYvgkEsMnkRg+icTwSSSGTyIxfBKJ4ZNIDJ9EYvgkEsP/F7vdjpycHJjNZoSGhiIlJQXbt2/H1atXVY9G04j/QvCB0dFR7NixA9XV1UhKSsLGjRsRFRUFp9OJ+vp62O12WK1W1WPSNAnK98BSobi4GNXV1SgoKMCxY8cQERExdtuNGzcQHR0dsGMf/PjLgD22NEffKfTr8xg+gObmZlRVVcFqtaKqqgqapvncnpycrGgyChSe6gDIzc2FzWbD5cuXkZWVNf4daNZj+ACioqIQFxeHrq4uJcfnqc708fdUR/yzOm63GwMDA1i8eLHqUWgGid/x+/v7ERsbi/T0dHR0dKgeh2aI+B0/JiYGS5cuxbVr19DQ0PDQ7devX1cwFQWa+B0fAGpqapCfnw+j0YgtW7YgLS0NfX19aGlpQXp6Ourq6lSPSNOM4T9w/vx5VFRUwOFwYHh4GGazGatXr0ZJSQmys7NVj0fTjOGTSOLP8Ukmhk8iMXwSieGTSAyfRGL4JBLDJ5EYPonE8Ekkhk8iMXwSieGTSAyfRGL4JBLDJ5EYPonE8Ekkhk8iMXwSieGTSAyfRGL4JBLDJ5EYPonE8Ekkhk8iMXwS6S/1MEik7b934gAAAABJRU5ErkJggg==\n",
"text/plain": [
"<Figure size 233.576x144.48 with 1 Axes>"
]
},
"execution_count": 5,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"Circ.draw(output=\"mpl\")"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"アダマール変換を削除する"
]
},
{
"cell_type": "code",
"execution_count": 6,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"[(<qiskit.extensions.standard.x.XGate at 0x27bc5572f08>,\n",
" [Qubit(QuantumRegister(1, 'q'), 0)],\n",
" [])]"
]
},
"execution_count": 6,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"Circ.data.pop()\n",
"Circ.data"
]
},
{
"cell_type": "code",
"execution_count": 7,
"metadata": {},
"outputs": [
{
"data": {
"image/png": "iVBORw0KGgoAAAANSUhEUgAAAJEAAAB7CAYAAAB0B2LHAAAABHNCSVQICAgIfAhkiAAAAAlwSFlzAAALEgAACxIB0t1+/AAAADh0RVh0U29mdHdhcmUAbWF0cGxvdGxpYiB2ZXJzaW9uMy4xLjEsIGh0dHA6Ly9tYXRwbG90bGliLm9yZy8QZhcZAAAFNklEQVR4nO3dT2gUZxjH8d/uJiY2EpIYgqCiaERIcAMKHtoG8dB2i6ke0iRV9KAQU6uHgLT10j/UNrFJWntoD+lNaJWNYcNeXKShmEZzMEH8l4p7MEUFQQQjColtdqeHWou1xdXH5Z0x3w/MZRbyPoQv78yy2UzI8zxPgEHY9QAIPiKCGRHBjIhgRkQwIyKYERHMiAhmRAQzIoIZEcGMiGBGRDAjIpgREcyICGZEBDMighkRwYyIYEZEMCMimBERzIgIZkQEMyKCGRHBrMD1AEEw56eUk3V/f+1NJ+s+LXYimBERzIgIZkQEMyKCGRHBjIhgRkQwIyKY+SaibDarnp4erVixQsXFxaqrq9PQ0JBWrlypnTt3uh4vZ97UlP5oekfZ4ZP/nLt/XzPtezXz2RfyslmH0+WHbyLasWOH9u/fr7a2NqVSKTU3N2vz5s26cuWK1qxZ43q8nIXmzlX47UZlfjwiz/PkZTLKfN4pFRYqsu8DhcK++ZU/N7747Ozw4cM6dOiQTpw4oXXr1kmS1q9frzNnziiRSAQqIkkKb3xL2f6EvJOnlD09Ju/WLRX0dCk0p9D1aHnhi4g6OzsVi8UeBvS36upqFRYWatWqVY4mezahucUKNzUq0/21VF6mgm++UqjkJddj5Y3zvfX69eu6ePGimpq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YEZEMCMimBERzIgIZkQEsz8B3M/FcLXYnucAAAAASUVORK5CYII=\n",
"text/plain": [
"<Figure size 173.376x144.48 with 1 Axes>"
]
},
"execution_count": 7,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"Circ.draw(output=\"mpl\")"
]
},
{
"cell_type": "code",
"execution_count": 8,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"{'qiskit-terra': '0.9.0',\n",
" 'qiskit-ignis': '0.2.0',\n",
" 'qiskit-aqua': '0.6.0',\n",
" 'qiskit': '0.12.0',\n",
" 'qiskit-aer': '0.3.0',\n",
" 'qiskit-ibmq-provider': '0.3.2'}"
]
},
"execution_count": 8,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"import qiskit\n",
"qiskit.__qiskit_version__"
]
}
],
"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.7.4"
}
},
"nbformat": 4,
"nbformat_minor": 4
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment