Skip to content

Issue 1195 track cycles in solution - #1309

Merged
valentinsulzer merged 19 commits into
pybamm-team:developfrom
lonnbornj:issue-1195-track-cycles-in-solution
Dec 31, 2020
Merged

Issue 1195 track cycles in solution#1309
valentinsulzer merged 19 commits into
pybamm-team:developfrom
lonnbornj:issue-1195-track-cycles-in-solution

Conversation

@lonnbornj

@lonnbornj lonnbornj commented Dec 28, 2020

Copy link
Copy Markdown
Contributor

Description

Altered the Experiment class to parse experiments expressed in terms of cycles (in the form of tuples of operating conditions). The Simulation class creates solution.cycles -- a list of cycles. Each cycle is a tuple of sub_solution objects.

Fixes #1195

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 Dec 28, 2020

Copy link
Copy Markdown

Codecov Report

Merging #1309 (692b19d) into develop (cbacc30) will increase coverage by 0.00%.
The diff coverage is 100.00%.

Impacted file tree graph

@@           Coverage Diff            @@
##           develop    #1309   +/-   ##
========================================
  Coverage    98.10%   98.10%           
========================================
  Files          272      272           
  Lines        15214    15229   +15     
========================================
+ Hits         14925    14940   +15     
  Misses         289      289           
Impacted Files Coverage Δ
pybamm/experiments/experiment.py 98.33% <100.00%> (+0.15%) ⬆️
pybamm/simulation.py 96.95% <100.00%> (+0.06%) ⬆️

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 cbacc30...692b19d. Read the comment docs.

@valentinsulzer valentinsulzer left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Thanks @lonnbornj , impressed how few changes you managed to do this in.
Just some edge cases to address. Also, can you edit the cccv.py and gitt.py examples to use cycles, since we want to encourage this in general, and add this change to the changelog.

Comment thread pybamm/experiments/experiment.py Outdated
cond for cycle in operating_conditions for cond in cycle
]
elif all([isinstance(cond, str) for cond in operating_conditions]):
self.cycle_lengths = [len(operating_conditions)]

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

What about the case where there is a mix of tuples and strings? This should either raise an error, or strings should be made into 1-tuples (i.e. cycles of length 1). Second option slightly better IMO.

@lonnbornj lonnbornj Dec 30, 2020

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

I've implemented a check for the cycles (tuple or str), and the conditions therein (str), and convert any strings to 1-tuples as suggested. The type-checking got a bit complicated so I hope my solution is not too opaque. I thought it made sense to keep all of this together, so I moved the check for string operating_conditions out of experiment.read_operating_conditions and do it all in __init__.

Comment thread pybamm/simulation.py
Comment thread tests/unit/test_experiments/test_experiment.py Outdated
@rtimms

rtimms commented Dec 30, 2020

Copy link
Copy Markdown
Contributor

This is a really neat solution, thanks @lonnbornj ! I think it would be good to add a "Getting Started" guide on how to use experiments, explaining the syntax for cycles etc., but this can be done as a separate issue.

@rtimms

rtimms commented Dec 30, 2020

Copy link
Copy Markdown
Contributor

Actually, just realised we already have an experiment guide here, so it can just be updated to show how to use cycles.

@valentinsulzer valentinsulzer left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Thanks @lonnbornj , looks good! Happy to merge, unless you want to update the tutorial @rtimms linked to

@valentinsulzer

Copy link
Copy Markdown
Member

@all-contributors add @lonnbornj for code, test, example

@allcontributors

Copy link
Copy Markdown
Contributor

@tinosulzer

I've put up a pull request to add @lonnbornj! 🎉

@valentinsulzer
valentinsulzer merged commit c573c78 into pybamm-team:develop Dec 31, 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.

Track cycles in solution

3 participants