total_search
概要
この関数では線形結合を構成するパウリ行列積の一覧から量子回路上で必要なビット数を算出する
引数一覧
argument name |
type |
role |
---|---|---|
ope_list |
list(elements:int) |
作用させるパウリ行列積の一覧 |
戻り値
np.array(bit_list).max()+1(int):作用先のビット番号のうち最大のものに1を足して出力する
1を足しているのは作用先のビット番号が0から始まるためである
Python code
def total_search(ope_list):
"""
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.
Parameters:
ope_list: the information about Pauli matrix product
Returns:
int: the number of qubits which express quantum state
"""
# Local Values
bit_list = [] # A list to store the results of the reading process for the number of qubits
app_list = "" # A temporary list to store the results of the reading process for the number of qubits
for i in range(len(ope_list) - 1):
for j in range(len(ope_list[i+1])-1):
app_switch = 0
if ope_list[i+1][j+1] == "X":
app_switch = 1
if ope_list[i+1][j+1] == "Y":
app_switch = 1
if ope_list[i+1][j+1] == "Z":
app_switch = 1
if ope_list[i+1][j+1] == "I":
app_switch = 1
if app_switch == 0:
app_list += str(ope_list[i+1][j+1])
if app_switch == 1:
bit_list.append(int(app_list))
app_list = ""
bit_list.append(int(app_list))
app_list = ""
return np.array(bit_list).max()+1
実行例
[1]:
import numpy as np
import pitbe
[2]:
ope = ['', 'X0X1Y2Y3', 'X0Y1Y2X3', 'Y0X1X2Y3', 'Y0Y1X2X3', 'Z0', 'Z0Z1', 'Z0Z2', 'Z0Z3', 'Z1', 'Z1Z2', 'Z1Z3', 'Z2', 'Z2Z3', 'Z3']
main = pitbe.total_search(ope)
print(main)
4
注意点
前述の通り入力情報は本パッケージ内の出力結果の利用を想定しているので異なる様式を用いた場合望んだ出力結果にならないこともあるので注意してほしい