<jupyter_start><jupyter_text>the total Hamiltonian. Require 12 qubits<jupyter_code>molecular_hamiltonian = molecule.get_molecular_hamiltonian()
molecular_hamiltonian
# Map operator to fermions and qubits.
fermion_hamiltonian = get_fermion_operator(molecular_hamiltonian)
fermion_hamiltonian
qubit_hamiltonian = bravyi_kitaev(fermion_hamiltonian)
qubit_hamiltonian.compress()
print('The bravyi_kitaev Hamiltonian in canonical basis follows:\n{}'.format(qubit_hamiltonian))<jupyter_output>The bravyi_kitaev Hamiltonian in canonical basis follows:
-4.190675029266599 [] +
0.027703022429271675 [X0 X1 X2] +
-0.0011638668740139235 [X0 X1 X2 X3 Y7 Y11] +
0.0008347535285203352 [X0 X1 X2 Y3 Y5] +
0.0015730729658833468 [X0 X1 X2 Z3] +
0.0028644887276281505 [X0 X1 Z2 X3 Y7 Z9 Y10 X11] +
0.003060574365605636 [X0 X1 Z2 Y3 Y4 X5] +
-0.0011486340643385767 [X0 X1 X3 X4 Y7 Y11] +
0.001178042500447122 [X0 X1 X3 Y4 Y5 Z6 Z7] +
0.0011486340643385767 [X0 X1 X3 Y4 Z5 Y7 Z9 Z10 X11] +
0.0025583843661766653 [X0 X1 X3 Z4 Y5 Y6 Z7] +
-0.002663691154223092 [X0 X1 X3 Z4 Z5 Y7 Z9 Y10 X11] +
-0.0015150570898845154 [X0 X1 X3 Z4 Y7 Z9 Y10 X11] +
0.0015552148742730414 [X0 X1 X3 X6 Y7 Y11] +
-0.001701100566020224 [X0 X1 X3 Z6 Y7 Z9 Y10 X11] +
0.0015552148742730414 [X0 X1 X3 Y7 X8 Y11] +
-0.0015552148742730414 [X0 X1 X3 Y7 Y8 Z10 X11] +
-0.001701100566020224 [X0 X1 X3 Y7 Z8 Z9 Y10 X11] +
-0.0001458856917471825 [X0 X1 X3 Y7 Z8 Y10 X11] +
-0.003016147442557296 [X0 X1 X3 Y7 Z9 Y10 X11] +
0.00078947031911811[...]<jupyter_text>active space on 1,2,3 orbits. Only 6 qubits required (considering spin degree of freedom)<jupyter_code>active_space_start = 1
active_space_stop = 4

molecular_hamiltonian = molecule.get_molecular_hamiltonian(
    occupied_indices=[0],
   active_indices=range(active_space_start, active_space_stop))
# Map operator to fermions and qubits.
fermion_hamiltonian = get_fermion_operator(molecular_hamiltonian)
qubit_hamiltonian = bravyi_kitaev(fermion_hamiltonian)
qubit_hamiltonian.compress()
print('The bravyi_kitaev Hamiltonian in canonical basis follows:\n{}'.format(qubit_hamiltonian))<jupyter_output>The bravyi_kitaev Hamiltonian in canonical basis follows:
-7.35242078318357 [] +
0.011766123640331288 [X0 X1 X2] +
0.0018147425194399152 [X0 X1 X2 Z3] +
0.004757740667859357 [X0 X1 Z3 X4] +
0.011683408753511006 [X0 Y1 Y2] +
0.003327602891004962 [X0 Y1 Y2 Z4] +
-0.0014301377768543954 [X0 Y1 Y2 Z4 Z5] +
0.004757740667859357 [X0 Y1 Z2 Y4 Z5] +
0.003056003615642556 [X0 Z1 X2] +
0.003056003615642556 [X0 Z1 X2 Z3] +
0.005754199313655931 [X0 Z1 X4] +
0.005754199313655931 [X0 X4 Z5] +
0.011766123640331288 [Y0 X1 Y2] +
0.0018147425194399152 [Y0 X1 Y2 Z3] +
0.004757740667859357 [Y0 X1 Z3 Y4] +
-0.011683408753511006 [Y0 Y1 X2] +
-0.003327602891004962 [Y0 Y1 X2 Z4] +
0.0014301377768543954 [Y0 Y1 X2 Z4 Z5] +
-0.004757740667859357 [Y0 Y1 Z2 X4 Z5] +
0.003056003615642556 [Y0 Z1 Y2] +
0.003056003615642556 [Y0 Z1 Y2 Z3] +
0.005754199313655931 [Y0 Z1 Y4] +
0.005754199313655931 [Y0 Y4 Z5] +
0.027882756551385356 [Z0] +
0.011766123640331288 [Z0 X1 Z2] +
0.001814742519439915 [Z0 X1 Z2 Z3] +
-0.0116834087535[...]<jupyter_text>Construct effective Hamiltonian on qubits 0,2,4, by average on |1> for qubit 1,3,5> using method in “Quantum chemistry calculations on a trapped-ion quantum simulator” ,Physical Review X 8, 031022 (2018)<jupyter_code>terms_dict=qubit_hamiltonian.terms
# the first qubit is 
def partial_average(key,drop_qubits=[1,3,5],avg_dict={'X':0,'Y':0,'Z':1},init_fock=0):
    key=list(key)
    factor=1
    new_key=[]
    for k in key:
        if k[0] not in drop_qubits:
            new_key.append(k)
        if k[0] in drop_qubits:
            if k[0]==0:
                factor*=avg_dict[k[1]]
            else:
                factor*=avg_dict[k[1]]
        #print(key)
    new_key=tuple(new_key)
    {new_key:factor}
    return (new_key,factor)
reduced_terms=[]
for key in terms_dict.keys():
    rt=partial_average(key)   
    reduced_terms.append(rt)
reduced_terms<jupyter_output><empty_output><jupyter_text>combining all same terms in sim_dict<jupyter_code>import numpy as np
ham_terms=np.array([f[0] for f in reduced_terms])
factors=np.array([f[1] for f in reduced_terms])
cs=np.array([c for c in qubit_hamiltonian.terms.values()])
cs_rescale=np.multiply(factors,cs)

reduced_terms_rescale=[]
for i in range(len(reduced_terms)):
    if cs_rescale[i] !=0:
        reduced_terms_rescale.append((reduced_terms[i][0],cs_rescale[i]))
reduced_terms_rescale
sim_dict={}
for term in reduced_terms_rescale:
    if term not in sim_dict.keys():
        sim_dict[term[0]]=term[1]
    else:
        sim_dict[term[0]]+=term[1]
[sim_dict.values()]<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.10695986336464561, 'fraction_numerical': 0.2568317677198975, 'mean_word_length': 4.907944514501891, 'pattern_counts': {'":': 0, '<': 15, '<?xml version=': 0, '>': 17, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '4', 'dir': 'jupyter-structured-clean-dedup', 'id': '78845', 'license': 'Apache-2.0', 'n_tokens_mistral': 2670, 'n_tokens_neox': 2047, 'n_words': 461, 'path': 'OpenFermion_tutorial.ipynb', 'repo_name': 'yintaophy/Quantum_meetup_20200611', 'size': '4684'}