電子配置のプールにフェルミオン遷移を追加する
ここでは、各電子配置に遷移演算子を作用させて得られる電子配置のプールを拡張する機能を紹介します。
次の形式の単一電子ホッピングを追加する方法を示します。
、 とし、電子配置のバッチに含まれるすべての に対して適用します。 まず、ランダムな電子配置のバッチを生成します。
# Added by doQumentation — installs the packages this notebook needs if they are missing
import importlib.util
_needed = {"numpy": "numpy", "qiskit_addon_sqd": "qiskit-addon-sqd"}
_missing = [pip for module, pip in _needed.items()
if importlib.util.find_spec(module) is None]
# One at a time, so a package that fails to install does not block the others
for _pip in _missing:
%pip install -q {_pip}
if not _missing:
print("\u2713 All required packages are installed")
import numpy as np
n_qubits = 8
n_orb = n_qubits // 2
rand_seed = 22
np.random.seed(rand_seed)
# Generate some random bitstrings for testing
def random_bitstrings(n_samples, n_qubits):
return (
np.round(np.random.rand(n_samples, n_qubits))
.astype("int")
.astype("bool")
)
bitstring_matrix = random_bitstrings(100, n_qubits)
励起演算子は、フェルミオンノード (またはクビット) の数と同じ長さの numpy 配列の中で指定します。配列の各要素は、次の値をとることができる文字列でなければなりません。
-
'I': Identity -
'+': 生成演算子 -
'-': 消滅演算子
(同じスピン種の間で) 可能なすべての単一電子遷移を生成します。
transitions_single = np.array(
[
["I" for i in range(2 * n_orb)]
for j in range(4 * (n_orb**2 - n_orb) // 2 + 1)
]
)
count = 1
for i in range(n_orb):
for j in range(i + 1, n_orb):
# spin up
transitions_single[count, i] = "+"
transitions_single[count, j] = "-"
count += 1
transitions_single[count, i] = "-"
transitions_single[count, j] = "+"
count += 1
# spin down
transitions_single[count, i + n_orb] = "+"
transitions_single[count, j + n_orb] = "-"
count += 1
transitions_single[count, i + n_orb] = "-"
transitions_single[count, j + n_orb] = "+"
count += 1
print(transitions_single)
[['I' 'I' 'I' 'I' 'I' 'I' 'I' 'I']
['+' '-' 'I' 'I' 'I' 'I' 'I' 'I']
['-' '+' 'I' 'I' 'I' 'I' 'I' 'I']
['I' 'I' 'I' 'I' '+' '-' 'I' 'I']
['I' 'I' 'I' 'I' '-' '+' 'I' 'I']
['+' 'I' '-' 'I' 'I' 'I' 'I' 'I']
['-' 'I' '+' 'I' 'I' 'I' 'I' 'I']
['I' 'I' 'I' 'I' '+' 'I' '-' 'I']
['I' 'I' 'I' 'I' '-' 'I' '+' 'I']
['+' 'I' 'I' '-' 'I' 'I' 'I' 'I']
['-' 'I' 'I' '+' 'I' 'I' 'I' 'I']
['I' 'I' 'I' 'I' '+' 'I' 'I' '-']
['I' 'I' 'I' 'I' '-' 'I' 'I' '+']
['I' '+' '-' 'I' 'I' 'I' 'I' 'I']
['I' '-' '+' 'I' 'I' 'I' 'I' 'I']
['I' 'I' 'I' 'I' 'I' '+' '-' 'I']
['I' 'I' 'I' 'I' 'I' '-' '+' 'I']
['I' '+' 'I' '-' 'I' 'I' 'I' 'I']
['I' '-' 'I' '+' 'I' 'I' 'I' 'I']
['I' 'I' 'I' 'I' 'I' '+' 'I' '-']
['I' 'I' 'I' 'I' 'I' '-' 'I' '+']
['I' 'I' '+' '-' 'I' 'I' 'I' 'I']
['I' 'I' '-' '+' 'I' 'I' 'I' 'I']
['I' 'I' 'I' 'I' 'I' 'I' '+' '-']
['I' 'I' 'I' 'I' 'I' 'I' '-' '+']]
次に、bitstring_matrix 内の電子配置に遷移演算子を適用します。
from qiskit_addon_sqd.fermion import enlarge_batch_from_transitions
bitstring_matrix_aug = enlarge_batch_from_transitions(
bitstring_matrix, transitions_single
)
print(bitstring_matrix_aug.shape)
print(bitstring_matrix_aug)
(723, 8)
[[False False False ... False False True]
[False True False ... True False False]
[ True True True ... True False True]
...
[ True False True ... False False True]
[ True True True ... True False True]
[False False False ... False False True]]