-
-
Notifications
You must be signed in to change notification settings - Fork 553
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]: casadi_interpolant_linear.dll
not found on Windows with IDAKLUSolver, fails when simulating a drive cycle using Interpolant
#3783
Comments
@agriyakhetarpal: Are you aware of this issue? |
Thanks @chmabaur – first time I am looking at this, will explore further. From an initial look, it looks like it's using some version of |
@agriyakhetarpal Thanks for the very fast reply :-). Seems like the dll is linked wrongly, as the folder C:\vcpkg does not exist on my computer. I have uninstalled casadi 3.6.4 and installed casadi 3.6.3, but still it is looking for C:\vcpkg\buildtrees\casadi\src\3.6.4-aa7d507b6b.clean\ .... (note version 3.6.4 ...). |
Fair enough. I will look into possible issues with the wheel for v24.1rc2. Could you check if v24.1rc1 and v24.1rc0 work with your script or do they raise the same error? |
casadi_interpolant_linear.dll
not found on Windows with IDAKLUSolver, fails when simulating a drive cycle using Interpolant
I have renamed the issue to reflect how this is a problem with the compilation of the solver rather than its use of it – it might work without issues on a different platform. |
Getting the same error for all 24.1 versions. |
@chmabaur that makes sense, though I think this is a CasADi problem. I ran
which suggests that the PyBaMM wheel is built properly since the top two of the DLLs in the list are provided by Windows APIs (I ran it on macOS which is why I don't have them, and in other words the wheel is now tested, even!). However, I am happy to suggest an array of options:
This is a very tricky bug to solve and I can't deny the plausibility of something being wrong in building the wheels on our end – I hope these solutions work for you. I am assuming that the |
@agriyakhetarpal I am a bit confused. I have found the file DependencyWalker on And yes, |
Thanks for your insights. I would say we didn't link the wheel wrongly, because I am unable to reproduce the issue; however I can only assume so – did adjusting/prepending PYTHONPATH, CASADIPATH, or PATH to the CasADi directory give any insights? Dependency Walker is a bit unreliable since it is a piece of legacy software hasn't been designed to work with newer Windows editions and does manage to bring up false positives too sometimes, not that it did so in this case. I am not aware of any popular alternatives. Does https://github.com/lucasg/Dependencies provide any insights – from a quick look it looks like a rewrite of the tool? I don't know if renaming and removing the It looks like an upstream bug in your case. I also found that Windows error 126 is also associated with insufficient permissions |
Yes I was using the Dependencies software actually as I got some errors with Dependency Walker :-). I have added You cannot reproduce the issue? I actually get the same error on two different Windows systems, so I expect this to occur also for other users. What operating system are you using? Do you use self-compiled package or do you use virtual environment with all installed with pip? |
I am able to reproduce the issue on a Windows 11 amd64 machine, now. I downloaded the 24.1 PyBaMM wheel that hit PyPI a few hours ago and installed it with I will try looking into this, it looks like we should be testing PyBaMM much more extensively after wheels for it are built, across platforms. The MWE looks like it works on my macOS system, however – it returns no errors there. |
cc: @jsbrittain and @martinjrobins, would appreciate your help debugging this especially because this has affected the |
@chmabaur, I'm just trying to ascertain when the problem arose – could you re-test the wheels from our conversation in #3100 (comment) with your MWE and check if it works as intended? |
@agriyakhetarpal I get the same error with https://github.com/agriyakhetarpal/PyBaMM/actions/runs/7137563916 these wheels. |
@agriyakhetarpal Hi - I don't have a solution, but wanted to add the following observations. I've managed to recreate the issue described above, and in addition tried to run a MWE using only casadi. The result is interesting, and makes me suspect that there is a bug in the pybamm wheel build process. Briefly, this code creates a linear interpolant in casadi (no pybamm): import numpy as np
from casadi import interpolant
u = np.linspace(1, 5, 10)
v = 2 * u
f = interpolant("interp", "linear", [u], v, {}) This runs fine on windows (github runner) and macos (my macbook). If you then remove or rename
This looks a lot like the error original reported, but with two important differences:
Moving the dll into the current working directory resolves the issue (i.e. does not produce the segmentation fault mentioned above; which is also reproducible). Trying the original MWE in the same environment produces the error listed at the top of this issue ( |
@agriyakhetarpal Installing PyBaMM 23.1 on Windows produces the (now resolved) |
Thank you for this investigation, @jsbrittain – from what I understand, it looks like Python-CasADi works well and as expected, but PyBaMM's IDAKLU-wrapped CasADi is looking at the wrong paths for its libraries. Perhaps, if we are able to use the Python-CasADi for our linkage on Windows (#3603)—trying which did not work during my experiments in #3100 as we had discussed and had similar issues with On an unrelated note, we should consider using From what you said, can we assume that we have a temporary workaround for this issue, i.e., "Moving the dll into the current working directory" which should make the drive cycle script work, or was this just for the CasADi code snippet? |
That was just for the casadi code snippet I'm afraid. Renaming the files for PyBaMM produces a segmentation fault (which suggests that it is not just the name, but a version mismatch also?). |
Fair enough, we can't realistically keep the CasADi versions in sync for the most part. We should be able to keep the build-system CasADi as such in order to build wheels with the same version as the one defined in the |
@agriyakhetarpal I'm not confident that I know where the fault is. There does seem to be an inconsistency in naming with casadi on Windows. When downloading and building using cmake the output files are |
Makes sense, @jsbrittain. Should we post this to the new P.S. My comment about removing the |
I wanted to post an update on this: based on the logs for pybop-team/PyBOP#176 where the IDAKLU solver is getting added to PyBOP, this issue is not just applicable for Windows wheels but for Linux and macOS wheels too, and I think I have some progress. I still haven't been able to ascertain the cause of the issue, but it has something to do where the Lines 89 to 93 in 4597143
i.e., an incorrect configuration of the runtime search path for the compiled CasADi files (the RPATH could be retained, but I can try to revisit this issue later this week and rebuild the wheels without this configuration, but I have a strong hunch that reverting the suitable changes in #3569 (just this file, not the SuiteSparse and SUNDIALS fixes for their RPATHs) should fix the issue. This may not resolve the Windows error, however. (Does RPATH have a significance on Windows? I am unaware). Another tidbit that might be unrelated, but, on a Windows machine I did try to copy all the Right now, a workaround is to build PyBaMM from source, where this issue does not seem to occur. This is appropriate for Linux and macOS, but for Windows it's a bit tricky and the reference is in the I think the lesson from this is to advocate for better testing for the wheels after they have been built. We don't bundle the test-related configurations and files inside the wheel (see #3617 and the publicly-announced GSoC project for it this year), but to get around that we should download these wheels as artifacts and test all of them manually in a job that installs them and runs all of the files under |
I also tried setting valid environment variables but still receive the same error on linux, can this issue be related casadi#1932 |
@arjxn-py and I have some progress on this; nothing concrete and I think we are nowhere close to resolution yet. What we think with a now-updated perspective is that the changes in #3569 were, in fact, not what ended up causing the mess, since we looked at all the relevant compiled files one-by-one for various wheels and inspected their runtime search paths, all of them look fine. I have compiled new wheels from a branch on my fork in this run, here: https://github.com/agriyakhetarpal/PyBaMM/actions/runs/8032835499. This branch reverts certain changes from #3569, including those made to the Note that there is a problem with the Previously (with the current PyPI wheels, that is), the script does not work even if @chmabaur, you had mentioned previously in that you received the same error for all 24.1 pre-releases and the final release in #3783 (comment) – additionally, could you please test whether the PyPI wheels for PyBaMM v23.5 and v23.9 are able to run the above script and confirm? Also, does the above set of wheels from the link to the workflow run, with I am unaware whether this is an issue coming from an incorrect repair for the wheels – neither does @jsbrittain, what I think is happening here is that when we link CasADi to the IDAKLU target during the compilation of the extension module, it just tries to find Also, cc @Saransh-cpp: since this issue had revealed that the PyBaMM wheel is broken for v24.1 for users of all platforms and dependents (see pybop-team/PyBOP#176), we had decided in the developer meeting on 19/02/2024 that once the issue gets fixed, a |
Update: @arjxn-py and I proceeded to do some more debugging, and we wanted to post the results – which are a bit more concerning. We tested the above reproducer script with multiple versions of PyBaMM and across architectures (Unix and Windows). We notice that through pybop-team/PyBOP#176 the installation of PyBaMM from source works on Linux and macOS, in the same way how it does for our CI pipelines as well – however, we have not compiled the IDAKLU solver on Windows on PR tests owing to the amount of time it takes (which was estimated to be around ~20-22 minutes because of the slow installation of SuiteSparse + METIS) – and this lack of testing might have been the reason we have never caught this bug before. On fresh and separate conda environments, we proceeded to install PyBaMM from PyPI wheels, both on Linux (WSL) and Windows. We installed PyBaMM v23.3, v23.4.1, v23.5, v23.9, and v24.1 –
Error tracePluginInterface::load_plugin: Cannot load shared library 'casadi_interpolant_linear.dll':
(
Searched directories: 1. casadipath from GlobalOptions
2. CASADIPATH env var
3. PATH env var (Windows)
4. LD_LIBRARY_PATH env var (Linux)
5. DYLD_LIBRARY_PATH env var (osx)
A library may be 'not found' even if the file exists:
* library is not compatible (different compiler/bitness)
* the dependencies are not found
)
Tried '' :
Error code (WIN32): 126
Tried '.' :
Error code (WIN32): 126 We tested and this was the case with v23.3, v23.4.1, v23.5, and v23.9 – which suggests that this bug was occuring silently with
This suggests that the IDAKLU solver has remained to be broken for possibly several released PyBaMM versions over the years across all platforms. I wonder how much of the test suite passes if we do compile the IDAKLU solver on Windows outside of building the wheels... (we don't currently do it for the scheduled tests either where CI completion time is not a concern, see #3664). I had posted some comments previously in about a workaround:
However, these are not exactly workarounds and Windows wheels have just a single DLL ( I'm not sure whether adding would be great to receive help here in order to fix the issue, and I hope that these additional insights are useful – tagging @martinjrobins, @jsbrittain, and @kratman! Perhaps this should lead us to test the built wheels at a priority during the pytest migration project this year rather than as a stretch goal. |
I triggered this workflow yesterday to run both the integration and the unit tests (please see the PR on my fork above) and these were the logs: and surprisingly all of the IDAKLU solver tests on all platforms pass when testing the built wheel, but those that use the IDAKLU solver such as our dependents, say, PyBOP: pybop-team/PyBOP#176 are facing quite a lot of failures. So, perhaps P.S. some of the failures in the tests are currently expected and can be ignored safely, because we have historically not added the testing data or the tests in general into the wheels, but this scenario can change during the the |
I've had a quick look at this. At first I thought it was a bit strange that the windows wheel was even looking for a dll, as far as I can tell we compile casadi statically on windows for the idaklu solver, so the wheel should be self-contained and no need to bring in any dlls. However, I see that casadi uses a plugin system and loads up certain dlls at runtime, including the interpolant one :( This is a pain because its entirely incompatible with our build process for the windows wheel. At the moment I'm not even sure if casadi supports static compilation of their plugins..... but will keep looking |
The solution here might be to avoid the use of the casadi plugin system in pybamm. At the moment we are using it since we use the
Instead we could try and use the explicit function on the This might complain at build time that we don't link in the interpolant lib, if so we might need to add this to our CMakeLists |
I'm not sure how to use |
Thanks, @martinjrobins! I would like to note that there are ways to repair and make the wheel self-contained for Windows too, with the I did a very quick experiment by trying to repair the CasADi Windows wheel with its own shared libraries with pipx run repairwheel casadi-3.6.5-cp312-none-win_amd64.whl --output-dir repaired_wheel/ --lib-dir casadi-3.6.5-cp312-none-win_amd64/casadi/ to get
which leads me to observe that because of this plugin system, CasADi wheels themselves are not properly repaired (on Windows – on Unix platforms it is) before being published to PyPI, and that reveals another source for the problem. One solution will be to run |
This might work, but you'll have to be careful that the version of casadi that we compile for the idaklu solver is the same version as the wheel! Also casadi cross-compile their wheels using mingw, whereas we nativly compile ours with visual studio, so there might be incompatibilities there |
Yes, indeed, compiling the IDAKLU solver (and its prerequisites of course) with something like MinGW or a full-fledged toolchain like MSYS2 is also something I have been thinking about doing, but not sure how much work that would require for porting from MSVC. I know that both SUNDIALS and SuiteSparse (upstream one, rather than the METIS-CMake-Windows one) can use MinGW-w64 (their CI does it) and we can get a BLAS vendor (mostly OpenBLAS) from As for keeping CasADi used to compile IDAKLU with in sync the same version, yes, we'll have to be more careful there at the time of every release, given that problems like #3100 came directly from there that were previously discussed 😬 |
…eam#3783 (pybamm-team#4077) * bug: use casadi MX.interpn_linear function instead of plugin pybamm-team#3783 * bug: fix for 2d and 3d linear interpolant pybamm-team#3783 * cover cubic interpolation in 2d pybamm-team#3783 * pybamm-team#3783 add to changelog --------- Co-authored-by: Agriya Khetarpal <74401230+agriyakhetarpal@users.noreply.github.com>
PyBaMM Version
24.1rc2
Python Version
3.10.11
Describe the bug
I want to simulate a drive cycle by passing an Interpolant function to the "Current function [A]" parameter. This however fails as casadi_interpolant_linear.dll is not found.
Steps to Reproduce
Relevant log output
The text was updated successfully, but these errors were encountered: