{ "cells": [ { "cell_type": "markdown", "id": "67563bc9", "metadata": {}, "source": [ "## total_search" ] }, { "cell_type": "markdown", "id": "7400e79e", "metadata": {}, "source": [ "### **Outline**\n", "This function calculates the number of qubits required on the quantum circuit based on the list of products of Pauli matrices that make up the linear combination." ] }, { "cell_type": "markdown", "id": "cfd89683", "metadata": {}, "source": [ "### **引数一覧**\n", "|argument name|type|role|\n", "|---|---|---|\n", "|ope_list|list(elements:int)|List of prodactions of Pauli matrices|" ] }, { "cell_type": "markdown", "id": "01b52249", "metadata": {}, "source": [ "### **戻り値**\n", "np.array(bit_list).max()+1(int):\\\n", "Returns the maximum target qubit index plus one.\n", "This is because qubit indices start from zero." ] }, { "cell_type": "markdown", "id": "3b8ec0f7", "metadata": {}, "source": [ "### **Python code**\n", "```python\n", "def total_search(ope_list):\n", " \"\"\"\n", " This function reads out the coefficients and Pauli matrix product information from the results of the Jordan–Wigner and Bravyi–Kitaev transformations performed using OpenFermion.\n", "\n", " Parameters:\n", " ope_list: the information about Pauli matrix product\n", "\n", " Returns:\n", " int: the number of qubits which express quantum state\n", " \"\"\"\n", " # Local Values\n", " bit_list = [] # A list to store the results of the reading process for the number of qubits\n", " app_list = \"\" # A temporary list to store the results of the reading process for the number of qubits\n", " for i in range(len(ope_list) - 1):\n", " for j in range(len(ope_list[i+1])-1):\n", " app_switch = 0\n", " if ope_list[i+1][j+1] == \"X\":\n", " app_switch = 1\n", " if ope_list[i+1][j+1] == \"Y\":\n", " app_switch = 1\n", " if ope_list[i+1][j+1] == \"Z\":\n", " app_switch = 1\n", " if ope_list[i+1][j+1] == \"I\":\n", " app_switch = 1\n", " if app_switch == 0:\n", " app_list += str(ope_list[i+1][j+1])\n", " if app_switch == 1:\n", " bit_list.append(int(app_list))\n", " app_list = \"\"\n", " bit_list.append(int(app_list))\n", " app_list = \"\"\n", " return np.array(bit_list).max()+1\n", "```" ] }, { "cell_type": "markdown", "id": "8df83144", "metadata": {}, "source": [ "### **実行例**" ] }, { "cell_type": "code", "execution_count": null, "id": "ac05812e", "metadata": {}, "outputs": [], "source": [ "import numpy as np\n", "import pitbe" ] }, { "cell_type": "code", "execution_count": null, "id": "958b7860", "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "4\n" ] } ], "source": [ "ope = ['', 'X0X1Y2Y3', 'X0Y1Y2X3', 'Y0X1X2Y3', 'Y0Y1X2X3', 'Z0', 'Z0Z1', 'Z0Z2', 'Z0Z3', 'Z1', 'Z1Z2', 'Z1Z3', 'Z2', 'Z2Z3', 'Z3']\n", "main = pitbe.total_search(ope)\n", "print(main)" ] } ], "metadata": { "language_info": { "name": "python" } }, "nbformat": 4, "nbformat_minor": 5 }