-
Notifications
You must be signed in to change notification settings - Fork 0
Remove need for _template.yaml #223
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
base: main
Are you sure you want to change the base?
Changes from all commits
dd2cb06
51eb28b
756be45
ed25c7d
b0350dc
44d784a
22d9ac2
5f7394b
7c973d2
f560b91
5b931b6
a2973ab
53b193b
d8332f9
4c9ee46
7b06030
b714df0
8e23b88
3664fa2
89304e2
4e0fde0
37242b3
7a3167c
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 |
|---|---|---|
|
|
@@ -22,7 +22,7 @@ | |
| from eko.matchings import Atlas, nf_default | ||
| from eko.quantities import heavy_quarks | ||
|
|
||
| from . import check, comparator, version | ||
| from . import check, comparator, opcard_template, version | ||
|
|
||
| logger = logging.getLogger(__name__) | ||
|
|
||
|
|
@@ -94,22 +94,31 @@ def get_convolution_suffix(convolution: pineappl.convolutions.Conv) -> str: | |
|
|
||
| def write_operator_card_from_file( | ||
| pineappl_path: os.PathLike, | ||
| default_card_path: os.PathLike, | ||
| card_path: os.PathLike, | ||
| tcard: dict, | ||
| ipd=4, | ||
| iil=True, | ||
| int_cores=1, | ||
| ): | ||
| """Generate operator card for a grid. | ||
|
|
||
| Parameters | ||
| ---------- | ||
| pineappl_path : str or os.PathLike | ||
| path to grid to evolve | ||
| default_card : str or os.PathLike | ||
| base operator card | ||
| card_path : str or os.PathLike | ||
| target path | ||
| tcard: dict | ||
| theory card for the run | ||
| ipd: | ||
| interpolation polynomial degree, taken from cli. | ||
| Set to default value | ||
| iil: | ||
| interpolation is log, taken from cli. | ||
| Set to default value | ||
| int_cores: | ||
| number of integration cores, taken | ||
| from cli. Set to default value | ||
|
|
||
| Returns | ||
| ------- | ||
|
|
@@ -124,11 +133,7 @@ def write_operator_card_from_file( | |
| raise FileNotFoundError(pineappl_path) | ||
| pineappl_grid = pineappl.grid.Grid.read(pineappl_path) | ||
| pineappl_grid.optimize() | ||
| default_card = yaml.safe_load( | ||
| pathlib.Path(default_card_path).read_text(encoding="utf-8") | ||
| ) | ||
|
|
||
| return write_operator_card(pineappl_grid, default_card, card_path, tcard) | ||
| return write_operator_card(pineappl_grid, card_path, tcard, ipd, iil, int_cores) | ||
|
|
||
|
|
||
| def dump_card( | ||
|
|
@@ -166,23 +171,29 @@ def dump_card( | |
|
|
||
| def write_operator_card( | ||
| pineappl_grid: pineappl.grid.Grid, | ||
| default_card: dict, | ||
| card_path: Union[str, os.PathLike], | ||
| tcard: dict, | ||
| ipd, | ||
| iil, | ||
| int_cores | ||
| ): | ||
| """Generate operator card for this grid. | ||
|
|
||
| Parameters | ||
| ---------- | ||
| pineappl_grid : pineappl.grid.Grid | ||
| grid to evolve | ||
| default_card : dict | ||
| base operator card | ||
| card_path : str or os.PathLike | ||
| target path | ||
| tcard: dict | ||
| theory card for the run, since some information in EKO is now required | ||
| in operator card, but before was in the theory card | ||
| ipd: | ||
| interpolation polynomial degree, taken from cli | ||
| iil: | ||
| interpolation is log, taken from cli | ||
| int_cores: | ||
| number of integration cores, taken from cli | ||
|
|
||
| Returns | ||
| ------- | ||
|
|
@@ -204,18 +215,28 @@ def write_operator_card( | |
| # ... to get the x and muF grids for the eko | ||
| evol_info = pineappl_grid.evolve_info(order_mask) | ||
| muf2_grid = evol_info.fac1 | ||
| operators_card = copy.deepcopy(default_card) | ||
| operators_card = {} | ||
| operators_card["configs"] = {} | ||
| sv_method = sv_scheme(tcard) | ||
| xif = 1.0 if sv_method is not None else tcard["XIF"] | ||
| # update scale variation method | ||
| operators_card["configs"]["scvar_method"] = sv_method | ||
|
|
||
| operators_card["configs"]["scvar_method"] = sv_scheme(tcard) | ||
| operators_card["configs"]["ev_op_max_order"] = opcard_template.CONSTANTS["configs"]["ev_op_max_order"] | ||
| operators_card["debug"] = opcard_template.CONSTANTS["debug"] | ||
| operators_card["init"] = (tcard["Q0"], tcard["nf0"]) | ||
| if default_card.get("init") is not None and default_card["init"] != [ | ||
| # setting the parameters from the cli | ||
| operators_card["configs"]["interpolation_polynomial_degree"] = ipd | ||
| operators_card["configs"]["interpolation_is_log"] = iil | ||
| operators_card["configs"]["n_integration_cores"] = int_cores | ||
| if opcard_template.CONSTANTS["init"] is not None and opcard_template.CONSTANTS["init"] != ( | ||
| tcard["Q0"], | ||
| tcard["nf0"], | ||
| ]: | ||
| raise ValueError("Template declares a value of Q0, nf0 different from theory") | ||
| ): | ||
| raise logger.warning( | ||
| f"Warning! Q0 and nf0 from your theory are different " | ||
| f"than default settings ({tcard['Q0']}, {tcard['nf0']} vs " | ||
| f"{opcard_template.CONSTANTS['init']}). Check if this is really what you want!" | ||
| ) | ||
|
|
||
| q2_grid = (xif * xif * muf2_grid).tolist() | ||
| # If we are producing nFONLL FKs we need to look to NfFF... | ||
|
|
@@ -232,44 +253,32 @@ def write_operator_card( | |
| x_grid = np.append(x_grid, 1.0) | ||
| operators_card["configs"]["interpolation_polynomial_degree"] = 1 | ||
| operators_card["xgrid"] = x_grid.tolist() | ||
| else: | ||
| operators_card["xgrid"] = opcard_template.xgrid | ||
|
|
||
| # Add the version of eko and pineko to the operator card | ||
| # using importlib.metadata.version to get the correct tag in editable mode | ||
| operators_card["eko_version"] = metadata.version("eko") | ||
|
|
||
| # Choose the evolution method according to the theory if the key is included | ||
| if "ModEv" in tcard: | ||
|
Contributor
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'm a friend of early exits in code, since they safe indents - thus I suggests if "ModEv" not in tcard:
raise ValueError("blub")
# no explicit `else` needed nor the associated indentationsame for |
||
| opconf = operators_card["configs"] | ||
| if tcard["ModEv"] == "TRN": | ||
| opconf["evolution_method"] = "truncated" | ||
| opconf["ev_op_iterations"] = 1 | ||
| operators_card["configs"]["evolution_method"] = "truncated" | ||
| operators_card["configs"]["ev_op_iterations"] = 1 | ||
| operators_card["configs"]["inversion_method"] = "expanded" | ||
|
Contributor
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. Can you maybe add a
Contributor
Author
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's now already possible to determine these from the CLI (when doing "pineko theory opcards ..." and when doing "pineko opcard ... ") edit: ah no, I'm sorry I was confused and talking about the other settings! I can add the to do |
||
| elif tcard["ModEv"] == "EXA": | ||
| opconf["evolution_method"] = "iterate-exact" | ||
| operators_card["configs"]["evolution_method"] = "iterate-exact" | ||
| operators_card["configs"]["inversion_method"] = "exact" | ||
| if "IterEv" in tcard: | ||
| opconf["ev_op_iterations"] = tcard["IterEv"] | ||
| elif "ev_op_iterations" not in default_card["configs"]: | ||
| operators_card["configs"]["ev_op_iterations"] = tcard["IterEv"] | ||
| else: | ||
| raise ValueError( | ||
| "EXA used but IterEv not found in the theory card and not ev_op_iterations set in the template" | ||
| "EXA used but IterEv not found in the theory card" | ||
| ) | ||
|
|
||
| # If the evolution method is defined in the template and it is different, fail | ||
| template_method = default_card["configs"].get("evolution_method") | ||
| if ( | ||
| template_method is not None | ||
| and template_method != opconf["evolution_method"] | ||
| ): | ||
| raise ValueError( | ||
| f"The template and the theory have different evolution method ({template_method} vs {opconf['key']})" | ||
| ) | ||
|
|
||
| # If the change is on the number of iterations, take the template value but warn the user | ||
| template_iter = default_card["configs"].get("ev_op_iterations") | ||
| if template_iter is not None and int(template_iter) != int( | ||
| opconf["ev_op_iterations"] | ||
| ): | ||
| raise ValueError( | ||
| f"The number of iteration in the theory and template is different, ({template_iter} vs {opconf['ev_op_iterations']})" | ||
| ) | ||
| else: | ||
| raise ValueError( | ||
| "Evolution method not set in theory card" | ||
| ) | ||
|
|
||
| # Some safety checks | ||
| if ( | ||
|
|
@@ -286,7 +295,6 @@ def write_operator_card( | |
|
|
||
| for conv in convolutions: | ||
| dump_card(card_path, operators_card, conv) | ||
|
|
||
| return operators_card["xgrid"], q2_grid | ||
|
|
||
|
|
||
|
|
||
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.
I think this can be removed entirely?
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.
At first I did that, but then I thought it would be useful to leave it in case at any point there is another adjustment to the code that needs some files. It's what I thought, but let me know if you think differently
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.
I would remove unnecessary code and then re-add it if needed given past experiences with having a very big graveyard of code