Skip to content

[Bug]: AttributeError: 'SPM' object has no attribute 'len_rhs_sens' on one machine, not another #380

@xindoreen

Description

@xindoreen

liionpack Version

0.4.0

Python Version

3.12.10 64-bit

Describe the bug

I am encountering an AttributeError: 'SPM' object has no attribute 'len_rhs_sens' when running liionpack example code on my laptop. The exact same code, environment setup (Python, PyBaMM, and liionpack versions), and dependencies run without any error on my desktop machine.

Environment
Operating System (Laptop): Windows (inferred from traceback paths)

Python Version: 3.12.10 (on both laptop and desktop)

PyBaMM Version: 25.6.0 (on both laptop and desktop)

liionpack Version: 0.4.0 (on both laptop and desktop)

CasADi Version: 3.6.7 (on both laptop and desktop)

Steps to Reproduce

  1. Here below is the code:
    import liionpack as lp
    import pybamm
    import numpy as np
    import matplotlib.pyplot as plt

I_mag = 30.0
OCV_init = 4.0 # used for intial guess
Ri_init = 5e-2 # used for intial guess
R_busbar = 1.5e-3
R_connection = 1e-2
Np = 4
Ns = 1
Nbatt = Np * Ns

netlist = lp.setup_circuit(Np=Np, Ns=Ns, Rb=R_busbar, Rc=R_connection, Ri=Ri_init, V=OCV_init, I=I_mag)

experiment = pybamm.Experiment(
["Charge at 15 A for 10 minutes", "Rest for 10 minutes", "Discharge at 15 A for 10 minutes", "Rest for 10 minutes"]*100,
period="30 seconds",)

parameter_values = pybamm.ParameterValues("Chen2020")

SPMe = pybamm.models.full_battery_models.lithium_ion.SPMe()

output_variables = [
"X-averaged negative particle surface concentration [mol.m-3]",
"X-averaged positive particle surface concentration [mol.m-3]",
]

output = lp.solve(
netlist=netlist,
parameter_values=parameter_values,
experiment=experiment,
output_variables=output_variables,
initial_soc=0.5
)

lp.plot_output(output)

  1. Actual Behavior
    On the laptop, the script terminates with an AttributeError, indicating that the SPM model object from PyBaMM does not have the attribute len_rhs_sens. This happens during the liionpack.solve call, specifically within liionpack.solver_utils.py and liionpack.solvers.py.

A pkg_resources deprecation warning is also observed, though this is likely unrelated to the core AttributeError.

Full Traceback
Traceback (most recent call last):
File "c:\Users.......\temp.py", line 30, in
output = lp.solve(
Resources is deprecated as an API. See https://setuptools.pypa.io/en/latest/pkg_resources.html. The pkg_resources package is slated for removal as early as 2025-11-30. Refrain from using this package or pin to Setuptools<81.
import pkg_resources
Traceback (most recent call last):
File "c:\Users..........\temp.py", line 30, in
output = lp.solve(
ckage is slated for removal as early as 2025-11-30. Refrain from using this package or pin to Setuptools<81.
import pkg_resources
Traceback (most recent call last):
File "c:\Users............\temp.py", line 30, in
output = lp.solve(
import pkg_resources
Traceback (most recent call last):
File "c:\Users................\temp.py", line 30, in
output = lp.solve(
Traceback (most recent call last):
File "c:\Users..............\temp.py", line 30, in
output = lp.solve(
File "c:\Users................\temp.py", line 30, in
output = lp.solve(
^^^^^^^^^
output = lp.solve(
^^^^^^^^^
^^^^^^^^^
File "C:\Users\R103098\AppData\Local\Programs\Python\Python312\Lib\site-packages\liionpack\solver_utils.py", line 428, in solve
output = rm.solve(
File "C:\Users\R103098\AppData\Local\Programs\Python\Python312\Lib\site-packages\liionpack\solver_utils.py", line 428, in solve
output = rm.solve(
428, in solve
output = rm.solve(
output = rm.solve(
^^^^^^^^^
File "C:\Users\R103098\AppData\Local\Programs\Python\Python312\Lib\site-packages\liionpack\solvers.py", line 229, ^^^^^^^^^
File "C:\Users\R103098\AppData\Local\Programs\Python\Python312\Lib\site-packages\liionpack\solvers.py", line 229, in solve
File "C:\Users\R103098\AppData\Local\Programs\Python\Python312\Lib\site-packages\liionpack\solvers.py", line 229, in solve
self.setup_actors(nproc, self.inputs_dict, initial_soc)
in solve
self.setup_actors(nproc, self.inputs_dict, initial_soc)
self.setup_actors(nproc, self.inputs_dict, initial_soc)
File "C:\Users\R103098\AppData\Local\Programs\Python\Python312\Lib\site-packages\liionpack\solvers.py", line 547, in setup_actors
in setup_actors
a.setup(
a.setup(
File "C:\Users\R103098\AppData\Local\Programs\Python\Python312\Lib\site-packages\liionpack\solvers.py", line 59,
in setup
in setup
casadi_objs = cco(
casadi_objs = cco(
^^^^
File "C:\Users\R103098\AppData\Local\Programs\Python\Python312\Lib\site-packages\liionpack\solver_utils.py", line 295, in _create_casadi_objects
model.len_rhs + model.len_rhs_sens + model.len_alg + model.len_alg_sens
^^^^^^^^^^^^^^^^^^
AttributeError: 'SPM' object has no attribute 'len_rhs_sens'

  1. Additional Context / Troubleshooting Attempts
    Verified that Python, PyBaMM, and liionpack versions are identical (3.12.10, 25.6.0, 0.4.0 respectively) on both machines.
    The code running is a direct copy of a liionpack example, which functions correctly on the desktop.
    The pkg_resources warning appears multiple times, but the core issue is the AttributeError.

Expected behaviour

No response

Relevant log output

Additional context

No response

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