Skip to content

Commit 37a259e

Browse files
committed
Add optional test for periodicity of Hamiltonian
1 parent 06ef997 commit 37a259e

File tree

3 files changed

+27
-5
lines changed

3 files changed

+27
-5
lines changed

examples/hm/haldane_model/haldane.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,9 @@ def Hamilton(k, m, t1, t2, phi):
2929

3030

3131
def get_chern(m, t1, t2, phi):
32-
system = z2pack.hm.System(lambda k: Hamilton(k, m, t1, t2, phi), bands=1)
32+
system = z2pack.hm.System(
33+
lambda k: Hamilton(k, m, t1, t2, phi), bands=1, check_periodic=True
34+
)
3335

3436
result = z2pack.surface.run(
3537
system=system,

examples/hm/kane_mele_model/run.py

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
pauli_y = np.array([[0, -1j], [1j, 0]], dtype=complex)
1717
pauli_z = np.array([[1, 0], [0, -1]], dtype=complex)
1818

19+
1920
def get_kane_mele_hamiltonian(t, lambda_v, lambda_R, lambda_SO):
2021
def inner(k):
2122
k = np.array(k) * 2 * np.pi
@@ -28,18 +29,21 @@ def inner(k):
2829
lambda_v * kron(pauli_z, identity) +
2930
lambda_R * (1 - cos(x) * cos(y)) * kron(pauli_y, pauli_x) +
3031
-sqrt(3) * lambda_R * sin(x) * sin(y) * kron(pauli_y, pauli_y) +
31-
2 * t * cos(x) * sin(y) * kron(pauli_y, identity) +
32-
lambda_SO * (2 * sin(2 * x) - 4 * sin(x) * cos(y)) * kron(pauli_z, pauli_z) +
32+
2 * t * cos(x) * sin(y) * kron(pauli_y, identity) + lambda_SO *
33+
(2 * sin(2 * x) - 4 * sin(x) * cos(y)) * kron(pauli_z, pauli_z) +
3334
lambda_R * cos(x) * sin(y) * kron(pauli_x, pauli_x) +
3435
-sqrt(3) * lambda_R * sin(x) * cos(y) * kron(pauli_x, pauli_y)
3536
)
37+
3638
return inner
3739

40+
3841
if __name__ == '__main__':
3942
system = z2pack.hm.System(
4043
get_kane_mele_hamiltonian(
4144
t=1, lambda_v=0.1, lambda_R=0.05, lambda_SO=0.06
42-
)
45+
),
46+
check_periodic=True
4347
)
4448
res = z2pack.surface.run(system=system, surface=lambda s, t: [s / 2, t, 0])
4549
print('Z2 invariant: {}'.format(z2pack.invariant.z2(res)))

z2pack/hm.py

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@
44
This module contains a class for creating Systems which are described by a Hamiltonian matrix (hm), such as k•p models.
55
"""
66

7+
import itertools
8+
79
import numpy as np
810
import scipy.linalg as la
911
from fsc.export import export
@@ -34,6 +36,9 @@ class System(EigenstateSystem):
3436
3537
:param convention: The convention used for the Hamiltonian, following the `pythtb formalism <http://www.physics.rutgers.edu/pythtb/_downloads/pythtb-formalism.pdf>`_. Convention 1 means that the eigenvalues of :math:`\mathcal{H}(\mathbf{k})` are wave vectors :math:`\left|\psi_{n\mathbf{k}}\right>`. With convention 2, they are the cell-periodic Bloch functions :math:`\left|u_{n\mathbf{k}}\right>`.
3638
:type convention: int
39+
40+
:param check_periodic: Evaluate the Hamiltonian at :math:`\{0, 1\}^d` as a simple check if it is periodic.
41+
:type check_periodic: bool
3742
"""
3843

3944
def __init__(
@@ -44,7 +49,8 @@ def __init__(
4449
pos=None,
4550
bands=None,
4651
hermitian_tol=1e-6,
47-
convention=2
52+
convention=2,
53+
check_periodic=False
4854
):
4955
self._hamilton = hamilton
5056
self._hermitian_tol = hermitian_tol
@@ -55,6 +61,16 @@ def __init__(
5561
format(self._convention)
5662
)
5763

64+
if check_periodic:
65+
k_values = itertools.product([0, 1], repeat=dim)
66+
ham_gamma = self._hamilton(next(k_values))
67+
for k in k_values:
68+
if not np.allclose(ham_gamma, self._hamilton(k)):
69+
raise ValueError(
70+
'The given Hamiltonian is not periodic: H(k=0) != H(k={})'
71+
.format(k)
72+
)
73+
5874
size = len(self._hamilton([0] * dim)) # assuming to be square...
5975
# add one atom for each orbital in the hamiltonian
6076
if pos is None:

0 commit comments

Comments
 (0)