PyBaMM icon indicating copy to clipboard operation
PyBaMM copied to clipboard

[Bug]: Different series lengths in get_data_dict() using starting_solution

Open tomjholland opened this issue 8 months ago • 0 comments

PyBaMM Version

25.4.2

Python Version

3.12.8

Describe the bug

Using the get_data_dict() method of a Solution returns a dictionary where the array in data_dict["Step"] has a different length (one greater) than the arrays under the other keys. This behaviour appears when calling get_data_dict() on a solution that has been solved from a starting solution. The code example below shows normal behaviour, followed by using a starting solution in the solve.

Steps to Reproduce

import pybamm
print(pybamm.__version__)
spm = pybamm.lithium_ion.SPM()
experiment = pybamm.Experiment(
    [
        (
            "Discharge at C/10 for 10 hours or until 3.3 V",
            "Rest for 1 hour",
            "Charge at 1 A until 4.1 V",
            "Hold at 4.1 V until 50 mA",
            "Rest for 1 hour",
        ),
    ]
    * 3
    + [
        "Discharge at 1C until 3.3 V",
    ],
)
sim = pybamm.Simulation(
    spm,
    experiment=experiment,
)
sol = sim.solve()
required_variables = [
            "Time [s]",
            "Current [A]",
            "Terminal voltage [V]",
            "Discharge capacity [A.h]",
        ]
data_dict = sol.get_data_dict(required_variables)
print("Length of Step:", len(data_dict["Step"]))
print("Length of Cycle:", len(data_dict["Cycle"]))
print("Length of time series:", len(data_dict["Time [s]"]))

experiment2 = pybamm.Experiment(
        [
            (
                "Discharge at 1C for 10 hours or until 3.3 V",
                "Rest for 1 hour",
                "Charge at 1 A until 4.1 V",
                "Hold at 4.1 V until 50 mA",
                "Rest for 1 hour",
            ),
        ]
        * 5,
    )
sim2 = pybamm.Simulation(
    spm,
    experiment=experiment2,
)

sol2 = sim2.solve(starting_solution=sol)
data_dict = sol2.get_data_dict(required_variables)
print("Length of Step:", len(data_dict["Step"]))
print("Length of Cycle:", len(data_dict["Cycle"]))
print("Length of time series:", len(data_dict["Time [s]"]))

Relevant log output

25.4.2
Length of Cycle: 620
Length of time series: 620
Length of Step: 1764
Length of Cycle: 1763
Length of time series: 1763

tomjholland avatar Apr 23 '25 11:04 tomjholland