Skip to content

Commit 63a74ef

Browse files
committed
add a careful option
1 parent e9f6fd3 commit 63a74ef

File tree

2 files changed

+42
-26
lines changed

2 files changed

+42
-26
lines changed

src/pineko/cli/fonll.py

Lines changed: 29 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -79,16 +79,18 @@ def tcards(theoryid):
7979
def ekos(theoryid, datasets, overwrite):
8080
"""Command to generate numerical FONLL ekos.
8181
82-
1. Create the 3 operator cards for the different flavor patches.
82+
1. Create all the operator cards for the different flavor patches.
8383
2. Run the 3 ekos for the different flavor patches.
8484
3. Inherit the ekos.
8585
"""
86-
for nf_id in ["00", "04", "05"]:
87-
# create opcards
86+
# Create all the operator cards as they are required for careful testing
87+
for nf_id in range(7):
8888
theory.TheoryBuilder(
89-
f"{theoryid}{nf_id}", datasets, overwrite=overwrite
89+
f"{theoryid}0{nf_id}", datasets, overwrite=overwrite
9090
).opcards()
9191

92+
# Most of the time only these 3 patches are necessary
93+
for nf_id in ["00", "04", "05"]:
9294
# run the ekos
9395
theory.TheoryBuilder(
9496
f"{theoryid}{nf_id}",
@@ -98,25 +100,29 @@ def ekos(theoryid, datasets, overwrite):
98100
overwrite=overwrite,
99101
).ekos()
100102

101-
# now inherit ekos
102-
# nf=3
103-
rich.print(f"[green] Inherit nf=3 ekos from theory {theoryid}00")
104-
theory.TheoryBuilder(f"{theoryid}00", datasets, overwrite=overwrite).inherit_ekos(
105-
f"{theoryid}01"
106-
)
107-
# nf=4
108-
rich.print(f"[green] Inherit nf=4 ekos from theory {theoryid}04")
109-
theory.TheoryBuilder(f"{theoryid}04", datasets, overwrite=overwrite).inherit_ekos(
110-
f"{theoryid}02"
111-
)
112-
theory.TheoryBuilder(f"{theoryid}04", datasets, overwrite=overwrite).inherit_ekos(
113-
f"{theoryid}03"
114-
)
115-
# nf=5
116-
rich.print(f"[green] Inherit nf=5 ekos from theory {theoryid}05")
117-
theory.TheoryBuilder(f"{theoryid}05", datasets, overwrite=overwrite).inherit_ekos(
118-
f"{theoryid}06"
119-
)
103+
# Now _attempt_ to inherit the ekos
104+
# _if_ a discrepancy is found between the eko and the grid, recompute
105+
106+
inheritance_map = {"00": ["01"], "04": ["02", "03"], "05": ["06"]}
107+
for i, (source, targets) in enumerate(inheritance_map.items()):
108+
source_tid = f"{theoryid}{source}"
109+
rich.print(f"[green] Inherit nf={3+i} ekos from theory {source_tid}")
110+
source_theory = theory.TheoryBuilder(source_tid, datasets, overwrite=overwrite)
111+
for target in targets:
112+
target_tid = f"{theoryid}{target}"
113+
try:
114+
source_theory.inherit_ekos(target_tid, careful=True)
115+
except AssertionError as e:
116+
rich.print(
117+
f"[red] Could not inherit from theory {source_tid} to {target_tid}, computing the EKO"
118+
)
119+
theory.TheoryBuilder(
120+
target_tid,
121+
datasets,
122+
silent=False,
123+
clear_logs=True,
124+
overwrite=overwrite,
125+
).ekos()
120126

121127

122128
@fonll_.command()

src/pineko/theory.py

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -199,7 +199,7 @@ def inherit_grids(self, target_theory_id):
199199
other.mkdir(exist_ok=True)
200200
self.iterate(self.inherit_grid, other=other)
201201

202-
def inherit_eko(self, name, grid, other):
202+
def inherit_eko(self, name, grid, other, careful=False):
203203
"""Inherit a EKO to a new theory.
204204
205205
Parameters
@@ -210,9 +210,17 @@ def inherit_eko(self, name, grid, other):
210210
path to grid
211211
other : pathlib.Path
212212
new folder
213+
careful : bool (default: False)
214+
check that grid and eko are compatible before forcing the inheritance
213215
"""
214216
names = get_eko_names(grid, name)
215217
for name in names:
218+
if careful:
219+
# Check the operator card of the parent
220+
parent_card = self.load_operator_card(name)
221+
child_card = self.__class__(other.name, []).load_operator_card(name)
222+
assert parent_card == child_card
223+
216224
eko_path = self.ekos_path() / f"{name}.tar"
217225
new = other / f"{name}.tar"
218226
if new.exists():
@@ -225,17 +233,19 @@ def inherit_eko(self, name, grid, other):
225233
if new.exists():
226234
rich.print(f"[green]Success:[/] Created link at {new}")
227235

228-
def inherit_ekos(self, target_theory_id):
236+
def inherit_ekos(self, target_theory_id, careful=False):
229237
"""Inherit ekos to a new theory.
230238
231239
Parameters
232240
----------
233241
target_theory_id : int
234242
target theory id
243+
careful : bool (default: False)
244+
check that grid and eko are compatible before forcing the inheritanc
235245
"""
236246
other = self.ekos_path(target_theory_id)
237247
other.mkdir(exist_ok=True)
238-
self.iterate(self.inherit_eko, other=other)
248+
self.iterate(self.inherit_eko, other=other, careful=careful)
239249

240250
def iterate(self, f, **kwargs):
241251
"""Iterate grids in datasets.

0 commit comments

Comments
 (0)