Commit 07b346d
committed
Ensemble: opt-in linear-memory q-space mode, plus four fixes on the Fourier path
Opt-in flag Ensemble(..., qspace_light=True), default False, so nothing
changes unless it is asked for. In light mode the dense (3N, 3N) supercell
polarization vectors are never materialized -- not even at construction --
and reweighting goes through update_weights_fourier, which works per q point.
This is what makes the q-space TDSCHA path linear in memory instead of
quadratic; it needs CellConstructor's DiagonalizeSupercell(q_only=True).
Because the polarization vectors do not exist in this mode, the routines that
genuinely need them (get_free_energy, get_free_energy_hessian_dev) now fail
with an explicit message instead of an AttributeError on None deep inside
CellConstructor.
refresh_qspace_caches_from_real_space() is public. After a real-space
update_weights the q-space caches are stale, and the consumer (tdscha) had to
call a private method and then reach into Ensemble.__dict__ to raise the
coherence marker. The public method raises the marker itself, so the
invariant cannot drift and no caller needs private state. The private name
remains as a deprecated alias.
Four bugs fixed on the Fourier path, all independent of the flag above:
* init(): "self.N = self.structures" assigned the list itself instead of its
length, so the following [None] * self.N and np.tile(..., (self.N,1,1))
could not work once that branch was taken.
* the Fourier sscha_energies used forces_qspace (the ab initio forces) where
it needs sscha_forces_qspace. The same expression is written correctly in
update_weights_fourier; the two sites now agree.
* init_from_structures() left the Fourier energies in Ry/Bohr (missing
BOHR_TO_ANGSTROM) and with the wrong overall sign, again unlike the
equivalent block elsewhere in the file.
update_weights_fourier also rejects, instead of silently mixing, a new
dynamical matrix whose q points are reordered or whose unit cell differs: the
Fourier update contracts dynq and u_disps_qspace index by index, and r_lat /
q_grid are fixed at generation.
Tested by tests/test_qspace_light (11 tests), which check that light and
standard ensembles agree and that the light path refuses what it cannot do.1 parent 70c3060 commit 07b346d
2 files changed
Lines changed: 634 additions & 23 deletions
0 commit comments