Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature: Logging Updates #501

Draft
wants to merge 76 commits into
base: develop
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from 43 commits
Commits
Show all changes
76 commits
Select commit Hold shift + click to select a range
4fa83ef
update for begin-end labels
gardner48 Jun 8, 2024
151db50
use raw string
gardner48 Jun 8, 2024
2f39fe8
get history ranges
gardner48 Jun 8, 2024
22beea0
add log function example
gardner48 Jun 8, 2024
92f243a
update logging output
gardner48 Jun 8, 2024
87a40fb
fix typo
gardner48 Jun 8, 2024
2051b42
update cvodes logging
gardner48 Jun 8, 2024
a831936
fix typo
gardner48 Jun 8, 2024
1ae3204
use __func__ in IDA logging
gardner48 Jun 8, 2024
7e699e9
use __func__ in IDAS logging
gardner48 Jun 8, 2024
60c5b37
add begin-end step logging IDA
gardner48 Jun 8, 2024
4bd27d8
add begin-end step logging IDAS
gardner48 Jun 8, 2024
fa056c9
make logging levels more consistent
gardner48 Jun 8, 2024
2fd347a
add begin-end step logging ARKODE
gardner48 Jun 8, 2024
0c02993
get mri history and add example
gardner48 Jun 8, 2024
5bc9f45
clean up
gardner48 Jun 8, 2024
1e3ba5d
formatting
gardner48 Jun 8, 2024
9b31c76
guard against non-existant keys
gardner48 Jun 8, 2024
0c05c91
plot multiple files
gardner48 Jun 8, 2024
530bd25
update help docs in examples
gardner48 Jun 8, 2024
b21f8e1
remove end-step log entry
gardner48 Jun 8, 2024
9627a03
update arkstep stage logging
gardner48 Jun 9, 2024
1dd2f01
formatting
gardner48 Jun 9, 2024
24e318e
update erkstep stage logging
gardner48 Jun 9, 2024
9afa485
add logging macros
gardner48 Jun 14, 2024
041b64c
update some ARKODE logging
gardner48 Jun 14, 2024
87163b4
more ARKODE logging updates
gardner48 Jun 14, 2024
154e46c
log vector array macro
gardner48 Jun 14, 2024
e5fcc27
more ARKODE logging updates
gardner48 Jun 14, 2024
9d44868
formatting
gardner48 Jun 14, 2024
2beeae1
update ARKODE LS logging
gardner48 Jun 14, 2024
44cf8d4
update CVODE logging
gardner48 Jun 14, 2024
a044472
update CVODES logging
gardner48 Jun 14, 2024
7b9e9fe
formatting
gardner48 Jun 14, 2024
64c8dad
update IDA logging
gardner48 Jun 15, 2024
da23747
update some IDAS logging
gardner48 Jun 15, 2024
4ff55f5
more IDAS logging updates
gardner48 Jun 15, 2024
484c4a6
update KINSOL logging
gardner48 Jun 15, 2024
01af2a1
update LS and NLS logging
gardner48 Jun 15, 2024
a134475
logging fixes
gardner48 Jun 15, 2024
bb77c6f
move stage logging to info level
gardner48 Jun 15, 2024
8c62115
parse stage logging output
gardner48 Jun 15, 2024
9614db8
formatting
gardner48 Jun 15, 2024
5c1b222
skip empty payload
gardner48 Jun 21, 2024
ccf0bbe
clean up vaiable names, comments
gardner48 Jun 21, 2024
3349578
update print formatting
gardner48 Jun 21, 2024
3d173f0
move Newton logging to info level
gardner48 Jun 21, 2024
f3e9e55
initial nonlinear solver parsing
gardner48 Jun 21, 2024
2cca1dc
use dict for NLS data
gardner48 Jun 21, 2024
5f79bb3
update logging output
gardner48 Jun 21, 2024
a0aeb9c
initial linear solver parsing
gardner48 Jun 22, 2024
532b546
initial linear solver logging updates
gardner48 Jun 22, 2024
89103ab
formatting
gardner48 Jun 22, 2024
1c29c6d
update nonlinear solver logging
gardner48 Jun 22, 2024
1204d1d
add empty dict when creating a new list
gardner48 Jun 22, 2024
4a30910
update var names
gardner48 Jun 22, 2024
9fba618
logging updates
gardner48 Jun 24, 2024
c8d6045
Add class to help with parsing log data
gardner48 Jun 24, 2024
60793b2
correct comment
gardner48 Jun 24, 2024
77d12a5
update comments
gardner48 Jun 24, 2024
0484219
formatting
gardner48 Jun 24, 2024
782de72
update function to print the log
gardner48 Jun 24, 2024
d0aafa3
update PCG logging
gardner48 Jun 25, 2024
f9a4305
update fixed-point logging
gardner48 Jun 25, 2024
25a1544
update spbcgs logging
gardner48 Jun 25, 2024
5a3b54f
add retval to failed spgmr log
gardner48 Jun 25, 2024
cc6d7f8
update spfgmr logging
gardner48 Jun 25, 2024
1b6bb17
update sptfqmr logging
gardner48 Jun 25, 2024
d361db0
formatting
gardner48 Jun 25, 2024
e667e61
fix typos, apply formatting
gardner48 Jun 25, 2024
da98824
Merge branch 'develop' into feature/logging-updates
gardner48 Jun 30, 2024
31ad3f4
move scripts
gardner48 Jun 30, 2024
90d2b42
update imports
gardner48 Jun 30, 2024
8ae53d7
ignore pycache
gardner48 Jun 30, 2024
3f790ce
Merge branch 'develop' into feature/logging-updates
gardner48 Jul 16, 2024
ac7903c
clean up comments, remove debugging code
gardner48 Jul 16, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
163 changes: 163 additions & 0 deletions scripts/sundialsdev/log_example.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,163 @@
#!/usr/bin/env python3
# -----------------------------------------------------------------------------
# Programmer(s): David J. Gardner @ LLNL
# -----------------------------------------------------------------------------
# SUNDIALS Copyright Start
# Copyright (c) 2002-2024, Lawrence Livermore National Security
# and Southern Methodist University.
# All rights reserved.
#
# See the top-level LICENSE and NOTICE files for details.
#
# SPDX-License-Identifier: BSD-3-Clause
# SUNDIALS Copyright End
# -----------------------------------------------------------------------------
# Example script demonstrating how to use Python functions to extract and plot
# logs produced by the SUNLogger for adaptive integrators.
# -----------------------------------------------------------------------------

