Skip to content

Issue 709 simplify on creation#801

Merged
valentinsulzer merged 14 commits into
masterfrom
issue-709-simplify-on-creation
Feb 6, 2020
Merged

Issue 709 simplify on creation#801
valentinsulzer merged 14 commits into
masterfrom
issue-709-simplify-on-creation

Conversation

@valentinsulzer

@valentinsulzer valentinsulzer commented Feb 2, 2020

Copy link
Copy Markdown
Member

Description

Simplify objects as soon as they are created, if they are constant.
Also, removed update_model functionality, as this can be more efficiently achieved by using InputParameter.
Fixes #709

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

codecov Bot commented Feb 3, 2020

Copy link
Copy Markdown

Codecov Report

Merging #801 into master will decrease coverage by 0.07%.
The diff coverage is 99.52%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master     #801      +/-   ##
==========================================
- Coverage   98.22%   98.14%   -0.08%     
==========================================
  Files         181      179       -2     
  Lines       10149     9935     -214     
==========================================
- Hits         9969     9751     -218     
- Misses        180      184       +4
Impacted Files Coverage Δ
...mm/expression_tree/operations/convert_to_casadi.py 90.76% <ø> (ø) ⬆️
pybamm/expression_tree/symbol.py 97.71% <0%> (-0.75%) ⬇️
pybamm/parameters/parameter_values.py 100% <100%> (ø) ⬆️
pybamm/solvers/casadi_solver.py 100% <100%> (+1.07%) ⬆️
pybamm/expression_tree/independent_variable.py 100% <100%> (ø) ⬆️
pybamm/solvers/solution.py 97.93% <100%> (+0.06%) ⬆️
pybamm/solvers/idaklu_solver.py 88.23% <100%> (+4.9%) ⬆️
pybamm/solvers/scikits_ode_solver.py 85.48% <100%> (-12.77%) ⬇️
pybamm/solvers/scipy_solver.py 100% <100%> (ø) ⬆️
pybamm/expression_tree/variable.py 100% <100%> (ø) ⬆️
... and 8 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 69c2aa2...27c118d. Read the comment docs.

@valentinsulzer valentinsulzer changed the base branch from issue-784-simplify-solver to master February 4, 2020 15:35

@Scottmar93 Scottmar93 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Looks good, just a couple of small comments

def __gt__(self, other):
"""return a :class:`Heaviside` object"""
return pybamm.Heaviside(other, self, equal=False)
return pybamm.simplify_if_constant(

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Instead of having pybamm.simplify_if_constant( ) in every function can we have self = pybamm.simplify_if_constant(self) in the __init__ of Symbol? Maybe this screws with the tree though?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

I tried but python doesn't let you assign self in the __init__, only its arguments (or at least I couldn't figure out how to), so this seems a bit safer

(self.mat @ self.vect).evaluate(), np.array([[5], [2], [3]])
)

def test_matrix_modification(self):

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Should this be removed? I don't see how it is related to simplifying on creation.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

simplifying on creation broke the test, then I thought we were never using this functionality so could get rid of the test. We might actually want to prevent matrix modification outright, to avoid weird bugs?

b = pybamm.Scalar(2)
sum = a + b
b = pybamm.Parameter("b")
summ = a + b

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

again simplify on creation broke the test

@valentinsulzer valentinsulzer merged commit 017529c into master Feb 6, 2020
@valentinsulzer valentinsulzer deleted the issue-709-simplify-on-creation branch February 6, 2020 04:37
Scottmar93 added a commit that referenced this pull request Mar 30, 2020
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 some objects on creation

2 participants