• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

Ruberhauptmann / quant-met / 17693769113

13 Sep 2025 07:53AM UTC coverage: 40.123% (-0.7%) from 40.81%
17693769113

Pull #136

github

web-flow
Merge 63136d052 into ba206def0
Pull Request #136: Prepare release

9 of 77 branches covered (11.69%)

Branch coverage included in aggregate %.

1 of 18 new or added lines in 4 files covered. (5.56%)

2 existing lines in 2 files now uncovered.

253 of 576 relevant lines covered (43.92%)

1.32 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

17.54
/src/quant_met/cli/q_loop.py
1
"""Functions to run self-consistent calculation for the order parameter."""
2

3
import logging
3✔
4
from pathlib import Path
3✔
5

6
import h5py
3✔
7
import numpy as np
3✔
8
import sisl
3✔
9

10
from quant_met import routines
3✔
11
from quant_met.parameters import Parameters
3✔
12
from quant_met.parameters.control import CritTemp, QLoop
3✔
13

14
logger = logging.getLogger(__name__)
3✔
15

16

17
def q_loop(parameters: Parameters) -> None:
3✔
18
    """Self-consistent calculation for the order parameter.
19

20
    Parameters
21
    ----------
22
    parameters: Parameters
23
        An instance of Parameters containing control settings, the model,
24
        and k-point specifications for the T_C calculation.
25
    """
26
    if not isinstance(parameters.control, QLoop):
×
27
        err_msg = "Wrong parameters for q-loop."
×
28
        raise TypeError(err_msg)
×
29

30
    result_path = Path(parameters.control.outdir)
×
31
    result_path.mkdir(exist_ok=True, parents=True)
×
32

33
    hamiltonian = sisl.get_sile(parameters.control.hamiltonian_file).read_hamiltonian()
×
34
    k_grid_obj = sisl.MonkhorstPack(
×
35
        hamiltonian.geometry,
36
        [parameters.k_points.nk1, parameters.k_points.nk2, 1],
37
    )
38

39
    if isinstance(parameters.control.crit_temp, CritTemp):
×
NEW
40
        result_path_crit_temp = Path(parameters.control.crit_temp.outdir)
×
NEW
41
        result_path_crit_temp.mkdir(exist_ok=True, parents=True)
×
UNCOV
42
        delta_vs_temp, critical_temperatures, fit_fig = routines.search_crit_temp(
×
43
            hamiltonian=hamiltonian,
44
            kgrid=k_grid_obj,
45
            hubbard_int_orbital_basis=np.array(
46
                parameters.control.crit_temp.hubbard_int_orbital_basis
47
            ),
48
            epsilon=parameters.control.crit_temp.conv_treshold,
49
            max_iter=parameters.control.crit_temp.max_iter,
50
            n_temp_points=20,
51
            q=np.array([0.0, 0.0, 0.0]),
52
        )
53
        logger.info("Search for T_C completed successfully.")
×
54
        logger.info("Obtained T_Cs: %s", critical_temperatures)
×
55

56
        fit_fig.savefig(
×
57
            result_path_crit_temp
58
            / f"{parameters.control.crit_temp.prefix}_critical_temperatures_fit.pdf",
59
            bbox_inches="tight",
60
        )
61

62
        result_file_crit_temp = (
×
63
            result_path_crit_temp
64
            / f"{parameters.control.crit_temp.prefix}_critical_temperatures.hdf5"
65
        )
66
        if result_file_crit_temp.exists():
×
NEW
67
            result_file_crit_temp.unlink()
×
68
        delta_vs_temp.to_hdf(result_file_crit_temp, key="delta_vs_temp")
×
69
        with h5py.File(result_file_crit_temp, mode="a") as file:
×
70
            for orbital, crit_temp_orbital in enumerate(critical_temperatures):
×
71
                file.attrs[f"T_C_{orbital}"] = crit_temp_orbital
×
72

73
        logger.info("Results saved to %s", result_file_crit_temp)
×
74
    else:
75
        critical_temperatures = []
×
76
        with h5py.File(f"{parameters.control.crit_temp}", mode="r") as file:
×
77
            for key, critical_temperature in file.attrs.items():
×
78
                if key.startswith("T_C"):
×
79
                    critical_temperatures.append(critical_temperature)
×
80
        logger.info("Read critical temperatures from file.")
×
81
        logger.info("Obtained T_Cs: %s", critical_temperatures)
×
82

83
    delta_vs_q = routines.loop_over_q(
×
84
        hamiltonian=hamiltonian,
85
        kgrid=k_grid_obj,
86
        hubbard_int_orbital_basis=np.array(parameters.control.hubbard_int_orbital_basis),
87
        epsilon=parameters.control.conv_treshold,
88
        max_iter=parameters.control.max_iter,
89
        n_q_points=parameters.control.n_q_points,
90
        crit_temps=np.array(critical_temperatures),
91
    )
92

93
    result_file_q = result_path / f"{parameters.control.prefix}_q.hdf5"
×
94

95
    if result_file_q.exists():
×
96
        result_file_q.unlink()
×
97
    for key, df in delta_vs_q.items():
×
98
        df.to_hdf(result_file_q, key=f"temp_{float(key):.6f}")
×
99
        with h5py.File(result_file_q, "a") as f:
×
100
            grp = f[f"temp_{float(key):.6f}"]
×
101
            grp.attrs["crit_temp"] = critical_temperatures
×
102
            grp.attrs["temp"] = float(key)
×
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc