diff --git a/README.md b/README.md index d24b027..4b39128 100644 --- a/README.md +++ b/README.md @@ -251,9 +251,3 @@ upper_wavelength_interp_limit: float interp_degree: int max degree of the Taylor polynomial fitting the dispersion data - -readjust_wavelength : bool - if a custom input field is set, it is likely that the maximum of its corresponding spectrum doesn't lies exactly at the - set wavelength. If this setting is True, the program will override the wavelength parameter so that the maximum of the spectrum - lies on the desired wavelength. - diff --git a/src/scgenerator/defaults.py b/src/scgenerator/defaults.py index 4335403..5a6097e 100644 --- a/src/scgenerator/defaults.py +++ b/src/scgenerator/defaults.py @@ -27,7 +27,6 @@ default_parameters = dict( upper_wavelength_interp_limit=2000e-9, interp_degree=8, ideal_gas=False, - readjust_wavelength=False, recovery_last_stored=0, ) diff --git a/src/scgenerator/initialize.py b/src/scgenerator/initialize.py index 6ddb06f..94231a6 100644 --- a/src/scgenerator/initialize.py +++ b/src/scgenerator/initialize.py @@ -133,13 +133,6 @@ class Params(BareParams): self.energy, self.field_0, ) = pulse.setup_custom_field(self) - if self.readjust_wavelength: - old_wl = self.wavelength - self.wavelength = pulse.correct_wavelength(self.wavelength, self.w_c, self.field_0) - logger.info(f"moved wavelength from {1e9*old_wl:.2f} to {1e9*self.wavelength:.2f}") - self.w_c, self.w0, self.w, self.w_power_fact = update_frequency_domain( - self.t, self.wavelength, self.interp_degree - ) return did_set_custom_pulse @@ -238,7 +231,6 @@ class Config(BareConfig): "upper_wavelength_interp_limit", "interp_degree", "ideal_gas", - "readjust_wavelength", "recovery_last_stored", ]: self.get(param) diff --git a/src/scgenerator/utils/__init__.py b/src/scgenerator/utils/__init__.py index d625991..612b6ea 100644 --- a/src/scgenerator/utils/__init__.py +++ b/src/scgenerator/utils/__init__.py @@ -4,9 +4,9 @@ scgenerator module but some function may be used in any python program """ -from argparse import ArgumentTypeError import itertools import multiprocessing +import random import re import threading from collections import abc @@ -14,13 +14,11 @@ from copy import deepcopy from dataclasses import asdict, replace from io import StringIO from pathlib import Path -from typing import Any, Dict, Iterable, Iterator, List, Tuple, TypeVar, Union +from typing import Any, Iterable, Iterator, TypeVar, Union import numpy as np -import random from tqdm import tqdm - from .. import env from ..const import PARAM_SEPARATOR from ..math import * @@ -168,7 +166,7 @@ def progress_worker( progress_queue : multiprocessing.Queue values are either Literal[0] : stop the worker and close the progress bars - Tuple[int, float] : worker id and relative progress between 0 and 1 + tuple[int, float] : worker id and relative progress between 0 and 1 """ with PBars( num_steps, "Simulating " + name, num_workers, head_kwargs=dict(unit="step") @@ -182,7 +180,7 @@ def progress_worker( pbars[0].update() -def format_variable_list(l: List[Tuple[str, Any]]): +def format_variable_list(l: list[tuple[str, Any]]): joints = 2 * PARAM_SEPARATOR str_list = [] for p_name, p_value in l: @@ -192,7 +190,7 @@ def format_variable_list(l: List[Tuple[str, Any]]): return joints[0].join(str_list) -def branch_id(branch: Tuple[Path, ...]) -> str: +def branch_id(branch: tuple[Path, ...]) -> str: return "".join("".join(re.sub(r"id\d+\S*num\d+", "", b.name).split()[2:-2]) for b in branch) @@ -237,7 +235,7 @@ def pretty_format_from_sim_name(name: str) -> str: return PARAM_SEPARATOR.join(out) -def variable_iterator(config: BareConfig) -> Iterator[Tuple[List[Tuple[str, Any]], dict[str, Any]]]: +def variable_iterator(config: BareConfig) -> Iterator[tuple[list[tuple[str, Any]], dict[str, Any]]]: """given a config with "variable" parameters, iterates through every possible combination, yielding a a list of (parameter_name, value) tuples and a full config dictionary. @@ -248,7 +246,7 @@ def variable_iterator(config: BareConfig) -> Iterator[Tuple[List[Tuple[str, Any] Yields ------- - Iterator[Tuple[List[Tuple[str, Any]], dict[str, Any]]] + Iterator[tuple[list[tuple[str, Any]], dict[str, Any]]] variable_list : a list of (name, value) tuple of parameter name and value that are variable. params : a dict[str, Any] to be fed to Params @@ -277,13 +275,13 @@ def variable_iterator(config: BareConfig) -> Iterator[Tuple[List[Tuple[str, Any] def required_simulations( *configs: BareConfig, -) -> Iterator[Tuple[List[Tuple[str, Any]], BareParams]]: +) -> Iterator[tuple[list[tuple[str, Any]], BareParams]]: """takes the output of `scgenerator.utils.variable_iterator` which is a new dict per different parameter set and iterates through every single necessary simulation Yields ------- - Iterator[Tuple[List[Tuple[str, Any]], dict]] + Iterator[tuple[list[tuple[str, Any]], dict]] variable_ind : a list of (name, value) tuple of parameter name and value that are variable. The parameter "num" (how many times this specific parameter set has been yielded already) and "id" (how many parameter sets have been exhausted already) are added to the list to make sure every yielded list is unique. @@ -322,9 +320,6 @@ def override_config(new: BareConfig, old: BareConfig = None) -> BareConfig: variable[k] = v for k in variable: new_dict[k] = None - - new_dict["readjust_wavelength"] = False - return replace(old, variable=variable, **new_dict) diff --git a/src/scgenerator/utils/parameter.py b/src/scgenerator/utils/parameter.py index a24bfa6..13e8983 100644 --- a/src/scgenerator/utils/parameter.py +++ b/src/scgenerator/utils/parameter.py @@ -286,7 +286,6 @@ valid_variable = { "tolerated_error", "step_size", "ideal_gas", - "readjust_wavelength", } hc_model_specific_parameters = dict( @@ -379,7 +378,6 @@ class BareParams: upper_wavelength_interp_limit: float = Parameter(in_range_incl(200e-9, 5000e-9)) interp_degree: int = Parameter(positive(int)) prev_sim_dir: str = Parameter(string) - readjust_wavelength: bool = Parameter(boolean) recovery_last_stored: int = Parameter(non_negative(int)) worker_num: int = Parameter(positive(int)) diff --git a/testing/configs/custom_field/mean_power.toml b/testing/configs/custom_field/mean_power.toml index f8aa27e..953ec5c 100644 --- a/testing/configs/custom_field/mean_power.toml +++ b/testing/configs/custom_field/mean_power.toml @@ -2,7 +2,6 @@ dt = 1e-15 field_file = "testing/configs/custom_field/init_field.npz" length = 1 mean_power = 220e-3 -readjust_wavelength = true repetition_rate = 40e6 t_num = 2048 wavelength = 1000e-9 diff --git a/testing/configs/custom_field/no_change.toml b/testing/configs/custom_field/no_change.toml index 7340c20..288b1fb 100644 --- a/testing/configs/custom_field/no_change.toml +++ b/testing/configs/custom_field/no_change.toml @@ -1,7 +1,6 @@ dt = 1e-15 field_file = "testing/configs/custom_field/init_field.npz" length = 1 -readjust_wavelength = true t_num = 2048 wavelength = 1000e-9 z_num = 32 diff --git a/testing/configs/custom_field/peak_power.toml b/testing/configs/custom_field/peak_power.toml index 064e04d..5ce44f8 100644 --- a/testing/configs/custom_field/peak_power.toml +++ b/testing/configs/custom_field/peak_power.toml @@ -2,7 +2,6 @@ dt = 1e-15 field_file = "testing/configs/custom_field/init_field.npz" length = 1 peak_power = 20000 -readjust_wavelength = false t_num = 2048 wavelength = 1593e-9 z_num = 32 diff --git a/testing/configs/custom_field/recover1.toml b/testing/configs/custom_field/recover1.toml index ad4dd7f..52400f3 100644 --- a/testing/configs/custom_field/recover1.toml +++ b/testing/configs/custom_field/recover1.toml @@ -2,7 +2,6 @@ dt = 1e-15 input_transmission = 1 length = 1 prev_data_dir = "testing/configs/custom_field/recover_data" -readjust_wavelength = true t_num = 2048 wavelength = 1000e-9 z_num = 32 diff --git a/testing/configs/custom_field/recover2.toml b/testing/configs/custom_field/recover2.toml index 5652c87..853b8ea 100644 --- a/testing/configs/custom_field/recover2.toml +++ b/testing/configs/custom_field/recover2.toml @@ -2,7 +2,6 @@ dt = 1e-15 input_transmission = 0.9 length = 1 prev_data_dir = "testing/configs/custom_field/recover_data" -readjust_wavelength = true t_num = 2048 wavelength = 1000e-9 z_num = 32 diff --git a/testing/configs/custom_field/wavelength_shift1.toml b/testing/configs/custom_field/wavelength_shift1.toml index 18e6537..ac7c53a 100644 --- a/testing/configs/custom_field/wavelength_shift1.toml +++ b/testing/configs/custom_field/wavelength_shift1.toml @@ -15,7 +15,6 @@ wavelength = 1050e-9 behaviors = ["spm", "raman", "ss"] lower_wavelength_interp_limit = 300e-9 raman_type = "agrawal" -readjust_wavelength = true t_num = 16384 time_window = 37e-12 tolerated_error = 1e-11 diff --git a/testing/configs/custom_field/wavelength_shift2.toml b/testing/configs/custom_field/wavelength_shift2.toml index 54b457d..2408c3e 100644 --- a/testing/configs/custom_field/wavelength_shift2.toml +++ b/testing/configs/custom_field/wavelength_shift2.toml @@ -14,7 +14,6 @@ quantum_noise = false behaviors = ["spm", "raman", "ss"] lower_wavelength_interp_limit = 300e-9 raman_type = "agrawal" -readjust_wavelength = true t_num = 16384 time_window = 37e-12 tolerated_error = 1e-11