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
Open
bigfooted
wants to merge
16
commits into
develop
Choose a base branch
from
feature_monitor
base: develop
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
16 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 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
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,115 @@ | ||
| #!/usr/bin/env python3 | ||
|
|
||
| import importlib.util | ||
| import sys | ||
| import tempfile | ||
| import unittest | ||
| 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()) | ||
|
|
||
| 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(1)) | ||
| self.assertEqual(reader.names, ["rms[Rho]", "rms[RhoE]"], header) | ||
| self.assertEqual(reader.n, 2, 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_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.