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]: starting_solution does not work if last cycle is not saved #3101

Closed
brosaplanella opened this issue Jul 4, 2023 · 4 comments · Fixed by #3177
Closed

[Bug]: starting_solution does not work if last cycle is not saved #3101

brosaplanella opened this issue Jul 4, 2023 · 4 comments · Fixed by #3177
Assignees
Labels
bug Something isn't working difficulty: medium Will take a few days in-progress Assigned in the core dev monthly meeting priority: high To be resolved as soon as possible

Comments

@brosaplanella
Copy link
Member

PyBaMM Version

23.5

Python Version

3.9.17

Describe the bug

When using starting_solution in solving a simulation, if the last cycle of the starting_solution is not saved, then the initialisation doesn't work: the new solution starts at t=0 and does not contain the previous states (not even the first cycle which should be always saved).

My guess is that when checking the solution for the last cycle it finds it is None and thus it treats it as if no starting_solution has been provided.

Steps to Reproduce

        model = pybamm.lithium_ion.SPM()

        experiment = pybamm.Experiment([
            # pybamm.step.string("Discharge at C/2 for 10 minutes", start_time=datetime(2023, 1, 1, 8, 0, 0)),
            pybamm.step.string("Discharge at C/2 for 10 minutes"),
            pybamm.step.string("Rest for 10 minutes"),
        ])

        sim = pybamm.Simulation(model, experiment=experiment)
        solution = sim.solve(save_at_cycles=[1])

        experiment = pybamm.Experiment([
            # pybamm.step.string("Discharge at C/2 for 20 minutes", start_time=datetime(2023, 1, 1, 10, 0, 0)),
            pybamm.step.string("Discharge at C/2 for 20 minutes"),
            pybamm.step.string("Rest for 20 minutes"),
        ])

        sim = pybamm.Simulation(model, experiment=experiment)
        new_solution = sim.solve(calc_esoh=False, starting_solution=solution)

Plotting new_solution yields:
image

If, instead, I do save_at_cycles=None in the first solve, I get the expected result:
image

Relevant log output

No response

@brosaplanella brosaplanella added bug Something isn't working difficulty: medium Will take a few days priority: high To be resolved as soon as possible labels Jul 4, 2023
@brosaplanella
Copy link
Member Author

brosaplanella commented Jul 4, 2023

Maybe not strictly related to this (but could be addressed at the same time as this), but another issue is that the way starting_time is currently implemented means that the initial_start_time is taken from the experiment, but if an initial solution is provided it should be taken from there.

@valentinsulzer
Copy link
Member

It should be reasonably easy to fix, we just need to save last_state regardless of whether the last cycle is saved and then use that for the starting solution

@brosaplanella
Copy link
Member Author

This issue might also align with #2484

@brosaplanella
Copy link
Member Author

I found an easier way: save always the final cycle. It is a bit more memory consuming but a lot more robust (IMO). This also fixes the fact that the last_state was not correctly defined either.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working difficulty: medium Will take a few days in-progress Assigned in the core dev monthly meeting priority: high To be resolved as soon as possible
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants