Repository navigation
Add SU2_MON history file monitor #2988
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
Merged
Merged
Changes from all commits
Commits
Show all changes
25 commits
Select commit
Hold shift + click to select a range
a5a0f42
Add SU2_MON history file monitor
bigfooted 513bdfd
Potential fix for pull request finding 'CodeQL / Unused import'
bigfooted 912866a
pre-commit
bigfooted e272352
Merge branch 'feature_monitor' of https://github.com/su2code/SU2 into…
bigfooted f50e93b
Revert unrelated pre-commit reformatting and black bump
bigfooted 0bd680f
SU2_MON: fix review findings, add tests and install entries
bigfooted 6db81b5
Revert unrelated formatting in test_aeroacoustics.py
bigfooted 5aeda01
SU2_MON: time-iteration switch, default when Time_Iter is present
bigfooted 4d17f15
SU2_MON: import matplotlib.figure explicitly
bigfooted b30f917
SU2_MON: silence the KDE ThumbCreator service warning
bigfooted fcbc647
Potential fix for pull request finding 'CodeQL / Module is imported w…
bigfooted 4b9af07
SU2_MON: black formatting
bigfooted d52521f
Merge branch 'feature_monitor' of https://github.com/su2code/su2 into…
bigfooted 821f3bb
Merge branch 'develop' into feature_monitor
bigfooted 6af0a4e
Merge branch 'develop' into feature_monitor
bigfooted 472b188
Merge branch 'develop' into feature_monitor
bigfooted f410dd3
SU2_MON: address review comments
bigfooted 2f2ef65
Merge branch 'develop' into feature_monitor
bigfooted 387790b
CI: run the SU2_MON tests as a standalone script
bigfooted f5e48ae
Merge branch 'feature_monitor' of https://github.com/su2code/su2 into…
bigfooted 5752e9e
Merge branch 'develop' into feature_monitor
rois1995 0f5fa75
Merge branch 'develop' into feature_monitor
rois1995 c673fe5
Merge branch 'develop' into feature_monitor
rois1995 d8d81f8
SU2_MON: rename ambiguous loop variable l (CodeFactor E741)
rois1995 42ecf66
Merge branch 'develop' into feature_monitor
rois1995 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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 | ||
| 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()) | ||
|
rois1995 marked this conversation as resolved.
Resolved
|
||
|
|
||
| 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() | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,2 @@ | ||
| #!/bin/bash | ||
| cd "$(dirname "$(readlink -f "$0")")" && python monitor.py "$@" |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.