more tests, wl adjusted on every custom field

This commit is contained in:
Benoît Sierro
2021-06-01 11:47:12 +02:00
parent e985f053ac
commit 045c4ba44e
6 changed files with 72 additions and 6 deletions

View File

@@ -715,7 +715,7 @@ def setup_custom_field(params: Dict[str, Any]) -> bool:
params["t"], params["field_0"] params["t"], params["field_0"]
) )
delta_w = params["w_c"][np.argmax(abs2(np.fft.fft(params["field_0"])))] delta_w = params["w_c"][np.argmax(abs2(np.fft.fft(params["field_0"])))]
logger.debug(f"had to adjust w by {delta_w}") logger.debug(f"adjusted w by {delta_w}")
params["wavelength"] = units.m.inv(units.m(params["wavelength"]) - delta_w) params["wavelength"] = units.m.inv(units.m(params["wavelength"]) - delta_w)
_update_frequency_domain(params) _update_frequency_domain(params)
return True return True

View File

@@ -413,7 +413,7 @@ def append_and_merge(final_sim_path: os.PathLike, new_name=None):
update_appended_params( update_appended_params(
final_sim_path / "initial_config.toml", destination_path / "initial_config.toml", z_arr final_sim_path / "initial_config.toml", destination_path / "initial_config.toml", z_arr
) )
pbars.close()
merge(destination_path, delete=True) merge(destination_path, delete=True)

View File

@@ -3,5 +3,5 @@ field_file = "testing/configs/custom_field/init_field.npz"
length = 1 length = 1
peak_power = 20000 peak_power = 20000
t_num = 2048 t_num = 2048
wavelength = 1000e-9 wavelength = 1593e-9
z_num = 32 z_num = 32

View File

@@ -0,0 +1,22 @@
name = "test config"
[fiber]
length = 1
model = "pcf"
pitch = 1.5e-6
pitch_ratio = 0.37
[pulse]
field_file = "testing/configs/custom_field/init_field.npz"
quantum_noise = false
wavelength = 1050e-9
[simulation]
behaviors = ["spm", "raman", "ss"]
lower_wavelength_interp_limit = 300e-9
raman_type = "agrawal"
t_num = 16384
time_window = 37e-12
tolerated_error = 1e-11
upper_wavelength_interp_limit = 1900e-9
z_num = 128

View File

@@ -0,0 +1,23 @@
name = "test config"
[fiber]
length = 1
model = "pcf"
pitch = 1.5e-6
pitch_ratio = 0.37
[pulse]
field_file = "testing/configs/custom_field/init_field.npz"
quantum_noise = false
[pulse.variable]
wavelength = [1050e-9, 1321e-9, 1593e-9]
[simulation]
behaviors = ["spm", "raman", "ss"]
lower_wavelength_interp_limit = 300e-9
raman_type = "agrawal"
t_num = 16384
time_window = 37e-12
tolerated_error = 1e-11
upper_wavelength_interp_limit = 1900e-9
z_num = 128

View File

@@ -6,6 +6,7 @@ import numpy as np
import toml import toml
from scgenerator import defaults, utils, math from scgenerator import defaults, utils, math
from scgenerator.errors import * from scgenerator.errors import *
from scgenerator.physics import units
def load_conf(name): def load_conf(name):
@@ -182,6 +183,7 @@ class TestInitializeMethods(unittest.TestCase):
result = init.setup_custom_field(conf) result = init.setup_custom_field(conf)
self.assertAlmostEqual(math.abs2(conf["field_0"]).max(), 20000, 4) self.assertAlmostEqual(math.abs2(conf["field_0"]).max(), 20000, 4)
self.assertTrue(result) self.assertTrue(result)
self.assertNotAlmostEqual(conf["wavelength"], 1593e-9)
conf = load_conf("custom_field/mean_power") conf = load_conf("custom_field/mean_power")
conf = init._generate_sim_grid(conf) conf = init._generate_sim_grid(conf)
@@ -201,6 +203,25 @@ class TestInitializeMethods(unittest.TestCase):
self.assertAlmostEqual((math.abs2(conf["field_0"]) / 0.9 - math.abs2(field)).sum(), 0) self.assertAlmostEqual((math.abs2(conf["field_0"]) / 0.9 - math.abs2(field)).sum(), 0)
self.assertTrue(result) self.assertTrue(result)
conf = load_conf("custom_field/wavelength_shift1")
result = init.compute_init_parameters(conf)
self.assertAlmostEqual(
units.m.inv(result["w"])[np.argmax(math.abs2(result["spec_0"]))], 1050e-9
)
conf = load_conf("custom_field/wavelength_shift1")
conf["pulse"]["wavelength"] = 1593e-9
result = init.compute_init_parameters(conf)
conf = load_conf("custom_field/wavelength_shift2")
for target, (variable, config) in zip(
[1050e-9, 1321e-9, 1593e-9], init.ParamSequence(conf)
):
self.assertAlmostEqual(
units.m.inv(config["w"])[np.argmax(math.abs2(config["spec_0"]))], target
)
print(config["wavelength"], target)
if __name__ == "__main__": if __name__ == "__main__":
conf = conf_maker("validate_types") conf = conf_maker("validate_types")