quant-met 0.0.8__py3-none-any.whl → 0.0.9__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -4,84 +4,37 @@
4
4
 
5
5
  """Provides the implementation for Graphene."""
6
6
 
7
- import pathlib
8
- from typing import Any
9
-
10
- import h5py
11
7
  import numpy as np
12
8
  import numpy.typing as npt
13
9
 
14
10
  from quant_met.geometry import GrapheneLattice
15
- from quant_met.mean_field._utils import _check_valid_array, _validate_float
11
+ from quant_met.mean_field._utils import _check_valid_array
16
12
  from quant_met.parameters.hamiltonians import GrapheneParameters
17
13
 
18
14
  from .base_hamiltonian import BaseHamiltonian
19
15
 
20
16
 
21
- class Graphene(BaseHamiltonian):
17
+ class Graphene(BaseHamiltonian[GrapheneParameters]):
22
18
  """Hamiltonian for Graphene."""
23
19
 
24
20
  def __init__(
25
21
  self,
26
22
  parameters: GrapheneParameters,
27
- *args: tuple[Any, ...],
28
- **kwargs: tuple[dict[str, Any], ...],
29
23
  ) -> None:
30
- del args
31
- del kwargs
32
- self._name = parameters.name
33
- self.hopping = _validate_float(parameters.hopping, "Hopping")
34
- if parameters.lattice_constant <= 0:
35
- msg = "Lattice constant must be positive"
36
- raise ValueError(msg)
37
- self._lattice = GrapheneLattice(
38
- lattice_constant=np.float64(
39
- _validate_float(parameters.lattice_constant, "Lattice constant")
40
- )
41
- )
42
- self.lattice_constant = self._lattice.lattice_constant
43
- self.chemical_potential = _validate_float(
44
- parameters.chemical_potential, "Chemical potential"
45
- )
46
- self.hubbard_int = _validate_float(parameters.hubbard_int, "Hubbard interaction")
47
- self._hubbard_int_orbital_basis = np.array([self.hubbard_int, self.hubbard_int])
48
- self._number_of_bands = 2
49
- if parameters.delta is None:
50
- self._delta_orbital_basis = np.zeros(self.number_of_bands, dtype=np.complex64)
51
- else:
52
- self._delta_orbital_basis = np.astype(parameters.delta, np.complex64)
53
-
54
- @property
55
- def name(self) -> str: # noqa: D102
56
- return self._name
57
-
58
- @property
59
- def lattice(self) -> GrapheneLattice: # noqa: D102
60
- return self._lattice
61
-
62
- @property
63
- def number_of_bands(self) -> int: # noqa: D102
64
- return self._number_of_bands
65
-
66
- @property
67
- def hubbard_int_orbital_basis(self) -> npt.NDArray[np.float64]: # noqa: D102
68
- return self._hubbard_int_orbital_basis
69
-
70
- @property
71
- def delta_orbital_basis(self) -> npt.NDArray[np.complex64]: # noqa: D102
72
- return self._delta_orbital_basis
24
+ super().__init__(parameters)
25
+ self.hopping = parameters.hopping
26
+ self.chemical_potential = parameters.chemical_potential
27
+ if parameters.delta is not None:
28
+ self.delta_orbital_basis = np.astype(parameters.delta, np.complex64)
73
29
 
74
- @delta_orbital_basis.setter
75
- def delta_orbital_basis(self, new_delta: npt.NDArray[np.complex64]) -> None:
76
- self._delta_orbital_basis = new_delta
30
+ def setup_lattice(self, parameters: GrapheneParameters) -> GrapheneLattice:
31
+ """Set up lattice based on parameters."""
32
+ return GrapheneLattice(lattice_constant=parameters.lattice_constant)
77
33
 
78
34
  @classmethod
79
- def from_file(cls, filename: pathlib.Path) -> "BaseHamiltonian": # noqa: D102
80
- with h5py.File(f"{filename}", "r") as f:
81
- config_dict = dict(f.attrs.items())
82
- config_dict["delta"] = f["delta"][()]
83
- parameters = GrapheneParameters.model_validate(config_dict)
84
- return cls(parameters=parameters)
35
+ def get_parameters_model(cls) -> type[GrapheneParameters]:
36
+ """Return the specific parameters model for the subclass."""
37
+ return GrapheneParameters
85
38
 
