Conversation
….py to avoid module clash
There was a problem hiding this comment.
For the following launch file I get unexpected output en_f and logging that I cannot get rid of. I set the logging info with a string, but with the requested int it didn't work either.
# -----------------------------
# Description of the simulation
# -----------------------------
# Please fill in a verbal description of the simulation.
# It will be printed at the beginning of the simulation and can be used to keep track of the different runs.
name = "Default Vlasov"
description = """
This is the default simulation for the model Vlasov.
It is meant to be a template for users to set up their own simulations with this model.
It contains all the necessary components of a Struphy simulation, including the model,
the environment options, the time stepping options, the geometry, the equilibrium,
the grid, the Derham options, and the initial conditions.
Users can modify this file to set up their own simulations with different parameters and initial conditions.
"""
# ------------------
# Import Struphy API
# ------------------
from struphy import (
BaseUnits,
DerhamOptions,
EnvironmentOptions,
FieldsBackground,
Simulation,
Time,
domains,
equils,
grids,
perturbations,
)
# For particles:
from struphy import (
BinningPlot,
BoundaryParameters,
KernelDensityPlot,
LoadingParameters,
WeightsParameters,
maxwellians,
)
# ---------------------
# Instance of the model
# ---------------------
from struphy.models import Vlasov
model = Vlasov()
# List all species and set their physical properties (charge and mass number, etc.)
model.kinetic_ions.set_species_properties()
# List all variables and decide whether to save their data
model.kinetic_ions.var.save_data = True
# --------------------------
# Instance of the simulation
# --------------------------
# Environment options
env = EnvironmentOptions()
# Units
base_units = BaseUnits()
# Time stepping
time_opts = Time(dt=0.2, Tend=10.0)
# Geometry
a1 = 0.00001
a2 = 5.0
Lz = 20.0
domain = domains.HollowCylinder(a1=a1, a2=a2, Lz=Lz)
# Fluid equilibrium (can be used as part of initial conditions)
B0x = 0.0
B0y = 0.0
B0z = 1.0
equil = equils.HomogenSlab(B0x=B0x, B0y=B0y, B0z=B0z)
# Grid
grid = grids.TensorProductGrid()
# Derham options
spl_kind = (False, True, True)
derham_opts = DerhamOptions(spl_kind=spl_kind)
# Simulation object
sim = Simulation(
model=model,
name=name,
description=description,
params_path=__file__,
env=env,
base_units=base_units,
time_opts=time_opts,
domain=domain,
equil=equil,
grid=grid,
derham_opts=derham_opts,
logging_level="WARNING",
)
# -------------------
# Particle parameters
# -------------------
loading_params = LoadingParameters(Np=20, seed=1234)
weights_params = WeightsParameters()
boundary_params = BoundaryParameters(bc=("remove", "periodic", "periodic"))
model.kinetic_ions.set_markers(
loading_params=loading_params, weights_params=weights_params, boundary_params=boundary_params
)
model.kinetic_ions.set_sorting_boxes()
model.kinetic_ions.set_save_data(n_markers=1.0)
# propagator options
model.propagators.push_vxb.options = model.propagators.push_vxb.Options(algo="analytic")
model.propagators.push_eta.options = model.propagators.push_eta.Options()
# initial conditions (background + perturbation)
perturbation = None
background = maxwellians.Maxwellian3D(n=(1.0, perturbation))
model.kinetic_ions.var.add_background(background)
if __name__ == "__main__":
sim.run(verbose=True)
This is the same error as in the tutorials test, not sure what causes it. |
|
I fixed the tutorials error with the last two commits, this is sg else. |
|
These lines should be rewritten using just a string argument:
should be:
error here: https://github.com/struphy-hub/struphy/actions/runs/23428915045/job/68150111653?pr=199 |
Fixed in 7d25987 |
|
Seems like the logging is now working @spossann, but I think we still need to think through the setup before merging. It's not clear to me where to call this |
Based on this tutorial: https://www.youtube.com/watch?v=9L77QExPmI0
Here are the logging levels:
I would suggest that the cases where we have
could be replaced by
logger.debug(message).Then we can set the default logging to INFO and if you wish to change it, you just set it to DEBUG and then all the verbose logging messages will be show.
Also, another nice thing is that we can add this rank filter so that instead of doing:
we can just do
logger.debug(message)and by default only rank == 0 logs. We can also add more handlers to which this filter does not apply, which might be the case for certain types of debugging, where you might want to log from every rank.