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