param pretty format; energy_to_mean_power
This commit is contained in:
@@ -54,6 +54,7 @@ VALID_VARIABLE = {
|
|||||||
"pitch_ratio",
|
"pitch_ratio",
|
||||||
"effective_mode_diameter",
|
"effective_mode_diameter",
|
||||||
"core_radius",
|
"core_radius",
|
||||||
|
"model",
|
||||||
"capillary_num",
|
"capillary_num",
|
||||||
"capillary_radius",
|
"capillary_radius",
|
||||||
"capillary_thickness",
|
"capillary_thickness",
|
||||||
@@ -99,6 +100,7 @@ MANDATORY_PARAMETERS = [
|
|||||||
"alpha",
|
"alpha",
|
||||||
"spec_0",
|
"spec_0",
|
||||||
"field_0",
|
"field_0",
|
||||||
|
"mean_power",
|
||||||
"input_transmission",
|
"input_transmission",
|
||||||
"z_targets",
|
"z_targets",
|
||||||
"length",
|
"length",
|
||||||
@@ -395,7 +397,7 @@ class Parameters(_AbstractParameters):
|
|||||||
# pulse
|
# pulse
|
||||||
field_file: str = Parameter(string)
|
field_file: str = Parameter(string)
|
||||||
repetition_rate: float = Parameter(
|
repetition_rate: float = Parameter(
|
||||||
non_negative(float, int), display_info=(1e-6, "MHz"), default=40e6
|
non_negative(float, int), display_info=(1e-3, "kHz"), default=40e6
|
||||||
)
|
)
|
||||||
peak_power: float = Parameter(positive(float, int), display_info=(1e-3, "kW"))
|
peak_power: float = Parameter(positive(float, int), display_info=(1e-3, "kW"))
|
||||||
mean_power: float = Parameter(positive(float, int), display_info=(1e3, "mW"))
|
mean_power: float = Parameter(positive(float, int), display_info=(1e3, "mW"))
|
||||||
@@ -479,6 +481,12 @@ class Parameters(_AbstractParameters):
|
|||||||
setattr(self, k, v)
|
setattr(self, k, v)
|
||||||
return results
|
return results
|
||||||
|
|
||||||
|
def pformat(self) -> str:
|
||||||
|
return "\n".join(
|
||||||
|
f"{k} = {VariationDescriptor.format_value(k, v)}"
|
||||||
|
for k, v in self.prepare_for_dump().items()
|
||||||
|
)
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def all_parameters(cls) -> list[str]:
|
def all_parameters(cls) -> list[str]:
|
||||||
return [f.name for f in fields(cls)]
|
return [f.name for f in fields(cls)]
|
||||||
@@ -749,13 +757,13 @@ class Evaluator:
|
|||||||
else:
|
else:
|
||||||
default = self.get_default(target)
|
default = self.get_default(target)
|
||||||
if default is None:
|
if default is None:
|
||||||
error = NoDefaultError(
|
error = error or NoDefaultError(
|
||||||
prefix
|
prefix
|
||||||
+ f"No default provided for {target}. Current lookup cycle : {self.__curent_lookup!r}"
|
+ f"No default provided for {target}. Current lookup cycle : {self.__curent_lookup!r}"
|
||||||
)
|
)
|
||||||
else:
|
else:
|
||||||
value = default
|
value = default
|
||||||
self.logger.info(f"using default value of {value} for {target}")
|
self.logger.info(prefix + f"using default value of {value} for {target}")
|
||||||
self.set_value(target, value, 0)
|
self.set_value(target, value, 0)
|
||||||
|
|
||||||
if value is None and error is not None:
|
if value is None and error is not None:
|
||||||
@@ -1089,6 +1097,7 @@ default_rules: list[Rule] = [
|
|||||||
Rule("peak_power", pulse.soliton_num_to_peak_power),
|
Rule("peak_power", pulse.soliton_num_to_peak_power),
|
||||||
Rule("energy", pulse.P0_to_E0, ["peak_power", "t0", "shape"]),
|
Rule("energy", pulse.P0_to_E0, ["peak_power", "t0", "shape"]),
|
||||||
Rule("energy", pulse.mean_power_to_energy, priorities=2),
|
Rule("energy", pulse.mean_power_to_energy, priorities=2),
|
||||||
|
Rule("mean_power", pulse.energy_to_mean_power),
|
||||||
Rule("t0", pulse.width_to_t0),
|
Rule("t0", pulse.width_to_t0),
|
||||||
Rule("t0", pulse.soliton_num_to_t0),
|
Rule("t0", pulse.soliton_num_to_t0),
|
||||||
Rule("width", pulse.t0_to_width),
|
Rule("width", pulse.t0_to_width),
|
||||||
|
|||||||
@@ -171,7 +171,10 @@ def combine_simulations(path: Path, dest: Path = None):
|
|||||||
if p.is_dir():
|
if p.is_dir():
|
||||||
paths[p.name.split()[1]].append(p)
|
paths[p.name.split()[1]].append(p)
|
||||||
for l in paths.values():
|
for l in paths.values():
|
||||||
l.sort(key=lambda el: re.search(r"(?<=num )[0-9]+", el.name)[0])
|
try:
|
||||||
|
l.sort(key=lambda el: re.search(r"(?<=num )[0-9]+", el.name)[0])
|
||||||
|
except TypeError:
|
||||||
|
pass
|
||||||
for pulses in paths.values():
|
for pulses in paths.values():
|
||||||
new_path = dest / update_path(pulses[0].name)
|
new_path = dest / update_path(pulses[0].name)
|
||||||
os.makedirs(new_path, exist_ok=True)
|
os.makedirs(new_path, exist_ok=True)
|
||||||
|
|||||||
@@ -9,7 +9,6 @@ from pydantic import validator
|
|||||||
from pydantic.main import BaseModel
|
from pydantic.main import BaseModel
|
||||||
|
|
||||||
from ..const import PARAM_SEPARATOR
|
from ..const import PARAM_SEPARATOR
|
||||||
from . import utils
|
|
||||||
|
|
||||||
T = TypeVar("T")
|
T = TypeVar("T")
|
||||||
|
|
||||||
@@ -135,6 +134,23 @@ class VariationDescriptor(BaseModel):
|
|||||||
"""
|
"""
|
||||||
cls._format_registry[p_name] = func
|
cls._format_registry[p_name] = func
|
||||||
|
|
||||||
|
@classmethod
|
||||||
|
def format_value(cls, name: str, value) -> str:
|
||||||
|
if value is True or value is False:
|
||||||
|
return str(value)
|
||||||
|
elif isinstance(value, (float, int)):
|
||||||
|
try:
|
||||||
|
return cls._format_registry[name](value)
|
||||||
|
except KeyError:
|
||||||
|
return format(value, ".9g")
|
||||||
|
elif isinstance(value, (list, tuple, np.ndarray)):
|
||||||
|
return "-".join([str(v) for v in value])
|
||||||
|
elif isinstance(value, str):
|
||||||
|
p = Path(value)
|
||||||
|
if p.exists():
|
||||||
|
return p.stem
|
||||||
|
return str(value)
|
||||||
|
|
||||||
class Config:
|
class Config:
|
||||||
allow_mutation = False
|
allow_mutation = False
|
||||||
|
|
||||||
@@ -166,22 +182,6 @@ class VariationDescriptor(BaseModel):
|
|||||||
self.identifier + PARAM_SEPARATOR + self.branch.identifier + PARAM_SEPARATOR + tmp_name
|
self.identifier + PARAM_SEPARATOR + self.branch.identifier + PARAM_SEPARATOR + tmp_name
|
||||||
)
|
)
|
||||||
|
|
||||||
def format_value(self, name: str, value) -> str:
|
|
||||||
if value is True or value is False:
|
|
||||||
return str(value)
|
|
||||||
elif isinstance(value, (float, int)):
|
|
||||||
try:
|
|
||||||
return self._format_registry[name](value)
|
|
||||||
except KeyError:
|
|
||||||
return format(value, ".9g")
|
|
||||||
elif isinstance(value, (list, tuple, np.ndarray)):
|
|
||||||
return "-".join([str(v) for v in value])
|
|
||||||
elif isinstance(value, str):
|
|
||||||
p = Path(value)
|
|
||||||
if p.exists():
|
|
||||||
return p.stem
|
|
||||||
return str(value)
|
|
||||||
|
|
||||||
def __getitem__(self, key) -> "VariationDescriptor":
|
def __getitem__(self, key) -> "VariationDescriptor":
|
||||||
return VariationDescriptor(
|
return VariationDescriptor(
|
||||||
raw_descr=self.raw_descr[key], index=self.index[key], separator=self.separator
|
raw_descr=self.raw_descr[key], index=self.index[key], separator=self.separator
|
||||||
|
|||||||
@@ -289,6 +289,10 @@ def mean_power_to_energy(mean_power: float, repetition_rate: float) -> float:
|
|||||||
return mean_power / repetition_rate
|
return mean_power / repetition_rate
|
||||||
|
|
||||||
|
|
||||||
|
def energy_to_mean_power(energy: float, repetition_rate: float) -> float:
|
||||||
|
return energy * repetition_rate
|
||||||
|
|
||||||
|
|
||||||
def soliton_num_to_peak_power(soliton_num, beta2, gamma, t0):
|
def soliton_num_to_peak_power(soliton_num, beta2, gamma, t0):
|
||||||
return soliton_num ** 2 * abs(beta2) / (gamma * t0 ** 2)
|
return soliton_num ** 2 * abs(beta2) / (gamma * t0 ** 2)
|
||||||
|
|
||||||
|
|||||||
@@ -128,6 +128,7 @@ def plot_init(
|
|||||||
lbl = plot_1_dispersion(lim_disp, tl, tr, style, lbl, params, loss_ax)
|
lbl = plot_1_dispersion(lim_disp, tl, tr, style, lbl, params, loss_ax)
|
||||||
lbl = plot_1_init_spec_field(lim_field, lim_spec, bl, br, style, lbl, params)
|
lbl = plot_1_init_spec_field(lim_field, lim_spec, bl, br, style, lbl, params)
|
||||||
all_labels.append(lbl)
|
all_labels.append(lbl)
|
||||||
|
print(params.pformat())
|
||||||
finish_plot(fig, tr, all_labels, params)
|
finish_plot(fig, tr, all_labels, params)
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user