simulations working
This commit is contained in:
@@ -250,7 +250,10 @@ class Evaluator:
|
|||||||
self.eval_stats[key].priority = priority
|
self.eval_stats[key].priority = priority
|
||||||
|
|
||||||
def validate_condition(self, rule: Rule) -> bool:
|
def validate_condition(self, rule: Rule) -> bool:
|
||||||
return all(self.compute(k) == v for k, v in rule.conditions.items())
|
try:
|
||||||
|
return all(self.compute(k) == v for k, v in rule.conditions.items())
|
||||||
|
except (EvaluatorError, KeyError, NoDefaultError):
|
||||||
|
return False
|
||||||
|
|
||||||
def attempted_rules_str(self, target: str) -> str:
|
def attempted_rules_str(self, target: str) -> str:
|
||||||
rules = ", ".join(str(r) for r in self.__failed_rules[target])
|
rules = ", ".join(str(r) for r in self.__failed_rules[target])
|
||||||
@@ -376,7 +379,7 @@ default_rules: list[Rule] = [
|
|||||||
Rule("raman_op", operators.NoRaman, priorities=-1),
|
Rule("raman_op", operators.NoRaman, priorities=-1),
|
||||||
Rule("nonlinear_operator", operators.EnvelopeNonLinearOperator),
|
Rule("nonlinear_operator", operators.EnvelopeNonLinearOperator),
|
||||||
Rule("loss_op", operators.CustomConstantLoss, priorities=3),
|
Rule("loss_op", operators.CustomConstantLoss, priorities=3),
|
||||||
Rule("loss_op", operators.CapillaryLoss, priorities=2),
|
Rule("loss_op", operators.CapillaryLoss, priorities=2, conditions=dict(loss="capillary")),
|
||||||
Rule("loss_op", operators.ConstantLoss, priorities=1),
|
Rule("loss_op", operators.ConstantLoss, priorities=1),
|
||||||
Rule("loss_op", operators.NoLoss, priorities=-1),
|
Rule("loss_op", operators.NoLoss, priorities=-1),
|
||||||
Rule("dispersion_op", operators.ConstantPolyDispersion),
|
Rule("dispersion_op", operators.ConstantPolyDispersion),
|
||||||
|
|||||||
@@ -253,8 +253,9 @@ class RK4IP:
|
|||||||
step sized used
|
step sized used
|
||||||
"""
|
"""
|
||||||
keep = False
|
keep = False
|
||||||
|
h_next_step = self.state.h
|
||||||
while not keep:
|
while not keep:
|
||||||
h = self.state.h
|
h = h_next_step
|
||||||
|
|
||||||
expD = np.exp(h / 2 * self.params.linear_operator(self.state))
|
expD = np.exp(h / 2 * self.params.linear_operator(self.state))
|
||||||
|
|
||||||
@@ -274,19 +275,20 @@ class RK4IP:
|
|||||||
progress_str = f"step {step} rejected with h = {h:.4e}, doing over"
|
progress_str = f"step {step} rejected with h = {h:.4e}, doing over"
|
||||||
self.logger.debug(progress_str)
|
self.logger.debug(progress_str)
|
||||||
keep = False
|
keep = False
|
||||||
self.state.h = h / 2
|
h_next_step = h / 2
|
||||||
elif cons_qty_change_ok < curr_p_change <= 2 * cons_qty_change_ok:
|
elif cons_qty_change_ok < curr_p_change <= 2 * cons_qty_change_ok:
|
||||||
keep = True
|
keep = True
|
||||||
self.state.h = h / self.size_fac
|
h_next_step = h / self.size_fac
|
||||||
elif curr_p_change < 0.1 * cons_qty_change_ok:
|
elif curr_p_change < 0.1 * cons_qty_change_ok:
|
||||||
keep = True
|
keep = True
|
||||||
self.state.h = h * self.size_fac
|
h_next_step = h * self.size_fac
|
||||||
else:
|
else:
|
||||||
keep = True
|
keep = True
|
||||||
self.state.h = h
|
h_next_step = h
|
||||||
else:
|
else:
|
||||||
keep = True
|
keep = True
|
||||||
self.state = new_state
|
self.state = new_state
|
||||||
|
self.state.h = h_next_step
|
||||||
self.state.z += h
|
self.state.z += h
|
||||||
return h
|
return h
|
||||||
|
|
||||||
|
|||||||
@@ -97,7 +97,6 @@ class ConfigFileParser:
|
|||||||
|
|
||||||
if len(fiber_list) == 0:
|
if len(fiber_list) == 0:
|
||||||
raise ValueError(f"No fiber in config {self.path}")
|
raise ValueError(f"No fiber in config {self.path}")
|
||||||
final_path = loaded_config.get("name")
|
|
||||||
configs = []
|
configs = []
|
||||||
for i, params in enumerate(fiber_list):
|
for i, params in enumerate(fiber_list):
|
||||||
configs.append(loaded_config | params)
|
configs.append(loaded_config | params)
|
||||||
@@ -444,7 +443,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 ValueError:
|
||||||
|
pass
|
||||||
for pulses in paths.values():
|
for pulses in paths.values():
|
||||||
new_path = dest / update_path_name(pulses[0].name)
|
new_path = dest / update_path_name(pulses[0].name)
|
||||||
os.makedirs(new_path, exist_ok=True)
|
os.makedirs(new_path, exist_ok=True)
|
||||||
|
|||||||
Reference in New Issue
Block a user