Skip to content

[Bug]: C-rate drive cycle calls wrong default duration #5086

@Daniel-Nicolae23

Description

@Daniel-Nicolae23

PyBaMM Version

25.6

Python Version

3.12

Describe the bug

Using a pybamm.step.CRate with a drive cycle and no explicit duration argument doesn't call the default_duration() method in the BaseStep class which is supposed to handle drive cycles, but rather its own function which is correct for single C-rate values only.

Should change CRate.default_duration() to:

def default_duration(self, value):
    if isinstance(value, np.ndarray):
        t = value[:, 0]
        return t[-1]
    else:
        # "value" is C-rate, so duration is "1 / value" hours in seconds
        # with a 2x safety factor
        return 1 / abs(value) * 3600 * 2

Steps to Reproduce

t = np.linspace(0, 100, 101)
I = np.sin(t)
drive_cycle = np.column_stack([t, I])
exp = pybamm.Experiment([pybamm.step.CRate(drive_cycle)])

Relevant log output

AttributeError: 'numpy.ndarray' object has no attribute 'lstrip'

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions