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 771 secondary broadcast #776

Merged
merged 19 commits into from
Jan 10, 2020
Merged

Conversation

valentinsulzer
Copy link
Member

@valentinsulzer valentinsulzer commented Jan 8, 2020

Description

Reformat broadcasting to make sure it's always done in the right order and get rid of hacks

Fixes #771

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

@codecov
Copy link

codecov bot commented Jan 8, 2020

Codecov Report

Merging #776 into master will increase coverage by 0.04%.
The diff coverage is 100%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master     #776      +/-   ##
==========================================
+ Coverage   98.38%   98.42%   +0.04%     
==========================================
  Files         179      179              
  Lines        9916     9931      +15     
==========================================
+ Hits         9756     9775      +19     
+ Misses        160      156       -4
Impacted Files Coverage Δ
pybamm/models/standard_variables.py 100% <ø> (ø) ⬆️
pybamm/expression_tree/broadcasts.py 100% <100%> (+5.97%) ⬆️
pybamm/expression_tree/operations/jacobian.py 100% <100%> (ø) ⬆️
pybamm/spatial_methods/spatial_method.py 95.55% <100%> (+0.43%) ⬆️
pybamm/expression_tree/functions.py 100% <100%> (ø) ⬆️
pybamm/expression_tree/binary_operators.py 98.87% <100%> (ø) ⬆️
pybamm/processed_variable.py 96.87% <100%> (-0.38%) ⬇️
pybamm/expression_tree/operations/simplify.py 94.96% <100%> (-0.02%) ⬇️
pybamm/expression_tree/concatenations.py 97.95% <100%> (ø) ⬆️
pybamm/models/submodels/particle/base_particle.py 97.29% <100%> (ø) ⬆️
... and 7 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 1e39620...a8c241c. Read the comment docs.

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.

looks great, thanks @tinosulzer ! just a few comments about docstrings/comments. not for this issue, but it might helpful to have a notebook that shows what the different broadcast types do, as i'm not sure it's obvious to new users why you need the different cases


class PrimaryBroadcast(Broadcast):
"""A node in the expression tree representing a primary broadcasting operator.
Broadcasts in a `primary` dimension only. That is, makes explicit copies
Copy link
Contributor

Choose a reason for hiding this comment

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

I'm not sure the "That is, makes explicit copies" is particularly clear?

Copy link
Member Author

Choose a reason for hiding this comment

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

oh yeah I got distracted while writing this 😅

# electrode to particle
if child.domain == []:
pass
elif child.domain[0] in [
Copy link
Contributor

Choose a reason for hiding this comment

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

can we do a similar check that if the domain is current collector, the broadcast domain must be and electrode or separator?



class PrimaryBroadcast(Broadcast):
class SecondaryBroadcast(Broadcast):
"""A node in the expression tree representing a primary broadcasting operator.
Broadcasts in a `primary` dimension only. That is, makes explicit copies
Copy link
Contributor

Choose a reason for hiding this comment

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

"secondary dimension only", and as above the last part of this isn't clear to me

"See :meth:`Broadcast.check_and_set_domains`"

# Can only do secondary broadcast from particle to electrode or from
# current collector to electrode
Copy link
Contributor

Choose a reason for hiding this comment

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

from electrode to current collector?

"Clear domains, bypassing checks"
self._domain = []
self._auxiliary_domains = {}

Copy link
Contributor

Choose a reason for hiding this comment

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

nice!

self.first_dimension = "r"
self.second_dimension = "x"
self.r_sol = first_dim_pts
self.x_sol = second_dim_pts
Copy link
Contributor

Choose a reason for hiding this comment

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

nice job tidying this up!

Copy link
Member Author

@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.

Have updated the docstrings and made the notebook, let me know if it's clearer

@rtimms
Copy link
Contributor

rtimms commented Jan 10, 2020

yep, this looks great thanks. the notebook is very clear!

@valentinsulzer valentinsulzer merged commit b1395e5 into master Jan 10, 2020
@valentinsulzer valentinsulzer deleted the issue-771-secondary-broadcast branch January 10, 2020 13:51
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.

Reintroduce secondary broadcast
2 participants