86
39
  def hamiltonian(self, k: npt.NDArray[np.float64]) -> npt.NDArray[np.complex64]:
87
40
  """
@@ -4,82 +4,34 @@
4
4
 
5
5
  """Provides the implementation for Graphene."""
6
6
 
7
- import pathlib
8
- from typing import Any
9
-
10
- import h5py
11
7
  import numpy as np
12
8
  import numpy.typing as npt
13
9
 
14
10
  from quant_met.geometry import SquareLattice
15
- from quant_met.mean_field._utils import _check_valid_array, _validate_float
11
+ from quant_met.mean_field._utils import _check_valid_array
16
12
  from quant_met.parameters import OneBandParameters
17
13
 
18
14
  from .base_hamiltonian import BaseHamiltonian
19
15
 
20
16
 
21
- class OneBand(BaseHamiltonian):
17
+ class OneBand(BaseHamiltonian[OneBandParameters]):
22
18
  """Hamiltonian for Graphene."""
23
19
 
24
- def __init__(
25
- self,
26
- parameters: OneBandParameters,
27
- *args: tuple[Any, ...],
28
- **kwargs: tuple[dict[str, Any], ...],
29
- ) -> None:
30
- del args
31
- del kwargs
32
- self._name = parameters.name
33
- self.hopping = _validate_float(parameters.hopping, "Hopping")
34
- if parameters.lattice_constant <= 0:
35
- msg = "Lattice constant must be positive"
36
- raise ValueError(msg)
37
- self._lattice = SquareLattice(
38
- np.float64(_validate_float(parameters.lattice_constant, "Lattice constant"))
39
- )
40
- self.lattice_constant = self._lattice.lattice_constant
41
- self.chemical_potential = _validate_float(
42
- parameters.chemical_potential, "Chemical potential"
43
- )
44
- self.hubbard_int = _validate_float(parameters.hubbard_int, "Hubbard interaction")
45
- self._hubbard_int_orbital_basis = np.array([self.hubbard_int])
46
- self._number_of_bands = 1
47
- if parameters.delta is None:
48
- self._delta_orbital_basis = np.zeros(self.number_of_bands, dtype=np.complex64)
49
- else:
50
- self._delta_orbital_basis = np.astype(parameters.delta, np.complex64)
51
-
52
- @property
53
- def name(self) -> str: # noqa: D102
54
- return self._name
55
-
56
- @property
57
- def lattice(self) -> SquareLattice: # noqa: D102
58
- return self._lattice
59
-
60
- @property
61
- def number_of_bands(self) -> int: # noqa: D102
62
- return self._number_of_bands
63
-
64
- @property
65
- def hubbard_int_orbital_basis(self) -> npt.NDArray[np.float64]: # noqa: D102
66
- return self._hubbard_int_orbital_basis
67
-
68
- @property
69
- def delta_orbital_basis(self) -> npt.NDArray[np.complex64]: # noqa: D102
70
- return self._delta_orbital_basis
20
+ def __init__(self, parameters: OneBandParameters) -> None:
21
+ super().__init__(parameters)
22
+ self.hopping = parameters.hopping
23
+ self.chemical_potential = parameters.chemical_potential
24
+ if parameters.delta is not None:
25
+ self.delta_orbital_basis = np.astype(parameters.delta, np.complex64)
71
26
 
72
- @delta_orbital_basis.setter
73
- def delta_orbital_basis(self, new_delta: npt.NDArray[np.complex64]) -> None:
74
- self._delta_orbital_basis = new_delta
27
+ def setup_lattice(self, parameters: OneBandParameters) -> SquareLattice:
28
+ """Set up lattice based on parameters."""
29
+ return SquareLattice(lattice_constant=parameters.lattice_constant)
75
30
 
76
31
  @classmethod
77
- def from_file(cls, filename: pathlib.Path) -> "BaseHamiltonian": # noqa: D102
78
- with h5py.File(f"{filename}", "r") as f:
79
- config_dict = dict(f.attrs.items())
80
- config_dict["delta"] = f["delta"][()]
81
- parameters = OneBandParameters.model_validate(config_dict)
82
- return cls(parameters=parameters)
32
+ def get_parameters_model(cls) -> type[OneBandParameters]:
33
+ """Return the specific parameters model for the subclass."""
34
+ return OneBandParameters
83
35
 
84
36
  def hamiltonian(self, k: npt.NDArray[np.float64]) -> npt.NDArray[np.complex64]:
85
37
  """
