-
Notifications
You must be signed in to change notification settings - Fork 0
Numerical FONLL #99
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
Numerical FONLL #99
Changes from all commits
9d24291
24cf458
16cce40
a3a4e76
715f231
3df8311
73f4b81
cbd6abe
3ca875c
b47308e
4620046
9cc79dc
80595d0
34638e0
761bdbc
a0201bb
db43104
a189ff7
bf985eb
986cf46
904cbb9
4b16a92
099523a
aecf0cd
0399a59
499f857
48c83d4
b4ca9b7
b474004
8b45356
1b206d0
12c1693
88e780d
9ac3cb7
77bfad4
967a9d7
6d6d310
f6906ec
74eb2fa
96394dd
c0e613c
e14e22f
ebcd6fe
524429a
24bfe64
c29463b
fbb7500
3778f27
fa7a60b
523498a
acd6d81
56ec7d9
6de60e0
b59b268
4a44d08
c718a1f
238f880
864742f
b4fd0d3
175ee2a
3708a89
f4f0a2c
a7d64ca
999daee
9aad606
5bca6e7
a2998a3
1b310eb
315ed38
04f0ed7
e116783
034db70
25a13d5
fba7f9f
35371fd
860e5f4
43bcaa3
b21ee31
91c527f
c8b8f03
11d8f84
03d061b
dada400
3f3c887
785fc11
233037b
3745e92
f0ec07c
8ad2d1f
f22cc27
5313744
cc66bb4
4cfc8dd
e364fff
d59ea5c
eb73599
1b32ca0
025a578
1a495a7
790c0a5
3e688bc
d7b610f
b8ca270
8a1c916
04374a4
efd9a0b
9b7edb1
73c5052
61b1802
837ce2a
f5cec44
115b820
ece695b
e406de6
5efe537
34fd85d
babe6ae
5a3252e
8c9fcef
bb0d3f4
bc78002
bcfe6ef
b284bb1
5ecc635
eb6d734
7e385a3
6d38acb
2e76e57
1165dd9
6d87995
e64aa94
61c487a
b5674d0
155200f
f28d9a2
17d5956
fdf9a05
78ab9c9
914dec1
b37cb54
e35a95f
7dca3a4
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 |
|---|---|---|
| @@ -0,0 +1,28 @@ | ||
| import numpy as np | ||
| import pytest | ||
| import yaml | ||
|
|
||
| import pineko | ||
|
|
||
|
|
||
| @pytest.mark.parametrize("theoryid,is_mixed", [(400, False), (208, True)]) | ||
| def benchmark_produce_fonll_tcards( | ||
| tmp_path, test_files, test_configs, theoryid, is_mixed | ||
| ): | ||
| tcard = pineko.theory_card.load(theoryid) | ||
| tcard_paths_list = pineko.fonll.dump_tcards(tcard, tmp_path, theoryid) | ||
| # Check they are correct | ||
| theorycards = [] | ||
| for path in tcard_paths_list: | ||
| with open(path, encoding="UTF-8") as f: | ||
| theorycards.append(yaml.safe_load(f)) | ||
| base_pto = pineko.fonll.FNS_BASE_PTO[tcard["FNS"]] | ||
| for num_fonll_tcard, cfg in zip( | ||
| theorycards, | ||
| pineko.fonll.MIXED_FNS_CONFIG if is_mixed else pineko.fonll.FNS_CONFIG, | ||
| ): | ||
| po = int(base_pto) + (cfg.delta_pto if is_mixed else 0) | ||
| assert num_fonll_tcard["FNS"] == cfg.scheme | ||
| assert num_fonll_tcard["NfFF"] == int(cfg.nf) | ||
| assert num_fonll_tcard["PTO"] == po - 1 if is_mixed and cfg.asy else po | ||
| assert num_fonll_tcard["FONLLParts"] == cfg.parts |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,3 +1,13 @@ | ||
| """CLI entry point.""" | ||
| from . import check, compare, convolute, gen_sv, kfactor, opcard, scaffold, theory_ | ||
| from . import ( | ||
| check, | ||
| compare, | ||
| convolute, | ||
| fonll, | ||
| gen_sv, | ||
| kfactor, | ||
| opcard, | ||
| scaffold, | ||
| theory_, | ||
| ) | ||
| from ._base import command |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,174 @@ | ||
| """CLI entry point to FONLL.""" | ||
| import pathlib | ||
|
|
||
| import click | ||
| import rich | ||
|
|
||
| from .. import configs, fonll, parser, theory_card | ||
| from ._base import command | ||
|
|
||
| config_setting = click.option( | ||
| "-c", | ||
| "--configs", | ||
| "cfg", | ||
| default=None, | ||
| type=click.Path(resolve_path=True, path_type=pathlib.Path), | ||
| help="Explicitly specify config file (it has to be a valid TOML file).", | ||
| ) | ||
|
|
||
|
|
||
| class TheoryCardError(Exception): | ||
| """Raised when asked for FONLL theory cards with an original tcard as input that is not asking for FONLL.""" | ||
|
|
||
|
|
||
| class InconsistentInputsError(Exception): | ||
| """Raised if the inputs are not consistent with FONLL.""" | ||
|
|
||
|
|
||
| def cfgpath(name, grid): | ||
| """Path of the fktable in 'name' called 'grid' if it exists, else None.""" | ||
| path = configs.configs["paths"]["fktables"] / name / grid | ||
| return path if path.exists() else None | ||
|
|
||
|
|
||
| def grids_names(yaml_file): | ||
| """Return the list of the grids in the yaml file.""" | ||
| yaml_content = parser._load_yaml(yaml_file) | ||
| # Turn the operands and the members into paths (and check all of them exist) | ||
| ret = [] | ||
| for operand in yaml_content["operands"]: | ||
| for member in operand: | ||
| ret.append(f"{member}.{parser.EXT}") | ||
| return ret | ||
|
|
||
|
|
||
| @command.command("combine_fonll") | ||
| @click.argument("theoryID", type=int) | ||
| @click.argument("dataset", type=str) | ||
| @click.option("--FFNS3", type=int, help="theoryID containing the ffns3 fktable") | ||
| @click.option("--FFN03", type=int, help="theoryID containing the ffn03 fktable") | ||
| @click.option("--FFNS4", type=int, help="theoryID containing the ffns4 fktable") | ||
| @click.option("--FFNS4til", type=int, help="theoryID containing the ffns4til fktable") | ||
| @click.option("--FFNS4bar", type=int, help="theoryID containing the ffns4bar fktable") | ||
| @click.option("--FFN04", type=int, help="theoryID containing the ffn04 fktable") | ||
| @click.option("--FFNS5", type=int, help="theoryID containing the ffns5 fktable") | ||
| @click.option("--FFNS5til", type=int, help="theoryID containing the ffns5til fktable") | ||
| @click.option("--FFNS5bar", type=int, help="theoryID containing the ffns5bar fktable") | ||
|
Comment on lines
+48
to
+56
Collaborator
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. Instead of a thousand options, couldn't we just use a list of integers with some encoding?
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. Maybe yes but they are all options because they are all optional. I believe that following your suggestion we may lose that flexibility or at least in clarity.
Collaborator
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. Actually, is this really the case? I believe you can choose to not have a flavor, or some part of it, but not all the options are independent. We may always have a scheme to interpret the list.
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. From the code point of view you have full flexibility. Of course from the physics point of view there are some choices that just do not make sense. The code would not fail though |
||
| @click.option("--overwrite", is_flag=True, help="Allow files to be overwritten") | ||
| @config_setting | ||
| def subcommand( | ||
| theoryid, | ||
| dataset, | ||
| ffns3, | ||
| ffn03, | ||
| ffns4, | ||
| ffns4til, | ||
| ffns4bar, | ||
| ffn04, | ||
| ffns5, | ||
| ffns5til, | ||
| ffns5bar, | ||
| overwrite, | ||
| cfg, | ||
| ): | ||
| """Combine the different FKs needed to produce the FONLL prescription.""" | ||
| path = configs.detect(cfg) | ||
| base_configs = configs.load(path) | ||
| configs.configs = configs.defaults(base_configs) | ||
| if cfg is not None: | ||
| print(f"Configurations loaded from '{path}'") | ||
|
|
||
| # Checks | ||
|
|
||
| if not ffns3 or not ffn03: | ||
| raise InconsistentInputsError("ffns3 and/or ffn03 is not provided.") | ||
|
|
||
| if any([ffns4, ffns4til, ffns4bar]): | ||
| if ffns4: | ||
| if any([ffns4til, ffns4bar]): | ||
| raise InconsistentInputsError( | ||
| "If ffns4 is provided no ffnstil or ffnsbar should be provided." | ||
| ) | ||
| else: | ||
| if ffns4til is None or ffns4bar is None: | ||
| raise InconsistentInputsError( | ||
| "if ffnstil is provided also ffnsbar should be provided, and vice versa." | ||
| ) | ||
| else: | ||
| raise InconsistentInputsError("ffns4 is not provided.") | ||
|
|
||
| # Do we consider two masses, i.e. mc and mb | ||
| two_masses = False | ||
| if any([ffns5, ffns5til, ffns5bar]): | ||
| two_masses = True | ||
| if ffns5: | ||
| if any([ffns5til, ffns5bar]): | ||
| raise InconsistentInputsError( | ||
| "If ffns5 is provided no ffnstil or ffnsbar should be provided." | ||
| ) | ||
| else: | ||
| if ffns5til is None or ffns5bar is None: | ||
| raise InconsistentInputsError( | ||
| "if ffnstil is provided also ffnsbar should be provided, and vice versa." | ||
| ) | ||
|
|
||
| if (ffn04 is None and two_masses) or (ffn04 is not None and not two_masses): | ||
| raise InconsistentInputsError( | ||
| "If two masses are to be considered, both ffn04 and the nf=5 coefficient should be provided" | ||
| ) | ||
|
|
||
| # Get theory info | ||
| tcard = theory_card.load(theoryid) | ||
| if not "DAMPPOWER" in tcard: | ||
| if tcard["DAMP"] != 0: | ||
| raise InconsistentInputsError("If DAMP is set, set also DAMPPOWER") | ||
| tcard["DAMPPOWER"] = None | ||
| # Getting the paths to the grids | ||
| grids_name = grids_names(configs.configs["paths"]["ymldb"] / f"{dataset}.yaml") | ||
| for grid in grids_name: | ||
| # Checking if it already exists | ||
| new_fk_path = configs.configs["paths"]["fktables"] / str(theoryid) / grid | ||
| if new_fk_path.exists(): | ||
| if not overwrite: | ||
| rich.print( | ||
| f"[green]Success:[/] skipping existing FK Table {new_fk_path}" | ||
| ) | ||
| return | ||
| fonll.produce_combined_fk( | ||
| *( | ||
| cfgpath(str(name), grid) | ||
| for name in ( | ||
| ffns3, | ||
| ffn03, | ||
| ffns4, | ||
| ffns4til, | ||
| ffns4bar, | ||
| ffn04, | ||
| ffns5, | ||
| ffns5til, | ||
| ffns5bar, | ||
| ) | ||
| ), | ||
| theoryid, | ||
| damp=(tcard["DAMP"], tcard["DAMPPOWER"]), | ||
| cfg=cfg, | ||
| ) | ||
| if new_fk_path.exists(): | ||
| rich.print(f"[green]Success:[/] Wrote FK table to {new_fk_path}") | ||
| else: | ||
| rich.print(f"[red]Failure:[/]") | ||
|
|
||
|
|
||
| @command.command("fonll_tcards") | ||
| @click.argument("theoryID", type=int) | ||
| @config_setting | ||
| def fonll_tcards(theoryid, cfg): | ||
| """Produce the FONLL tcards starting from the original tcard given by the theoryID.""" | ||
| path = configs.detect(cfg) | ||
| base_configs = configs.load(path) | ||
| configs.configs = configs.defaults(base_configs) | ||
| tcard = theory_card.load(theoryid) | ||
| tcard_parent_path = theory_card.path(theoryid).parent | ||
| if "FONLL" not in tcard["FNS"]: | ||
| raise TheoryCardError("The theorycard does not correspond to an FONLL scheme.") | ||
| fonll.dump_tcards(tcard, tcard_parent_path, theoryid) | ||
Uh oh!
There was an error while loading. Please reload this page.