Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
21 commits
Select commit Hold shift + click to select a range
a5a0f42
Add SU2_MON history file monitor
bigfooted Oct 17, 2026
513bdfd
Potential fix for pull request finding 'CodeQL / Unused import'
bigfooted Oct 17, 2026
912866a
pre-commit
bigfooted Oct 17, 2026
e272352
Merge branch 'feature_monitor' of https://github.com/su2code/SU2 into…
bigfooted Oct 17, 2026
f50e93b
Revert unrelated pre-commit reformatting and black bump
bigfooted Oct 23, 2026
0bd680f
SU2_MON: fix review findings, add tests and install entries
bigfooted Oct 23, 2026
6db81b5
Revert unrelated formatting in test_aeroacoustics.py
bigfooted Oct 23, 2026
5aeda01
SU2_MON: time-iteration switch, default when Time_Iter is present
bigfooted Oct 23, 2026
4d17f15
SU2_MON: import matplotlib.figure explicitly
bigfooted Oct 23, 2026
b30f917
SU2_MON: silence the KDE ThumbCreator service warning
bigfooted Oct 23, 2026
fcbc647
Potential fix for pull request finding 'CodeQL / Module is imported w…
bigfooted Oct 23, 2026
4b9af07
SU2_MON: black formatting
bigfooted Oct 23, 2026
d52521f
Merge branch 'feature_monitor' of https://github.com/su2code/su2 into…
bigfooted Oct 23, 2026
821f3bb
Merge branch 'develop' into feature_monitor
bigfooted Oct 24, 2026
6af0a4e
Merge branch 'develop' into feature_monitor
bigfooted Oct 29, 2026
472b188
Merge branch 'develop' into feature_monitor
bigfooted Oct 31, 2026
f410dd3
SU2_MON: address review comments
bigfooted Nov 14, 2026
2f2ef65
Merge branch 'develop' into feature_monitor
bigfooted Nov 14, 2026
387790b
CI: run the SU2_MON tests as a standalone script
bigfooted Nov 14, 2026
f5e48ae
Merge branch 'feature_monitor' of https://github.com/su2code/su2 into…
bigfooted Nov 14, 2026
5752e9e
Merge branch 'develop' into feature_monitor
rois1995 Nov 15, 2026
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
22 changes: 22 additions & 0 deletions .github/workflows/python-tests.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
name: Python Tests
on:
pull_request:
paths:
- "bin/monitor.py"
- "SU2_PY/tests/**"
- ".github/workflows/python-tests.yml"

