mostly working with this weird file handling system

This commit is contained in:
Benoît Sierro
2021-02-03 09:09:10 +01:00
parent 3c2e98d1e9
commit d2a85713b9
44 changed files with 674 additions and 292 deletions

View File

@@ -0,0 +1,25 @@
[fiber]
core_radius = 50e-6
length = 50e-2
model = "marcatili"
[gas.variable]
gas_name = ["air", "helium"]
[pulse]
power = 100e3
wavelength = 800e-9
[pulse.variable]
width = [250e-15, 240e-15, 230e-15, 220e-15, 210e-15]
[simulation]
parallel = true
repeat = 4
t_num = 16384
time_window = 37e-12
tolerated_error = 1e-11
z_num = 128
[simulation.variable]
behaviors = [["spm", "raman", "ss"], ["spm", "raman"], ["spm"]]

View File

@@ -10,7 +10,7 @@ gas_name = "air"
power = 100e3
wavelength = 800e-9
[pulse.varying]
[pulse.variable]
width = [250e-15]
[simulation]

View File

@@ -11,7 +11,7 @@ soliton_num = 5
wavelength = 800e-9
width = 250e-15
[pulse.varying]
[pulse.variable]
shape = ["gaussian", "sech"]
[simulation]

View File

@@ -15,7 +15,7 @@ quantum_noise = true
shape = "gaussian"
wavelength = 1050e-9
[pulse.varying]
[pulse.variable]
intensity_noise = [0.05e-2, 0.1e-2]
[simulation]

View File

@@ -14,7 +14,7 @@ quantum_noise = true
shape = "gaussian"
wavelength = 1050e-9
[pulse.varying]
[pulse.variable]
intensity_noise = [0.05e-2, 0.1e-2]
soliton_num = [1, 2, 3, 4]

View File

@@ -15,7 +15,7 @@ quantum_noise = true
shape = "gaussian"
wavelength = 1050e-9
[pulse.varying]
[pulse.variable]
intensity_noise = [0.05e-2, 0.1e-2]
width = [50e-15, 100e-15, 200e-15]

View File

@@ -16,7 +16,7 @@ shape = "gaussian"
wavelength = 1050e-9
width = 120e-15
[pulse.varying]
[pulse.variable]
intensity_noise = [0.05e-2, 0.1e-2]
width = [50e-15, 100e-15, 200e-15]

View File

@@ -17,7 +17,7 @@ quantum_noise = true
shape = "gaussian"
wavelength = 1050e-9
[pulse.varying]
[pulse.variable]
intensity_noise = [0.05e-2, 0.1e-2]
width = [50e-15, 100e-15, 200e-15]

View File

@@ -16,7 +16,7 @@ quantum_noise = true
shape = "gaussian"
wavelength = 1050e-9
[pulse.varying]
[pulse.variable]
intensity_noise = [0.05e-2, 0.1e-2]
width = [50e-15, 100e-15, 200e-15]

View File

@@ -14,7 +14,7 @@ quantum_noise = true
shape = "gaussian"
wavelength = 1050e-9
[pulse.varying]
[pulse.variable]
intensity_noise = [0.05e-2, 0.1e-2]
width = [50e-15, 100e-15, 200e-15]

View File

@@ -15,7 +15,7 @@ quantum_noise = true
shape = "gaussian"
wavelength = 1050e-9
[pulse.varying]
[pulse.variable]
intensity_noise = [0.05e-2, 0.1e-2]
width = [50e-15, 100e-15, 200e-15]

View File

@@ -13,7 +13,7 @@ quantum_noise = true
shape = "gaussian"
wavelength = 1050e-9
[pulse.varying]
[pulse.variable]
intensity_noise = [0.05e-2, 0.1e-2]
width = [50e-15, 100e-15, 200e-15]

View File

@@ -14,7 +14,7 @@ model = "hasan"
[gas]
gas_name = "helium"
[gas.varying]
[gas.variable]
temperature = [300, 350, 400]
[pulse]
@@ -23,7 +23,7 @@ quantum_noise = true
shape = "gaussian"
wavelength = 1050e-9
[pulse.varying]
[pulse.variable]
intensity_noise = [0.05e-2, 0.1e-2]
width = [50e-15, 100e-15, 200e-15]

View File

@@ -14,7 +14,7 @@ quantum_noise = true
shape = "gaussian"
wavelength = 1050e-9
[pulse.varying]
[pulse.variable]
intensity_noise = [0.05e-2, 0.1e-2]
width = [50e-15, 100e-15, 200e-15]

