-
-
Notifications
You must be signed in to change notification settings - Fork 409
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
[config-system] Validator rewrite: Use jsonschema #576
Changes from 1 commit
1f22f03
a072b78
b6467b5
1ae9996
8ee81b4
1573fe4
58c9258
0519f4f
1a1520b
da2d387
cd812e5
2c8fc4c
f2abb1c
2cd9832
001abe7
d59c357
60d1d1d
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 |
---|---|---|
|
@@ -11,7 +11,7 @@ | |
import tardis | ||
from tardis.io.model_reader import ( | ||
read_density_file, calculate_density_after_time, read_abundances_file) | ||
from tardis.io.config_validator import ConfigurationValidator | ||
from tardis.io import config_validator | ||
from tardis.io.util import YAMLLoader, yaml_load_file | ||
from tardis import atomic | ||
from tardis.util import (species_string_to_tuple, parse_quantity, | ||
|
@@ -27,6 +27,7 @@ | |
|
||
default_config_definition_file = os.path.join(data_dir, | ||
'tardis_config_definition.yml') | ||
config_schema_file = os.path.join(config_validator.schema_dir, 'base.yml') | ||
#File parsers for different file formats: | ||
|
||
|
||
|
@@ -486,7 +487,9 @@ def parse_spectrum_list2dict(spectrum_list): | |
""" | ||
Parse the spectrum list [start, stop, num] to a list | ||
""" | ||
|
||
if isinstance(spectrum_list, dict): | ||
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. how about we change to 'if 'start' in spectrum_list and 'stop' in spectrum list and 'num' in spectrum_list`: 😉 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. I was expecting a comment on this line. I'll do the change... |
||
spectrum_list = [spectrum_list['start'], spectrum_list['stop'], | ||
spectrum_list['num']] | ||
if spectrum_list[0].unit.physical_type != 'length' and \ | ||
spectrum_list[1].unit.physical_type != 'length': | ||
raise ValueError('start and end of spectrum need to be a length') | ||
|
@@ -621,13 +624,8 @@ def from_config_dict(cls, config_dict, config_definition_file=None): | |
|
||
""" | ||
|
||
if config_definition_file is None: | ||
config_definition_file = default_config_definition_file | ||
|
||
config_definition = yaml_load_file(config_definition_file) | ||
|
||
return cls(ConfigurationValidator(config_definition, | ||
config_dict).get_config()) | ||
return cls(config_validator.validate_dict( | ||
config_dict, config_schema_file)) | ||
|
||
def __init__(self, value=None): | ||
if value is None: | ||
|
@@ -793,8 +791,8 @@ def from_config_dict(cls, config_dict, atom_data=None, test_parser=False, | |
|
||
config_definition = yaml_load_file(config_definition_file) | ||
if validate: | ||
validated_config_dict = ConfigurationValidator(config_definition, | ||
config_dict).get_config() | ||
validated_config_dict = config_validator.validate_dict(config_dict, | ||
config_schema_file) | ||
else: | ||
validated_config_dict = config_dict | ||
|
||
|
@@ -850,7 +848,9 @@ def from_config_dict(cls, config_dict, atom_data=None, test_parser=False, | |
structure_section = model_section['structure'] | ||
|
||
if structure_section['type'] == 'specific': | ||
start, stop, num = model_section['structure']['velocity'] | ||
velocity = model_section['structure']['velocity'] | ||
start, stop, num = velocity['start'], velocity['stop'], \ | ||
velocity['num'] | ||
num += 1 | ||
velocities = quantity_linspace(start, stop, num) | ||
|
||
|
@@ -1018,7 +1018,7 @@ def from_config_dict(cls, config_dict, atom_data=None, test_parser=False, | |
|
||
|
||
|
||
if montecarlo_section['convergence_strategy'] is None: | ||
if 'convergence_stragegy' not in montecarlo_section: | ||
logger.warning('No convergence criteria selected - ' | ||
'just damping by 0.5 for w, t_rad and t_inner') | ||
montecarlo_section['convergence_strategy'] = ( | ||
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. Since we decided to use default values for now, I propose to move these default values to either the schema or the Simulation class 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. good idea. 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. Done, nice and clean in the schema! |
||
|
@@ -1031,19 +1031,19 @@ def from_config_dict(cls, config_dict, atom_data=None, test_parser=False, | |
black_body_section = montecarlo_section['black_body_sampling'] | ||
montecarlo_section['black_body_sampling'] = {} | ||
montecarlo_section['black_body_sampling']['start'] = \ | ||
black_body_section[0] | ||
black_body_section['start'] | ||
montecarlo_section['black_body_sampling']['end'] = \ | ||
black_body_section[1] | ||
black_body_section['stop'] | ||
montecarlo_section['black_body_sampling']['samples'] = \ | ||
black_body_section[2] | ||
black_body_section['num'] | ||
virtual_spectrum_section = montecarlo_section['virtual_spectrum_range'] | ||
montecarlo_section['virtual_spectrum_range'] = {} | ||
montecarlo_section['virtual_spectrum_range']['start'] = \ | ||
virtual_spectrum_section[0] | ||
virtual_spectrum_section['start'] | ||
montecarlo_section['virtual_spectrum_range']['end'] = \ | ||
virtual_spectrum_section[1] | ||
virtual_spectrum_section['stop'] | ||
montecarlo_section['virtual_spectrum_range']['samples'] = \ | ||
virtual_spectrum_section[2] | ||
virtual_spectrum_section['num'] | ||
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. What's the reason we keep this? 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. This is part of the next and final big milestone/PR (configuration system restructure). My purpose in this PR was to only do changes related and absolutely necessary to the validator. 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. @yeganer that's dangerous as older configuration files need to work. I would flag it but leave it for now. 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. I think we should have a function/module that provides the backwards compatibility.
This function would then consecutively update from the config version the config is in to the latest verstion. |
||
|
||
###### END of convergence section reading | ||
|
||
|
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.
Do we still need this line?
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.
No, removed all the references to
tardis_config_definition.yml
and the file itself.