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 1230 simplify #1252

Merged
merged 28 commits into from
Nov 25, 2020
Merged

Issue 1230 simplify #1252

merged 28 commits into from
Nov 25, 2020

Conversation

valentinsulzer
Copy link
Member

Description

Automatically simplify expressions that can be simplified, e.g. 1*x becomes x.
This can be bypassed by creating the binary operator explicitly, e.g. pybamm.Multiplication(1, x)

Fixes #1230
Fixes #986

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

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 good to me, just a typo to fix. Thanks Tino!

@@ -457,6 +456,15 @@ def test_x_average(self):
self.assertEqual(av_a.children[0].integration_variable[0].domain, x.domain)
self.assertEqual(av_a.domain, [])

# whole electrode domain is different as the divisioni by 1 gets simplified out
Copy link
Sponsor Member

Choose a reason for hiding this comment

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

Typo in "divisioni"

@codecov
Copy link

codecov bot commented Nov 17, 2020

Codecov Report

Merging #1252 (82fe27a) into develop (20fb565) will increase coverage by 0.05%.
The diff coverage is 100.00%.

Impacted file tree graph

@@             Coverage Diff             @@
##           develop    #1252      +/-   ##
===========================================
+ Coverage    97.99%   98.05%   +0.05%     
===========================================
  Files          264      264              
  Lines        14748    14841      +93     
===========================================
+ Hits         14453    14552      +99     
+ Misses         295      289       -6     
Impacted Files Coverage Δ
...rrent_collector/quite_conductive_potential_pair.py 100.00% <ø> (ø)
pybamm/simulation.py 96.81% <ø> (ø)
pybamm/spatial_methods/finite_volume.py 98.15% <ø> (+0.20%) ⬆️
pybamm/expression_tree/binary_operators.py 97.47% <100.00%> (+1.46%) ⬆️
pybamm/expression_tree/broadcasts.py 100.00% <100.00%> (ø)
pybamm/expression_tree/concatenations.py 97.61% <100.00%> (+0.04%) ⬆️
pybamm/expression_tree/functions.py 100.00% <100.00%> (ø)
pybamm/expression_tree/input_parameter.py 100.00% <100.00%> (ø)
pybamm/expression_tree/operations/jacobian.py 100.00% <100.00%> (ø)
pybamm/expression_tree/operations/simplify.py 93.35% <100.00%> (-1.80%) ⬇️
... and 13 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 20fb565...82fe27a. Read the comment docs.

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 Tino! Great job :)

Copy link
Contributor

@rtimms rtimms left a comment

Choose a reason for hiding this comment

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

thanks @tinosulzer !

else:
return False
return self.shape_for_testing == ()
# result = self.evaluate_ignoring_errors()
Copy link
Contributor

Choose a reason for hiding this comment

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

can this commented code be removed?

@valentinsulzer valentinsulzer merged commit 834be0c into develop Nov 25, 2020
@valentinsulzer valentinsulzer deleted the issue-1230-simplify branch November 25, 2020 15:13
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.

Simplify all objects on creation Simplify basic operations
3 participants