Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ tests/**/*.hdf5
.idea/
.vscode/
.claude/
.codex/
.superpowers/

# other
Expand Down
4 changes: 4 additions & 0 deletions dgamore/DGAmore.py
Original file line number Diff line number Diff line change
Expand Up @@ -773,6 +773,8 @@ def counts(rank: int) -> tuple[int, int, int, int]:
groups.setdefault(counts(rank), [rank, 0])[1] += 1
node_groups.append((list(groups.values()), 0 in ranks, avail * NODE_MEMORY_FRACTION))

# the momentum maps of the point group, which every rank builds in the self-energy step anyway
point_group = config.lattice.k_grid.auto_point_group()
niv_pp = min(config.box.niw_core // 2, config.box.niv_core // 2)
# Must mirror the giwk_full window the SDE section starts from in nonlocal_sde.calculate_self_energy_q.
niv_cut = min(config.box.niw_core + config.box.niv_full + 10, config.box.niv_dmft)
Expand Down Expand Up @@ -807,6 +809,8 @@ def counts(rank: int) -> tuple[int, int, int, int]:
warm_start=bool(config.self_consistency.previous_sc_path),
previous_proposal=config.self_consistency.max_iter > 1,
with_jacobian_tracker=config.stabilization.use_jacobian_stabilization,
n_symmetries=len(config.lattice.k_grid._auto_group or ()),
n_point_operations=0 if point_group is None else len(point_group[0]),
)
# the estimates of this call, keyed by the counts, the budgets and the exact-Jacobian flag, which can be disabled
estimates: dict = {}
Expand Down
55 changes: 22 additions & 33 deletions dgamore/bubble_gen.py
Original file line number Diff line number Diff line change
Expand Up @@ -189,7 +189,7 @@ def create_generalized_chi0_q_fft(
g_flat = np.reshape(g_r.mat, (k_grid.nk_tot, nb * nb, -1))
rev = BubbleGenerator._reversed_momenta(k_grid.nk)
pair_products = BubbleGenerator._pair_products(nb, None if components is None else components[0])
sums = np.zeros((len(k_grid.irrk_ind), nb**4, len(wn), len(pieces)), dtype=g_r.mat.dtype)
sums = np.zeros((len(k_grid.irrk_ind), nb**4, len(wn)), dtype=g_r.mat.dtype)
summed = np.empty((k_grid.nk_tot, len(pair_products)), dtype=g_r.mat.dtype)
g_r = np.asarray(g_r.mat[..., start:end], order="C")
g_r_rev = np.asarray(g_r_rev.mat, order="C")
Expand Down Expand Up @@ -223,19 +223,20 @@ def create_generalized_chi0_q_fft(
if found.any():
crossed = np.conj(gchi0_q_mat[..., iw, :n_v][..., found].transpose(0, 3, 4, 1, 2, 5))
gchi0_q_mat[..., iw, partners[mine][found] % (2 * n_keep)] = crossed
for p, piece in enumerate(pieces):
for piece in pieces:
BubbleGenerator._sum_column_products(summed, g_flat, rev, start + piece, wn_i, pair_products)
rows = sp.fft.ifftn(summed.reshape(*k_grid.nk, -1), axes=(0, 1, 2), overwrite_x=True)
rows = rows.reshape(k_grid.nk_tot, -1)[k_grid.irrk_ind]
if components is None:
sums[:, :, iw, p] = rows
sums[:, :, iw] += rows
else:
sums[:, components[0], iw, p], sums[:, components[1], iw, p] = rows, rows[:, components[2]]
sums[:, components[0], iw] += rows
sums[:, components[1], iw] += rows[:, components[2]]

gchi0_q_mat *= -beta / k_grid.nk_tot
if pieces:
shell_mat = BubbleGenerator._add_pieces(sums, beta, k_grid.nk_tot)
shell_mat = shell_mat.reshape(len(k_grid.irrk_ind), nb, nb, nb, nb, len(wn))
sums *= -beta / k_grid.nk_tot
shell_mat = sums.reshape(len(k_grid.irrk_ind), nb, nb, nb, nb, len(wn))
gchi0_q_mat = mpi_dist_irrk.scatter(gchi0_q_mat)

bubble = FourPoint(
Expand Down Expand Up @@ -417,22 +418,6 @@ def _sum_column_products(
product[:n] += term[:n]
out[r0 : r0 + n] = product[:n].reshape(n, -1)[:, pairs]

@staticmethod
def _add_pieces(sums: np.ndarray, beta: float, nk_tot: int) -> np.ndarray:
r"""
Returns the sum of the transformed pieces of summed columns, added in their order and scaled as the bubble.

:param sums: The transformed pieces on the last axis, ``[..., n_pieces]``.
:param beta: Inverse temperature :math:`\beta`.
:param nk_tot: Number of momenta of the grid.
:return: The scaled sum ``[...]``.
"""
total = sums[..., 0].copy()
for p in range(1, sums.shape[-1]):
total += sums[..., p]
total *= -beta / nk_tot
return total

@staticmethod
def _add_product(out: np.ndarray, left: np.ndarray, right: np.ndarray, block: np.ndarray) -> None:
"""
Expand Down Expand Up @@ -546,8 +531,9 @@ def _create_generalized_chi0_q_fft_distributed(
:meth:`_summed_pieces`): a piece is one more column of its bosonic frequency, filled with the summed products
of all its components at once (see :meth:`_sum_column_products`; that buffer of one full-grid column of
every component is held from a rank's first piece to its first core column), and transformed and exchanged
as a column is. The pieces come first in the schedule, so the rounds that hold them hold little else, and each
is stored on its own until all have arrived and are added in their order.
as a column is. The pieces run first, one pass per piece of every bosonic frequency, so each arrives after the
one before it and is added to its frequency's sum at once: a rank stores one sum per bosonic frequency, not
every piece.

:param mpi_dist_irrk: MPI distributor over the irreducible BZ q-points (see :class:`MpiDistributor`).
:param giwk: The momentum-dependent :class:`GreensFunction`.
Expand Down Expand Up @@ -603,8 +589,8 @@ def build_g_r() -> np.ndarray:
# contiguous, columns w-major; one stored bosonic frequency per array with blocks
width = 2 * n_keep if blocks else len(wn) * 2 * n_keep
mat_cols = [np.reshape(mat, (my_nq, nb**4, width), copy=False) for mat in mats]
# the transformed pieces of every bosonic frequency, each on its own until they are added in their order
sums = [np.empty((my_nq, nb**4, n_sum), dtype=g_r_mat.dtype) for _ in wn] if n_sum else []
# one sum of the transformed pieces per bosonic frequency
sums = [np.zeros((my_nq, nb**4), dtype=g_r_mat.dtype) for _ in wn] if n_sum else []

# chi0_1234(R) = G_14(R) G_32(-R): the flat factor pairs of every transformed component, the orbital swap
# of the partner, and the column's two factors, orbital-major, gathered once per column
Expand Down Expand Up @@ -650,7 +636,8 @@ def put(target: slice, values: np.ndarray) -> None:
kept columns, or subtracts them (``subtract_from``)."""
iw, first = divmod(target.start, vpos)
if first < n_sum:
sums[iw][:, :, first : first + target.stop - target.start] = values
# a pass holds one piece per bosonic frequency, so the pieces are added in their order
sums[iw] += values[..., 0]
return
kept = iw * 2 * n_keep + first - n_sum
b = kept // width
Expand Down Expand Up @@ -701,15 +688,16 @@ def column(kept: np.ndarray) -> np.ndarray:
kept, partners = BubbleGenerator._crossing_columns(wn, n_keep)
partner_of = np.full(len(wn) * vpos, -1)
partner_of[column(kept)] = np.where(partners >= 0, column(partners), -1)
# every piece before the first kept column
columns = np.concatenate(((np.arange(len(wn))[:, None] * vpos + np.arange(n_sum)).ravel(), column(kept)))
columns = column(kept)
if release is not None:
release()
comp_shape = (nb,) * 4 if components is None else (len(components[0]),)
group = max(1, ROUND_BUFFER_BYTES // (nk_tot * g_r_mat.itemsize))
BubbleGenerator._run_columns(
mpi_dist_irrk, k_grid, len(wn), vpos, 1, comp_shape, g_r_mat.dtype, fill, deliver, columns, group
)
# one pass per piece of every bosonic frequency, then the kept columns
for passed in [np.arange(len(wn)) * vpos + p for p in range(n_sum)] + [columns]:
BubbleGenerator._run_columns(
mpi_dist_irrk, k_grid, len(wn), vpos, 1, comp_shape, g_r_mat.dtype, fill, deliver, passed, group
)
g_r_mat = None
if g_r_win is not None:
node_comm.Barrier()
Expand All @@ -728,7 +716,8 @@ def column(kept: np.ndarray) -> np.ndarray:
return bubbles if blocks else bubbles[0]
shells = []
while sums:
total = BubbleGenerator._add_pieces(sums.pop(0), beta, nk_tot).reshape(my_nq, nb, nb, nb, nb, 1)
total = sums.pop(0).reshape(my_nq, nb, nb, nb, nb, 1)
total *= -beta / nk_tot
shells.append(FourPoint(total, SpinChannel.NONE, k_grid.nk, 1, 0, False, True, True).filter_small_values())
return bubbles, shells

Expand Down
31 changes: 22 additions & 9 deletions dgamore/eliashberg_solver.py
Original file line number Diff line number Diff line change
Expand Up @@ -2859,6 +2859,25 @@ def _solve_sectors_in_memory(
return results


def combine_pairing_vertices(f_dens_pp: FourPoint, f_magn_pp: FourPoint) -> tuple[FourPoint, FourPoint]:
r"""
Returns the singlet and triplet pairing vertices of the density and magnetic full ladder vertices in pp notation,
:math:`\Gamma_{\mathrm{sing}} = \tfrac{1}{2} F_{\mathrm{d}} - \tfrac{3}{2} F_{\mathrm{m}}` and
:math:`\Gamma_{\mathrm{trip}} = \Gamma_{\mathrm{sing}} + 2 F_{\mathrm{m}}`. The singlet vertex is built in the
density vertex and the magnetic vertex is freed, so the step holds three vertices at most.

:param f_dens_pp: The density full ladder vertex :math:`F_{\mathrm{d}}`; overwritten with the singlet vertex.
:param f_magn_pp: The magnetic full ladder vertex :math:`F_{\mathrm{m}}`; freed.
:return: The pair ``(singlet, triplet)``.
"""
gamma_sing_pp = f_dens_pp.scale(0.5).sub(f_magn_pp.scale(1.5, copy=True), copy=False)
gamma_sing_pp.channel = SpinChannel.SING
gamma_trip_pp = gamma_sing_pp.add(f_magn_pp.scale(2.0))
gamma_trip_pp.channel = SpinChannel.TRIP
f_magn_pp.free()
return gamma_sing_pp, gamma_trip_pp


def solve(
giwk_dga: GreensFunction | None,
g_dmft: GreensFunction,
Expand Down Expand Up @@ -2975,15 +2994,9 @@ def solve(
if comm.rank == 0:
output_files.delete_files(config.output.eliashberg_path, f"{output_files.GIWK_FILE_STEM}.npy")

gamma_sing_pp = f_dens_pp.scale(0.5).sub(f_magn_pp.scale(1.5, copy=True), copy=False)
del f_dens_pp
gamma_sing_pp.channel = SpinChannel.SING
logger.info("Calculated full ladder-vertex (singlet) in pp notation.")

gamma_trip_pp = gamma_sing_pp.add(f_magn_pp.scale(2.0))
gamma_trip_pp.channel = SpinChannel.TRIP
f_magn_pp.free()
logger.info("Calculated full ladder-vertex (triplet) in pp notation.")
gamma_sing_pp, gamma_trip_pp = combine_pairing_vertices(f_dens_pp, f_magn_pp)
del f_dens_pp, f_magn_pp
logger.info("Calculated full ladder-vertex (singlet and triplet) in pp notation.")

if config.misc.bare_vertex:
# Eqs. (4.49)-(4.52) with the bare up-down vertex U as the local full vertex and no pp-reducible diagrams:
Expand Down
Loading
Loading