Skip to content

Commit

Permalink
more tests and options for solution history
Browse files Browse the repository at this point in the history
  • Loading branch information
lehner committed Sep 5, 2024
1 parent c58bb68 commit 28efde3
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 14 deletions.
6 changes: 5 additions & 1 deletion lib/gpt/algorithms/inverter/solution_history.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,10 @@


class solution_history(base):
def __init__(self, solution_space, inverter, N):
def __init__(self, solution_space, inverter, N, optimize = None):

Check failure on line 25 in lib/gpt/algorithms/inverter/solution_history.py

View workflow job for this annotation

GitHub Actions / lint

E251:unexpected spaces around keyword / parameter equals

Check failure on line 25 in lib/gpt/algorithms/inverter/solution_history.py

View workflow job for this annotation

GitHub Actions / lint

E251:unexpected spaces around keyword / parameter equals
super().__init__()
self.inverter = inverter
self.optimize = optimize
self.N = N
self.solution_space = solution_space

Expand All @@ -46,6 +47,9 @@ def inv(psi, src, t):
space.pop()
space.insert(0, psi)

if self.optimize is not None:
self.optimize(space, mat, self.N)

self.log(f"solution space now has {len(self.solution_space)} / {self.N} elements")

return g.matrix_operator(
Expand Down
46 changes: 33 additions & 13 deletions tests/manual/mpi.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,18 +43,6 @@ def D_DWF(dst, src, U, b, c, mass, M5):
for precision in [g.single, g.double]:
grid = g.grid(arg_grid, precision)

# test global sums
local_value = g.random(str(grid.processor)).cnormal()
global_value = grid.globalsum(local_value)

ref_global_value = 0.0
for i in range(grid.Nprocessors):
ref_global_value += g.random(str(i)).cnormal()

eps = abs(global_value - ref_global_value) / abs(global_value)
g.message(f"Test global sum: {eps}")
assert eps < precision.eps * 100

# test mobius dwf against cshift version
U = g.qcd.gauge.random(grid, rng)
Ls = 12
Expand Down Expand Up @@ -82,4 +70,36 @@ def D_DWF(dst, src, U, b, c, mass, M5):
eps = (g.norm2(dst_ref - dst) / g.norm2(dst_ref)) ** 0.5
g.message(f"Test mobius implementation: {eps}")
assert eps < precision.eps * 100


# test global sums
for it in range(10):
local_value = g.random(str(it) + "-" + str(grid.processor)).cnormal()
global_value = grid.globalsum(local_value)

ref_global_value = 0.0
for i in range(grid.Nprocessors):
ref_global_value += g.random(str(it) + "-" + str(i)).cnormal()

eps = abs(global_value - ref_global_value) / abs(global_value)
g.message(f"Test global sum {i}: {eps}")
assert eps < precision.eps * 100

# now have double-precision grid
exact_prec = 1e-10
pc = g.qcd.fermion.preconditioner
inv = g.algorithms.inverter
g.default.set_verbose("cg_convergence")
cg_e_inner = inv.cg({"eps": 1e-4, "eps_abs": exact_prec * 0.3, "maxiter": 40000, "miniter": 50})
cg_e = inv.defect_correcting(
#inv.mixed_precision(inv.preconditioned(pc.eo2_ne(), cg_e_inner), g.single, g.double),
inv.preconditioned(pc.eo2_ne(), cg_e_inner),
eps=exact_prec,
maxiter=100,
)

prop = cg_e(mobius)
dst0 = g(prop * src)
dst1 = g(prop * src)
eps = (g.norm2(dst0 - dst1)/g.norm2(dst0))**0.5
g.message(f"Reproduce mixed precision solve: {eps}")
assert eps < precision.eps * 100

0 comments on commit 28efde3

Please sign in to comment.