Skip to content
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

Move permanent part of fkutils here #12

Merged
merged 37 commits into from
Mar 29, 2022
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
37 commits
Select commit Hold shift + click to select a range
006280c
Move towards datasets
felixhekhorn Mar 1, 2022
1e9cb65
Expose opcard generation for datasets
felixhekhorn Mar 1, 2022
5ff8e64
Add theory_ekos
felixhekhorn Mar 1, 2022
fc6ed74
Attempt on logging
felixhekhorn Mar 1, 2022
6ee0fb1
Drop Configurations class
felixhekhorn Mar 3, 2022
4eb7947
Fix eko logging
felixhekhorn Mar 3, 2022
f2b3d29
Upgrade syntax with pylint
felixhekhorn Mar 3, 2022
1d1d10e
Add theory_fks
felixhekhorn Mar 3, 2022
1d3c2b7
Add FK comparison log
felixhekhorn Mar 3, 2022
68cd123
Merge branch 'main' into fkutils-move
felixhekhorn Mar 9, 2022
e7ef4a6
Add comparison after evolution
felixhekhorn Mar 9, 2022
512332a
Init TheoryBuilder
felixhekhorn Mar 9, 2022
096f760
Move theory opcards
felixhekhorn Mar 10, 2022
a0d58fd
Reshuffle fks into theory
felixhekhorn Mar 14, 2022
784dee8
Regroup theory cli
felixhekhorn Mar 14, 2022
3a53e56
Update config
felixhekhorn Mar 15, 2022
cb516d5
Add inherit-grids command
felixhekhorn Mar 15, 2022
4900d4a
Drop paths.grids.common, add Readme
felixhekhorn Mar 15, 2022
e0bffc4
Fix Readme
felixhekhorn Mar 15, 2022
36205d7
Move old stuff
felixhekhorn Mar 15, 2022
2e4829e
Introduce overwrite option and skipping
felixhekhorn Mar 15, 2022
c2e3459
Make inherit-grids more consistent
felixhekhorn Mar 16, 2022
1e35e50
Make inherit-grids yet more consistent
felixhekhorn Mar 16, 2022
11e52ae
Update Readme
felixhekhorn Mar 16, 2022
9c3dd18
Add inherit-ekos command
felixhekhorn Mar 16, 2022
a10887b
Drop config.add_scope
felixhekhorn Mar 16, 2022
23449b6
Improve logging
felixhekhorn Mar 16, 2022
b464b52
Improve logging
felixhekhorn Mar 16, 2022
19ccfee
Adjust README a bit
cschwan Mar 16, 2022
f5702e5
Remove common grids dir
felixhekhorn Mar 21, 2022
d2018a4
Move pylint and apply some suggestions
felixhekhorn Mar 22, 2022
24674cf
Remove old code and folder
felixhekhorn Mar 22, 2022
b69353e
Drop module entry point
felixhekhorn Mar 22, 2022
ada17a4
Update parser
felixhekhorn Mar 22, 2022
3bf4bbc
Fix compare arg names
felixhekhorn Mar 23, 2022
0e0b141
Recover file base operations
felixhekhorn Mar 24, 2022
ee6b9da
Run poetry update
felixhekhorn Mar 24, 2022
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 6 additions & 6 deletions src/pineko/cli/theory_.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,11 +32,11 @@ def opcards(theory_id, datasets, overwrite):
@theory_.command()
@click.argument("theory_id", type=click.INT)
@click.argument("datasets", type=click.STRING, nargs=-1)
@click.option("--logs", is_flag=True, help="dump logs")
@click.option("--no-logs", is_flag=True, help="suppress logs")
@click.option("--overwrite", is_flag=True, help="Allow files to be overwritten")
def ekos(theory_id, datasets, logs, overwrite):
def ekos(theory_id, datasets, no_logs, overwrite):
"""Compute EKOs for all FK tables in all datasets."""
theory.TheoryBuilder(theory_id, datasets, overwrite).ekos(logs)
theory.TheoryBuilder(theory_id, datasets, overwrite).ekos(no_logs)


@theory_.command()
Expand All @@ -52,8 +52,8 @@ def inherit_ekos(source_theory_id, target_theory_id, datasets, overwrite):
@click.argument("theory_id", type=click.INT)
@click.argument("datasets", type=click.STRING, nargs=-1)
@click.option("--pdf", "-p", default=None, help="comparison PDF")
@click.option("--logs", is_flag=True, help="dump comparison")
@click.option("--no-logs", is_flag=True, help="suppress logs with comparison")
@click.option("--overwrite", is_flag=True, help="Allow files to be overwritten")
def fks(theory_id, datasets, pdf, logs, overwrite):
def fks(theory_id, datasets, pdf, no_logs, overwrite):
"""Compute FK tables in all datasets."""
theory.TheoryBuilder(theory_id, datasets, overwrite).fks(pdf, logs)
theory.TheoryBuilder(theory_id, datasets, overwrite).fks(pdf, no_logs)
95 changes: 58 additions & 37 deletions src/pineko/theory.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
# -*- coding: utf-8 -*-
import logging
import time

import eko
import rich
Expand All @@ -8,6 +9,9 @@
from . import configs, evolve, parser, theory_card, parser


logger = logging.getLogger(__name__)


class TheoryBuilder:
"""Common builder application to create the ingredients for a theory.

Expand All @@ -31,7 +35,7 @@ def operator_cards_path(self):
"""Suffix paths.operator_cards with theory id."""
return configs.configs["paths"]["operator_cards"] / str(self.theory_id)

def eko_path(self, tid=None):
def ekos_path(self, tid=None):
"""Suffix paths.ekos with theory id.

Parameters
Expand All @@ -49,7 +53,7 @@ def eko_path(self, tid=None):
return configs.configs["paths"]["ekos"] / str(tid)

@property
def fk_path(self):
def fks_path(self):
"""Suffix paths.fktables with theory id."""
return configs.configs["paths"]["fktables"] / str(self.theory_id)

Expand Down Expand Up @@ -141,7 +145,7 @@ def inherit_eko(self, name, _grid, other):
other : pathlib.Path
new folder
"""
eko = self.eko_path() / f"{name}.tar"
eko = self.ekos_path() / f"{name}.tar"
new = other / f"{name}.tar"
if new.exists():
if not self.overwrite:
Expand All @@ -162,7 +166,7 @@ def inherit_ekos(self, target_theory_id):
target_theory_id : int
target theory id
"""
other = self.eko_path(target_theory_id)
other = self.ekos_path(target_theory_id)
other.mkdir(exist_ok=True)
self.iterate(self.inherit_eko, other=other)

Expand Down Expand Up @@ -208,9 +212,10 @@ def opcard(self, name, grid):

def opcards(self):
"""Write operator cards."""
self.operator_cards_path.mkdir(exist_ok=True)
self.iterate(self.opcard)

def eko(self, name, _grid, tcard, logs):
def eko(self, name, _grid, tcard, no_logs):
"""Compute a single eko.

Parameters
Expand All @@ -222,46 +227,50 @@ def eko(self, name, _grid, tcard, logs):
tcard : dict
theory card
logs : bool
save eko logs?
save logs?
"""
# setup data
paths = configs.configs["paths"]
# activate logging
if not no_logs and paths["logs"]["eko"]:
log_path = paths["logs"]["eko"] / f"{self.theory_id}-{name}.log"
log_file = logging.FileHandler(log_path)
log_file.setLevel(logging.INFO)
log_file.setFormatter(logging.Formatter("%(asctime)s %(name)s/%(levelname)s: %(message)s"))
for logger_ in (logger, logging.getLogger("eko")):
logger_.handlers = []
logger_.addHandler(log_file)
logger_.setLevel(logging.INFO)
# setup data
opcard_path = self.operator_cards_path / f"{name}.yaml"
with open(opcard_path, encoding="utf-8") as f:
ocard = yaml.safe_load(f)
eko_filename = self.eko_path() / f"{name}.tar"
eko_filename = self.ekos_path() / f"{name}.tar"
if eko_filename.exists():
if not self.overwrite:
rich.print(f"Skipping existing operator {eko_filename}")
return
# activate logging
if logs and paths["logs"]["eko"]:
log_path = paths["logs"]["eko"] / f"{self.theory_id}-{name}.log"
log_file = logging.FileHandler(log_path)
log_file.setLevel(logging.INFO)
log_file.setFormatter(logging.Formatter("%(message)s"))
logging.getLogger("eko").handlers = []
logging.getLogger("eko").addHandler(log_file)
logging.getLogger("eko").setLevel(logging.INFO)
# do it!
logger.info("Start computation of %s", name)
start_time = time.perf_counter()
ops = eko.run_dglap(theory_card=tcard, operators_card=ocard)
ops.dump_tar(eko_filename)
logger.info("Finished computation of %s - took %f s", name, time.perf_counter() - start_time)
if eko_filename.exists():
rich.print(f"[green]Success:[/] Wrote EKO to {eko_filename}")

