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

Issue 1500 print parameter info by submodel #3846

Conversation

cringeyburger
Copy link
Contributor

@cringeyburger cringeyburger commented Feb 28, 2024

Description

Further improved on "print_parameter_info" by implementing "by_submodel" feature which allow users to print parameters sub-model wise.

Fixes #1500 and supersedes #3628

Type of change

Please add a line in the relevant section of CHANGELOG.md to document the change (include PR #) - note reverse order of PR #s. If necessary, also add to the list of breaking changes.

  • New feature (non-breaking change which adds functionality)
  • Optimization (back-end change that speeds up the code)
  • Bug fix (non-breaking change which fixes an issue)

Key checklist:

  • No style issues: $ pre-commit run (or $ nox -s pre-commit) (see CONTRIBUTING.md for how to set this up to run automatically when committing locally, in just two lines of code)
  • All tests pass: $ python run-tests.py --all (or $ nox -s tests)
  • The documentation builds: $ python run-tests.py --doctest (or $ nox -s doctests)

You can run integration tests, unit tests, and doctests together at once, using $ python run-tests.py --quick (or $ nox -s quick).

Further checks:

  • Code is commented, particularly in hard-to-understand areas
  • Tests added that prove fix is effective or that feature works

cringeyburger and others added 30 commits December 17, 2023 23:31
… added by get_coupled_variables in model.variables
… added by get_coupled_variables in model.variables V2
… name as key and its variables as value.

Modified `get_parameter_info` to parse through the submodels' variables and give out `parameter_info` in `by_submodel=True` condition
Modified `print_parameter_info` to print `parameter_info` of a model with an option to print submodel wise using `by_submodel=True`
…er_info" or "print_parameter_info" directly on a submodel
…er_info" or "print_parameter_info" directly on a submodel V2
…r "print_parameter_info" is used on a submodel.
noxfile.py Outdated Show resolved Hide resolved
@kratman
Copy link
Contributor

kratman commented Apr 2, 2024

@agriyakhetarpal, @arjxn-py Is anything left on this one?

@agriyakhetarpal
Copy link
Member

The changes on the superseded PR (#3628) were going through code review, so we're waiting on that I guess (tagging @rtimms who had some suggested changes which to me look to have been addressed). IMO the tabular output here looks nice and consistent, better than the previous implementation.

CHANGELOG.md Outdated Show resolved Hide resolved
noxfile.py Outdated Show resolved Hide resolved
kratman
kratman previously requested changes Apr 2, 2024
pybamm/models/base_model.py Show resolved Hide resolved
pybamm/models/submodels/base_submodel.py Outdated Show resolved Hide resolved
@kratman
Copy link
Contributor

kratman commented Apr 2, 2024

@cringeyburger Can you take care of these minor items. Then once @rtimms approves then we can get this merged

@rtimms
Copy link
Contributor

rtimms commented Apr 2, 2024

The changes in response to my review look good. I'll do a more thorough re-review once everything else is fixed up. Tag me when it's ready. Thanks for working on this and sorry the review process has taken a while.

@cringeyburger
Copy link
Contributor Author

@kratman, I have resolved the issues. Please look at them and let me know if anything more is to be done!

@rtimms
Copy link
Contributor

rtimms commented Apr 3, 2024

Thanks, looks great! The failing tests seem unrelated, let's see what happens after we merge develop.

@agriyakhetarpal
Copy link
Member

I think SciPy deprecated something in scipy.sparse, which we'll need to handle on develop itself for Python 3.9 and later (Python 3.8 is okay because SciPy had dropped support for it, so we're using an older version there)

@kratman kratman dismissed their stale review April 4, 2024 13:48

Changes applied

@kratman
Copy link
Contributor

kratman commented Apr 4, 2024

Lychee error is unrelated. I will try re-triggering that one

@agriyakhetarpal
Copy link
Member

Might need to trigger again, some of them failed with an internal error

@kratman
Copy link
Contributor

kratman commented Apr 4, 2024

Looks like this is working now. I will squash it soon

@kratman kratman merged commit fe4ac31 into pybamm-team:develop Apr 4, 2024
37 checks passed
js1tr3 pushed a commit to js1tr3/PyBaMM that referenced this pull request Aug 12, 2024
* Add "by_submodel" feature and modify docstring

* Added line in CHANGELOG.md

* Implemented error handling if `get_parameter_info` method is used directly on any submodel.

* Implement changes to fix problem: Keep a track of what variables were added by get_coupled_variables in model.variables

* Implement changes to fix problem: Keep a track of what variables were added by get_coupled_variables in model.variables V2

* Created object `self.variables_by_submodel` which contains submodel's name as key and its variables as value.
Modified `get_parameter_info` to parse through the submodels' variables and give out `parameter_info` in `by_submodel=True` condition
Modified `print_parameter_info` to print `parameter_info` of a model with an option to print submodel wise using `by_submodel=True`

* Removed redundant comments.

* style: pre-commit fixes

* Implemented "NotImplementedError" when user tries to use "get_parameter_info" or "print_parameter_info" directly on a submodel

* Implemented "NotImplementedError" when user tries to use "get_parameter_info" or "print_parameter_info" directly on a submodel V2

* Updated Docstring of "get_parameter_info"

* Added Test Case for "NotImplementedError" when "get_parameter_info" or "print_parameter_info" is used on a submodel.

* Renamed variables, updated test, updated docstring

* Added "_find_symbols_by_submodel" method and modified "get_parameter_info" to get new parameters

* Optimised "print_parameter_info" by simplification, improved readability and reduced repetition

* Removed "calculate_max_lengths" and "format_table_row" from being nested inside into semi-private methods

* Tests for "get_parameter_info" for both "by_submodel=False" and "by_submodel=True"

* Removed duplicate test in "test_base_submodel" for when "get_parameter_info" is used directly on a submodel

* added `test_get_parameter_info_submodel` test using custom model

* added `test_print_parameter_info` and `test_print_parameter_info_submodel`

* Modified `test_get_parameter_info_submodel` to include edge cases

* formatted `test_base_model.py`

* Moved change log to unreleased

* Changed the formatted table's style

* Added `UTF-8` encoding to the format table

* Updated jupyter notebook `parameterization.ipynb` and added `UTF-8` encoding in environment variables

* added utf-8 encoding in PYBAMM_ENV

* Resolve minor issues

---------

Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
Co-authored-by: Robert Timms <[email protected]>
Co-authored-by: Arjun Verma <[email protected]>
Co-authored-by: Eric G. Kratz <[email protected]>
Co-authored-by: Agriya Khetarpal <[email protected]>
Co-authored-by: cringeyburger <cringeyburger>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Print parameter info by submodel
5 participants