xref: /libCEED/examples/fluids/stdoutParsing.py (revision daadeac6547c0bce0e170b8a41c931051f52e9a3)
1# Copyright (c) 2017, Lawrence Livermore National Security, LLC.
2# Produced at the Lawrence Livermore National Laboratory. LLNL-CODE-734707.
3# All Rights reserved. See files LICENSE and NOTICE for details.
4#
5# This file is part of CEED, a collection of benchmarks, miniapps, software
6# libraries and APIs for efficient high-order finite element and spectral
7# element discretizations for exascale applications. For more information and
8# source code availability see http://github.com/ceed
9#
10# The CEED research is supported by the Exascale Computing Project 17-SC-20-SC,
11# a collaborative effort of two U.S. Department of Energy organizations (Office
12# of Science and the National Nuclear Security Administration) responsible for
13# the planning and preparation of a capable exascale ecosystem, including
14# software, applications, hardware, advanced system engineering and early
15# testbed platforms, in support of the nation's exascale computing imperative.
16
17import re
18import pandas as pd
19from pathlib import Path
20
21# Regex to parse STDOUT of the navierstokes run
22logreg = re.compile(
23    r".*(?:^Degree of FEM Space: (\d+)).*(?:^Global FEM nodes: (\d{2,})).*(?:^dm_plex_box_faces: (\S+)).*(?:^Time taken for solution: (\d*\.?\d+)).*(?:^Relative Error: (\d*\.?\d+))",
24    re.DOTALL | re.MULTILINE,
25)
26
27
28def parseFile(file):
29    """Returns dictionary of parsed logfile contents.
30
31    Parameters
32    ----------
33    file : Path-like object
34        Path to the file to be parsed.
35
36    Returns
37    -------
38    dict
39        Values of "dofs",  "time", "error", "degree", and "box_faces"'
40    """
41
42    values = {}
43    with file.open() as filer:
44        filestring = filer.read()
45    match = logreg.match(filestring)
46    values["degree"] = match[1]
47    values["dofs"] = match[2]
48    box_faceStr = match[3]
49    values["time"] = match[4]
50    values["error"] = match[5]
51
52    # Splitting box_face argument str into individual entries
53    box_faceList = box_faceStr.split(",")
54    for i, box_face in enumerate(box_faceList):
55        values["box_face" + str(i)] = box_face
56
57    return values
58
59
60if __name__ == "__main__":
61    # Directory location of log files
62    runlogDir = Path("./")
63
64    results = pd.DataFrame()
65    for file in runlogDir.glob("*.log"):
66        values = parseFile(file)
67        results = results.append(values, ignore_index=True)
68
69    # Convert string values to numeric type
70    results = results.apply(lambda col: pd.to_numeric(col, errors="coerce"))
71