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'] 7The 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.
- class valjean.eponine.tripoli4.scan.HomogMatOutput[source]
Class to store the homogenized material output.
- class valjean.eponine.tripoli4.scan.BatchResultScanner(current_batch, para, line)[source]
Class to build batchs collection.
- Parameters:
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.
- 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
- 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 fromcollections.abc.Mapping
so many methods are implemented or available by default:keys
,items
,values
,get
,__contains__
(used viain
).__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 usingscan_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 intresult_*
is strOrder follows the listing order, so increasing
batch_number
Members needed at initialization:
- __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 betweenbatch_number
andbatch_index
using -1 or 0)
Use:
Scanner[X]
- __iter__()[source]
Iteration over the collection of results, on the keys to match
dict
andcollections.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).
- 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)
- 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:
- fname (