QSpaceHessian API Reference¶
tdscha.QSpaceHessian
¶
Q-Space Free Energy Hessian¶
Computes the free energy Hessian d²F/dRdR in q-space (Bloch basis).
Instead of building the full D4 matrix explicitly (O(N⁴) memory, O(N⁶) time), solves L_static(q) x = e_i for each band at each irreducible q-point, where L_static is the static Liouvillian operator. The Hessian is then H(q) = inv(G(q)), where G(q) is the static susceptibility.
The static L operator is DIFFERENT from the spectral L used in Lanczos: - Static: R sector = +w², W sector = 1/Lambda (one 2-phonon sector) - Spectral: R sector = -w², a'/b' sectors = -(w1∓w2)² (two sectors)
Both share the same anharmonic core (ensemble averages of D3/D4).
The q-space block-diagonal structure gives a speedup of ~N_cell³ / N_q_irr over the real-space approach.
References: Monacelli & Mauri 2021 (Phys. Rev. B)
QSpaceHessian(ensemble, verbose=True, ignore_v3=False, ignore_v4=False, **kwargs)
¶
Compute the free energy Hessian in q-space via iterative linear solves.
Uses the static Liouvillian operator L_static, which has the structure: - R sector: w² * R (positive, unlike spectral -w²) - W sector: (1/Lambda) * W (static 2-phonon propagator) - Anharmonic coupling via ensemble averages (same Julia core)
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
ensemble
|
Ensemble
|
The SSCHA ensemble. |
required |
verbose
|
bool
|
If True, print progress information. |
True
|
**kwargs
|
Additional keyword arguments passed to QSpaceLanczos. |
{}
|
Source code in tdscha/QSpaceHessian.py
70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 | |
init(use_symmetries=True)
¶
Initialize the Lanczos engine and find irreducible q-points.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
use_symmetries
|
bool
|
If True, use symmetries to reduce q-points. |
True
|
Source code in tdscha/QSpaceHessian.py
116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 | |
save_status(fname)
¶
Save checkpoint state (H_q_dict + metadata) to an NPZ file.
Only the master MPI rank writes the file.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
fname
|
str
|
Path to the output file. '.npz' extension is added if missing. |
required |
Source code in tdscha/QSpaceHessian.py
132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 | |
load_status(fname)
¶
Load checkpoint state from an NPZ file and validate metadata.
Master rank reads the file and broadcasts to all MPI ranks.
Populates H_q_dict with the saved Hessian matrices.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
fname
|
str
|
Path to the NPZ file. '.npz' extension is added if missing. |
required |
Returns:
| Name | Type | Description |
|---|---|---|
completed_iqs |
set of int
|
Set of irreducible q-point indices that have been completed. |
Raises:
| Type | Description |
|---|---|
ValueError
|
If any metadata field in the checkpoint does not match the current object. |
Source code in tdscha/QSpaceHessian.py
174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 | |
compute_hessian_at_q(iq, tol=1e-06, max_iters=500, use_preconditioner=True, dense_fallback=False, use_mode_symmetry=True)
¶
Compute the free energy Hessian at a single q-point.
Solves L_static(q) x_i = e_i for each non-acoustic band. G_q[j,i] = x_i[j] (R-sector), H_q = inv(G_q).
When use_mode_symmetry=True and degenerate modes are present, exploits Schur's lemma: L_static commutes with the little group of q, so G_q restricted to a d-dimensional irrep block is c*I_d. Only one solve per degenerate block is needed instead of d solves.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
iq
|
int
|
Q-point index. |
required |
tol
|
float
|
Convergence tolerance for the iterative solver. |
1e-06
|
max_iters
|
int
|
Maximum number of iterations. |
500
|
use_preconditioner
|
bool
|
If True, use harmonic preconditioner. |
True
|
dense_fallback
|
bool
|
If True, fall back to dense solve when iterative solvers fail. WARNING: this builds a psi_size x psi_size dense matrix, which can be very large for big supercells. Default is False. |
False
|
use_mode_symmetry
|
bool
|
If True, exploit mode degeneracy to reduce the number of GMRES solves. Within each degenerate block, only one solve is performed and G_q is filled using Schur's lemma (G_block = c * I). |
True
|
Returns:
| Name | Type | Description |
|---|---|---|
H_q |
(ndarray(n_bands, n_bands), complex128)
|
The Hessian matrix in the mode basis at q-point iq. |
Source code in tdscha/QSpaceHessian.py
720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 | |
compute_full_hessian(tol=1e-06, max_iters=500, use_preconditioner=True, dense_fallback=False, use_mode_symmetry=True, checkpoint=None)
¶
Compute the Hessian at all q-points and return as CC.Phonons.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
tol
|
float
|
Convergence tolerance for iterative solver. |
1e-06
|
max_iters
|
int
|
Maximum iterations per linear solve. |
500
|
use_preconditioner
|
bool
|
If True, use harmonic preconditioner. |
True
|
dense_fallback
|
bool
|
If True, fall back to dense solve when iterative solvers fail. WARNING: this builds a psi_size x psi_size dense matrix, which can be very large for big supercells. Default is False. |
False
|
use_mode_symmetry
|
bool
|
If True, exploit mode degeneracy to reduce GMRES solves. |
True
|
checkpoint
|
str or None
|
If a string path, auto-save after each completed irreducible q-point and resume from the checkpoint file on restart. The '.npz' extension is added automatically if missing. |
None
|
Returns:
| Name | Type | Description |
|---|---|---|
hessian |
Phonons
|
The free energy Hessian as a Phonons object (Ry/bohr²). |
Source code in tdscha/QSpaceHessian.py
958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 | |
from_qspace_lanczos(qlanc, verbose=True, use_symmetries=True)
classmethod
¶
Create a QSpaceHessian from an existing QSpaceLanczos object.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
qlanc
|
QSpaceLanczos
|
An initialized QSpaceLanczos object (e.g., from load_distributed_tdscha). |
required |
verbose
|
bool
|
If True, print progress information. |
True
|
use_symmetries
|
bool
|
If True, use symmetries to find irreducible q-points. |
True
|
Returns:
| Type | Description |
|---|---|
QSpaceHessian
|
A QSpaceHessian object with the given qlanc as its Lanczos engine. |
Source code in tdscha/QSpaceHessian.py
1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090 1091 1092 1093 1094 1095 1096 1097 1098 1099 1100 1101 1102 1103 1104 1105 1106 1107 1108 1109 1110 1111 1112 1113 1114 1115 1116 1117 1118 1119 1120 1121 1122 1123 1124 1125 1126 1127 1128 | |
load_distributed_hessian(data_dir, population_id, dyn, T, lo_to_split=None, use_symmetries=True, n_configs=None, final_dyn=None, final_T=None, verbose=True, ignore_v3=False, ignore_v4=False, **kwargs)
¶
Load QSpaceHessian with distributed configurations across MPI ranks.
Loads the ensemble on master rank only, then distributes configuration data across all ranks. Combines load_distributed_tdscha and QSpaceHessian.from_qspace_lanczos.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
data_dir
|
str
|
Directory containing the ensemble data files. |
required |
population_id
|
int
|
Population ID of the ensemble to load. |
required |
dyn
|
Phonons
|
Dynamical matrix object (used to create the ensemble). |
required |
T
|
float
|
Temperature in Kelvin. |
required |
lo_to_split
|
str, ndarray, or None
|
LO-TO splitting mode. |
None
|
use_symmetries
|
bool
|
If True, use q-space symmetries. |
True
|
n_configs
|
int or None
|
Number of configs to load. |
None
|
final_dyn
|
Phonons
|
Final dynamical matrix from the SSCHA calculation. If provided, the ensemble weights are updated using update_weights(final_dyn, final_T). |
None
|
final_T
|
float
|
Temperature for weight updates. Defaults to T if not specified. |
None
|
verbose
|
bool
|
If True, print progress information. |
True
|
ignore_v3
|
bool
|
If True, exclude cubic (D3) anharmonic contributions. |
False
|
ignore_v4
|
bool
|
If True, exclude quartic (D4) anharmonic contributions. |
False
|
**kwargs
|
Additional arguments passed to QSpaceLanczos. |
{}
|
Returns:
| Type | Description |
|---|---|
QSpaceHessian
|
QSpaceHessian with distributed ensemble. Already initialized. |
Usage
mpirun -np 8 python your_script.py
Example with weight update (recommended for production): final_dyn = CC.Phonons.Phonons("final_dyn_", nqirr=3) hess = load_distributed_hessian( "data/", 1, initial_dyn, 300, final_dyn=final_dyn, final_T=300 ) hessian_dyn = hess.compute_full_hessian()
Example without weight update (for testing/debugging): hess = load_distributed_hessian("data/", 1, dyn, 300) hessian_dyn = hess.compute_full_hessian()
Source code in tdscha/QSpaceHessian.py
1131 1132 1133 1134 1135 1136 1137 1138 1139 1140 1141 1142 1143 1144 1145 1146 1147 1148 1149 1150 1151 1152 1153 1154 1155 1156 1157 1158 1159 1160 1161 1162 1163 1164 1165 1166 1167 1168 1169 1170 1171 1172 1173 1174 1175 1176 1177 1178 1179 1180 1181 1182 1183 1184 1185 1186 1187 1188 1189 1190 1191 1192 1193 1194 1195 1196 1197 1198 1199 1200 1201 1202 1203 1204 1205 1206 1207 1208 1209 1210 1211 | |