better logging

This commit is contained in:
Benoît Sierro
2022-09-13 14:25:22 +02:00
parent 579532a4d3
commit 243f41feec
6 changed files with 19 additions and 9 deletions

7
TODO.md Normal file
View File

@@ -0,0 +1,7 @@
* plot cli command should show by default, not save
* logger should hook to pbar when it exists
* find a way to make evaluator debugging easier
# Ideas
* have a `scan` section in the config to more granularly control parameter scanning. That way, the user provides single default values to all necessary parameters and then call the single-sim or scan commands to run the config accordingly.

View File

@@ -234,7 +234,7 @@ class Evaluator:
else: else:
v_str = format(returned_value).replace("\n", "") v_str = format(returned_value).replace("\n", "")
success_str = f"computed {param_name}={v_str} " success_str = f"computed {param_name}={v_str} "
self.logger.info( self.logger.debug(
prefix prefix
+ success_str + success_str
+ f"using {rule.func.__name__} from {rule.func.__module__}" + f"using {rule.func.__name__} from {rule.func.__module__}"
@@ -382,6 +382,9 @@ default_rules: list[Rule] = [
), ),
Rule("n2", materials.gas_n2), Rule("n2", materials.gas_n2),
Rule("n2", lambda: 2.2e-20, priorities=-1), Rule("n2", lambda: 2.2e-20, priorities=-1),
Rule("gamma", lambda gamma_arr: gamma_arr[0], priorities=-1),
Rule("gamma", fiber.gamma_parameter),
Rule("gamma_arr", fiber.gamma_parameter, ["n2", "w0", "A_eff_arr"]),
# operators # operators
Rule("n_op", operators.ConstantRefractiveIndex), Rule("n_op", operators.ConstantRefractiveIndex),
Rule("n_op", operators.MarcatiliRefractiveIndex), Rule("n_op", operators.MarcatiliRefractiveIndex),
@@ -411,10 +414,6 @@ envelope_rules = default_rules + [
fiber.load_custom_dispersion, fiber.load_custom_dispersion,
priorities=[2, 2, 2], priorities=[2, 2, 2],
), ),
# Nonlinearity
Rule("gamma", lambda gamma_arr: gamma_arr[0], priorities=-1),
Rule("gamma", fiber.gamma_parameter),
Rule("gamma_arr", fiber.gamma_parameter, ["n2", "w0", "A_eff_arr"]),
# Operators # Operators
Rule("gamma_op", operators.ConstantGamma, priorities=1), Rule("gamma_op", operators.ConstantGamma, priorities=1),
Rule("gamma_op", operators.ConstantScalarGamma), Rule("gamma_op", operators.ConstantScalarGamma),
@@ -446,6 +445,7 @@ full_field_rules = default_rules + [
# Dispersion # Dispersion
Rule(["wl_for_disp", "dispersion_ind"], fiber.lambda_for_full_field_dispersion), Rule(["wl_for_disp", "dispersion_ind"], fiber.lambda_for_full_field_dispersion),
Rule("frame_velocity", fiber.frame_velocity), Rule("frame_velocity", fiber.frame_velocity),
Rule("beta2", lambda beta2_arr, w0_ind: beta2_arr[w0_ind]),
# Nonlinearity # Nonlinearity
Rule("chi3", materials.gas_chi3), Rule("chi3", materials.gas_chi3),
# Operators # Operators

View File

@@ -627,6 +627,7 @@ def beta2(w_for_disp: np.ndarray, n_eff: np.ndarray) -> np.ndarray:
return np.gradient(np.gradient(beta(w_for_disp, n_eff), w_for_disp), w_for_disp) return np.gradient(np.gradient(beta(w_for_disp, n_eff), w_for_disp), w_for_disp)
def frame_velocity(beta1_arr: np.ndarray, w0_ind: int) -> float: def frame_velocity(beta1_arr: np.ndarray, w0_ind: int) -> float:
return 1.0 / beta1_arr[w0_ind] return 1.0 / beta1_arr[w0_ind]

View File

@@ -131,6 +131,7 @@ class RK4IP:
def run(self) -> list[np.ndarray]: def run(self) -> list[np.ndarray]:
time_start = datetime.today() time_start = datetime.today()
state = self.init_state state = self.init_state
self.logger.info(f"integration scheme : {self.params.integration_scheme}")
for num, state in self.irun(): for num, state in self.irun():
if self.save_data: if self.save_data:
self._save_current_spectrum(state.actual_spectrum, num) self._save_current_spectrum(state.actual_spectrum, num)

View File

@@ -897,7 +897,7 @@ def uniform_axis(
plt_range = new_axis_spec plt_range = new_axis_spec
else: else:
raise TypeError(f"Don't know how to interpret {new_axis_spec}") raise TypeError(f"Don't know how to interpret {new_axis_spec}")
tmp_axis, ind, ext = sort_axis(axis, plt_range) tmp_axis, ind, ext = sort_axis(axis, plt_range)
values = np.atleast_2d(values) values = np.atleast_2d(values)
if np.allclose((diff := np.diff(tmp_axis))[0], diff): if np.allclose((diff := np.diff(tmp_axis))[0], diff):

View File

@@ -23,7 +23,8 @@ class Variationer:
Example Example
------- -------
`>> var = Variationer([dict(a=[1, 2]), [dict(b=["000", "111"], c=["a", "-1"])]]) ```
>> var = Variationer([dict(a=[1, 2]), [dict(b=["000", "111"], c=["a", "-1"])]])
list(v.raw_descr for v in var.iterate()) list(v.raw_descr for v in var.iterate())
[ [
@@ -31,8 +32,8 @@ class Variationer:
((("a", 1),), (("b", "111"), ("c", "-1"))), ((("a", 1),), (("b", "111"), ("c", "-1"))),
((("a", 2),), (("b", "000"), ("c", "a"))), ((("a", 2),), (("b", "000"), ("c", "a"))),
((("a", 2),), (("b", "111"), ("c", "-1"))), ((("a", 2),), (("b", "111"), ("c", "-1"))),
]` ]
```
""" """
all_indices: list[list[int]] all_indices: list[list[int]]