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

[Bug]: [24.5rc0] Simulations with pybamm.Experiment terminate after 24 h #4224

Closed
ejfdickinson opened this issue Jun 27, 2024 · 11 comments · Fixed by #4239
Closed

[Bug]: [24.5rc0] Simulations with pybamm.Experiment terminate after 24 h #4224

ejfdickinson opened this issue Jun 27, 2024 · 11 comments · Fixed by #4239
Labels
bug Something isn't working

Comments

@ejfdickinson
Copy link

PyBaMM Version

24.5rc0

Python Version

3.9.13

Describe the bug

Simulations using pybamm.Experiment with a voltage cut-off only appear to terminate with a time cut-off after 24 h.

I'm afraid I haven't had time to get into logs to figure out why this is happening!

Steps to Reproduce

The following simulation should proceed for approximately 100 h = 360000 s, until the specified voltage cut-off. However, it terminates after 24 h.

import pybamm

parameter_values = pybamm.ParameterValues("Chen2020")
model = pybamm.lithium_ion.DFN()
experiment = pybamm.Experiment(
    [
        "Discharge at 0.01C until 2.5 V",
    ]
)

sim = pybamm.Simulation(
    model,
    parameter_values=parameter_values,
    experiment=experiment,
)

sol = sim.solve()
sim.plot()

print(f'Last time step at {sim.solution["Time [s]"].entries[-1] / 3600} h')

Relevant log output

No response

@ejfdickinson ejfdickinson added the bug Something isn't working label Jun 27, 2024
@agriyakhetarpal
Copy link
Member

Hi, @ejfdickinson – looks like a duplicate of #4155?

@ejfdickinson
Copy link
Author

@agriyakhetarpal Yes, it is.

v24.1 does not do this, so it should be in your release notes for v24.5rc0.

Any recommendations on how to work around?

@MarcBerliner
Copy link
Member

MarcBerliner commented Jun 27, 2024

Any recommendations on how to work around?

@ejfdickinson you can include a duration in the experiment step, e.g.,

experiment = pybamm.Experiment(
    [
        "Discharge at 0.01C for 100 hours or until 2.5 V",
    ]
)

and it won't cut off at 24 hours.

image

@ejfdickinson
Copy link
Author

Thanks @MarcBerliner !

@agriyakhetarpal
Copy link
Member

v24.1 does not do this, so it should be in your release notes for v24.5rc0.

I think we should mark this as a breaking change, @valentinsulzer?

@rtimms
Copy link
Contributor

rtimms commented Jun 28, 2024

IMO we should fix this before 24.5 proper. I don't know what logic changed or if there was a longer default before.

Update: the logic used to be

                if op_conds.type == "current":
                    # Current control: max simulation time: 3h / C-rate
                    Crate = op_conds.value / capacity
                    dt = 3 / abs(Crate) * 3600  # seconds
                else:
                    # max simulation time: 1 day
                    dt = 24 * 3600  # seconds

@rtimms
Copy link
Contributor

rtimms commented Jun 28, 2024

Alternatively, should we require a duration to avoid unexpected behaviour?

@brosaplanella
Copy link
Sponsor Member

Why did we move away from that logic? As in, if we bring it back will it break anything?

rtimms added a commit that referenced this issue Jun 28, 2024
@rtimms
Copy link
Contributor

rtimms commented Jun 28, 2024

It got moved to the Step class instead of the Simulation class. It's easy to put the same logic back in for C-rate, but not current, as the default duration needs to return a float, not a symbol (see the commit above). It's fixable but needs a bit of work, and I'm leaning towards requiring a duration as it's less ambiguous. It would be a breaking change but easy for users to fix.

@ejfdickinson
Copy link
Author

@rtimms For our use cases, a maximum duration would be fine, so long as it's declared on simulation exit like a "Time" stop rather than occurring silently. As noted in #4155 , 24 h is well within typical simulation times for normal experiments, so if the purpose is just to avoid hanging the solver due to an absurd duration, adding a few orders of magnitude to the default might be more sensible!

@valentinsulzer
Copy link
Member

Should be fixed by #4239 . @ejfdickinson and @aabills can you make sure it works for your use case? Then can @kratman or @agriyakhetarpal cherry pick this into 24.5? Thanks

valentinsulzer added a commit that referenced this issue Jul 10, 2024
kratman pushed a commit that referenced this issue Jul 11, 2024
* make longer default duration and calculate it for C-rate

* add tests

* typo

* #4224 add warning for time termination and add abs

* fix tests

* #4224 keep non-C-rate default at 24h for performance reasons

* trying to fix experiment

* fix example

* #4224 eric comments

* fix bug
kratman pushed a commit that referenced this issue Jul 11, 2024
* make longer default duration and calculate it for C-rate

* add tests

* typo

* #4224 add warning for time termination and add abs

* fix tests

* #4224 keep non-C-rate default at 24h for performance reasons

* trying to fix experiment

* fix example

* #4224 eric comments

* fix bug
kratman pushed a commit that referenced this issue Jul 12, 2024
* make longer default duration and calculate it for C-rate

* add tests

* typo

* #4224 add warning for time termination and add abs

* fix tests

* #4224 keep non-C-rate default at 24h for performance reasons

* trying to fix experiment

* fix example

* #4224 eric comments

* fix bug
js1tr3 pushed a commit to js1tr3/PyBaMM that referenced this issue Aug 12, 2024
* make longer default duration and calculate it for C-rate

* add tests

* typo

* pybamm-team#4224 add warning for time termination and add abs

* fix tests

* pybamm-team#4224 keep non-C-rate default at 24h for performance reasons

* trying to fix experiment

* fix example

* pybamm-team#4224 eric comments

* fix bug
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

6 participants