Refactor to use PathSim solver#2
Conversation
|
Usually |
|
Thanks, I realized it's actually not needed! Removed it. Good to merge from your side? |
|
give me a moment, I am currently reviewing it again, missed some things about how pybamm works |
|
So I did some digging now. The current implementation wraps The correct approach is to extract pybamms discretized ODE/DAE after The Sorry for the confusion. |
|
Thanks, I got it! I was able to refactor it using PyBaMMs own Can you have another look please? If there is no show stopper from your side, after merging I'd reach out to the PyBaMM dev to give feedback directly, whether they think this is the right approach. (For curiosity: one of the PyBaMM main devs demonstrated here https://github.com/FaradayInstitution/pybamm_simulink_example long ago how to call PyBaMM from Simulink, and it also uses |
|
I'll check! :) |
There was a problem hiding this comment.
Pull request overview
This PR refactors the PyBaMM-based cell blocks to integrate with PathSim by exporting CasADi dynamics at construction time (instead of stepping PyBaMM internally), and updates tests/docs to reflect the new integration approach.
Changes:
- Refactor
_CellBaseto subclassDynamicalSystemand expose CasADi RHS/Jacobian + output functions for PathSim integration. - Update cell integration tests to run via
pathsim.Simulation(Constants + Connections) instead of callingbuffer/step/updatedirectly. - Minor formatting/lint cleanups and README updates describing immediate model discretisation.
Reviewed changes
Copilot reviewed 4 out of 4 changed files in this pull request and generated 5 comments.
| File | Description |
|---|---|
src/pathsim_batt/cells/pybamm_cell.py |
Replaces internal PyBaMM stepping with CasADi-exported dynamics for PathSim solvers. |
tests/cells/test_pybamm_cell.py |
Updates tests to exercise PathSim-driven integration and validates CasADi setup. |
src/pathsim_batt/thermal/lumped.py |
Small formatting/tidy changes; no substantive logic change. |
README.md |
Updates integration description from lazy build to immediate discretisation. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 4 out of 4 changed files in this pull request and generated 6 comments.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 4 out of 4 changed files in this pull request and generated 3 comments.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
|
@milanofthe I think now it's worth to have another look 🙂 |
|
@DavidMStraub do you know how intertwined casadi is into pybamm? And sorry for the late reply, I will review it this weekend. |
|
@DavidMStraub looks much better now! :) A few small last things:
Besides that, looks good! |
|
Thanks for the feedback! You're right to wonder about the patched PyBaMM calculates lots of other observables (not just the ones I wired into the output ports) and this was a way to make them accessible, but a hacky way. Is there a way to expose (a potentially large number of) additional variables without making them output ports? Also updated the doc string as suggested. I will merge this now. As a next step, I'll ping the PyBaMM devs via the project's Slack channel and ask them for feedback. Let me know if I should transfer the repo to the pathsim org now. |
|
@DavidMStraub great! Since the pybamm object lives inside of the block, its attributes should still be accessible directly that way. If you want something more direct Id say add a somple getter method to the block thatmis specifically for retrieving these values. Otherwise I think you can transfer the repo. |
|
Github says
Can you add me to the pathsim org with the permissions required? After transfer, also maintainer access to the repo. Create repository access can be removed again after the migration. |
|
@DavidMStraub you can just transfer the repo, this works through the dangerous section. I will add you as maintainer to the repo afer that. |
|
That's what I meant - I can't do that, error message above. It makes sense that org non-members cannot just move arbitrary repos into an org. |
|
gocha, give me a minute |
|
i have sent an invite |
@milanofthe except for lint and formatter fixes, the relevant change here is the override of
set_solverin_CellBase. Is this allowed? If not, what's the right way to make it work?PS: regarding formatting, I think it makes sense to use ruff, but you can tune the settings to match your preferred style.