def main():

import argparse
import matplotlib.pyplot as plt
import matplotlib.ticker as tik

import logs as sunlog

parser = argparse.ArgumentParser(description='Plots')

parser.add_argument('logfiles', type=str, nargs='+',
help='Log files to plot')

parser.add_argument('--val', type=str, default='h',
choices=['h', 'q', 'dsm'],
help='Value to plot (default: %(default)s)')

parser.add_argument('--step-range', type=int, nargs=2,
default=None, metavar=('LOWER_BOUND', 'UPPER_BOUND'),
help='Step range to plot')

parser.add_argument('--time-range', type=float, nargs=2,
default=None, metavar=('LOWER_BOUND', 'UPPER_BOUND'),
help='Time range to plot')

parser.add_argument('--step-number', action='store_true',
help='Plot value vs step number')

parser.add_argument('--scatter', action='store_true',
help='Create scatter plot')

parser.add_argument('--logx', action='store_true',
help='Use log scale for x-axis')

parser.add_argument('--logy', action='store_true',
help='Use log scale for y-axis')

parser.add_argument('--labels', type=str, nargs='+',
help='Plot labels')

parser.add_argument('--save', type=str, nargs='?', const='fig.pdf',
default=None, metavar='FILE_NAME',
help='''Save figure to file''')

# parse command line args
args = parser.parse_args()

fig, ax = plt.subplots()
colors = plt.get_cmap("tab10")

for idx, lf in enumerate(args.logfiles):

# parse log file
log = sunlog.log_file_to_list(lf)

# get successful step data
steps_s, times_s, vals_s = sunlog.get_history(log, args.val, 'success',
step_range=args.step_range,
time_range=args.time_range)

# get data for error test failures
steps_etf, times_etf, vals_etf = sunlog.get_history(log, args.val, 'failed error test',
step_range=args.step_range,
time_range=args.time_range)

# get data for solver failures
steps_sf, times_sf, vals_sf = sunlog.get_history(log, args.val, 'failed solve',
step_range=args.step_range,
time_range=args.time_range)

