Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Lossless Compression Manager #383

Open
wants to merge 6 commits into
base: compression
Choose a base branch
from
Open
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
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,10 @@
*detail.txt
data/*
step_*.png
/pySDC/projects/compression/*.png
/pySDC/projects/compression/*.txt
/pySDC/projects/compression/*.csv
.flakeheaven_cache/
*.pkl
*.swp

Expand Down
3 changes: 2 additions & 1 deletion pySDC/implementations/datatype_classes/mesh.py
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,8 @@ def __array_ufunc__(self, ufunc, method, *inputs, out=None, **kwargs):
args.append(input_)

results = super(mesh, self).__array_ufunc__(ufunc, method, *args, **kwargs).view(mesh)
if type(self) == type(results):
# if type(self) == type(results):
if not method == 'reduce':
results._comm = comm
return results

Expand Down
18 changes: 9 additions & 9 deletions pySDC/implementations/hooks/log_errors.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ class LogError(hooks):
to work, be it a reference solution or something analytical.
"""

def log_global_error(self, step, level_number, suffix=''):
def log_global_error(self, step, level_number, suffix=""):
"""
Function to add the global error to the stats

Expand All @@ -37,7 +37,7 @@ def log_global_error(self, step, level_number, suffix=''):
level=L.level_index,
iter=step.status.iter,
sweep=L.status.sweep,
type=f'e_global{suffix}',
type=f"e_global{suffix}",
value=abs(u_ref - L.uend),
)
self.add_to_stats(
Expand All @@ -51,7 +51,7 @@ def log_global_error(self, step, level_number, suffix=''):
value=abs(u_ref - L.uend) / abs(u_ref),
)

def log_local_error(self, step, level_number, suffix=''):
def log_local_error(self, step, level_number, suffix=""):
"""
Function to add the local error to the stats

Expand Down Expand Up @@ -96,7 +96,7 @@ def log_local_error(self, step, level_number, suffix=''):
class LogGlobalErrorPostStep(LogError):
def post_step(self, step, level_number):
super().post_step(step, level_number)
self.log_global_error(step, level_number, '_post_step')
self.log_global_error(step, level_number, "_post_step")


class LogGlobalErrorPostIter(LogError):
Expand Down Expand Up @@ -153,7 +153,7 @@ def post_step(self, step, level_number):
"""
super().post_step(step, level_number)
self.t_last_solution = step.levels[0].time + step.levels[0].dt
self.num_restarts = step.status.get('restarts_in_a_row', 0)
self.num_restarts = step.status.get("restarts_in_a_row", 0)

def post_run(self, step, level_number):
"""
Expand All @@ -175,7 +175,7 @@ def post_run(self, step, level_number):
u_num = L.uend
u_ref = L.prob.u_exact(t=self.t_last_solution)

self.logger.info(f'Finished with a global error of e={abs(u_num-u_ref):.2e}')
self.logger.info(f"Finished with a global error of e={abs(u_num-u_ref):.2e}")

self.add_to_stats(
process=step.status.slot,
Expand All @@ -184,7 +184,7 @@ def post_run(self, step, level_number):
level=L.level_index,
iter=step.status.iter,
sweep=L.status.sweep,
type='e_global_post_run',
type="e_global_post_run",
value=abs(u_num - u_ref),
)
self.add_to_stats(
Expand All @@ -208,7 +208,7 @@ class LogLocalErrorPostStep(LogError):

def post_step(self, step, level_number):
super().post_step(step, level_number)
self.log_local_error(step, level_number, suffix='_post_step')
self.log_local_error(step, level_number, suffix="_post_step")


class LogLocalErrorPostIter(LogError):
Expand All @@ -227,4 +227,4 @@ def post_iteration(self, step, level_number):
"""
super().post_iteration(step, level_number)

self.log_local_error(step, level_number, suffix='_post_iteration')
self.log_local_error(step, level_number, suffix="_post_iteration")
6 changes: 3 additions & 3 deletions pySDC/implementations/hooks/log_solution.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,8 @@ def post_step(self, step, level_number):
level=L.level_index,
iter=step.status.iter,
sweep=L.status.sweep,
type='u',
value=L.uend,
type="u",
value=L.uend[:],
)


Expand Down Expand Up @@ -60,6 +60,6 @@ def post_iteration(self, step, level_number):
level=L.level_index,
iter=step.status.iter,
sweep=L.status.sweep,
type='u',
type="u",
value=L.uend,
)
33 changes: 21 additions & 12 deletions pySDC/implementations/problem_classes/AllenCahn_MPIFFT.py
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ def __init__(
nvars = (128, 128)

if not (isinstance(nvars, tuple) and len(nvars) > 1):
raise ProblemError('Need at least two dimensions')
raise ProblemError("Need at least two dimensions")

# Creating FFT structure
ndim = len(nvars)
Expand All @@ -97,7 +97,16 @@ def __init__(
# invoke super init, passing the communicator and the local dimensions as init
super().__init__(init=(tmp_u.shape, comm, tmp_u.dtype))
self._makeAttributeAndRegister(
'nvars', 'eps', 'radius', 'spectral', 'dw', 'L', 'init_type', 'comm', localVars=locals(), readOnly=True
"nvars",
"eps",
"radius",
"spectral",
"dw",
"L",
"init_type",
"comm",
localVars=locals(),
readOnly=True,
)

L = np.array([self.L] * ndim, dtype=float)
Expand All @@ -115,7 +124,7 @@ def __init__(
k = [np.fft.fftfreq(n, 1.0 / n).astype(int) for n in N[:-1]]
k.append(np.fft.rfftfreq(N[-1], 1.0 / N[-1]).astype(int))
K = [ki[si] for ki, si in zip(k, s)]
Ks = np.meshgrid(*K, indexing='ij', sparse=True)
Ks = np.meshgrid(*K, indexing="ij", sparse=True)
Lp = 2 * np.pi / L
for i in range(ndim):
Ks[i] = (Ks[i] * Lp[i]).astype(float)
Expand Down Expand Up @@ -190,7 +199,7 @@ def solve_system(self, rhs, factor, u0, t):

else:
me = self.dtype_u(self.init)
rhs_hat = self.fft.forward(rhs)
rhs_hat = self.fft.forward(rhs[:])
rhs_hat /= 1.0 + factor * self.K2
me[:] = self.fft.backward(rhs_hat)

Expand All @@ -211,17 +220,17 @@ def u_exact(self, t):
The exact solution.
"""

assert t == 0, 'ERROR: u_exact only valid for t=0'
assert t == 0, "ERROR: u_exact only valid for t=0"
me = self.dtype_u(self.init, val=0.0)
if self.init_type == 'circle':
if self.init_type == "circle":
r2 = (self.X[0] - 0.5) ** 2 + (self.X[1] - 0.5) ** 2
if self.spectral:
tmp = 0.5 * (1.0 + np.tanh((self.radius - np.sqrt(r2)) / (np.sqrt(2) * self.eps)))
me[:] = self.fft.forward(tmp)
else:
me[:] = 0.5 * (1.0 + np.tanh((self.radius - np.sqrt(r2)) / (np.sqrt(2) * self.eps)))
elif self.init_type == 'circle_rand':
ndim = len(me.shape)
elif self.init_type == "circle_rand":
ndim = len(me[:].shape)
L = int(self.L)
# get random radii for circles/spheres
np.random.seed(1)
Expand All @@ -245,7 +254,7 @@ def u_exact(self, t):
else:
me[:] = tmp[:]
else:
raise NotImplementedError('type of initial value not implemented, got %s' % self.init_type)
raise NotImplementedError("type of initial value not implemented, got %s" % self.init_type)

return me

Expand Down Expand Up @@ -324,22 +333,22 @@ def eval_f(self, u, t):
f.expl[:] = self.fft.forward(tmpf)

else:
u_hat = self.fft.forward(u)
u_hat = self.fft.forward(u[:])
lap_u_hat = -self.K2 * u_hat
f.impl[:] = self.fft.backward(lap_u_hat, f.impl)

if self.eps > 0:
f.expl = -2.0 / self.eps**2 * u * (1.0 - u) * (1.0 - 2.0 * u)

# build sum over RHS without driving force
Rt_local = float(np.sum(f.impl + f.expl))
Rt_local = float(np.sum(f.impl[:] + f.expl[:]))
if self.comm is not None:
Rt_global = self.comm.allreduce(sendobj=Rt_local, op=MPI.SUM)
else:
Rt_global = Rt_local

# build sum over driving force term
Ht_local = float(np.sum(6.0 * u * (1.0 - u)))
Ht_local = float(np.sum(6.0 * u[:] * (1.0 - u[:])))
if self.comm is not None:
Ht_global = self.comm.allreduce(sendobj=Ht_local, op=MPI.SUM)
else:
Expand Down
Loading