Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Check Hamiltonians are hermitian #56

Merged
merged 7 commits into from
May 27, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions impurityModel/ed/finite.py
Original file line number Diff line number Diff line change
Expand Up @@ -287,6 +287,10 @@ def daggerOp(op):
return opDagger


def assert_hermitian(op: dict[tuple, int | float | complex]):
assert daggerOp(op) == op


def get_basis(nBaths, valBaths, dnValBaths, dnConBaths, dnTol, n0imp):
"""
Return restricted basis of product states.
Expand Down
4 changes: 3 additions & 1 deletion impurityModel/ed/get_spectra.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
# Local stuff
from impurityModel.ed import finite, spectra
from impurityModel.ed.average import k_B
from impurityModel.ed.finite import c2i
from impurityModel.ed.finite import assert_hermitian, c2i


def main(
Expand Down Expand Up @@ -413,6 +413,8 @@ def get_hamiltonian_operator(nBaths, nValBaths, slaterCondon, SOCs, DCinfo, hFie
hOp = {}
for process, value in hOperator.items():
hOp[tuple((c2i(nBaths, spinOrb), action) for spinOrb, action in process)] = value

assert_hermitian(hOp)
return hOp


Expand Down
4 changes: 3 additions & 1 deletion impurityModel/ed/get_spectra_using_CF.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
# Local stuff
from impurityModel.ed import finite, spectra
from impurityModel.ed.average import k_B
from impurityModel.ed.finite import c2i
from impurityModel.ed.finite import assert_hermitian, c2i


def main(
Expand Down Expand Up @@ -425,6 +425,8 @@ def get_hamiltonian_operator_using_CF(
hOp = {}
for process, value in hOperator.items():
hOp[tuple((c2i(nBaths, spinOrb), action) for spinOrb, action in process)] = value

assert_hermitian(hOp)
return hOp


Expand Down
2 changes: 2 additions & 0 deletions impurityModel/test/test_h0.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import os
from glob import glob

from impurityModel.ed.finite import assert_hermitian
from impurityModel.ed.get_spectra import read_pickled_file

DIR_PATH = os.path.dirname(os.path.realpath(__file__))
Expand Down Expand Up @@ -36,6 +37,7 @@ def sanity_check_non_interacting_hamiltonian(h0: dict[tuple, complex], nBaths: d
nBaths:
angular momentum: number of bath states coupled to the correlated orbitals with this angular momentum.
"""
assert_hermitian(h0)
for process, value in h0.items():
assert isinstance(value, complex)
assert len(process) == 2 # two events in non-interacting Hamiltonian
Expand Down
Loading