-
Notifications
You must be signed in to change notification settings - Fork 4
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
Order of filters in yaml's #409
Comments
This is duplicate of this issue: Was there an error you received with a UFO YAML filter? As far as I know, order shouldn't matter for YAMLs, indents and the way they are written as list matter. Follow-up after the meeting today: The order of UFO filters matter, JEDI/UFO apply some sort of hierarchy (that is controlled by |
The solution might be to use There are multiple locations in SWELL where For instance, I don't think the order matters for EVA dictionaries, @asewnath do you agree? |
@Dooruk agreed, order doesn't matter for the eva configs |
Point 2 here is a duplicate of (or at least, closely related to) #330. That one is effectively an aesthetic/organizational issue (albeit still a legitimate one with UX implications!) with the order that Swell config files are read and written, but doesn't impact the order in which tasks are actually executed. However, Point 1 is a different and more important issue. That's about actually making sure that specific tasks (in this case, filters) get executed in a specific order. Trivial example:
Lists have a meaningful order. So, one way to enforce this in YAML is to make sure we're always using lists rather than dicts; i.e., the following YAML: x1:
a: 5
b: 6
c: 7
x2:
- g: 5
- h: 6
- i: 7 ...produces the following results: import yaml
with open("example.yaml", "r") as f:
dat = yaml.safe_load(f)
# {'x1': {'a': 5, 'b': 6, 'c': 7}, 'x2': [{'g': 5}, {'h': 6}, {'i': 7}]} Note that Strictly speaking, a better data structure for capturing order-specificity is probably a Directed Acyclic Graph (DAG). # `a` depends on `b` and `d`, but the order doesn't matter
# `d` depends on `b`
# `b` depends on `c`
x = {
"a": {"b", "d"},
"b": {"c"},
"d": {"b"}
}
# In what order should we do things?
import graphlib
xts = graphlib.TopologicalSorter(x)
tuple(xts.static_order())
# ('c', 'b', 'd', 'a') |
Ok, sounds like @ashiklom, does the option you provide require dependency keys? Because I don't think the filters we talk about have them. Without that would I've done some further digging to see what JCSDA is doing, came up with two more options.
An example code block (model formats are just define datetime): from ruamel.yaml import YAML
.
.
.
def substitute_template_file(template_file_path, ctx):
def _load_template(template):
try:
if Path(template).is_file():
with open(template) as f:
return f.read()
else:
return template
except:
if isinstance(template, str):
return template
yaml = YAML(typ='rt')
jenv = jinja2.Environment(loader=jinja2.FunctionLoader(_load_template))
jenv.filters['jedifnformat'] = jedifnformat
jenv.filters['geosformat'] = geosformat
jenv.filters['mpasformat'] = mpasformat
jenv.filters['ufsformat'] = ufsformat
yamlfile = jenv.get_template(str(template_file_path)).render(**ctx)
return NamedDict(yaml.load(yamlfile))
|
I tested what Doruk had in the branch earlier today -and: Results from keeping the yaml ordering faithful to what is in the source code do change, but only in the tenth decimal place for the norm reduction (after 60+ iterations) ... in any case, I believe it's better for python/swell not to re-order the yaml entries. If nothing else, it is so much easier to map what we put in the source code/swell and what actually gets used - easier to read the final yaml. |
I understand we might be moving away from YAMLs in the longer term but just an update on this. |
As most of you know, the order of filters in the observers matters. Certain actions must be done first, others later, etc. This issue requests that we work to make sure the following two things are done:
That the order of the filters as implemented in the swell yamls is indeed the order they should be applied - logically consistent and also consistent w/ what GSI does.
That the machinery that processes the observation yamls and creates the final yaml for the variational analysis, or UFO, of HOF, does not get shuffled or alphabetically organized. Within a given filter, the order of statements is not important, but the sequence of each filter is of fundamental importance and it should not be changed.
The text was updated successfully, but these errors were encountered: