-
Notifications
You must be signed in to change notification settings - Fork 16
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
Migrate PROCESS solver to new interface #1146
Migrate PROCESS solver to new interface #1146
Conversation
* ✨ process species additions * 🎨 improvements spurred by comments * ✅ add a test * 🐛 pass if process not installed * 🐛 pass if process not installed * Update bluemira/codes/process/api.py Co-authored-by: Harry Saunders <33317174+hsaunders1904@users.noreply.github.com> Co-authored-by: Harry Saunders <33317174+hsaunders1904@users.noreply.github.com>
This logging is more consistent with what's in PROCESS, solver and more specific about what's happening.
Parameters whose values contained a trailing comma could not be read by PROCESS. The file format is no longer supported by PROCESS, so we no longer support it either. Remove the trailing commas so the IN.DAT file is usable in tests.
This was causing the patched function being called in subsequent tests! Whoops
Mock out the PROCESS file reader so that the Teardown class's logic can be testing without PROCESS being installed.
PROCESS does not necessarily output all the values we need for a radial build. There are certainly some MFiles which are missing some parameters. Catch these cases and raise a better error.
The below was not needed. The files are not required to run the solver.
This will cause an error later on anyway, so the check is not needed.
One of the tests was passing, but because an error of a similar type was caught. Check the error message to make sure the right error is thrown.
This allows us to access the available run modes for a solver, without prior knowledge of which Solver class it is.
Codecov Report
@@ Coverage Diff @@
## hsaunders1904/956_move_existing_solvers_to_new_interface #1146 +/- ##
===========================================================================================
Coverage ? 75.22%
===========================================================================================
Files ? 185
Lines ? 21655
Branches ? 0
===========================================================================================
Hits ? 16289
Misses ? 5366
Partials ? 0 Continue to review full report at Codecov.
|
The look_and_feel.print_banner test fails if the git branch is too long. The long name caused a new line in the banner, which made the asserted banner length incorrect.
These had been removed as part of the refactor of the PROCESS API.
The mock was overwriting the PROCESS module, instead of patching it. The effect of this was causing a subsequent test to fail.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good I have nothing major to say. I will have a little run of the example just to get a feel for it
self.rebuild_RB_dict() | ||
|
||
def rebuild_RB_dict(self): # noqa :N802 | ||
""" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just a comment to flag that at some point we should try and remove the need for this, there is an issue somewhere about it I think can't find where. Probably should try and remove the majority of this wrapper when process finishes their api
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is it this one #722?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think it was a combination of that and #164 I was thinking of
Kudos, SonarCloud Quality Gate passed! 0 Bugs No Coverage information |
a2857f6
into
hsaunders1904/956_move_existing_solvers_to_new_interface
* Process api additions (#1055) * ✨ process species additions * 🎨 improvements spurred by comments * ✅ add a test * 🐛 pass if process not installed * 🐛 pass if process not installed * Update bluemira/codes/process/api.py Co-authored-by: Harry Saunders <33317174+hsaunders1904@users.noreply.github.com> Co-authored-by: Harry Saunders <33317174+hsaunders1904@users.noreply.github.com> * Fix PROCESS enum value typo CYRO -> CRYO * Add refactored Setup class for PROCESS solver * Add refactored Run class for PROCESS solver * Remove unused attribute in test class * Clean up logging in plasmod Run class This logging is more consistent with what's in PROCESS, solver and more specific about what's happening. * Write tests ahead of PROCESS Teardown refactor * Make PROCESS solver's Teardown tests pass * Add refactored PROCESS solver class * Remove old PROCESS solver implementation * Fix typo in test that was causing it to pass * Correct docstring in PROCESS solver * Remove trailing commas from PROCESS test IN.DAT Parameters whose values contained a trailing comma could not be read by PROCESS. The file format is no longer supported by PROCESS, so we no longer support it either. Remove the trailing commas so the IN.DAT file is usable in tests. * Fix PROCESS test not stopping mock.patch This was causing the patched function being called in subsequent tests! Whoops * Add tests for PROCESS run modes * Fix some find-replace errors * Make solver's Teardown testable without PROCESS Mock out the PROCESS file reader so that the Teardown class's logic can be testing without PROCESS being installed. * Catch case where PROCESS result missing param PROCESS does not necessarily output all the values we need for a radial build. There are certainly some MFiles which are missing some parameters. Catch these cases and raise a better error. * Resolve PROCESS solver TODO The below was not needed. The files are not required to run the solver. * Fix unused variable in PROCESS solver * Remove check for empty file This will cause an error later on anyway, so the check is not needed. * Fix misbehaving PROCESS tests One of the tests was passing, but because an error of a similar type was caught. Check the error message to make sure the right error is thrown. * Add missing docstrings to PROCESS Teardown * Remove unused constant in test * Replace old codes.interface module * Restore 'plot_radial_build' to PROCESS API * Add run_mode_cls property to Solver This allows us to access the available run modes for a solver, without prior knowledge of which Solver class it is. * Update codes.wrapper to use new Solver interface * Add __all__ imports to codes.plasmod * Use run and read directories in PROCESS Teardown * Fix file paths in PROCESS system tests * Update codes.interface tests * Add some missing docstrings in PROCESS solver * Fix flake8 warning in base.design * Fix test that fails for long git branch names The look_and_feel.print_banner test fails if the git branch is too long. The long name caused a new line in the banner, which made the asserted banner length incorrect. * Restore species methods to PROCESS solver These had been removed as part of the refactor of the PROCESS API. * Fix mocking of PROCESS module The mock was overwriting the PROCESS module, instead of patching it. The effect of this was causing a subsequent test to fail. * Remove superfluous comment * Use walrus operator to summarise if statement * Remove unused imports Co-authored-by: je-cook <81617086+je-cook@users.noreply.github.com>
* Process api additions (#1055) * ✨ process species additions * 🎨 improvements spurred by comments * ✅ add a test * 🐛 pass if process not installed * 🐛 pass if process not installed * Update bluemira/codes/process/api.py Co-authored-by: Harry Saunders <33317174+hsaunders1904@users.noreply.github.com> Co-authored-by: Harry Saunders <33317174+hsaunders1904@users.noreply.github.com> * Fix PROCESS enum value typo CYRO -> CRYO * Add refactored Setup class for PROCESS solver * Add refactored Run class for PROCESS solver * Remove unused attribute in test class * Clean up logging in plasmod Run class This logging is more consistent with what's in PROCESS, solver and more specific about what's happening. * Write tests ahead of PROCESS Teardown refactor * Make PROCESS solver's Teardown tests pass * Add refactored PROCESS solver class * Remove old PROCESS solver implementation * Fix typo in test that was causing it to pass * Correct docstring in PROCESS solver * Remove trailing commas from PROCESS test IN.DAT Parameters whose values contained a trailing comma could not be read by PROCESS. The file format is no longer supported by PROCESS, so we no longer support it either. Remove the trailing commas so the IN.DAT file is usable in tests. * Fix PROCESS test not stopping mock.patch This was causing the patched function being called in subsequent tests! Whoops * Add tests for PROCESS run modes * Fix some find-replace errors * Make solver's Teardown testable without PROCESS Mock out the PROCESS file reader so that the Teardown class's logic can be testing without PROCESS being installed. * Catch case where PROCESS result missing param PROCESS does not necessarily output all the values we need for a radial build. There are certainly some MFiles which are missing some parameters. Catch these cases and raise a better error. * Resolve PROCESS solver TODO The below was not needed. The files are not required to run the solver. * Fix unused variable in PROCESS solver * Remove check for empty file This will cause an error later on anyway, so the check is not needed. * Fix misbehaving PROCESS tests One of the tests was passing, but because an error of a similar type was caught. Check the error message to make sure the right error is thrown. * Add missing docstrings to PROCESS Teardown * Remove unused constant in test * Replace old codes.interface module * Restore 'plot_radial_build' to PROCESS API * Add run_mode_cls property to Solver This allows us to access the available run modes for a solver, without prior knowledge of which Solver class it is. * Update codes.wrapper to use new Solver interface * Add __all__ imports to codes.plasmod * Use run and read directories in PROCESS Teardown * Fix file paths in PROCESS system tests * Update codes.interface tests * Add some missing docstrings in PROCESS solver * Fix flake8 warning in base.design * Fix test that fails for long git branch names The look_and_feel.print_banner test fails if the git branch is too long. The long name caused a new line in the banner, which made the asserted banner length incorrect. * Restore species methods to PROCESS solver These had been removed as part of the refactor of the PROCESS API. * Fix mocking of PROCESS module The mock was overwriting the PROCESS module, instead of patching it. The effect of this was causing a subsequent test to fail. * Remove superfluous comment * Use walrus operator to summarise if statement * Remove unused imports Co-authored-by: je-cook <81617086+je-cook@users.noreply.github.com>
* Move plasmod solver to new interface (#1054) * Refactor test helper into new module * Use ParameterFrame not Dict in Task constructor * Start on Plasmod interface refactor - Setup * Add plasmod Run task The run_subprocess function has been moved to a separate utility. This allows us to mock our own `run_subprocess` function in tests, and not worry about if we want to change the implementation of how we run our shell commands. E.g., if we wanted to start using os.system rather than subprocess.Popen, for whatever reason. * Refactor plasmod solver interface's Teardown * Fix bug in run_subprocess + add test reminder * Fix param mappings in refactored Plasmod interface * Fix dataclass attribute/method ordering Apparently dataclass attributes need to be declared first for the corresponding kwarg to be added to the constructor. Declare the methods after the attributes to fix this. * Add missing Plasmod Teardown tests * Remove extraneous dict init in plasmod.params * Add refactored plasmod Solver class * Add end-to-end test for plasmod solver * Add 'cwol' to PlasmodOutput dataclass * Add test for error on bad Plasmod result flag * Add test for writing PlasmodInput params * Convert PlasmodInput models to enums on init * Create new PlasmodInputs on Solver.update_inputs This allows for the post-init processing to do its magic. * Fix typing in plasmod MODEL_MAP * Replace old plasmod Solver with refactored * Add warning if plasmod output param has no value Adds back change made in #1009 after refactor. * Split up large files in plasmod.solver * Allow using enum name to specify plasmod models * Warn when using unrecognised inputs in plasmod * Add get_profile back into plasmod.Solver This was temporarily removed as part of a refactor. * Add get_profiles method back into plasmod.Solver This had been temporarily removed during a refactor. * Add 'scalar_outputs' method to plasmod.Solver This replaces the previous 'get_raw_variables' function. Using a structure as an output means that users know exactly what attributes are allowed. IDEs can then make suggestions about attributes, and also spot typos that wouldn't be spotted using strings. * Allow param edits between calls of plasmod solver * Put modify_mappings back into plasmod solver * Flesh out plasmod Task constructor docstrings * Update plasmod example to use new solver interface * Add CodesSolver base class This is intended to replace the FileProgramInterface class, as part of the refactor of the solvers interface. * Move plasmod.Solver functionality to base class * Extract plasmod.Solver general setup to base class * Re-add 'jiter' as plasmod output parameter This had been lost in a refactor. * Separate profiles and scalars in plasmod outputs * Move plasmod exit code check to Teardown task This makes more sense than throwing when reading the outputs. * Undo change in plasmod example's transport model This was an accidental change made during a refactor. * Change to a better method in CodesTeardown * Use plasmod.Profiles enums in Sovler.get_profile This is in-line with the effort towards: "All text based choices should be enumified" #1044 * Remove resolved TODO * Write tests to resolve TODO * Resolve flake8 warnings * Resolve ambiguity in plasmod solver Setup var name This attempts to resolve the ambiguity around the 'input_file' variable name. * Update plasmod solver directory structure This is more consistent with the structure in PROCESS's solver * Fix plasmod example's get_profile usage * Fix sphinx build * Fix file path in flake8 ignores I'd forgotten to update the file path after moving the file. * Fix import in tests * Simplify import in plasmod example * Add missing type hint in CodesTask._run_subprocess * Add Optional to typing * Add better typing + docstrings to udpate_inputs * Migrate PROCESS solver to new interface (#1146) * Process api additions (#1055) * ✨ process species additions * 🎨 improvements spurred by comments * ✅ add a test * 🐛 pass if process not installed * 🐛 pass if process not installed * Update bluemira/codes/process/api.py Co-authored-by: Harry Saunders <33317174+hsaunders1904@users.noreply.github.com> Co-authored-by: Harry Saunders <33317174+hsaunders1904@users.noreply.github.com> * Fix PROCESS enum value typo CYRO -> CRYO * Add refactored Setup class for PROCESS solver * Add refactored Run class for PROCESS solver * Remove unused attribute in test class * Clean up logging in plasmod Run class This logging is more consistent with what's in PROCESS, solver and more specific about what's happening. * Write tests ahead of PROCESS Teardown refactor * Make PROCESS solver's Teardown tests pass * Add refactored PROCESS solver class * Remove old PROCESS solver implementation * Fix typo in test that was causing it to pass * Correct docstring in PROCESS solver * Remove trailing commas from PROCESS test IN.DAT Parameters whose values contained a trailing comma could not be read by PROCESS. The file format is no longer supported by PROCESS, so we no longer support it either. Remove the trailing commas so the IN.DAT file is usable in tests. * Fix PROCESS test not stopping mock.patch This was causing the patched function being called in subsequent tests! Whoops * Add tests for PROCESS run modes * Fix some find-replace errors * Make solver's Teardown testable without PROCESS Mock out the PROCESS file reader so that the Teardown class's logic can be testing without PROCESS being installed. * Catch case where PROCESS result missing param PROCESS does not necessarily output all the values we need for a radial build. There are certainly some MFiles which are missing some parameters. Catch these cases and raise a better error. * Resolve PROCESS solver TODO The below was not needed. The files are not required to run the solver. * Fix unused variable in PROCESS solver * Remove check for empty file This will cause an error later on anyway, so the check is not needed. * Fix misbehaving PROCESS tests One of the tests was passing, but because an error of a similar type was caught. Check the error message to make sure the right error is thrown. * Add missing docstrings to PROCESS Teardown * Remove unused constant in test * Replace old codes.interface module * Restore 'plot_radial_build' to PROCESS API * Add run_mode_cls property to Solver This allows us to access the available run modes for a solver, without prior knowledge of which Solver class it is. * Update codes.wrapper to use new Solver interface * Add __all__ imports to codes.plasmod * Use run and read directories in PROCESS Teardown * Fix file paths in PROCESS system tests * Update codes.interface tests * Add some missing docstrings in PROCESS solver * Fix flake8 warning in base.design * Fix test that fails for long git branch names The look_and_feel.print_banner test fails if the git branch is too long. The long name caused a new line in the banner, which made the asserted banner length incorrect. * Restore species methods to PROCESS solver These had been removed as part of the refactor of the PROCESS API. * Fix mocking of PROCESS module The mock was overwriting the PROCESS module, instead of patching it. The effect of this was causing a subsequent test to fail. * Remove superfluous comment * Use walrus operator to summarise if statement * Remove unused imports Co-authored-by: je-cook <81617086+je-cook@users.noreply.github.com> * Update power cycle solver for new api (#1167) * Update EUDEMO power cycle solver for new interface * Remove erroneously restored file after rebase A bad rebase restored a previously deleted file. Re-delete it * Update Solver API example (#1169) * Update Solver API example Updates the example to use a ParameterFrame. * Update PROCESS solver example * Tidy solvers with walrus operator * Fix quotation marks in PROCESS solver warning Co-authored-by: je-cook <81617086+je-cook@users.noreply.github.com>
Linked Issues
Partially addresses #956
Description
Re-writes the PROCESS solver with the new solver API. Also added are tests that do not require PROCESS being installed, so the tests can run in the CI.
There are a couple of changes to the
SolverABC
class - notably, use ofParameterFrame
s, and therun_mode_cls
abstract property. I intend to update the solver example to reflect this.After this has been merged, the next step is to rebase
hsaunders1904/956_move_existing_solvers_to_new_interface
and quickly update the Balance of Plant solver that went in recently. Also update the example mentioned above.Interface Changes
PROCESS solver moved to new API.
Checklist
I confirm that I have completed the following checks:
pytest tests --reactor
flake8
andblack .
sphinx-build -W documentation/source documentation/build