jobs:
monitor:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v6
- name: Setup python
uses: actions/setup-python@v6
with:
python-version: '3.10'
- name: Install dependencies
run: pip install numpy pandas matplotlib
- name: Run monitor tests
run: python3 SU2_PY/tests/test_monitor.py
7 changes: 7 additions & 0 deletions SU2_PY/meson.build
Original file line number Diff line number Diff line change
Expand Up @@ -74,3 +74,10 @@ install_data(['SU2_Nastran/__init__.py',
install_dir: join_paths(get_option('bindir'), 'SU2_Nastran'))

install_subdir(['../externals/FADO'], install_dir: get_option('bindir'))

install_data(['../bin/monitor.py'],
install_dir: join_paths(get_option('bindir')))

install_data(['../bin/SU2_MON'],
install_dir: join_paths(get_option('bindir')),
install_mode: 'rwxr-xr-x')
138 changes: 138 additions & 0 deletions SU2_PY/tests/test_monitor.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,138 @@
#!/usr/bin/env python3

import importlib.util
import sys
import tempfile
import unittest
Comment thread
github-advanced-security[bot] marked this conversation as resolved.
Fixed
import unittest.mock
from pathlib import Path

import numpy as np

for module in (
"PyQt5",
"PyQt5.QtCore",
"PyQt5.QtGui",
"PyQt5.QtWidgets",
"matplotlib.backends.backend_qt5agg",
):
sys.modules.setdefault(module, unittest.mock.MagicMock())

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[P2] Import unittest.mock explicitly before using it

A fresh python3 SU2_PY/tests/test_monitor.py exits here with AttributeError: module 'unittest' has no attribute 'mock', before running any tests. Importing unittest alone does not load its mock submodule.

Please add import unittest.mock. Preloading that import in the runner lets all seven tests pass, so this has a one-line fix.


MODULE_PATH = Path(__file__).parents[2] / "bin" / "monitor.py"
SPEC = importlib.util.spec_from_file_location("su2_monitor", MODULE_PATH)
MONITOR = importlib.util.module_from_spec(SPEC)
SPEC.loader.exec_module(MONITOR)

NAMES = '"Inner_Iter","rms[Rho]","rms[RhoE]","CD"'
LEGACY = 'TITLE = "SU2 history"\nVARIABLES = ' + NAMES + '\nZONE T= "Convergence"\n'
TECPLOT = (
'TITLE = "SU2 history"\nVARIABLES = \\\n' + NAMES + '\nZONE T= "Convergence"\n'
)
CSV = NAMES + "\n"


def row(i):
return f"{i}, {-1.0 - 0.1 * i}, {-2.0 - 0.1 * i}, 0.5\n"


class MonitorTests(unittest.TestCase):
def setUp(self):
self.dir = tempfile.TemporaryDirectory()
self.path = Path(self.dir.name) / "history.csv"

def tearDown(self):
self.dir.cleanup()

def reader(self, text):
self.path.write_text(text)
reader = MONITOR.HistoryReader(str(self.path))
reader.update()
return reader

def test_header_formats(self):
for header in (LEGACY, TECPLOT, CSV):
reader = self.reader(header + row(0) + row(10) + row(20))
self.assertEqual(reader.names, ["rms[Rho]", "rms[RhoE]"], header)
self.assertEqual(reader.n, 3, header)
np.testing.assert_array_equal(reader.iters[:3], [0, 10, 20], header)

def test_time_iterations(self):
names = '"Time_Iter","Inner_Iter","rms[Rho]"\n'
body = "".join(
f"{t}, {i}, {-t - 0.1 * i}\n" for t in range(3) for i in range(4)
)
reader = self.reader(names + body)
self.assertTrue(reader.hasTime())
np.testing.assert_array_equal(reader.iters[: reader.n][:5], [0, 1, 2, 3, 0])
rows = reader.rowsFrom(1, byTime=True)
np.testing.assert_array_equal(reader.times[rows], [1, 2])
np.testing.assert_array_equal(reader.iters[rows], [3, 3])
self.assertFalse(self.reader(CSV + row(0) + row(1)).hasTime())

def test_steady_time_counter_does_not_advance(self):
names = '"Time_Iter","Inner_Iter","rms[Rho]"\n'
reader = self.reader(names + "".join(f"0, {i}, {-0.1 * i}\n" for i in range(5)))
self.assertTrue(reader.hasTime())
self.assertFalse(reader.timeAdvances())
unsteady = self.reader(names + "0, 0, -1\n1, 0, -2\n")
self.assertTrue(unsteady.timeAdvances())

def test_first_row_kept_when_it_passes_the_filter(self):
names = '"Time_Iter","Inner_Iter","rms[Rho]"\n'
reader = self.reader(names + "100, 0, -1\n")
np.testing.assert_array_equal(reader.rowsFrom(100, byTime=True), [0])

def test_partial_zone_line_is_deferred(self):
self.path.write_text(CSV + 'ZONE T="Conv')
reader = MONITOR.HistoryReader(str(self.path))
self.assertFalse(reader.update())
self.path.write_text(CSV + 'ZONE T="Convergence"\n' + row(0) + row(1))
self.assertTrue(reader.update())
self.assertEqual(reader.n, 2)

def test_incomplete_header_is_deferred(self):
self.path.write_text('TITLE = "x"\nVARIABLES = \\\n"Inner_Iter","rms[Rho]')
reader = MONITOR.HistoryReader(str(self.path))
self.assertFalse(reader.update())
self.assertIsNone(reader.cols)
self.path.write_text(TECPLOT + row(0))
self.assertTrue(reader.update())
self.assertEqual(reader.n, 1)

def test_sparse_iterations_and_start_filter(self):
reader = self.reader(CSV + row(0) + row(10) + row(20) + row(30))
np.testing.assert_array_equal(reader.iters[: reader.n], [0, 10, 20, 30])
rows = reader.rowsFrom(15)
np.testing.assert_array_equal(reader.iters[rows], [20, 30])

def test_incremental_append_and_incomplete_line(self):
reader = self.reader(CSV + row(0) + row(1))
with open(self.path, "a") as f:
f.write(row(2)[:5])
self.assertFalse(reader.update())
self.assertEqual(reader.n, 2)
with open(self.path, "a") as f:
f.write(row(2)[5:] + row(3))
version = reader.version
self.assertTrue(reader.update())
self.assertEqual(reader.n, 4)
self.assertGreater(reader.version, version)

def test_reset_invalidates_cache_key(self):
reader = self.reader(CSV + "".join(row(i) for i in range(50)))
version = reader.version
self.path.write_text(CSV + row(0) + row(1))
reader.update()
self.assertEqual(reader.n, 2)
self.assertGreater(reader.version, version)

def test_reset_without_complete_rows_changes_version(self):
reader = self.reader(CSV + "".join(row(i) for i in range(50)))
version = reader.version
self.path.write_text("")
reader.update()
self.assertGreater(reader.version, version)


if __name__ == "__main__":
unittest.main()
2 changes: 2 additions & 0 deletions bin/SU2_MON
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
#!/bin/bash
cd "$(dirname "$(readlink -f "$0")")" && python monitor.py "$@"
Loading
Loading