def test_phonon_onsite(): gs = Mps.gs(mol_list, max_entangled=False) assert not gs.ph_occupations.any() b2 = Mpo.ph_onsite(mol_list, r"b^\dagger", 0, 0) p1 = b2.apply(gs).normalize() assert np.allclose(p1.ph_occupations, [1, 0, 0, 0, 0, 0]) p2 = b2.apply(p1).normalize() assert np.allclose(p2.ph_occupations, [2, 0, 0, 0, 0, 0]) b = b2.conj_trans() assert b.distance(Mpo.ph_onsite(mol_list, r"b", 0, 0)) == 0 assert b.apply(p2).normalize().distance(p1) == pytest.approx(0, abs=1e-5)
def test_intersite(scheme): local_mlist = mol_list.switch_scheme(scheme) mpo1 = Mpo.intersite(local_mlist, {0: r"a^\dagger"}, {}, Quantity(1.0)) mpo2 = Mpo.onsite(local_mlist, r"a^\dagger", mol_idx_set=[0]) assert mpo1.distance(mpo2) == pytest.approx(0, abs=1e-5) mpo3 = Mpo.intersite(local_mlist, {2: r"a^\dagger a"}, {}, Quantity(1.0)) mpo4 = Mpo.onsite(local_mlist, r"a^\dagger a", mol_idx_set=[2]) assert mpo3.distance(mpo4) == pytest.approx(0, abs=1e-5) mpo5 = Mpo.intersite(local_mlist, {2: r"a^\dagger a"}, {}, Quantity(0.5)) assert mpo5.add(mpo5).distance(mpo4) == pytest.approx(0, abs=1e-5) mpo6 = Mpo.intersite(local_mlist, { 0: r"a^\dagger", 2: "a" }, {}, Quantity(1.0)) mpo7 = Mpo.onsite(local_mlist, "a", mol_idx_set=[2]) assert mpo2.apply(mpo7).distance(mpo6) == pytest.approx(0, abs=1e-5) # the tests are based on the similarity between scheme 2 and scheme 3 # so scheme 3 and scheme 4 will be skipped if scheme == 2: mpo8 = Mpo(local_mlist) # a dirty hack to switch from scheme 2 to scheme 3 test_mlist = local_mlist.switch_scheme(2) test_mlist.scheme = 3 mpo9 = Mpo(test_mlist) mpo10 = Mpo.intersite(test_mlist, { 0: r"a^\dagger", 2: "a" }, {}, Quantity(local_mlist.j_matrix[0, 2])) mpo11 = Mpo.intersite(test_mlist, { 2: r"a^\dagger", 0: "a" }, {}, Quantity(local_mlist.j_matrix[0, 2])) assert mpo11.conj_trans().distance(mpo10) == pytest.approx(0, abs=1e-6) assert mpo8.distance(mpo9 + mpo10 + mpo11) == pytest.approx(0, abs=1e-6) test_mlist.periodic = True mpo12 = Mpo(test_mlist) assert mpo12.distance(mpo9 + mpo10 + mpo11) == pytest.approx(0, abs=1e-6) ph_mpo1 = Mpo.ph_onsite(local_mlist, "b", 1, 1) ph_mpo2 = Mpo.intersite(local_mlist, {}, {(1, 1): "b"}) assert ph_mpo1.distance(ph_mpo2) == pytest.approx(0, abs=1e-6)
def test_intersite(scheme): local_mlist = holstein_model.switch_scheme(scheme) mpo1 = Mpo.intersite(local_mlist, {0: r"a^\dagger"}, {}, Quantity(1.0)) mpo2 = Mpo.onsite(local_mlist, r"a^\dagger", dof_set=[0]) assert mpo1.distance(mpo2) == pytest.approx(0, abs=1e-5) mpo3 = Mpo.intersite(local_mlist, {2: r"a^\dagger a"}, {}, Quantity(1.0)) mpo4 = Mpo.onsite(local_mlist, r"a^\dagger a", dof_set=[2]) assert mpo3.distance(mpo4) == pytest.approx(0, abs=1e-5) mpo5 = Mpo.intersite(local_mlist, {2: r"a^\dagger a"}, {}, Quantity(0.5)) assert mpo5.add(mpo5).distance(mpo4) == pytest.approx(0, abs=1e-5) mpo6 = Mpo.intersite(local_mlist, { 0: r"a^\dagger", 2: "a" }, {}, Quantity(1.0)) mpo7 = Mpo.onsite(local_mlist, "a", dof_set=[2]) assert mpo2.apply(mpo7).distance(mpo6) == pytest.approx(0, abs=1e-5) mpo8 = Mpo.intersite(local_mlist, { 0: r"a^\dagger", 2: "a" }, {}, Quantity(local_mlist.j_matrix[0, 2])) mpo9 = Mpo.intersite(local_mlist, { 2: r"a^\dagger", 0: "a" }, {}, Quantity(local_mlist.j_matrix[0, 2])) assert mpo9.conj_trans().distance(mpo8) == pytest.approx(0, abs=1e-6) ph_mpo1 = Mpo.ph_onsite(local_mlist, "b", 1, 1) ph_mpo2 = Mpo.intersite(local_mlist, {}, {(1, 1): "b"}) assert ph_mpo1.distance(ph_mpo2) == pytest.approx(0, abs=1e-6)
def test_general_mpo_others(): mol_list2 = MolList2.MolList_to_MolList2(mol_list) # onsite mpo_std = Mpo.onsite(mol_list, r"a^\dagger", mol_idx_set=[0]) mpo = Mpo.onsite(mol_list2, r"a^\dagger", mol_idx_set=[0]) check_result(mpo, mpo_std) # general method mpo = Mpo.general_mpo(mol_list2, model={("e_0", ): [(Op(r"a^\dagger", 0), 1.0)]}, model_translator=ModelTranslator.general_model) check_result(mpo, mpo_std) mpo_std = Mpo.onsite(mol_list, r"a^\dagger a", dipole=True) mpo = Mpo.onsite(mol_list2, r"a^\dagger a", dipole=True) check_result(mpo, mpo_std) mpo = Mpo.general_mpo(mol_list2, model={ ("e_0", ): [(Op(r"a^\dagger a", 0), mol_list2.dipole[("e_0", )])], ("e_1", ): [(Op(r"a^\dagger a", 0), mol_list2.dipole[("e_1", )])], ("e_2", ): [(Op(r"a^\dagger a", 0), mol_list2.dipole[("e_2", )])] }, model_translator=ModelTranslator.general_model) check_result(mpo, mpo_std) # intersite mpo_std = Mpo.intersite(mol_list, { 0: r"a^\dagger", 2: "a" }, {(0, 1): "b^\dagger"}, Quantity(2.0)) mpo = Mpo.intersite(mol_list2, { 0: r"a^\dagger", 2: "a" }, {(0, 1): r"b^\dagger"}, Quantity(2.0)) check_result(mpo, mpo_std) mpo = Mpo.general_mpo(mol_list2, model={ ("e_0", "e_2", "v_1"): [(Op(r"a^\dagger", 1), Op(r"a", -1), Op(r"b^\dagger", 0), 2.0)] }, model_translator=ModelTranslator.general_model) check_result(mpo, mpo_std) # phsite mpo_std = Mpo.ph_onsite(mol_list, r"b^\dagger", 0, 0) mpo = Mpo.ph_onsite(mol_list2, r"b^\dagger", 0, 0) check_result(mpo, mpo_std) mpo = Mpo.general_mpo(mol_list2, model={ (mol_list2.map[(0, 0)], ): [(Op(r"b^\dagger", 0), 1.0)] }, model_translator=ModelTranslator.general_model) check_result(mpo, mpo_std)