-
-
Notifications
You must be signed in to change notification settings - Fork 553
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
Return event state #1300
Return event state #1300
Conversation
Codecov Report
@@ Coverage Diff @@
## develop #1300 +/- ##
========================================
Coverage 98.10% 98.10%
========================================
Files 272 272
Lines 15229 15236 +7
========================================
+ Hits 14940 14947 +7
Misses 289 289
Continue to review full report at Codecov.
|
one problem this has caused is that doing the extra single step to go from the event time to the next time based on the period adds extra sub solutions. this makes it so that there can be more sub solutions that instructions (e.g. the cccv example now has 19 sub solutions instead of 15, which breaks the custom plot of the discharge). |
I think |
I agree with Tino. In addition, if you want the solution at the evenly spaced times you provided (which probably will be for storing or further processing), you can always evaluate the processed variables at the desired points. |
thanks, I've removed this as an option and the solvers now always return the event time and state. I've left the step in that gets you back to the times defined by the period based on the initial time. the reason I wanted to do this was incase people were doing e.g. lots of cycles and wanted to use a long period as they are only interested in the solution at the end of the cycle. if you have a long period then when an event is triggered you might get thrown a long way off. at least this way you should be able to trust the solution at the returned times, and aren't getting killed by interpolation error. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks great, thanks Rob!
About the mac tests, I think that this is a GitHub issue (they are doing some maintenance this week which affects mac-os Actions).
I tried merging this into my LithiumPlating branch and got the following error: AttributeError Traceback (most recent call last) |
@DrSOKane not sure if this is the cause of the problem you are having, but you would get a similar error if you haven't solved your model yet and ask for the |
@brosaplanella I haven't asked for the set up time. The line raising the error is 840 of base_simulation.py. solution, the object Python is saying is NoneType, is defined on line 837. If solution is NoneType, that implies the integration on line 837 didn't work. |
pybamm/simulation.py
Outdated
exp_inputs["period"] | ||
- (self._solution.t[-1] - self._solution.t[-2]) | ||
* self._solution.timescale_eval | ||
) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
dt_event
can be negative here if switching from a longer period (e.g. 180s) to a shorter period (e.g. w60s), since in that case (self._solution.t[-1] - self._solution.t[-2]) * self._solution.timescale_eval
(e.g. 150s) can be longer than the new period even though it is shorter than the old period
This error arises when the casadi solver receives a time [t, t+dt] where dt is negative. To be honest, I'm not sure we should be doing this to get back on the correct time period? e.g. in your [0,30,32,60,90] example, from the point of view of the phase after the event, the times will be [28,30,30,...] which seems a bit weird |
ah good catch, thanks. i’m happy for that step to get to the original period to be removed - it messes with the sub solutions anyway. my thinking was that it would be nice to get the solution at the times you would expect based on starting at t=0 with a given period, and that the event times would just be appended in. i probably won’t get round to this until the new year, so if someone else wants this to be merged into develop sooner then please go ahead and make the changes |
thanks @tinosulzer ! I’ll revert the cccv script and update the changelog etc. after the holidays |
Description
UPDATE (16/12/20): the event time and state are now always returned as part of
solution.t
andsolution.y
. The solver option for this has been removed.Add a solver option to return the event time and state as part of
solution.t
andsolution.y
.Also changes the way stepping works in experiments when an event is triggered so that the solution gets back on to the correct reporting period. e.g. if the period is 30s and an event is triggered at 32s we now return the times [0, 30, 32, 60] instead of [0, 30, 32, 62]Open to suggestions on the option name and on how I've implemented this. Question: should the default be
True
? I left it asFalse
as typically it seems that solvers don't return the event in this way. Maybe it should be true for experiments at least? I think it is important to get the event time and state back when looking at the solution, especially for doing calculations after the fact.See here that you now hit the event spot on, regardless of the period
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.
Key checklist:
$ flake8
$ python run-tests.py --unit
$ cd docs
and then$ make clean; make html
You can run all three at once, using
$ python run-tests.py --quick
.Further checks: