pinefarm package
Produce theory predictions from external sources.
Subpackages
- pinefarm.cli package
- pinefarm.external package
Submodules
pinefarm.configs module
Configuration tools.
- pinefarm.configs.NAME = 'pinefarm.toml'
Name of the config while (wherever it is placed).
- pinefarm.configs.PATHS_SECTIONS = ('paths', 'commands')
Sections containing only paths.
- pinefarm.configs.basic_paths(root: Path) dict[source]
Build all default independent paths.
Independent on anything but
root.
- pinefarm.configs.configs = {}
Holds loaded configurations.
- pinefarm.configs.detect(path: PathLike | None = None) Path[source]
Detect configuration files.
- Parameters:
path (os.PathLike or None) – optional explicit path to file to be used as configs (default: None)
- Returns:
configuration file path
- Return type:
- Raises:
FileNotFoundError – in case no valid configuration file is found
- pinefarm.configs.load(path: PathLike | None = None) dict[source]
Load configuration file.
If no path is explicitly passed, a minimal configuration is used instead (just setting root folder to the current one).
- Parameters:
path (os.PathLike or None) – the path to the configuration file (default: None)
- Returns:
loaded configurations
- Return type:
- pinefarm.configs.nestupdate(base: dict, update: dict)[source]
Merge nested dictionaries.
Pay attention, base will be mutated in place. So the second one will overwrite the first.
Note
Modifying in place avoids a lot of copies. But not being performance intensive, it would be possible to obtain a non in-place alternative just adding a first line:
base = copy.deepcopy(base)
but it would be called at every recursion (the lots of copies above). A simpler alternative is just to copy before calling, if needed:
mycopy = copy.deepcopy(mydict) nestupdate(mycopy, update)
that will make a single copy.
Note
Another option could appear to be using something like
collections.ChainMap. This is a smart way to implement cascade configurations, but it is not going to support nesting:configs = ChainMap({'a': {'b': 0}}, {'a': {'c': 1}})
in this case, even if there is no clash for
configs['a']['c'], this would result in aKeyError(since onceconfigs['a']is executed, the result is just a normaldict, and the first one encountered). Any refinement would involve a custom__geitem__(), with even more complicate logic.
pinefarm.info module
Provide inspection tools.
pinefarm.install module
Install tools.
- pinefarm.install.LHAPDF_VERSION = 'LHAPDF-6.5.4'
Version of LHAPDF to be used by default (if not already available).
- pinefarm.install.PINEAPPL_REPO = 'https://github.com/N3PDF/pineappl.git'
Git repo location for pineappl.
- pinefarm.install.hawaiian_vrap()[source]
Install a version of vrap flavoured with pineappl from https://github.com/NNPDF/hawaiian_vrap.
- Returns:
whether vrap is now installed
- Return type:
- pinefarm.install.is_exe(command: PathLike) bool[source]
Check if given path exists and is executable.
- pinefarm.install.lhapdf()[source]
Install LHAPDF C++ library.
This is currently needed by every tool due to postprocessing requirements.
- pinefarm.install.lhapdf_conf(pdf)[source]
Initialize LHAPDF.
- Parameters:
pdf (str) – LHAPDF name of the required PDF
- pinefarm.install.mg5amc()[source]
Initialize MadGraph5_aMC@NLO.
- Returns:
whether the main executable is now existing.
- Return type:
- pinefarm.install.update_lhapdf_path(path)[source]
Update LHAPDF path, both in environment and lhapdf_management.
- Parameters:
path (str or pathlib.Path) – path to LHAPDF data
pinefarm.log module
Logging tools.
- class pinefarm.log.Tee(name, stdout=True, stderr=False)[source]
Bases:
objectContext manager to tee stdout to file.
- Parameters:
name (str or pathlib.Path) – path to redirect stdout to
- exception pinefarm.log.WhileRedirectedError(*args, file, **kwargs)[source]
Bases:
RuntimeErrorError to signal a generic error, while stderr was redirected to file.
- Parameters:
*args – arguments passed to
RuntimeErrorfile (str) – path to file to which stderr is redirected
**kwargs – keyword arguments passed to
RuntimeError
- pinefarm.log.subprocess(*args, cwd, out)[source]
Wrap
subprocess.Popento print the output to screen and capture it.
pinefarm.table module
Comparison tools.
- pinefarm.table.convolute_grid(grid, pdf_name, integrated=False)[source]
Call convolute via PineAPPL CLI.
- pinefarm.table.print_table(pineappl_results, external_results, dest)[source]
Print comparison table to screen.
- Parameters:
pineappl_results (pandas.DataFrame) – results from the generated grid
external_results (pandas.DataFrame) – results from the external program
dest (pathlib.Path) – path to output file
pinefarm.tools module
Auxilariy tools.
- pinefarm.tools.common_substring(s1, s2, *sn)[source]
Return the longest common part of two iterables, starting from the begininng.
- Parameters:
s1 (Sequence) – first sequence to compare
s2 (Sequence) – second sequence to compare
*sn (Sequence) – any further sequence to compare
- Returns:
longest common subsequence
- Return type:
Sequence
Examples
>>> common_substring("test test", "test toast") "test t" >>> common_substring("test test", "test test test") "test test" >>> common_substring("test test", "") "" >>> common_substring("test test", "test test test", "test") "test" >>> common_substring("test test", "test test test", "test toast") "test t"
- pinefarm.tools.compress(path)[source]
Compress a file into lz4.
- Parameters:
path (pathlib.Path) – input path
- Returns:
path to compressed file
- Return type:
- pinefarm.tools.create_output_folder(name, theoryid)[source]
Create output folder.
- Parameters:
name (str) – dataset name
- Returns:
path to output folder
- Return type:
- pinefarm.tools.decompress(path)[source]
Decompress a file from lz4.
- Parameters:
path (pathlib.Path) – path to compressed file
- Returns:
path to raw file
- Return type:
- pinefarm.tools.git_pull(repo, remote_name='origin', branch='master')[source]
Pull a remote repository.
- Parameters:
repo (pygit2.Repository) – repository
remote_name (str) – remote name
branch (str) – branch to get
- pinefarm.tools.nine_points = [(0.5, 0.5, 1.0), (0.5, 1.0, 1.0), (0.5, 2.0, 1.0), (1.0, 0.5, 1.0), (1.0, 1.0, 1.0), (1.0, 2.0, 1.0), (2.0, 0.5, 1.0), (2.0, 1.0, 1.0), (2.0, 2.0, 1.0)]
Nine points prescription for scale variations (as couples, referred to
(fact, ren, frag=1.0)scales).
- pinefarm.tools.parse_metadata(file)[source]
Parse metadata file.
- Parameters:
file (io.TextIOBase) – the file to read
- Returns:
the metadata entries
- Return type:
- pinefarm.tools.patch(patch, base_dir='.')[source]
Apply patch.
- Parameters:
patch (str) – patch to apply (text content, not path)
base_dir (str or pathlib.Path) – path to dir where to apply patch (default:
.)
- pinefarm.tools.print_time(t0, what=None)[source]
Report completion together with timing to the user.
- pinefarm.tools.set_grid_metadata(grid, entries=None, entries_from_file=None)[source]
Set metadata on a pineappl grid (in-place operation).
- pinefarm.tools.three_points = [0.5, 1.0, 2.0]
Three points prescription for scale variations.
- pinefarm.tools.twentyseven_points = [(0.5, 0.5, 0.5), (0.5, 0.5, 1.0), (0.5, 0.5, 2.0), (0.5, 1.0, 0.5), (0.5, 1.0, 1.0), (0.5, 1.0, 2.0), (0.5, 2.0, 0.5), (0.5, 2.0, 1.0), (0.5, 2.0, 2.0), (1.0, 0.5, 0.5), (1.0, 0.5, 1.0), (1.0, 0.5, 2.0), (1.0, 1.0, 0.5), (1.0, 1.0, 1.0), (1.0, 1.0, 2.0), (1.0, 2.0, 0.5), (1.0, 2.0, 1.0), (1.0, 2.0, 2.0), (2.0, 0.5, 0.5), (2.0, 0.5, 1.0), (2.0, 0.5, 2.0), (2.0, 1.0, 0.5), (2.0, 1.0, 1.0), (2.0, 1.0, 2.0), (2.0, 2.0, 0.5), (2.0, 2.0, 1.0), (2.0, 2.0, 2.0)]
27 points prescription for scale variations (as couples, referred to
(fact, ren, frag)scales).