@@ -0,0 +1,116 @@
1
+ # SPDX-FileCopyrightText: 2024 Tjark Sievers
2
+ #
3
+ # SPDX-License-Identifier: MIT
4
+
5
+ """Provides the implementation for Graphene."""
6
+
7
+ import numpy as np
8
+ import numpy.typing as npt
9
+
10
+ from quant_met.geometry import SquareLattice
11
+ from quant_met.mean_field._utils import _check_valid_array
12
+ from quant_met.parameters import ThreeBandParameters
13
+
14
+ from .base_hamiltonian import BaseHamiltonian
15
+
16
+
17
+ class ThreeBand(BaseHamiltonian[ThreeBandParameters]):
18
+ """Hamiltonian for Graphene."""
19
+
20
+ def __init__(self, parameters: ThreeBandParameters) -> None:
21
+ super().__init__(parameters)
22
+ self.hopping = parameters.hopping
23
+ self.chemical_potential = parameters.chemical_potential
24
+ if parameters.delta is not None:
25
+ self.delta_orbital_basis = np.astype(parameters.delta, np.complex64)
26
+
27
+ def setup_lattice(self, parameters: ThreeBandParameters) -> SquareLattice:
28
+ """Set up lattice based on parameters."""
29
+ return SquareLattice(lattice_constant=parameters.lattice_constant)
30
+
31
+ @classmethod
32
+ def get_parameters_model(cls) -> type[ThreeBandParameters]:
33
+ """Return the specific parameters model for the subclass."""
34
+ return ThreeBandParameters
35
+
36
+ def hamiltonian(self, k: npt.NDArray[np.float64]) -> npt.NDArray[np.complex64]:
37
+ """
38
+ Return the normal state Hamiltonian in orbital basis.
39
+
40
+ Parameters
41
+ ----------
42
+ k : :class:`numpy.ndarray`
43
+ List of k points.
44
+
45
+ Returns
46
+ -------
47
+ :class:`numpy.ndarray`
48
+ Hamiltonian in matrix form.
49
+
50
+ """
51
+ assert _check_valid_array(k)
52
+ hopping = self.hopping
53
+ lattice_constant = self.lattice.lattice_constant
54
+ chemical_potential = self.chemical_potential
55
+ if k.ndim == 1:
56
+ k = np.expand_dims(k, axis=0)
57
+
58
+ h = np.zeros((k.shape[0], self.number_of_bands, self.number_of_bands), dtype=np.complex64)
59
+
60
+ h[:, 0, 0] = (
61
+ -2 * hopping * (np.cos(k[:, 1] * lattice_constant) + np.cos(k[:, 0] * lattice_constant))
62
+ )
63
+ h[:, 1, 1] = (
64
+ -2 * hopping * (np.cos(k[:, 1] * lattice_constant) + np.cos(k[:, 0] * lattice_constant))
65
+ )
66
+ h[:, 2, 2] = (
67
+ -2 * hopping * (np.cos(k[:, 1] * lattice_constant) + np.cos(k[:, 0] * lattice_constant))
68
+ )
69
+ h[:, 2, 0] = 0.5
70
+ h[:, 0, 2] = 0.5
71
+
72
+ h[:, 0, 0] -= chemical_potential
73
+ h[:, 1, 1] -= chemical_potential
74
+ h[:, 2, 2] -= chemical_potential
75
+
76
+ return h.squeeze()
77
+
78
+ def hamiltonian_derivative(
79
+ self, k: npt.NDArray[np.float64], direction: str
80
+ ) -> npt.NDArray[np.complex64]:
81
+ """
82
+ Deriative of the Hamiltonian.
83
+
84
+ Parameters
85
+ ----------
86
+ k: :class:`numpy.ndarray`
87
+ List of k points.
88
+ direction: str
89
+ Direction for derivative, either 'x' oder 'y'.
90
+
91
+ Returns
92
+ -------
93
+ :class:`numpy.ndarray`
94
+ Derivative of Hamiltonian.
95
+
96
+ """
97
+ assert _check_valid_array(k)
98
+ assert direction in ["x", "y"]
99
+
100
+ hopping = self.hopping
101
+ lattice_constant = self.lattice.lattice_constant
102
+ if k.ndim == 1:
103
+ k = np.expand_dims(k, axis=0)
104
+
105
+ h = np.zeros((k.shape[0], self.number_of_bands, self.number_of_bands), dtype=np.complex64)
106
+
107
+ if direction == "x":
108
+ h[:, 0, 0] = -2 * hopping * lattice_constant * np.sin(lattice_constant * k[:, 0])
109
+ h[:, 1, 1] = -2 * hopping * lattice_constant * np.sin(lattice_constant * k[:, 0])
110
+ h[:, 2, 2] = -2 * hopping * lattice_constant * np.sin(lattice_constant * k[:, 0])
111
+ else:
112
+ h[:, 0, 0] = -2 * hopping * lattice_constant * np.sin(lattice_constant * k[:, 0])
113
+ h[:, 1, 1] = -2 * hopping * lattice_constant * np.sin(lattice_constant * k[:, 0])
114
+ h[:, 2, 2] = -2 * hopping * lattice_constant * np.sin(lattice_constant * k[:, 0])
115
+
116
+ return h.squeeze()
@@ -0,0 +1,107 @@
1
+ # SPDX-FileCopyrightText: 2024 Tjark Sievers
2
+ #
3
+ # SPDX-License-Identifier: MIT
4
+
5
+ """Provides the implementation for Graphene."""
6
+
7
+ import numpy as np
8
+ import numpy.typing as npt
9
+
10
+ from quant_met.geometry import SquareLattice
11
+ from quant_met.mean_field._utils import _check_valid_array
12
+ from quant_met.parameters import TwoBandParameters
13
+
14
+ from .base_hamiltonian import BaseHamiltonian
15
+
16
+
17
+ class TwoBand(BaseHamiltonian[TwoBandParameters]):
18
+ """Hamiltonian for Graphene."""
19
+
20
+ def __init__(self, parameters: TwoBandParameters) -> None:
21
+ super().__init__(parameters)
22
+ self.hopping = parameters.hopping
23
+ self.chemical_potential = parameters.chemical_potential
24
+ if parameters.delta is not None:
25
+ self.delta_orbital_basis = np.astype(parameters.delta, np.complex64)
26
+
27
+ def setup_lattice(self, parameters: TwoBandParameters) -> SquareLattice:
28
+ """Set up lattice based on parameters."""
29
+ return SquareLattice(lattice_constant=parameters.lattice_constant)
30
+
31
+ @classmethod
32
+ def get_parameters_model(cls) -> type[TwoBandParameters]:
33
+ """Return the specific parameters model for the subclass."""
34
+ return TwoBandParameters
35
+
36
+ def hamiltonian(self, k: npt.NDArray[np.float64]) -> npt.NDArray[np.complex64]:
37
+ """
38
+ Return the normal state Hamiltonian in orbital basis.
39
+
40
+ Parameters
41
+ ----------
42
+ k : :class:`numpy.ndarray`
43
+ List of k points.
44
+
45
+ Returns
46
+ -------
47
+ :class:`numpy.ndarray`
48
+ Hamiltonian in matrix form.
49
+
50
+ """
51
+ assert _check_valid_array(k)
52
+ hopping = self.hopping
53
+ lattice_constant = self.lattice.lattice_constant
54
+ chemical_potential = self.chemical_potential
55
+ if k.ndim == 1:
56
+ k = np.expand_dims(k, axis=0)
57
+
58
+ h = np.zeros((k.shape[0], self.number_of_bands, self.number_of_bands), dtype=np.complex64)
59
+
60
+ h[:, 0, 0] = (
61
+ -2 * hopping * (np.cos(k[:, 1] * lattice_constant) + np.cos(k[:, 0] * lattice_constant))
62
+ )
63
+ h[:, 1, 1] = (
64
+ -2 * hopping * (np.cos(k[:, 1] * lattice_constant) + np.cos(k[:, 0] * lattice_constant))
65
+ )
66
+ h[:, 0, 0] -= chemical_potential
67
+ h[:, 1, 1] -= chemical_potential
68
+
69
+ return h.squeeze()
70
+
71
+ def hamiltonian_derivative(
72
+ self, k: npt.NDArray[np.float64], direction: str
73
+ ) -> npt.NDArray[np.complex64]:
74
+ """
75
+ Deriative of the Hamiltonian.
76
+
77
+ Parameters
78
+ ----------
79
+ k: :class:`numpy.ndarray`
80
+ List of k points.
81
+ direction: str
82
+ Direction for derivative, either 'x' oder 'y'.
83
+
84
+ Returns
85
+ -------
86
+ :class:`numpy.ndarray`
87
+ Derivative of Hamiltonian.
88
+
89
+ """
90
+ assert _check_valid_array(k)
91
+ assert direction in ["x", "y"]
92
+
93
+ hopping = self.hopping
94
+ lattice_constant = self.lattice.lattice_constant
95
+ if k.ndim == 1:
96
+ k = np.expand_dims(k, axis=0)
97
+
98
+ h = np.zeros((k.shape[0], self.number_of_bands, self.number_of_bands), dtype=np.complex64)
99
+
100
+ if direction == "x":
101
+ h[:, 0, 0] = -2 * hopping * lattice_constant * np.sin(lattice_constant * k[:, 0])
102
+ h[:, 1, 1] = -2 * hopping * lattice_constant * np.sin(lattice_constant * k[:, 0])
103
+ else:
104
+ h[:, 0, 0] = -2 * hopping * lattice_constant * np.sin(lattice_constant * k[:, 0])
105
+ h[:, 1, 1] = -2 * hopping * lattice_constant * np.sin(lattice_constant * k[:, 0])
106
+
107
+ return h.squeeze()
@@ -8,10 +8,11 @@ import numpy as np
8
8
  import numpy.typing as npt
