-
Notifications
You must be signed in to change notification settings - Fork 13
Logfile #31
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
Logfile #31
Changes from 41 commits
ddb2cbb
37355f1
28d4c74
d04601b
35f5090
70e5f61
8ba80b5
57d9695
869fdb9
5d6afec
44df15c
2b2dbef
8d1de64
5f6b384
c8776ea
9865cd5
8ea836f
7dfbf30
9807faf
17df67e
a2dd44e
c4ee763
597c7e7
57f2903
baebebe
9a1e2da
e301c3d
c853b4b
b27588b
796080a
c5a0ed5
c54d7f2
6bf3abf
5583963
f016124
e198fb9
f22c209
d7e3840
a19ab61
c1f59e0
9a68490
534792c
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,67 @@ | ||
| # copyright ################################# # | ||
| # This file is part of the wakis Package. # | ||
| # Copyright (c) CERN, 2025. # | ||
| # ########################################### # | ||
|
|
||
| from tqdm import tqdm | ||
|
|
||
| import numpy as np | ||
| import time | ||
| import h5py | ||
| import os | ||
| import json | ||
|
|
||
| from scipy.constants import c as c_light, epsilon_0 as eps_0, mu_0 as mu_0 | ||
| from scipy.sparse import csc_matrix as sparse_mat | ||
| from scipy.sparse import diags, hstack, vstack | ||
|
|
||
|
|
||
|
|
||
| class Logger(): | ||
|
|
||
| def __init__(self): | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. to stick to camelCase convention, we should avoid using underscores
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yes I think that is fine. Should I remove them?
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Fixed |
||
| self.grid = {} | ||
| self.solver = {} | ||
| self.wakeSolver = {} | ||
|
|
||
| def save_logs(self): | ||
| """ | ||
| Save all logs (grid, solver, wakeSolver) into log-file inside the results folder. | ||
| """ | ||
| logfile = os.path.join(self.wakeSolver["results_folder"], "wakis.log") | ||
|
|
||
| # Write sections | ||
| if not os.path.exists(self.wakeSolver["results_folder"]): | ||
| os.mkdir(self.wakeSolver["results_folder"]) | ||
|
|
||
| with open(logfile, "w", encoding="utf-8") as fh: | ||
| fh.write("Simulation Parameters\n") | ||
| fh.write("""=====================\n\n""") | ||
|
|
||
| sections = [ | ||
| ("WakeSolver Logs", self.wakeSolver), | ||
| ("Solver Logs", self.solver), | ||
| ("Grid Logs", self.grid), | ||
| ] | ||
|
|
||
| for title, data in sections: | ||
| fh.write(f"\n## {title} ##\n") | ||
| if not data: | ||
| fh.write("(empty)\n") | ||
| continue | ||
|
|
||
| # convert non-serializable values to strings recursively | ||
| def _convert(obj): | ||
| if isinstance(obj, dict): | ||
| return {k: _convert(v) for k, v in obj.items()} | ||
| if isinstance(obj, (list, tuple)): | ||
| return [_convert(v) for v in obj] | ||
| try: | ||
| json.dumps(obj) | ||
| return obj | ||
| except Exception: | ||
| return str(obj) | ||
|
|
||
| clean = _convert(data) | ||
| fh.write(json.dumps(clean, indent=2, ensure_ascii=False)) | ||
| fh.write("\n") | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -17,6 +17,7 @@ | |
| from .materials import material_lib | ||
| from .plotting import PlotMixin | ||
| from .routines import RoutinesMixin | ||
| from .logger import Logger | ||
|
|
||
| try: | ||
| from cupyx.scipy.sparse import csc_matrix as gpu_sparse_mat | ||
|
|
@@ -93,7 +94,8 @@ def __init__(self, grid, wake=None, cfln=0.5, dt=None, | |
| ''' | ||
|
|
||
| self.verbose = verbose | ||
| if verbose: t0 = time.time() | ||
| t0 = time.time() | ||
| self.logger = Logger() | ||
|
|
||
| # Flags | ||
| self.step_0 = True | ||
|
|
@@ -110,10 +112,11 @@ def __init__(self, grid, wake=None, cfln=0.5, dt=None, | |
| self.one_step = self._one_step | ||
| if use_stl: | ||
| self.use_conductors = False | ||
| self.update_logger(['use_gpu', 'use_mpi']) | ||
|
|
||
| # Grid | ||
| self.grid = grid | ||
|
|
||
| self.background = bg | ||
| self.Nx = self.grid.Nx | ||
| self.Ny = self.grid.Ny | ||
| self.Nz = self.grid.Nz | ||
|
|
@@ -131,6 +134,7 @@ def __init__(self, grid, wake=None, cfln=0.5, dt=None, | |
| self.iA = self.grid.iA | ||
| self.tL = self.grid.tL | ||
| self.itA = self.grid.itA | ||
| self.update_logger(['grid','background']) | ||
|
|
||
| # Wake computation | ||
| self.wake = wake | ||
|
|
@@ -175,6 +179,7 @@ def __init__(self, grid, wake=None, cfln=0.5, dt=None, | |
| if verbose: print('Applying boundary conditions...') | ||
| self.bc_low = bc_low | ||
| self.bc_high = bc_high | ||
| self.update_logger(['bc_low', 'bc_high']) | ||
| self.apply_bc_to_C() | ||
|
|
||
| # Materials | ||
|
|
@@ -203,6 +208,7 @@ def __init__(self, grid, wake=None, cfln=0.5, dt=None, | |
| self.pml_hi = 1.e-1 | ||
| self.pml_func = np.geomspace | ||
| self.fill_pml_sigmas() | ||
| self.update_logger(['n_pml']) | ||
|
|
||
| # Timestep calculation | ||
| if verbose: print('Calculating maximal stable timestep...') | ||
|
|
@@ -212,6 +218,7 @@ def __init__(self, grid, wake=None, cfln=0.5, dt=None, | |
| else: | ||
| self.dt = dt | ||
| self.dt = dtype(self.dt) | ||
| self.update_logger(['dt']) | ||
|
|
||
| if self.use_conductivity: # relaxation time criterion tau | ||
|
|
||
|
|
@@ -252,6 +259,9 @@ def __init__(self, grid, wake=None, cfln=0.5, dt=None, | |
|
|
||
| if verbose: print(f'Total initialization time: {time.time() - t0} s') | ||
|
|
||
| self.solverInitializationTime = time.time() - t0 | ||
| self.update_logger(['solverInitializationTime']) | ||
|
|
||
| def update_tensors(self, tensor='all'): | ||
| '''Update tensor matrices after | ||
| Field ieps, imu or sigma have been modified | ||
|
|
@@ -1107,4 +1117,14 @@ def reset_fields(self): | |
| for d in ['x', 'y', 'z']: | ||
| self.E[:, :, :, d] = 0.0 | ||
| self.H[:, :, :, d] = 0.0 | ||
| self.J[:, :, :, d] = 0.0 | ||
| self.J[:, :, :, d] = 0.0 | ||
|
|
||
| def update_logger(self, attrs): | ||
| """ | ||
| Assigns the parameters handed via attrs to the logger | ||
| """ | ||
| for atr in attrs: | ||
| if atr == 'grid': | ||
| self.logger.grid = self.grid.logger.grid | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. grid is very heavy on memory, which information are we saving there?
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We are giving the dictionary 'logger.grid' further to the logger object of the solver.
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I see! You are just checking that, if the attribute is named |
||
| else: | ||
| self.logger.solver[atr] = getattr(self, atr) | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same comment as in
SolverFIT3D