pinefarm package

Produce theory predictions from external sources.

Subpackages

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: pathlib.Path) dict[source]

Build all default independent paths.

Independent on anything but root.

pinefarm.configs.commands(paths: dict) dict[source]

Set all default commands.

pinefarm.configs.configs = {}

Holds loaded configurations.

pinefarm.configs.detect(path: Optional[os.PathLike] = None) pathlib.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

pathlib.Path

Raises

FileNotFoundError – in case no valid configuration file is found

pinefarm.configs.force_paths()[source]

Convert values in chosen sections to paths.

pinefarm.configs.load(path: Optional[os.PathLike] = 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

dict

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 a KeyError (since once configs['a'] is executed, the result is just a normal dict, and the first one encountered). Any refinement would involve a custom __geitem__(), with even more complicate logic.

Parameters
  • base (dict) – dictionary to be updated

  • update (dict) – dictionary containing update

pinefarm.configs.paths(paths: dict) dict[source]

Build all default dependent paths.

pinefarm.configs.raw(original: dict) dict[source]

Convert configs (or dict) into serializable equivalent.

Parameters

original (dict) – original dictionary to convert

Returns

converted dictionary

Return type

dict

See also

rawscalar(), used

pinefarm.configs.rawscalar(value)[source]

Turn scalar into serializable equivalent.

Available conversions:

pathlib.Path -> str
Parameters

value (any) – value to convert

Returns

converted value, if no converter available the original one

Return type

any

pinefarm.info module

Provide inspection tools.

class pinefarm.info.Info(color: str, external: Type[pinefarm.external.interface.External], kind: pinefarm.info.Kind)[source]

Bases: object

Info type.

color: str
external: Type[pinefarm.external.interface.External]
kind: pinefarm.info.Kind
class pinefarm.info.Kind(value)[source]

Bases: enum.Enum

Interface types.

dis = 1
ftdy = 3
hadronic = 4
integrability = 5
positivity = 2
pinefarm.info.label(dataset: str) pinefarm.info.Info[source]

Generate associated Info type.

pinefarm.install module

Install tools.

pinefarm.install.LHAPDF_VERSION = 'LHAPDF-6.4.0'

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.cargo()[source]

Initialize Rust and Cargo.

Returns

path to cargo

Return type

str

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

bool

pinefarm.install.init_prefix()[source]

Set up paths.

pinefarm.install.is_exe(command: os.PathLike) bool[source]

Check if given path exists and is executable.

pinefarm.install.lhapdf()[source]

Install LHAPDF C++ library.

Not needed:
  • for mg5, since it’s vendored

  • for yadism, since we depend on the PyPI version

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

bool

pinefarm.install.pineappl(capi=True, cli=False)[source]

Initialize PineAPPL.

Parameters
  • capi (bool) – whether to install PineAPPl CAPI (by default True, since it’s the only thing required)

  • cli (bool) – whether to install even PineAPPL CLI (by default False, since it’s not required to run)

Returns

whether pineappl and pineappl_capi are now available.

Return type

bool

pinefarm.install.update_environ()[source]

Adjust necessary environment files.

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.ChildStream(parent)[source]

Bases: object

Inner stream.

write(data)[source]

Write to stream.

class pinefarm.log.Tee(name, stdout=True, stderr=False)[source]

Bases: object

Context manager to tee stdout to file.

Parameters

name (str or pathlib.Path) – path to redirect stdout to

flush()[source]

Flush stream.

write(data, stream)[source]

Write to stream.

exception pinefarm.log.WhileRedirectedError(*args, file, **kwargs)[source]

Bases: RuntimeError

Error to signal a generic error, while stderr was redirected to file.

Parameters
  • *args – arguments passed to RuntimeError

  • file (str) – path to file to which stderr is redirected

  • **kwargs – keyword arguments passed to RuntimeError

pinefarm.log.subprocess(*args, cwd, out)[source]

Wrap subprocess.Popen to print the output to screen and capture it.

Parameters
  • args – positional arguments to pass to subprocess.Popen

  • cwd (path-like or str) – directory where to execute the command

  • out (path-like or str) – file to which (also) redirect the output

Returns

output of the command run in the subprocess

Return type

str

pinefarm.table module

Comparison tools.

pinefarm.table.convolute_grid(grid, pdf_name, integrated=False)[source]

Call convolute via PineAPPL CLI.

Parameters
  • grid (str) – grid path

  • pdf_name (str) – PDF name

  • integrated (bool) – whether the bins have to be integrated with bins normalizations

Returns

(essential) output splitted by line

Return type

list(str)

pinefarm.table.print_table(pineappl_results, external_results, dest)[source]

Print comparison table to screen.

Parameters

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

pathlib.Path

pinefarm.tools.create_output_folder(name, theoryid)[source]

Create output folder.

Parameters

name (str) – dataset name

Returns

path to output folder

Return type

pathlib.Path

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

pathlib.Path

pinefarm.tools.git_pull(repo, remote_name='origin', branch='master')[source]

Pull a remote repository.

Parameters
pinefarm.tools.nine_points = [(0.5, 0.5), (0.5, 1.0), (0.5, 2.0), (1.0, 0.5), (1.0, 1.0), (1.0, 2.0), (2.0, 0.5), (2.0, 1.0), (2.0, 2.0)]

Nine points prescription for scale variations (as couples, referred to (fact, ren) scales).

pinefarm.tools.parse_metadata(file)[source]

Parse metadata file.

Parameters

file (io.TextIOBase) – the file to read

Returns

the metadata entries

Return type

dict

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.

Parameters
  • t0 (int) – start time

  • what (str) – subject that is completed

pinefarm.tools.set_grid_metadata(grid, entries=None, entries_from_file=None)[source]

Set metadata on a pineappl grid (in-place operation).

Parameters
  • input_grid (pineappl.grid.Grid) – input grid on which to set metadata

  • entries (dict) – mapping of key-value to store in the grid

  • entries_from_file (dict) – mapping of key-value pairs, whose value are file paths of which storing the content

pinefarm.tools.three_points = [0.5, 1.0, 2.0]

Three points prescription for scale variations.

pinefarm.tools.update_grid_metadata(input_file, output_file, entries=None, entries_from_file=None)[source]

Set metadata on a pineappl grid stored in a file, and save in a new one.

Parameters
  • input_file (path-like) – file storing input grid

  • output_file (path-like) – file to store the result

  • entries (dict) – mapping of key-value to store in the grid

  • entries_from_file (dict) – mapping of key-value pairs, whose value are file paths of which storing the content