Skip to content

Commit 55e9274

Browse files
committed
Fix test for Kramers pairs
1 parent dc91d85 commit 55e9274

File tree

3 files changed

+33
-3
lines changed

3 files changed

+33
-3
lines changed

tests/test_z2_invariant.py

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,14 @@ def test_trivial(num_lines, num_wcc, patch_surface_data):
3535
"""
3636
wcc = [np.linspace(0, 1, num_wcc) for j in range(num_lines)]
3737
data = SurfaceData(wcc)
38-
assert z2pack.invariant.z2(data) == 0
38+
assert z2pack.invariant.z2(data, check_kramers_pairs=False) == 0
39+
40+
41+
def test_no_kramers_pairs(N, M, patch_surface_data): # pylint: disable=invalid-name
42+
wcc = [np.linspace(0, 1, 2 * M + 1) for j in range(N + 1)]
43+
data = SurfaceData(wcc)
44+
with pytest.raises(ValueError):
45+
z2pack.invariant.z2(data)
3946

4047

4148
def test_linear(num_lines_nonzero, x, patch_surface_data):

z2pack/_utils.py

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,3 +69,16 @@ def _pol_step(pol_list):
6969
for pol_left, pol_right in zip(pol_list[:-1], pol_list[1:]):
7070
res.append(min((pol_right - pol_left + o for o in offset), key=abs))
7171
return res
72+
73+
74+
def _check_kramers_pairs(wcc, tol=1e-3):
75+
return _get_degenerate_dist(wcc) < tol
76+
77+
78+
def _get_degenerate_dist(wcc):
79+
"""
80+
Get the maximum distance between pairs of approximately degenerate WCC.
81+
"""
82+
if len(wcc) % 2 != 0:
83+
raise ValueError('The number of WCC must be even!')
84+
return _get_max_move(wcc[::2], wcc[1::2])

z2pack/invariant.py

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66

77
from fsc.export import export
88

9-
from ._utils import _pol_step, _sgng
9+
from ._utils import _pol_step, _sgng, _check_kramers_pairs
1010

1111

1212
@export
@@ -28,13 +28,16 @@ def chern(surface_result):
2828

2929

3030
@export
31-
def z2(surface_result): # pylint: disable=invalid-name
31+
def z2(surface_result, check_kramers_pairs=True): # pylint: disable=invalid-name
3232
r"""
3333
Computes the :math:`\mathbb{Z}_2` invariant corresponding to a given surface result.
3434
3535
:param surface_result: Result of a WCC calculation on a Surface.
3636
:type surface_result: :class:`.SurfaceResult` or :class:`.SurfaceData`
3737
38+
:param check_kramers_pairs: Check whether the WCC at the edge of the surface come in degenerate pairs. This is a requirement for having a well-defined Z2 invariant.
39+
:type check_kramers_pairs: bool
40+
3841
Example code:
3942
4043
.. code :: python
@@ -43,6 +46,13 @@ def z2(surface_result): # pylint: disable=invalid-name
4346
print(z2pack.invariant.z2(result)) # Prints the Z2 invariant
4447
"""
4548
wcc = surface_result.wcc
49+
if check_kramers_pairs and len(wcc) > 0: # pylint: disable=len-as-condition
50+
if not _check_kramers_pairs(list(wcc[0])) and _check_kramers_pairs(
51+
list(wcc[-1])
52+
):
53+
raise ValueError(
54+
'The given WCC are not degenerate Kramers pairs at the edges of the surface.'
55+
)
4656
gap = surface_result.gap_pos
4757
inv = 1
4858
for gap_left, gap_right, wcc_right in zip(gap, gap[1:], wcc[1:]):

0 commit comments

Comments
 (0)