View File

@@ -16,7 +16,7 @@ quantum_noise = true
shape = "gaussian"
wavelength = 1050e-9
[pulse.varying]
[pulse.variable]
intensity_noise = [0.05e-2, 0.1e-2]
width = [50e-15, 100e-15, 200e-15]

View File

@@ -0,0 +1,29 @@
# raman_type should be added
name = "test config"
[fiber]
gamma = 0.018
length = 1
model = "pcf"
pitch = 1.5e-6
pitch_ratio = 0.37
[pulse]
power = 100e3
quantum_noise = true
shape = "gaussian"
wavelength = 1050e-9
width = 50e-15
[pulse.variable]
intensity_noise = [0.10000000005e-2, 0.1e-2]
[simulation]
behaviors = ["spm", "raman", "ss"]
parallel = true
repeat = 4
t_num = 16384
time_window = 37e-12
tolerated_error = 1e-11
z_num = 128

View File

@@ -0,0 +1,29 @@
# raman_type should be added
name = "test config"
[fiber]
gamma = 0.018
length = 1
model = "pcf"
pitch = 1.5e-6
pitch_ratio = 0.37
[pulse]
power = 100e3
quantum_noise = true
shape = "gaussian"
wavelength = 1050e-9
width = 50e-15
[pulse.variable]
intensity_noise = [0.1e-2, 0.001]
[simulation]
behaviors = ["spm", "raman", "ss"]
parallel = true
repeat = 4
t_num = 16384
time_window = 37e-12
tolerated_error = 1e-11
z_num = 128

View File

@@ -0,0 +1,27 @@
# raman_type should be added
name = "test config"
[fiber]
gamma = 0.018
length = 1
model = "pcf"
pitch = 1.5e-6
pitch_ratio = 0.37
[pulse]
intensity_noise = 0.1e-2
power = 100e3
quantum_noise = true
shape = "gaussian"
wavelength = 1050e-9
width = 50e-15
[simulation]
behaviors = ["spm", "raman", "ss"]
parallel = true
repeat = 4
t_num = 16384
time_window = 37e-12
tolerated_error = 1e-11
z_num = 128

View File

@@ -19,7 +19,7 @@ length = 0.02
power = 10000
t0 = 2.84e-14
[pulse.varying]
[pulse.variable]
wavelength = [835e-9, 830e-9]
[simulation]

View File

@@ -15,7 +15,7 @@ quantum_noise = true
shape = "gaussian"
wavelength = 1050e-9
[pulse.varying]
[pulse.variable]
intensity_noise = [0.05e-2, 0.1e-2]
width = [50e-15, 100e-15, 200e-15]

View File

@@ -15,7 +15,7 @@ quantum_noise = true
shape = "gaussian"
wavelength = 1050e-9
[pulse.varying]
[pulse.variable]
intensity_noise = [0.05e-2, 0.1e-2]
width = [50e-15, 100e-15, 200e-15]

View File

@@ -15,7 +15,7 @@ quantum_noise = true
shape = "gaussian"
wavelength = 1050e-9
[pulse.varying]
[pulse.variable]
intensity_noise = [0.05e-2, 0.1e-2]
width = ["gaussian", "sech"]

View File

@@ -1,4 +1,4 @@
# parallel should not be varying
# parallel should not be variable
name = "test config"
@@ -15,7 +15,7 @@ quantum_noise = true
shape = "gaussian"
wavelength = 1050e-9
[pulse.varying]
[pulse.variable]
intensity_noise = [0.05e-2, 0.1e-2]
width = [50e-15, 100e-15, 200e-15]
@@ -28,5 +28,5 @@ time_window = 37e-12
tolerated_error = 1e-11
z_num = 1
[simulation.varying]
[simulation.variable]
parallel = [true, false]

View File

@@ -1,4 +1,4 @@
#varying parameters should be lists
#variable parameters should be lists
name = "test config"
@@ -15,7 +15,7 @@ quantum_noise = true
shape = "gaussian"
wavelength = 1050e-9
[pulse.varying]
[pulse.variable]
intensity_noise = 0.05e-2
width = [50e-15, 100e-15, 200e-15]

View File

@@ -16,7 +16,7 @@ quantum_noise = true
shape = "gaussian"
wavelength = 1050e-9
[pulse.varying]
[pulse.variable]
width = [50e-15, 100e-15, 200e-15]
[simulation]

View File

@@ -13,7 +13,7 @@ quantum_noise = true
shape = "gaussian"
wavelength = 1050e-9
[pulse.varying]
[pulse.variable]
intensity_noise = []
width = [50e-15, 100e-15, 200e-15]

