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

Ruberhauptmann / quant-met / 16553145710

27 Jul 2025 04:20PM UTC coverage: 41.213% (-0.3%) from 41.536%
16553145710

push

github

web-flow
Bugfixes (#127)

10 of 74 branches covered (13.51%)

Branch coverage included in aggregate %.

0 of 4 new or added lines in 1 file covered. (0.0%)

255 of 569 relevant lines covered (44.82%)

1.34 hits per line

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

18.18
/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):
×
40
        delta_vs_temp, critical_temperatures, fit_fig = routines.search_crit_temp(
×
41
            hamiltonian=hamiltonian,
42
            kgrid=k_grid_obj,
43
            hubbard_int_orbital_basis=np.array(parameters.control.crit_temp.hubbard_int_orbital_basis),
44
            epsilon=parameters.control.crit_temp.conv_treshold,
45
            max_iter=parameters.control.crit_temp.max_iter,
46
            n_temp_points=20,
47
        )
48
        logger.info("Search for T_C completed successfully.")
×
49
        logger.info("Obtained T_Cs: %s", critical_temperatures)
×
50

51
        fit_fig.savefig(
×
52
            result_path / f"{parameters.control.crit_temp.prefix}_critical_temperatures_fit.pdf",
53
            bbox_inches="tight",
54
        )
55

56
        result_file_crit_temp = (
×
57
            result_path / f"{parameters.control.crit_temp.prefix}_critical_temperatures.hdf5"
58
        )
NEW
59
        if result_file_crit_temp.exists():
×
NEW
60
            result_file_crit_temp.exists()
×
61
        delta_vs_temp.to_hdf(result_file_crit_temp, key="delta_vs_temp")
×
62
        with h5py.File(result_file_crit_temp, mode="a") as file:
×
63
            for orbital, crit_temp_orbital in enumerate(critical_temperatures):
×
64
                file.attrs[f"T_C_{orbital}"] = crit_temp_orbital
×
65

66
        logger.info("Results saved to %s", result_file_crit_temp)
×
67
    else:
68
        critical_temperatures = []
×
69
        with h5py.File(f"{parameters.control.crit_temp}", mode="r") as file:
×
70
            for key, critical_temperature in file.attrs.items():
×
71
                if key.startswith("T_C"):
×
72
                    critical_temperatures.append(critical_temperature)
×
73
        logger.info("Read critical temperatures from file.")
×
74
        logger.info("Obtained T_Cs: %s", critical_temperatures)
×
75

76
    delta_vs_q = routines.loop_over_q(
×
77
        hamiltonian=hamiltonian,
78
        kgrid=k_grid_obj,
79
        hubbard_int_orbital_basis=np.array(parameters.control.hubbard_int_orbital_basis),
80
        epsilon=parameters.control.conv_treshold,
81
        max_iter=parameters.control.max_iter,
82
        n_q_points=parameters.control.n_q_points,
83
        crit_temps=np.array(critical_temperatures),
84
    )
85

86
    result_file_q = result_path / f"{parameters.control.prefix}_q.hdf5"
×
87

NEW
88
    if result_file_q.exists():
×
NEW
89
        result_file_q.unlink()
×
90
    for key, df in delta_vs_q.items():
×
91
        df.to_hdf(result_file_q, key=f"temp_{float(key):.6f}")
×
92
        with h5py.File(result_file_q, "a") as f:
×
93
            grp = f[f"temp_{float(key):.6f}"]
×
94
            grp.attrs["crit_temp"] = critical_temperatures
×
95
            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