scan – Scan Tripoli-4 outputs and select relevant results

Module performing a scan of Tripoli-4 output listing in order to only keep relevant parts of it = results to be used for V&V or analysis or the run.

Summary

  • Quickly reads the results file

  • Recognize beginning and end of results sections

  • Get the required number of batchs

  • Get the edition batch numbers (if exists)

Use of scan

To use this module you need to create a Scanner object giving at least the path to the file you want to read. This file should be a Tripoli-4 output containing at least the flags precised in Caveats.

>>> import os
>>> from valjean.eponine.tripoli4.scan import Scanner
>>> results = Scanner(os.path.join(work_dir, 'spam.res'))
>>> results.normalend
True
>>> len(results)
1
>>> results.times['initialization_time']
7

The expected key of the Scanner object is the batch number, not an index. If you have the index you need to obtain the corresponding batch number first.

>>> 'simulation time' in results[10]  # batch number = 10
True
>>> 'simulation time' in results[-1]  # -1 can only be an index, like 0
Traceback (most recent call last):
    ...
KeyError: -1
>>> 'simulation time' in results[results.batch_number(-1)]
True

Note

It will probably be better to directly load a test file…

Caveats

Beginning and end of results sections

Important for the scan: results will be kept

  • from “RESULTS ARE GIVEN”

  • to an end flag available in the list Scanner.end_flags. Possibilities are:

    • Default end flag is "simulation time";

    • For exploitation jobs use "exploitation time" (example: Green bands);

    • for jobs running in parallel, "elapsed time" will also appear, after "simulation time" normal.

Module API

valjean.eponine.tripoli4.scan.profile(fmem)[source]

Deactivate profiling if not required in command line.

class valjean.eponine.tripoli4.scan.PhEmEpBalanceOutput[source]

Class to store photon-electron-positron balance.

__init__()[source]
add_line(line)[source]

Add line to the photon electron positron output and counts.

class valjean.eponine.tripoli4.scan.HomogMatOutput[source]

Class to store the homogenized material output.

__init__()[source]
add_line(line)[source]

Add line to the homogenized material output and count.

class valjean.eponine.tripoli4.scan.BatchResultScanner(current_batch, para, line)[source]

Class to build batchs collection.

Parameters:
  • current_batch (int) – current batch number

  • para (bool) – flag to identify outputs run in parallel

  • line (str) – current line in file

Note

  • current_batch normally refers to lines before flag “RESULTS ARE GIVEN”. They can be used if “Edition after batch number” does not appear in the file.

  • line should contain “RESULTS ARE GIVEN” here. It is used to initialize the list of strings corresponding to the result block.

__init__(current_batch, para, line)[source]
build_result(line)[source]

Scan line to build batch result: mainly deals with specific patterns and store line.

Parameters:

line (str) – last line to be taken into account

check_batch_number()[source]

Check batch number value and replace it by current value or by the greater value if needed.

get_result()[source]

Send result. Called if end flag has been found, add last line and concatenates result.

Returns:

string build from list of strings junction

exception valjean.eponine.tripoli4.scan.ScannerException[source]

An error that may be raised by the Scanner class.

class valjean.eponine.tripoli4.scan.Scanner(fname, end_flag='')[source]

Class to scan the Tripoli-4 listing and keep the relevant parts of it like results per batch used for edition or times.

There are no class variables, but instance variables (initialized when the object is built or when the file is read). They are directly accessible from the object. Main results are accessible directly from the Scanner object.

Instance variables:

fname (str)

name of the file that will be scanned

batches (dict)

keep the number of batches and the packet_length (read from file fname)

normalend (bool)

presence of “NORMAL COMPLETION”

end_flags (list (str))

possible end flags to stop the saving of results

para (bool)

True in parallel mode

countwarnings (int)

count number of warnings (for statistics)

counterrors (int)

count number of errors (for statistics)

times (collections.OrderedDict)

save times (initialization, simulation, exploitation and elapsed if exists). Mandatory ones are 'initialization time' and 'simulation time' or 'exploitation time'. 'elapsed time' only appears in listings from parallel jobs.

last_generator_state (str)

keep the random generator state (not included in the result as given after endflag)

phemep_balance (dict)

keep the photon electron positron balance as str indexed by batch number

homog_mat (dict)

keep the homogenized material dump as str indexed by batch number

Available methods:

Scanner inherits from collections.abc.Mapping so many methods are implemented or available by default: keys, items, values, get, __contains__ (used via in). __getitem (used with []), __iter__ (when iterators are required), __len__ and __reversed__ are redefined.

This class points on the collections.OrderedDict that it contains. The keys are the available batch numbers in the Tripoli-4 output, obtained using scan_obj.keys().

__init__(fname, end_flag='')[source]

Initialize the instance from the file fname, meaning reads the file and store the relevant parts of it, i.e. result block for each batch edition.

Results are stored in an internal collections.OrderedDict: {batch_number_1: 'result_1', batch_number_2: 'result_2', ...}

  • batch_number_* is int

  • result_* is str

  • Order follows the listing order, so increasing batch_number

Members needed at initialization:

Parameters:
  • fname (str) – name of the input file

  • end_flag (str) – end flag of the results block in Tripoli-4 listing

__getitem__(batch_number)[source]

Get result corresponding to batch_number.

A warning is printed if the last batch_number doesn’t correspond to the number of batchs required.

Parameters:

batch_number (int) – batch number (>0), corresponding the keys of Scanner.

Raises:

KeyError – if batch_number does not exist (for example if confusion between batch_number and batch_index using -1 or 0)

Use: Scanner[X]

__iter__()[source]

Iteration over the collection of results, on the keys to match dict and collections.OrderedDict behaviour.

__len__()[source]

Return length of the collection of results, equivalent to get the number of edited batchs.

__reversed__()[source]

Reversed the collections.OrderedDict order (easier to get last element).

batch_index(batch_number)[source]

Get the index of the batch_number in the results list.

batch_number(batch_index)[source]

Get the batch number from the batch index.

fatal_error()[source]

Return the fatal error message if found.

global_variables(batch_number)[source]

Return a dictionary of the global quantities in the TRIPOILI-4 output:

  • warnings

  • errors

  • number of tasks (to distinguish MONO and PARA for example)

  • normal end

  • required batches

  • partial (if the job as been stopped)

  • batch number, especially when ‘edition after batch number’ is not in the Tripoli-4 output

  • t4_file: path to the scanned file

  • times of the required batch (can be simulation time, initialisation time, elapsed time)

Parameters:

batch_number (int) – batch number (used for times)

Return type:

dict

print_statistics()[source]

Print statistics of the listing scanned: normal end, number of warnings and errors.

check_times()[source]

Check times.

If the results come from a parallel job, the times dictionary should contain the 'elapsed_time' key. In all kind of outputs or 'simulation_time' or 'exploitation_time' should be found (in parallel case the only possibility is in reality 'simulation_time'). Finally, while 'initialization_time' value is an int as occuring only once, the others are lists with length equal to the number of batches in the edition for 'simulation_time' and 'exploitation_time' and equal to the number of batches + 1 for 'elapsed_time'. If all these checks are successful True is returned, else False.

Return type:

bool