# plot log data
if args.step_number:
x_s = steps_s
x_etf = steps_etf
x_sf = steps_sf
else:
x_s = times_s
x_etf = times_etf
x_sf = times_sf

if len(args.logfiles) == 1:
s_color = 'green'
etf_color = 'red'
sf_color = 'darkorange'
else:
s_color = colors(idx)
etf_color = s_color
sf_color = s_color

if args.labels:
s_label = f'{args.labels[idx]} successful'
etf_label = f'{args.labels[idx]} error test failed'
sf_label = f'{args.labels[idx]} solver failed'
else:
s_label = 'successful'
etf_label = 'error test failed'
sf_label = 'solver failed'

# plot successful data
if args.scatter:
ax.scatter(x_s, vals_s, color=s_color, marker='o', label=s_label,
zorder=0.1)
else:
ax.plot(x_s, vals_s, color=s_color, marker='.', label=s_label,
zorder=0.1)

# always add failures as scatter plot
ax.scatter(x_etf, vals_etf, color=etf_color, marker='x', label=etf_label,
zorder=0.2)

ax.scatter(x_sf, vals_sf, color=sf_color, marker='d', label=sf_label,
zorder=0.2)

if args.logx:
ax.set_xscale("log")
if args.logy:
ax.set_yscale("log")

if args.step_number:
ax.set_xlabel("step")
else:
ax.set_xlabel("time")

if args.val == 'h':
ax.set_ylabel("step size")
elif args.val == 'q':
ax.set_ylabel("order")
ax.yaxis.set_major_locator(tik.MaxNLocator(integer=True))
elif args.val == 'dsm':
ax.set_ylabel("LTE estimate")

ax.legend(loc='best')

ax.grid(alpha=0.3, linestyle='--')

if args.save:
plt.savefig(args.save, bbox_inches='tight')
else:
plt.show()


# run the main routine
if __name__ == '__main__':
import sys
sys.exit(main())
83 changes: 83 additions & 0 deletions scripts/sundialsdev/log_example_mri.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
#!/usr/bin/env python3
# -----------------------------------------------------------------------------
# Programmer(s): David J. Gardner @ LLNL
# -----------------------------------------------------------------------------
# SUNDIALS Copyright Start
# Copyright (c) 2002-2024, Lawrence Livermore National Security
# and Southern Methodist University.
# All rights reserved.
#
# See the top-level LICENSE and NOTICE files for details.
#
# SPDX-License-Identifier: BSD-3-Clause
# SUNDIALS Copyright End
# -----------------------------------------------------------------------------
# Example script demonstrating how to use Python functions to extract and plot
# logs produced by the SUNLogger with an MRI method.
# -----------------------------------------------------------------------------

def main():

import argparse
import matplotlib.pyplot as plt

import logs as sunlog

parser = argparse.ArgumentParser(description='Plots')

parser.add_argument('logfile', type=str,
help='Log file to plot')

parser.add_argument('--step-number', action='store_true',
help='Plot value vs step number')

parser.add_argument('--step-range', type=int, nargs=2,
default=None, metavar=('LOWER_BOUND', 'UPPER_BOUND'),
help='Step range to plot')

parser.add_argument('--time-range', type=float, nargs=2,
default=None, metavar=('LOWER_BOUND', 'UPPER_BOUND'),
help='Time range to plot')

parser.add_argument('--save', type=str, nargs='?', const='fig.pdf',
default=None, metavar='FILE_NAME',
help='''Save figure to file''')

# parse command line args
args = parser.parse_args()

# parse log file
log = sunlog.log_file_to_list(args.logfile)

# plot log data
steps, times, vals = sunlog.get_history(log, 'h',
step_range=args.step_range,
time_range=args.time_range)

if args.step_number:
x = steps
else:
x = times

fig, ax = plt.subplots()

ax.scatter(x, vals, color='green', marker='o')

if args.step_number:
ax.set_xlabel("step")
else:
ax.set_xlabel("time")

ax.set_ylabel("step size")
ax.grid(alpha=0.3, linestyle='--')

if args.save:
plt.savefig(args.save, bbox_inches='tight')
else:
plt.show()


# run the main routine
if __name__ == '__main__':
import sys
sys.exit(main())
Loading
Loading