9
9
 
10
10
  from quant_met.mean_field.hamiltonians.base_hamiltonian import BaseHamiltonian
11
+ from quant_met.parameters import GenericParameters
11
12
 
12
13
 
13
14
  def quantum_metric(
14
- h: BaseHamiltonian, k_grid: npt.NDArray[np.float64], bands: list[int]
15
+ h: BaseHamiltonian[GenericParameters], k_grid: npt.NDArray[np.float64], bands: list[int]
15
16
  ) -> npt.NDArray[np.float64]:
16
17
  """Calculate the quantum metric in the normal state.
17
18
 
@@ -60,7 +61,7 @@ def quantum_metric(
60
61
 
61
62
 
62
63
  def quantum_metric_bdg(
63
- h: BaseHamiltonian, k_grid: npt.NDArray[np.float64], bands: list[int]
64
+ h: BaseHamiltonian[GenericParameters], k_grid: npt.NDArray[np.float64], bands: list[int]
64
65
  ) -> npt.NDArray[np.float64]:
65
66
  """Calculate the quantum metric in the BdG state.
66
67
 
@@ -8,42 +8,33 @@ import numpy as np
8
8
  import numpy.typing as npt
9
9
 
10
10
  from quant_met.mean_field.hamiltonians.base_hamiltonian import BaseHamiltonian
