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

add unit benchmarks #2092

Merged
merged 3 commits into from
Jun 15, 2022

Conversation

Vaibhav-Chopra-GT
Copy link
Contributor

Description

Created unit benchmarks (create an expression, parameterise a model, discretise a model, and solve a model) using this example.

I tried developing these benchmarks using classes and inheritance, but asv runs time_* functions of the parent class in the child classes too. This results in benchmarks running multiple times.

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: $ flake8
  • All tests pass: $ python run-tests.py --unit
  • The documentation builds: $ cd docs and then $ make clean; make html

You can run all three at once, using $ python run-tests.py --quick.

Further checks:

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


def time_parameterise():

global param
Copy link
Member

Choose a reason for hiding this comment

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

you should be able to do this without using global. I have never seen a good reason to use it

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The benchmarks don't work without these global variables even after adding the setup functions. I don't know why this is the case, but when I run the benchmarks with the global variables they work

R = 1e-5


def time_create_expression():
Copy link
Sponsor Member

Choose a reason for hiding this comment

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

You should define a class like with the other benchmarks. The first bit can be pushed under the setup method, and then have the different benchmarks.

time_discretise.setup = setup_discretise


def setup_solve():
Copy link
Sponsor Member

Choose a reason for hiding this comment

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

The discretisation and parameterisation methods modify the model, so if you define model to be a variable of the class then hopefully you do not need to initialise every single time.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I tried this but got an error because asv runs every method separately, so the changes made in one method don't carry on to others. For example-
for the time_solve benchmark to work we will need to run previous methods in its setup, and a class cannot have more than 1 setup; hence, I cannot put this under the class containing other time_* functions as they require a different setup

@codecov
Copy link

codecov bot commented Jun 8, 2022

Codecov Report

Merging #2092 (194af38) into develop (e1f52ff) will decrease coverage by 0.00%.
The diff coverage is n/a.

@@             Coverage Diff             @@
##           develop    #2092      +/-   ##
===========================================
- Coverage    99.38%   99.38%   -0.01%     
===========================================
  Files          348      348              
  Lines        19255    19234      -21     
===========================================
- Hits         19136    19115      -21     
  Misses         119      119              
Impacted Files Coverage Δ
pybamm/expression_tree/concatenations.py 98.70% <0.00%> (-0.04%) ⬇️
pybamm/expression_tree/binary_operators.py 99.53% <0.00%> (-0.01%) ⬇️
pybamm/models/base_model.py 99.26% <0.00%> (-0.01%) ⬇️
pybamm/solvers/base_solver.py 100.00% <0.00%> (ø)
pybamm/expression_tree/functions.py 100.00% <0.00%> (ø)
pybamm/discretisations/discretisation.py 99.79% <0.00%> (ø)
pybamm/expression_tree/unary_operators.py 100.00% <0.00%> (ø)
pybamm/parameters/lithium_ion_parameters.py 100.00% <0.00%> (ø)
...ybamm/expression_tree/operations/evaluate_julia.py 100.00% <0.00%> (ø)
...bamm/expression_tree/operations/evaluate_python.py 98.29% <0.00%> (ø)
... and 2 more

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update e1f52ff...194af38. Read the comment docs.

Copy link
Member

@valentinsulzer valentinsulzer left a comment

Choose a reason for hiding this comment

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

Thanks, this looks much cleaner!

Copy link
Sponsor Member

@brosaplanella brosaplanella left a comment

Choose a reason for hiding this comment

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

Looks great, thanks Vaibhav!

@valentinsulzer valentinsulzer merged commit d0f8f35 into pybamm-team:develop Jun 15, 2022
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.

None yet

3 participants