n3fit.io package

Submodules

n3fit.io.input_utils module

Input validation and classes for the n3fit runcard

The parsers (declared at the end of the file as parse_) should be used.

class n3fit.io.input_utils.DebugOptions(log_level: str = 'info', printeach: int = 100, timer: bool = False, print_logs: bool = False)[source]

Bases: object

Parsed debug_options namespace of the n3fit runcard.

All debug-related options should live in this object, which should be passed around to the internal fitting routines.

Variables:
  • log_level (str) – level of the n3fit logger

  • printeach (int) – print the training/validation stats every printeach epochs

  • timer (bool) – enable the per-epoch timing callback independently of debug

  • print_logs (bool) – force the per-epoch stats to be printed to stdout

log_level: str = 'info'
property logger_level
print_logs: bool = False
property print_summary: bool

Whether the network summaries should be printed. Print only for info and debug. Note that hyperopt always supresses the network summaries.

printeach: int = 100
timer: bool = False
n3fit.io.input_utils.parse_debug_options(debug_options=None)[source]

n3fit.io.writer module

Module containing functions dedicated to the write down of the output of n3fit

The goal is to generate the same folder/file structure as the old nnfit code so previously active scripts can still work.

class n3fit.io.writer.SuperEncoder(*, skipkeys=False, ensure_ascii=True, check_circular=True, allow_nan=True, sort_keys=False, indent=None, separators=None, default=None)[source]

Bases: JSONEncoder

Custom json encoder to get around the fact that np.float32 =/= float

default(o)[source]

Implement this method in a subclass such that it returns a serializable object for o, or calls the base implementation (to raise a TypeError).

For example, to support arbitrary iterators, you could implement default like this:

def default(self, o):
    try:
        iterable = iter(o)
    except TypeError:
        pass
    else:
        return list(iterable)
    # Let the base class default method raise the TypeError
    return super().default(o)
class n3fit.io.writer.WriterWrapper(replica_numbers, pdf_objects, stopping_object, all_chi2s, theory, timings, trials)[source]

Bases: object

write_data(save_path, fitname, weights_name)[source]

Save all the data of a fit, for all replicas.

Parameters:
  • save_path – path for the fit results, ex: ${PWD}/runcard_name/nnfit

  • fitname – name of the fit, ex: Basic_runcard

  • weights_name – name of the file to save weights to, if not empty

n3fit.io.writer.evln2lha(evln, nf=6)[source]
n3fit.io.writer.jsonfit(best_epoch, positivity_status, preprocessing, arc_lengths, integrability_numbers, tr_chi2, vl_chi2, true_chi2, stop_epoch, timing, hyperparam_info)[source]

Generates a dictionary containing all relevant metadata for the fit

Parameters:
  • best_epoch (int) – epoch at which the best fit was found

  • positivity_status (str) – string describing the positivity status of the fit

  • preprocessing (dict) – dictionary of the preprocessing factors

  • arc_lengths (list) – list of the arc lengths of the different PDFs

  • integrability_numbers (list) – list of the integrability numbers of the different PDFs

  • tr_chi2 (float) – chi2 for the training

  • vl_chi2 (float) – chi2 for the validation

  • true_chi2 (float) – chi2 for the exp (unreplica’d data)

  • epoch_stop (int) – epoch at which the stopping stopped (not the one for the best fit!)

  • timing (dict) – dictionary of the timing of the different events that happened

  • hyperparam_info (dict) – dictionary of hyperparameter settings

n3fit.io.writer.storefit(pdf_object, replica, out_path, theory)[source]

One-trick function which generates all output in the NNPDF format so that all other scripts can still be used.

Parameters:
  • pdf_object – N3PDF object constructed from the pdf_model that receives as input a point in x and returns an array of 14 flavours

  • replica – the replica index

  • out_path – the path where to store the output

  • theory – theory information of the fit

n3fit.io.writer.version()[source]

Generates a dictionary with misc version info for this run