pybamm-team / PyBaMM

Fast and flexible physics-based battery models in Python
https://www.pybamm.org/
BSD 3-Clause "New" or "Revised" License
1.13k stars 549 forks source link

Infinite loop occurs #1493

Closed gyouhoc closed 3 years ago

gyouhoc commented 3 years ago

While I conduct multiple simulation with Pybamm, I find that the simulation generates an infinite loop and causes the python program to be halted.

error_shot The script stops here (no response)

error_shot_2

valentinsulzer commented 3 years ago

Can you try using CasadiSolver("fast with events") instead?

gyouhoc commented 3 years ago

for me, ("fast with events") doesn't work. I tried three different solver options and "old safe" is working with an warning.

"safe": SolverError: Maximum number of decreased steps occurred at t=0.0. Try solving the model up to this time only or reducing dt_max (currently, dt_max=81.88051713742692).

"fast": SolverError: .../casadi/interfaces/sundials/idas_interface.cpp:569: IDASolve returned "IDA_CONV_FAIL". Consult IDAS documentation.

"old safe": working with an warning psetup failed: .../casadi/interfaces/sundials/idas_interface.cpp:827: Calculating Jacobian failed

valentinsulzer commented 3 years ago

Please provide an entire script that can be run to test this

gyouhoc commented 3 years ago

Here is the script and required data.

On Wed, May 26, 2021 at 11:15 AM Valentin Sulzer @.***> wrote:

Please provide an entire script that can be run to test this

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub https://github.com/pybamm-team/PyBaMM/issues/1493#issuecomment-848856146, or unsubscribe https://github.com/notifications/unsubscribe-auth/AOPG4HUKVTOZEZ2RCUTO2U3TPUF7XANCNFSM45PQUH5Q .

valentinsulzer commented 3 years ago

I don't see it

Prasanna-murata commented 2 years ago

Can you please say the solution to this in case you discussed it

Sunnyturicum commented 1 year ago

Hey, I have the same issue. Is there a solution to this problem?

brosaplanella commented 1 year ago

Please provide a minimum working example and the full error log, so we can look into it.

Sunnyturicum commented 1 year ago

Thank you for taking the time. I have attached a minimal working example and full error log.

import pybamm
import matplotlib.pyplot as plt
import numpy as np

model = pybamm.lithium_ion.DFN(
    {
        "lithium plating": "partially reversible",
        "lithium plating porosity change": "true",  # alias for "SEI porosity change"
    }
)

param = pybamm.ParameterValues("OKane2022")

cycle_number = 1000
exp = pybamm.Experiment(
    ["Hold at 4.2 V until C/100",
    "Rest for 4 hours",
    "Discharge at 0.1C until 2.5 V",  # initial capacity check
    "Charge at 0.3C until 4.2 V",
    "Hold at 4.2 V until C/100",]
    + [("Discharge at 1C until 2.5 V",  # ageing cycles
    "Charge at 0.3C until 4.2 V",
    "Hold at 4.2 V until C/100",)] * cycle_number
    + ["Discharge at 0.1C until 2.5 V"],  # final capacity check
    period="5 minutes"
)

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

# safe solver
safe_solver = pybamm.CasadiSolver(atol=1e-3, rtol=1e-3, mode="safe", dt_max=100)

sol = sim.solve(solver=safe_solver)

The error message is:

At t = 299.979 and h = 4.56806e-09, the corrector convergence failed repeatedly or with |h| = hmin. 2023-08-07 08:57:26.287 - [ERROR] callbacks.on_experiment_error(224): Simulation error: Error in Function::call for 'F' [IdasInterface] at .../casadi/core/function.cpp:1401: Error in Function::call for 'F' [IdasInterface] at .../casadi/core/function.cpp:330: .../casadi/interfaces/sundials/idas_interface.cpp:596: IDASolve returned "IDA_CONV_FAIL". Consult IDAS documentation. ERROR:pybamm.logger:Simulation error: Error in Function::call for 'F' [IdasInterface] at .../casadi/core/function.cpp:1401: Error in Function::call for 'F' [IdasInterface] at .../casadi/core/function.cpp:330: .../casadi/interfaces/sundials/idas_interface.cpp:596: IDASolve returned "IDA_CONV_FAIL". Consult IDAS documentation.

brosaplanella commented 1 year ago

Using the following solver works for me:

safe_solver = pybamm.CasadiSolver(mode="safe")
Sunnyturicum commented 1 year ago

Thank you for your answer. I ran the model with your solver. Unfortunately, I still get the following error message after 319/1000 cycles.

""" At t = 299.973 and h = 1.45273e-09, the corrector convergence failed repeatedly or with |h| = hmin. 2023-08-07 19:28:09.253 - [ERROR] callbacks.on_experiment_error(224): Simulation error: Error in Function::call for 'F' [IdasInterface] at .../casadi/core/function.cpp:1401: Error in Function::call for 'F' [IdasInterface] at .../casadi/core/function.cpp:330: .../casadi/interfaces/sundials/idas_interface.cpp:596: IDASolve returned "IDA_CONV_FAIL". Consult IDAS documentation. ERROR:pybamm.logger:Simulation error: Error in Function::call for 'F' [IdasInterface] at .../casadi/core/function.cpp:1401: Error in Function::call for 'F' [IdasInterface] at .../casadi/core/function.cpp:330: .../casadi/interfaces/sundials/idas_interface.cpp:596: IDASolve returned "IDA_CONV_FAIL". Consult IDAS documentation. """

Do you have an idea why this happens? From the IDAS documentation, it is unclear to me what causes the error IDA_CONV_FAIL.

brosaplanella commented 1 year ago

That's strange, mine ran all 1000 cycles. Check that you are using the most recent version of PyBaMM and Casadi.

Sunnyturicum commented 1 year ago

By separately installing the Casadi Solver, the new version got installed, and it works now - thank you.

%pip install casadi
%pip install pybamm
flag2freefish commented 1 year ago

using pybamm>23.5 will output log like they said. it might be a bug.

GeXu66 commented 11 months ago

By separately installing the Casadi Solver, the new version got installed, and it works now - thank you.

%pip install casadi
%pip install pybamm

hello! I met the same problem, could you tell me your casadi and pybamm version? Thank you!

Sunnyturicum commented 10 months ago

By separately installing the Casadi Solver, the new version got installed, and it works now - thank you.

%pip install casadi
%pip install pybamm

hello! I met the same problem, could you tell me your casadi and pybamm version? Thank you!

Look at this: https://github.com/ArnaudOlt/dissertation_pybamm