ekobox.genpdf package

Create fake PDF sets for debugging.

ekobox.genpdf.take_data(parent_pdf_set: str | dict | None = None, members: bool = False, xgrid: List[float] | None = None, evolgrid: List[Tuple[float, int]] | None = None)[source]

Auxiliary function for generate_pdf.

It provides the info, the heads of the member files and the blocks to be generated to generate_pdf.

Returns:

  • info (dict) – info dictionary

  • heads (list(str)) – heads of member files if necessary

  • blocks (list(dict)) – data blocks

ekobox.genpdf.generate_pdf(name: str, labels: List[int], parent_pdf_set=None, members=False, info_update=None, install: bool = False, xgrid: List[float] | None = None, evolgrid: List[Tuple[float, int]] | None = None)[source]

Generate a new PDF from a parent PDF with a set of flavors.

If parent_pdf_set is the name of an available PDF set, it will be used as parent. In order to use the toy PDF as parent, it is enough to set parent_pdf_set to “toy”. In order to use the toy Polarized PDF as parent, it is enough to set parent_pdf_set to “toy_pol”. If parent_pdf_set is not specified, a debug PDF constructed as x * (1-x) for every flavor will be used as parent. It is also possible to provide custom functions for each flavor in the form of a dictionary: {pid: f(x,Q2)}.

With labels it is possible to pass a list of PIDs or evolution basis combinations to keep in the generated PDF. In order to project on custom combinations of PIDs, it is also possible to pass a list containing the desired factors for each flavor.

The default behavior is to generate only one member for a PDF set (the zero member) but it can be changed setting to True the members flag.

The info_update argument is a dictionary and provide to the user as a way to change the info file of the generated PDF set. If a key of info_update matches with one key of the standard info file, the information are updated, otherwise they are simply added.

Turning True the value of the install flag, it is possible to automatically install the generated PDF to the lhapdf directory. By default install is False.

Examples

To generate a PDF with a fixed function f(x,Q2) for some flavors you can use the following snippet:

>>> # f = lambda x,Q2 ... put the desired function here
>>> # mask = [list of active PIDs]
>>> generate_pdf(name, labels, parent_pdf_set={pid: f for pid in mask})

The API also provides the possibility to extract arbitrary flavor combinations: using the debug PDF settings we can construct a “anti-QED-singlet” combination that is usefull in debugging DIS codes since it does not couple in LO, but only through the pure-singlet contributions (starting at NNLO)

>>> from eko import basis_rotation as br
>>> from ekobox import genpdf
>>> import numpy as np
>>> anti_qed_singlet = np.zeros_like(br.flavor_basis_pids, dtype=np.float_)
>>> anti_qed_singlet[br.flavor_basis_pids.index(1)] = -4
>>> anti_qed_singlet[br.flavor_basis_pids.index(-1)] = -4
>>> anti_qed_singlet[br.flavor_basis_pids.index(2)] = 1
>>> anti_qed_singlet[br.flavor_basis_pids.index(-2)] = 1
>>> genpdf.generate_pdf("anti_qed_singlet", [anti_qed_singlet])
ekobox.genpdf.install_pdf(name)[source]

Install set into LHAPDF.

The set to be installed has to be in the current directory.

Parameters:

name (str) – source pdf name

ekobox.genpdf.generate_block(xfxQ2: Callable, xgrid: List[float], sorted_q2grid: List[float], pids: List[int]) dict[source]

Generate an LHAPDF data block from a callable.

Submodules

ekobox.genpdf.cli module

ekobox.genpdf.export module

PDF set writer.

ekobox.genpdf.export.list_to_str(ls, fmt='%.6e')[source]

Convert a list of numbers to a string.

Parameters:
Returns:

final string

Return type:

str

ekobox.genpdf.export.array_to_str(ar)[source]

Convert an array of numbers to a string.

Parameters:

ar (list(list(float))) – array

Returns:

final string

Return type:

str

ekobox.genpdf.export.dump_blocks(name, member, blocks, pdf_type=None)[source]

Write LHAPDF data file.

Parameters:
  • name (str or os.PathLike) – target name or path

  • member (int) – PDF member

  • blocks (list(dict)) – pdf blocks of data

  • inherit (str) – str to be copied in the head of member files

ekobox.genpdf.export.dump_info(name, info)[source]

Write LHAPDF info file.

NOTE: Since LHAPDF info files are not truely yaml files, we have to use a slightly more complicated function to dump the info file.

Parameters:
  • name (str or os.Pathlike) – target name or path

  • info (dict) – info dictionary

ekobox.genpdf.export.dump_set(name, info, member_blocks, pdf_type_list=None)[source]

Dump a whole set.

Parameters:
  • name (str) – target name

  • info (dict) – info dictionary

  • member_blocks (list(list(dict))) – blocks for all members

  • pdf_type (list(str)) – list of strings to be copied in the head of member files

ekobox.genpdf.flavors module

Collection of flavor tools.

ekobox.genpdf.flavors.pid_to_flavor(pids)[source]

Create flavor representations from PIDs.

Parameters:

pids (list(int)) – active PIDs

Returns:

list of reprentations for each PID

Return type:

numpy.ndarray

ekobox.genpdf.flavors.evol_to_flavor(labels)[source]

Create flavor representations from evolution members.

Parameters:

labels (list(str)) – active evolution distributions

Returns:

list of reprentations for each distribution

Return type:

numpy.ndarray

ekobox.genpdf.flavors.project(blocks, reprs)[source]

Project some combination of flavors defined by reprs from the blocks.

Parameters:
  • blocks (list(dict)) – PDF blocks

  • reprs (list(int)) – active distributions in flavor representation

Returns:

filtered blocks

Return type:

list(dict)

ekobox.genpdf.flavors.is_evolution_labels(labels)[source]

Check whether the labels are provided in evolution basis.

Parameters:

labels (list()) – list of labels

Returns:

is evolution basis

Return type:

bool

ekobox.genpdf.flavors.is_pid_labels(labels)[source]

Check whether the labels are provided in flavor basis.

Parameters:

labels (list()) – list of labels

Returns:

is flavor basis

Return type:

bool

ekobox.genpdf.load module

PDF set elements loaders.

ekobox.genpdf.load.load_info_from_file(pdfset_name)[source]

Load the info file from a parent pdf.

Parameters:

pdfset_name (str) – parent pdf name

Returns:

info dictionary

Return type:

dict

ekobox.genpdf.load.load_blocks_from_file(pdfset_name, member)[source]

Load a pdf from a parent pdf.

Parameters:
  • pdfset_name (str) – parent pdf name

  • member (int) – pdf member

Returns:

  • str – head of member file

  • list(dict) – pdf blocks of data