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 329 deepcopy #403

Merged
merged 14 commits into from
May 21, 2019
Merged

Issue 329 deepcopy #403

merged 14 commits into from
May 21, 2019

Conversation

valentinsulzer
Copy link
Member

@valentinsulzer valentinsulzer commented May 14, 2019

Description

Create function make_new_copy to replace deepcopy
Fixes #329

Type of change

  • New feature (non-breaking change which adds functionality)

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
  • Any dependent changes have been merged and published in downstream modules

@codecov
Copy link

codecov bot commented May 14, 2019

Codecov Report

Merging #403 into master will increase coverage by 0.05%.
The diff coverage is 100%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master     #403      +/-   ##
==========================================
+ Coverage   96.75%   96.81%   +0.05%     
==========================================
  Files          60       60              
  Lines        3919     3928       +9     
==========================================
+ Hits         3792     3803      +11     
+ Misses        127      125       -2
Impacted Files Coverage Δ
pybamm/expression_tree/scalar.py 100% <100%> (ø) ⬆️
pybamm/expression_tree/vector.py 97.87% <100%> (+0.09%) ⬆️
pybamm/expression_tree/broadcasts.py 100% <100%> (+5.88%) ⬆️
pybamm/models/lithium_ion/spme.py 100% <100%> (ø) ⬆️
pybamm/expression_tree/variable.py 100% <100%> (ø) ⬆️
pybamm/models/lead_acid/composite.py 100% <100%> (ø) ⬆️
pybamm/expression_tree/binary_operators.py 95.49% <100%> (+0.12%) ⬆️
pybamm/parameters/parameter_values.py 98.11% <100%> (+0.69%) ⬆️
pybamm/expression_tree/simplify.py 95.86% <100%> (-0.12%) ⬇️
pybamm/expression_tree/independent_variable.py 100% <100%> (ø) ⬆️
... and 6 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 18bb6ac...b3f1186. Read the comment docs.

@codecov
Copy link

codecov bot commented May 14, 2019

Codecov Report

Merging #403 into master will increase coverage by 0.02%.
The diff coverage is 98.97%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master     #403      +/-   ##
==========================================
+ Coverage   96.46%   96.49%   +0.02%     
==========================================
  Files          59       60       +1     
  Lines        3876     3879       +3     
==========================================
+ Hits         3739     3743       +4     
+ Misses        137      136       -1
Impacted Files Coverage Δ
pybamm/parameters/parameter_values.py 98.05% <100%> (+0.71%) ⬆️
pybamm/expression_tree/simplify.py 95.81% <100%> (-0.16%) ⬇️
pybamm/discretisations/discretisation.py 98.9% <100%> (-0.08%) ⬇️
pybamm/expression_tree/parameter.py 100% <100%> (ø) ⬆️
pybamm/expression_tree/unary_operators.py 94.08% <100%> (+0.19%) ⬆️
pybamm/expression_tree/copy.py 100% <100%> (ø)
pybamm/expression_tree/symbol.py 96.19% <100%> (-0.11%) ⬇️
pybamm/expression_tree/concatenations.py 96.18% <100%> (+0.18%) ⬆️
pybamm/expression_tree/broadcasts.py 94.73% <66.66%> (+0.61%) ⬆️

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 10d6f63...91dcded. Read the comment docs.

Copy link
Contributor

@martinjrobins martinjrobins left a comment

Choose a reason for hiding this comment

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

I'm a bit unsure about the structure of make_new_copy, see comment below

import pybamm


def make_new_copy(symbol):
Copy link
Contributor

Choose a reason for hiding this comment

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

make_new_copy seems very similar in structure to simplify or evaluate, perhaps we should do this in a similar way. That is, have a new_copy function on Symbol, which is overridden on derived classes. You are already sorta doing that for the unary operators and concatenate anyway. What do you think?

Copy link
Member Author

Choose a reason for hiding this comment

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

Yeah, it is a bit inconsistent at the moment. I was trying to keep it in line with the ParameterValues.process_symbol, Discretisation.process_symbol and simplify functions. The advantage of those is that we could later add a dictionary of already-processed symbols so that we avoid re-processing the same symbol multiple times. But maybe copying is straightforward enough that it should just be a function on Symbol.

Copy link
Contributor

Choose a reason for hiding this comment

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

don't think we could use a dictionary of already-processed symbols here. Even if we've already copied a symbol, we still need to make another copy even if we find an identical symbol in the tree

Copy link
Member Author

Choose a reason for hiding this comment

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

I think it would work, because what's causing problems with anytree is the parent attribute. So if we have a dict of variables whose parent is None, we can insert them into different places in the tree (since they get shallow-copied in Symbol.__init__) without having to deepcopy them again. As an aside, if we can find a better way of making a copy of an object in anytree with parent removed, then we don't need this whole thing

@valentinsulzer
Copy link
Member Author

@martinjrobins - have now updated to your suggestion above

@valentinsulzer valentinsulzer mentioned this pull request May 20, 2019
7 tasks
Copy link
Contributor

@martinjrobins martinjrobins 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 . merging now

@martinjrobins martinjrobins merged commit 7af8746 into master May 21, 2019
@martinjrobins martinjrobins deleted the issue-329-deepcopy branch May 21, 2019 11:47
valentinsulzer added a commit that referenced this pull request Nov 20, 2022
…er-constant

#403 add special case for constant function parameter
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.

Reduce the number of deepcopies in the workflow
2 participants