11
+ from quant_met.parameters import GenericParameters
11
12
 
12
13
 
13
14
  def self_consistency_loop(
14
- h: BaseHamiltonian,
15
+ h: BaseHamiltonian[GenericParameters],
15
16
  k_space_grid: npt.NDArray[np.float64],
16
- beta: np.float64,
17
17
  epsilon: float,
18
- q: npt.NDArray[np.float64] | None = None,
19
- ) -> BaseHamiltonian:
18
+ ) -> BaseHamiltonian[GenericParameters]:
20
19
  """Self-consistency loop.
21
20
 
22
21
  Parameters
23
22
  ----------
24
- lattice
25
- q
26
- beta
27
- number_of_k_points
23
+ k_space_grid
28
24
  h
29
25
  epsilon
30
26
  """
31
- if q is None:
32
- q = np.array([0, 0])
33
-
34
27
  rng = np.random.default_rng()
35
28
  delta_init = np.zeros(shape=h.delta_orbital_basis.shape, dtype=np.complex64)
36
- delta_init += (
37
- 2 * rng.random(size=h.delta_orbital_basis.shape)
38
- - 1
39
- + 1.0j * (2 * rng.random(size=h.delta_orbital_basis.shape) - 1)
29
+ delta_init += (0.2 * rng.random(size=h.delta_orbital_basis.shape) - 1) + 1.0j * (
30
+ 0.2 * rng.random(size=h.delta_orbital_basis.shape) - 1
40
31
  )
41
32
  h.delta_orbital_basis = delta_init
42
33
 
43
34
  while True:
44
- new_gap = h.gap_equation(k=k_space_grid, q=q, beta=beta)
35
+ new_gap = h.gap_equation(k=k_space_grid)
45
36
  if (np.abs(h.delta_orbital_basis - new_gap) < epsilon).all():
46
37
  h.delta_orbital_basis = new_gap
47
38
  return h
48
- mixing_greed = 0.1
39
+ mixing_greed = 0.5
49
40
  h.delta_orbital_basis = mixing_greed * new_gap + (1 - mixing_greed) * h.delta_orbital_basis
@@ -8,10 +8,11 @@ import numpy as np
8
8
  import numpy.typing as npt
9
9
 
10
10
  from quant_met.mean_field.hamiltonians.base_hamiltonian import BaseHamiltonian
11
+ from quant_met.parameters import GenericParameters
11
12
 
12
13
 
13
14
  def superfluid_weight(
14
- h: BaseHamiltonian,
15
+ h: BaseHamiltonian[GenericParameters],
15
16
  k_grid: npt.NDArray[np.float64],
16
17
  ) -> tuple[npt.NDArray[np.complex64], npt.NDArray[np.complex64]]:
17
18
  """Calculate the superfluid weight.
@@ -54,7 +55,7 @@ def superfluid_weight(
54
55
 
55
56
 
56
57
  def _current_operator(
57
- h: BaseHamiltonian, direction: str, k: npt.NDArray[np.float64]
58
+ h: BaseHamiltonian[GenericParameters], direction: str, k: npt.NDArray[np.float64]
58
59
  ) -> npt.NDArray[np.complex64]:
59
60
  j = np.zeros(shape=(h.number_of_bands, h.number_of_bands), dtype=np.complex64)
60
61
 
@@ -71,7 +72,9 @@ def _current_operator(
71
72
  return j
72
73
 
73
74
 
74
- def _c_factor(h: BaseHamiltonian, k: npt.NDArray[np.float64]) -> npt.NDArray[np.complex64]:
75
+ def _c_factor(
76
+ h: BaseHamiltonian[GenericParameters], k: npt.NDArray[np.float64]
77
+ ) -> npt.NDArray[np.complex64]:
75
78
  bdg_energies, bdg_functions = h.diagonalize_bdg(k)
76
79
  c_mnpq = np.zeros(
77
80
  shape=(
@@ -15,7 +15,22 @@ Parameters (:mod:`quant_met.parameters`)
15
15
  Parameters
16
16
  """ # noqa: D205, D400
17
17
 
18
- from .hamiltonians import DressedGrapheneParameters, GrapheneParameters, OneBandParameters
18
+ from .hamiltonians import (
19
+ DressedGrapheneParameters,
20
+ GenericParameters,
21
+ GrapheneParameters,
22
+ OneBandParameters,
23
+ ThreeBandParameters,
24
+ TwoBandParameters,
25
+ )
19
26
  from .main import Parameters
20
27
 
21
- __all__ = ["Parameters", "DressedGrapheneParameters", "GrapheneParameters", "OneBandParameters"]
28
+ __all__ = [
29
+ "Parameters",
30
+ "DressedGrapheneParameters",
31
+ "GrapheneParameters",
32
+ "OneBandParameters",
33
+ "TwoBandParameters",
34
+ "ThreeBandParameters",
35
+ "GenericParameters",
36
+ ]