def ekos(self, logs):
def ekos(self, no_logs):
"""Compute all ekos.

Parameters
----------
logs : bool
save eko logs?
no_logs : bool
suppress logs?
"""
tcard = theory_card.load(self.theory_id)
self.eko_path().mkdir(exist_ok=True)
self.iterate(self.eko, tcard=tcard, logs=logs)
self.ekos_path().mkdir(exist_ok=True)
self.iterate(self.eko, tcard=tcard, no_logs=no_logs)

def fk(self, name, grid_path, tcard, pdf, logs):
def fk(self, name, grid_path, tcard, pdf, no_logs):
"""Compute a single FK table.

Parameters
Expand All @@ -274,40 +283,52 @@ def fk(self, name, grid_path, tcard, pdf, logs):
theory card
pdf : str
comparison PDF
logs : bool
save eko logs?
no_logs : bool
suppress logs?
"""
# setup data
# activate logging
paths = configs.configs["paths"]
eko_filename = self.eko_path() / f"{name}.tar"
fk_filename = self.fk_path / f"{name}.{parser.ext}"
do_log = not no_logs and paths["logs"]["fk"]
if do_log:
log_path = paths["logs"]["fk"] / f"{self.theory_id}-{name}-{pdf}.log"
log_file = logging.FileHandler(log_path)
log_file.setLevel(logging.INFO)
log_file.setFormatter(logging.Formatter("%(asctime)s %(name)s/%(levelname)s: %(message)s"))
logger.handlers = []
logger.addHandler(log_file)
logger.setLevel(logging.INFO)

# setup data
eko_filename = self.ekos_path() / f"{name}.tar"
fk_filename = self.fks_path / f"{name}.{parser.ext}"
if fk_filename.exists():
if not self.overwrite:
rich.print(f"Skipping existing FK Table {fk_filename}")
return
max_as = 1 + int(tcard["PTO"])
max_al = 0
# do it!
logger.info("Start computation of %s", name)
start_time = time.perf_counter()
_grid, _fk, comparison = evolve.evolve_grid(
grid_path, eko_filename, fk_filename, max_as, max_al, pdf
)
# activate logging
if logs and paths["logs"]["fk"] and comparison:
logfile = paths["logs"]["fk"] / f"{self.theory_id}-{name}-{pdf}.log"
logfile.write_text(comparison.to_string())
logger.info("Finished computation of %s - took %f s", name, time.perf_counter() - start_time)
if do_log and comparison is not None:
logger.info("Comparison with %s:\n %s", pdf, comparison.to_string())
if fk_filename.exists():
rich.print(f"[green]Success:[/] Wrote FK table to {fk_filename}")

def fks(self, pdf, logs):
def fks(self, pdf, no_logs):
"""Compute all FK tables.

Parameters
----------
pdf : str
comparison PDF
logs : bool
save eko logs?
no_logs : bool
suppress logs?
"""
tcard = theory_card.load(self.theory_id)
self.fk_path.mkdir(exist_ok=True)
self.iterate(self.fk, tcard=tcard, pdf=pdf, logs=logs)
self.fks_path.mkdir(exist_ok=True)
self.iterate(self.fk, tcard=tcard, pdf=pdf, no_logs=no_logs)