-
Notifications
You must be signed in to change notification settings - Fork 123
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Caching of Non-Equilibrium parameters(Evib, Erot) #511
base: develop
Are you sure you want to change the base?
Changes from 2 commits
8d54cee
07f395f
e44e614
e1b38fc
d9ef631
c69a395
ef7bffa
cc63533
ef4e771
3c57ebc
b4d90a1
7832b49
f1989b4
4f46630
29106ef
3be0712
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -5,6 +5,7 @@ | |
@author: erwan | ||
""" | ||
|
||
import os | ||
import time | ||
from os.path import exists, getmtime, splitext | ||
|
||
|
@@ -831,56 +832,105 @@ def test_caching_noneq_params(verbose=True, plot=True, *args, **kwargs): | |
verbose=2, | ||
) | ||
s.fetch_databank("hitemp", load_energies=True, load_columns="noneq") | ||
s1 = s.non_eq_spectrum(Tvib=2000, Trot=3000) | ||
s2 = s.non_eq_spectrum(Tvib=2000, Trot=3000) | ||
# Loading variables | ||
molecule = s.input.molecule | ||
isotope = s.input.isotope | ||
state = "X" | ||
# Checking that the cache file exists | ||
# Checking that the cache file exists, removing if it does | ||
cache_filename = ( | ||
splitext(s.params.dbpath.split(",", 1)[0])[0] | ||
+ "_extra_columns_EvibErot.h5.extra" | ||
) | ||
engine = "pytables" | ||
if exists(cache_filename): | ||
last_modif = getmtime(cache_filename) | ||
os.remove(cache_filename) | ||
# Generating first spectrum | ||
s1 = s.non_eq_spectrum(Tvib=2000, Trot=3000) | ||
assert exists(cache_filename) | ||
# Generating second spectrum using another SpectrumFactory object: | ||
sf = SpectrumFactory( | ||
wavelength_min=1500, | ||
wavelength_max=2000, | ||
cutoff=1e-27, | ||
pressure=1, | ||
molecule="CO", | ||
isotope="1,2", | ||
truncation=5, | ||
neighbour_lines=5, | ||
path_length=0.1, | ||
mole_fraction=1e-3, | ||
medium="vacuum", | ||
optimization=None, # No optimization strategy used | ||
chunksize=None, # Initialising chunksize as None for comparison | ||
wstep="auto", | ||
verbose=2, | ||
Comment on lines
+849
to
+863
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. to simplify reading, can you add all of this in a dictionary and use the same dictionary many times. conditions = {
"wavelength_min":1500,
"wavelength_max":2000,
#etc, fix for dictionary syntax :
cutoff=1e-27,
pressure=1,
molecule="CO",
isotope="1,2",
truncation=5,
neighbour_lines=5,
path_length=0.1,
mole_fraction=1e-3,
medium="vacuum",
optimization=None, # No optimization strategy used
chunksize=None, # Initialising chunksize as None for comparison
wstep="auto",
verbose=2,
}
s1 = SpectrumFactory(**conditions)
s2 = SpectrumFactory(**conditions)
# or change one :
new_conditions = conditions.copy()
new_conditions["wavelength_min=1800"]
s3 = SpectrumFactory(**new_conditions) There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Also, remove all parametesr that are not relevant. pressure, Path_length, mole_fraction, medium, optimization, chunksize, wstep, verbose are not relevant here. Keep the defaults |
||
) | ||
sf.fetch_databank("hitemp", load_energies=True, load_columns="noneq") | ||
s2 = sf.non_eq_spectrum(Tvib=2000, Trot=3000) | ||
# Checking proper regeneration of the cache file | ||
assert exists(cache_filename) | ||
assert getmtime(cache_filename) > last_modif | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It seems to me the conditions are the same. Shouldn't the modification time be the same (i.e. file is not regenerated) |
||
|
||
cache_file_data = DataFileManager(engine).read(cache_filename) | ||
# Checking that the dataframe non-equilibrium columns are the same | ||
assert sf.df0["Evibu"].equals(cache_file_data["Evibu"]) | ||
assert sf.df0["Evibl"].equals(cache_file_data["Evibl"]) | ||
assert sf.df0["Erotu"].equals(cache_file_data["Erotu"]) | ||
assert sf.df0["Erotl"].equals(cache_file_data["Erotl"]) | ||
|
||
# Loading variables | ||
molecule = sf.input.molecule | ||
isotope = sf.input.isotope | ||
state = "X" | ||
|
||
elec_state = s.get_partition_function_calculator( | ||
molecule, s._get_isotope_list(molecule)[0], state | ||
).ElecState | ||
spectroscopic_constant_file = elec_state.jsonfile | ||
|
||
# Checking that the metadata is correct, else regenerating the cache file | ||
existing_file_metadata = DataFileManager(engine).read_metadata(cache_filename) | ||
|
||
# Checking that the metadata is correct | ||
if "isotope" in existing_file_metadata: | ||
assert isotope == existing_file_metadata["isotope"] | ||
else: | ||
os.remove(cache_filename) | ||
if "number_of_lines" in existing_file_metadata: | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Wait. Why are you testing this here ?? These validity checks should be in the code itself, not in the test. Here you should only be testing (and asserting) that if you change isotope, the cache file is properly regenerated (ie new_modif_time > last_modif_time) Same for wavenumbers, etc. |
||
assert len(s.df0) == existing_file_metadata["number_of_lines"] | ||
assert len(sf.df0) == existing_file_metadata["number_of_lines"] | ||
else: | ||
os.remove(cache_filename) | ||
if "wavenum_min" in existing_file_metadata: | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Test should happen always. If key is not in metadata you should regenerate the cache |
||
assert s.input.wavenum_min == existing_file_metadata["wavenum_min"] | ||
assert sf.input.wavenum_min == existing_file_metadata["wavenum_min"] | ||
else: | ||
os.remove(cache_filename) | ||
if "wavenum_max" in existing_file_metadata: | ||
assert s.input.wavenum_max == existing_file_metadata["wavenum_max"] | ||
assert sf.input.wavenum_max == existing_file_metadata["wavenum_max"] | ||
else: | ||
os.remove(cache_filename) | ||
if "spectroscopic_constant_file" in existing_file_metadata: | ||
assert ( | ||
spectroscopic_constant_file | ||
== existing_file_metadata["spectroscopic_constant_file"] | ||
) | ||
else: | ||
os.remove(cache_filename) | ||
if "last_modification" in existing_file_metadata: | ||
assert ( | ||
time.ctime(getmtime(spectroscopic_constant_file)) | ||
== existing_file_metadata["last_modification"] | ||
) | ||
else: | ||
os.remove(cache_filename) | ||
if "neighbour_lines" in existing_file_metadata: | ||
assert s.params.neighbour_lines == existing_file_metadata["neighbour_lines"] | ||
assert sf.params.neighbour_lines == existing_file_metadata["neighbour_lines"] | ||
else: | ||
os.remove(cache_filename) | ||
if "cutoff" in existing_file_metadata: | ||
assert s.params.cutoff == existing_file_metadata["cutoff"] | ||
assert sf.params.cutoff == existing_file_metadata["cutoff"] | ||
else: | ||
os.remove(cache_filename) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. same as comment above. You shouldn't be conditionning the presence of "last_modifcation" etc in the metadata. It must be there. You should even be asserting that it is there. |
||
|
||
res = get_residual(s1, s2, "radiance_noslit") | ||
if verbose: | ||
print( | ||
"Res for non-equilibrium spectrum with molecule = {0}, wavenumber range = {1} to {2}: {3}".format( | ||
s.input.molecule, s.df0["wav"].min(), s.df0["wav"].max(), res | ||
s.input.molecule, s.input.wavenum_min, s.input.wavenum_max, res | ||
) | ||
) | ||
assert res < 1e-6 | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
shouldn't last_modif be measured after computing the new spectrum, i.e.> l846 ?