Logparser: Introduction#

This simple example demonstrates how to analyze the OGS (OpenGeoSys) log output to extract performance information regarding various computational parts of OGS. Here we utilize the project file from the benchmark titled: OGS: Constant viscosity (Hydro-Thermal)

Complete example#

For detailed explanation see all sections below.

import pandas as pd

from ogstools.examples import (
    log_const_viscosity_thermal_convection,
)
from ogstools.logparser import (
    fill_ogs_context,
    parse_file,
    time_step_vs_iterations,
)

records = parse_file(log_const_viscosity_thermal_convection)
df_records = pd.DataFrame(records)
df_log = fill_ogs_context(df_records)
df_ts_it = time_step_vs_iterations(df_log)
df_ts_it
iteration_number
time_step
0 1
1 2
2 1
3 1
4 1
5 3
6 1
7 1
8 1
9 2
10 2
11 2
12 4
13 1
14 4
15 1
16 4
17 4
18 5
19 5
20 7
21 7
22 8
23 9
24 17
25 23
26 20


The log file#

Running ogs in the command line outputs the logs into the console output. With tee in Linux and Mac and Tee-Object in Windows Powershell the log gets directed into a file and into the console.

  • Linux/Mac: ogs <your_prj_file> | tee <your_log_file>

  • Windows: ogs <your_prj_file> | Tee-Object -FilePath <your_log_file>

For first step we recommend to use either `ogs -l info` or ogs - l debug. Make sure the log file does not contain ANSI escape (e.g.color) code. You can remove it with: cat ogs.log | sed 's/\x1b\[[0-9;]*m//g' > ogs.log

Parsing steps#

The functions ogstools.logparser.parse_file and ogstools.logparser.fill_ogs_context are explained in Logparser: Advanced topics. All predefined analyses need the result of fill_ogs_context. Here const_viscosity_thermal_convection_log is string representing the location of the ogs log file.

print(log_const_viscosity_thermal_convection)
/builds/ogs/tools/ogstools/ogstools/examples/logs/ConstViscosityThermalConvection.log
records = parse_file(log_const_viscosity_thermal_convection)
df_records = pd.DataFrame(records)
df_log = fill_ogs_context(df_records)

Use predefined analyses#

ogstools.logparser.time_step_vs_iterations is one of many predefined analyses. All possibilities are shown here: Logparser: Predefined Analyses.

Here we are interested in every time step of the simulation and how many iterations have been needed. The predefined analyses only work with logs from ogs run with level info or finer (debug), like ogs -l info or ogs - l debug. (see OGS Developer Guide - log and debug output

df_ts_it = time_step_vs_iterations(df_log)
# The result is a pandas.DataFrame. You may manipulate the dataframe to your
# needs with pandas functionality.
pd.set_option("display.max_rows", 8)  # for visualization only
df_ts_it
iteration_number
time_step
0 1
1 2
2 1
3 1
... ...
23 9
24 17
25 23
26 20

27 rows × 1 columns



Pandas to plot#

You can directly use plot ` <https://pandas.pydata.org/pandas-docs/stable/reference/api/pandas.DataFrame.plot.html>`_ from pandas.

df_ts_it.plot(grid=True)
plot 100 logparser intro
<Axes: xlabel='time_step'>

Total running time of the script: (0 minutes 0.098 seconds)