Unawain ang mga opsyong open-shell kumpara sa closed-shell at ang epekto sa pagbuo ng subspace
Sa gabay na ito, ipapakita namin kung paano pumili ng mga dimensyon ng subspace sa package na qiskit_addon_sqd para i-post-process ang mga quantum sample gamit ang self-consistent configuration recovery technique.
Higit sa lahat, binibigyang-diin din ng gabay na ito ang ilang pagkakaiba sa gawi ng pagbuo ng subspace kapag pinatakbo sa mode na open_shell = False o open_shell = True:
-
Gumagana lang ang
open_shell = Falsekapag pareho ang bilang ng mga spin-up at spin-down na electron. -
Dapat gamitin ang
open_shell = Truekapag magkaiba ang bilang ng mga spin-up at spin-down na electron. Magagamit din ito kapag pareho ang bilang ng mga spin-up at spin-down na electron. Gayunpaman, sa huling kasong ito, may pagkakaiba sa laki ng mga subspace na nabubuo sa pagitan ngopen_shell = Falseatopen_shell = True, gaya ng tinalakay sa gabay na ito.
TANDAAN: Ang ilan sa mga manipulasyon ng electronic-configuration (bitstring) sa package na ito ay may layuning panatilihin ang kabuuang spin symmetry na . Hindi eksaktong maipapatupad ng mga karaniwang Selected Configuration Interaction (SCI) solver ang konserbasyon ng . Kaya, tinatantiya lang nila ito sa pamamagitan ng Lagrange multiplier.
Malaki rin ang epekto ng pagpili ng mga electronic configuration na papasok sa eigenstate solver sa konserbasyon ng spin. Halimbawa, sa isang (2-electron, 2-orbital) na sistema, puwedeng mag-sample ng configuration na (na may iisang spin-up excitation sa ibabaw ng RHF state na ), na isang linear combination ng open-shell na singlet at triplet state, na ayon sa pagkakabanggit ay . Kung hindi nai-sample ang configuration na |0110⟩, hindi makakabuo ng alinman sa mga eigenfunction ng kabuuang spin, na humahantong sa spin contamination o redundancy (ang configuration na |1001⟩ ay kasama sa isang CI calculation, pero may coefficient na 0 sa CI vector). Dahil iisang sample na ang nabubuo sa quantum computer, ganito hinahawakan ng package na sqd ang sitwasyong ito:
-
open_shell = False:-
Hinahati sa gitna ang bitstring na , na kumakatawan sa mga spin-up at spin-down na configuration: (up) at (down).
-
Binubuo ang listahan ng mga natatanging spin-polarized na configuration: .
-
Pagkatapos, isinasaalang-alang natin ang lahat ng posibleng kombinasyon ng mga elemento ng para buuin ang basis: , na naglalaman ng mga singlet at triplet state.
-
-
open_shell = True:- Taliwas sa kasong
open_shell = False, hindi natin pinagsasama ang mga kalahati ng bitstring para buuin ang basis.
- Taliwas sa kasong
Saradong shell
Ipinapakita ng halimbawang ito kung paano minamanipula ang mga bitstring sa isang (2-electron, 4-orbital) na sistema.
# Added by doQumentation — installs the packages this notebook needs if they are missing
import importlib.util
_needed = {"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")
# Specify molecule properties
num_orbitals = 4
num_elec_a = num_elec_b = 1
open_shell = False
Tukuyin nang mano-mano ang isang dictionary ng mga resulta ng pagsukat:
counts_dict = {
"00010010": 1 / 2.0 - 0.01,
"01001000": 1 / 2.0 - 0.01,
"00010001": 0.02,
}
Gawing bitstring matrix at probability array ang counts na dict para sa post-processing:
from qiskit_addon_sqd.counts import counts_to_arrays
# Convert counts into bitstring and probability arrays
bitstring_matrix_full, probs_arr_full = counts_to_arrays(counts_dict)
print(bitstring_matrix_full)
print(probs_arr_full)
[[False False False True False False True False]
[False True False False True False False False]
[False False False True False False False True]]
[0.49 0.49 0.02]
Mag-subsample ng isang batch na may sukat na dalawa:
-
n_batches = 1: Bilang ng mga batch ng configuration na ginagamit ng iba't ibang tawag sa eigenstate solver -
samples_per_batch = 2: Bilang ng mga natatanging configuration na isasama sa bawat batch
from qiskit_addon_sqd.subsampling import (
postselect_by_hamming_right_and_left,
subsample,
)
n_batches = 1
samples_per_batch = 2
# seed for random number generator
rand_seed = 48
# Post-select the configurations with the correct Hamming weight on each half
bitstring_matrix_postsel, probs_arr_postsel = (
postselect_by_hamming_right_and_left(
bitstring_matrix_full,
probs_arr_full,
hamming_right=num_elec_a,
hamming_left=num_elec_b,
)
)
# Generate the batches
batches = subsample(
bitstring_matrix_postsel,
probs_arr_postsel,
samples_per_batch,
n_batches,
rand_seed=rand_seed,
)
print(batches[0])
[[False False False True False False True False]
[False True False False True False False False]]
Kunin ang decimal na representasyon ng mga spin-up at spin-down na bitstring na ginagamit ng eigenstate solver.
Ang unang elemento sa tuple ay tumutugma sa decimal na representasyon ng mga spin-up na configuration, habang ang ikalawang elemento sa tuple ay tumutugma sa decimal na representasyon ng mga spin-down na configuration:
from qiskit_addon_sqd.fermion import bitstring_matrix_to_ci_strs
ci_strs = bitstring_matrix_to_ci_strs(batches[0], open_shell=open_shell)
print(ci_strs)
(array([1, 2, 4, 8], dtype=int64), array([1, 2, 4, 8], dtype=int64))
Tandaan na kahit dalawa ang bilang ng mga sample bawat batch, at ang mga na-sample na bitstring ay: at , apat na electronic configuration ang nabubuo bawat spin-species. Sa kasong ito, ang set ng mga natatanging spin-polarized na configuration ay:
na ang base-10 na decimal na representasyon ay
Basis ng subspace:
Kinukuha ng eigenstate solver ang lahat ng posibleng pares ng spin-up at spin-down na bitstring para buuin ang basis na ng subspace:
-
Elemento 1:
-
Elemento 2:
-
Elemento 3:
-
Elemento 4:
-
Elemento 5:
-
Elemento 6:
-
Elemento 7:
-
Elemento 8:
-
Elemento 9:
-
Elemento 10:
-
Elemento 11:
-
Elemento 12:
-
Elemento 13:
-
Elemento 14:
-
Elemento 15:
-
Elemento 16:
ci_strs_up, ci_strs_dn = ci_strs
print("Basis elements of the subspace:")
for ci_str_up in ci_strs_up:
for ci_str_dn in ci_strs_dn:
format_name = "{0:0" + str(num_orbitals) + "b}"
print(
"|"
+ format_name.format(ci_str_up)
+ format_name.format(ci_str_dn)
+ ">"
)
Basis elements of the subspace:
|00010001>
|00010010>
|00010100>
|00011000>
|00100001>
|00100010>
|00100100>
|00101000>
|01000001>
|01000010>
|01000100>
|01001000>
|10000001>
|10000010>
|10000100>
|10001000>
Ang dimensyon ng subspace ay may upper bound na: (samples_per_batch).
Bukas na shell
Ipinapakita ng halimbawang ito kung paano minamanipula ang mga bitstring sa isang (2-electron, 4-orbital) na sistema.
# Specify molecule properties
num_orbitals = 4
num_elec_a = num_elec_b = 1
open_shell = True
Tukuyin nang mano-mano ang isang dictionary ng mga resulta ng pagsukat:
counts_dict = {
"00010010": 1 / 2.0 - 0.01,
"01001000": 1 / 2.0 - 0.01,
"00010001": 0.02,
}
Gawing bitstring matrix at probability array ang counts na dict para sa post-processing:
# Convert counts into bitstring and probability arrays
bitstring_matrix_full, probs_arr_full = counts_to_arrays(counts_dict)
print(bitstring_matrix_full)
print(probs_arr_full)
[[False False False True False False True False]
[False True False False True False False False]
[False False False True False False False True]]
[0.49 0.49 0.02]
Mag-subsample ng isang batch na may sukat na dalawa:
-
n_batches = 1: Bilang ng mga batch ng configuration na ginagamit ng iba't ibang tawag sa eigenstate solver -
samples_per_batch = 2: Bilang ng mga natatanging configuration na isasama sa bawat batch
n_batches = 1
samples_per_batch = 2
# seed for random number generator
rand_seed = 48
# Post-select the configurations with the correct Hamming weight on each half
bitstring_matrix_postsel, probs_arr_postsel = (
postselect_by_hamming_right_and_left(
bitstring_matrix_full,
probs_arr_full,
hamming_right=num_elec_a,
hamming_left=num_elec_b,
)
)
# Generate the batches
batches = subsample(
bitstring_matrix_postsel,
probs_arr_postsel,
samples_per_batch,
n_batches,
rand_seed=rand_seed,
)
print(batches[0])
[[False False False True False False True False]
[False True False False True False False False]]
Kunin ang decimal na representasyon ng mga spin-up at spin-down na bitstring na ginagamit ng eigenstate solver.
Ang unang elemento sa tuple ay tumutugma sa decimal na representasyon ng mga spin-up na configuration, habang ang ikalawang elemento sa tuple ay tumutugma sa decimal na representasyon ng mga spin-down na configuration:
ci_strs = bitstring_matrix_to_ci_strs(batches[0], open_shell=open_shell)
print(ci_strs)
(array([2, 8], dtype=int64), array([1, 4], dtype=int64))
Kapag tinukoy nating open_shell = True, hindi natin isinasama ang lahat ng natatanging half-bitstring bilang mga spin-up at spin-down na configuration, kaya mas maliit ang nabubuong basis kaysa kapag tinukoy ang open_shell = False.
Basis ng subspace:
Kinukuha ng eigenstate solver ang lahat ng posibleng pares ng spin-up at spin-down na bitstring para buuin ang basis na ng subspace:
-
Elemento 1:
-
Elemento 2:
-
Elemento 3:
-
Elemento 4:
ci_strs_up, ci_strs_dn = ci_strs
print("Basis elements of the subspace:")
for ci_str_up in ci_strs_up:
for ci_str_dn in ci_strs_dn:
format_name = "{0:0" + str(num_orbitals) + "b}"
print(
"|"
+ format_name.format(ci_str_up)
+ format_name.format(ci_str_dn)
+ ">"
)
Basis elements of the subspace:
|00100001>
|00100100>
|10000001>
|10000100>
Ang dimensyon ng subspace ay may upper bound na: (samples_per_batch).