View File

@@ -13,7 +13,7 @@ quantum_noise = true
shape = "gaussian"
wavelength = 1050e-9
[pulse.varying]
[pulse.variable]
intensity_noise = [0.05e-2, 0.1e-2]
width = [50e-15, 100e-15, 200e-15]

View File

@@ -0,0 +1,36 @@
import shutil
import unittest
import toml
from scgenerator import initialize, io, logger
from send2trash import send2trash
TMP = "testing/.tmp"
class TestRecoveryParamSequence(unittest.TestCase):
def setUp(self):
shutil.copytree("/Users/benoitsierro/sc_tests/scgenerator_full anomalous55", TMP)
self.conf = toml.load(TMP + "/initial_config.toml")
logger.DEFAULT_LEVEL = logger.logging.FATAL
io.set_data_folder(55, TMP)
def test_remaining_simulations_count(self):
param_seq = initialize.RecoveryParamSequence(self.conf, 55)
self.assertEqual(5, len(param_seq))
def test_only_one_to_complete(self):
param_seq = initialize.RecoveryParamSequence(self.conf, 55)
i = 0
for expected, (vary_list, params) in zip([True, False, False, False, False], param_seq):
i += 1
self.assertEqual(expected, "recovery_last_stored" in params)
self.assertEqual(5, i)
def tearDown(self):
send2trash(TMP)
if __name__ == "__main__":
unittest.main()

View File

@@ -1,8 +1,10 @@
import unittest
import toml
from copy import deepcopy
import scgenerator.initialize as init
import toml
from scgenerator import utils
from scgenerator.errors import *
from prettyprinter import pprint
def load_conf(name):
@@ -18,6 +20,36 @@ def conf_maker(folder):
return conf
class TestParamSequence(unittest.TestCase):
def iterconf(self, files):
conf = conf_maker("param_sequence")
for path in files:
yield init.ParamSequence(conf(path))
def test_no_repeat_in_sub_folder_names(self):
for param_seq in self.iterconf(["almost_equal", "equal", "no_variations"]):
l = []
s = []
for vary_list, _ in param_seq.iterate_without_computing():
self.assertNotIn(vary_list, l)
self.assertNotIn(utils.format_variable_list(vary_list), s)
l.append(vary_list)
s.append(utils.format_variable_list(vary_list))
def test_init_config_not_affected_by_iteration(self):
for param_seq in self.iterconf(["almost_equal", "equal", "no_variations"]):
config = deepcopy(param_seq.config)
for _ in param_seq.iterate_without_computing():
self.assertEqual(config.items(), param_seq.config.items())
def test_no_variations_yields_only_num_and_id(self):
for param_seq in self.iterconf(["no_variations"]):
for vary_list, _ in param_seq.iterate_without_computing():
self.assertEqual(vary_list[1][0], "num")
self.assertEqual(vary_list[0][0], "id")
self.assertEqual(2, len(vary_list))
class TestInitializeMethods(unittest.TestCase):
def test_validate_types(self):
conf = lambda s: load_conf("validate_types/" + s)

View File

@@ -1,6 +1,8 @@
import unittest
from scgenerator import utils, initialize
import numpy as np
import toml
from scgenerator import initialize, utils
def load_conf(name):
@@ -20,11 +22,34 @@ class TestUtilsMethods(unittest.TestCase):
def test_count_variations(self):
conf = conf_maker("count_variations")
self.assertEqual((1, 0), utils.count_variations(conf("1sim_0vary")))
self.assertEqual((1, 1), utils.count_variations(conf("1sim_1vary")))
self.assertEqual((2, 1), utils.count_variations(conf("2sim_1vary")))
self.assertEqual((2, 0), utils.count_variations(conf("2sim_0vary")))
for sim, vary in [(1, 0), (1, 1), (2, 1), (2, 0), (120, 3)]:
self.assertEqual((sim, vary), utils.count_variations(conf(f"{sim}sim_{vary}vary")))
def test_format_value(self):
values = [
122e-6,
True,
["raman", "ss"],
np.arange(5),
1.123,
1.1230001,
0.002e122,
12.3456e-9,
]
s = [
"0.000122",
"True",
"raman-ss",
"0-1-2-3-4",
"1.123",
"1.1230001",
"2e+119",
"1.23456e-08",
]
for value, target in zip(values, s):
self.assertEqual(target, utils.format_value(value))
if __name__ == "__main__":
unittest.main()
unittest.main()