-
-
Notifications
You must be signed in to change notification settings - Fork 543
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]: 23.9 - ShapeError from electrolyte equation when specifying "Ambient temperature [K]" as pybamm.Interpolant #3630
Comments
Correct, you need to wrap the |
This should have been documented as a breaking change. I don't know if there is some nice way to automatically detect if it is just a function of a single variable, in which case it is assumed to be a function of time only. |
Yes, that is a fair point. At the moment, every |
Historically, most of the thermal stuff in PyBaMM was developed for single-layer pouch cell models, so there are lots of hangovers from design choices based on that. |
I'd feel it's most Pythonic to put optional arguments last, and explicitly allow them to be optional. In general we don't want to have to write functions whose return values don't depend on their arguments, right? What's happened here is that you've enabled complicated behaviour by requiring simple behaviour to have a complicated calling pattern! |
Sorry, can you offer example code? I tried substituting the interpolant with a callable as follows, but got the same
and got the same error. |
#
# Example showing how to solve the DFN with a varying ambient temperature
#
import pybamm
import numpy as np
pybamm.set_logging_level("DEBUG")
# load model
options = {"thermal": "lumped"}
model = pybamm.lithium_ion.DFN(options)
# create geometry
geometry = model.default_geometry
# load parameter values and process model and geometry
times = np.arange(0, 1810, 10)
tmax = max(times)
def ambient_temperature(y, z, t):
return pybamm.Interpolant(times, 298.15 + 20 * (times / tmax), pybamm.t)
param = model.default_parameter_values
param.update(
{"Ambient temperature [K]": ambient_temperature}, check_already_exists=False
)
param.process_model(model)
param.process_geometry(geometry)
# set mesh
var_pts = {"x_n": 30, "x_s": 30, "x_p": 30, "r_n": 10, "r_p": 10}
mesh = pybamm.Mesh(geometry, model.default_submesh_types, var_pts)
# discretise model
disc = pybamm.Discretisation(mesh, model.default_spatial_methods)
disc.process_model(model)
# solve model
t_eval = np.linspace(0, 3600 / 2, 100)
solver = pybamm.CasadiSolver(mode="fast", atol=1e-6, rtol=1e-3)
solution = solver.solve(model, t_eval)
# plot
plot = pybamm.QuickPlot(
solution, ["X-averaged cell temperature [K]", "Ambient temperature [K]"]
)
plot.dynamic_plot() |
That works, but I get an error with your example. Will look into it. |
@rtimms Any further insight into why the fix is not effective for the test case I suggested? |
@ejfdickinson I'll make it a priority to look this week |
@ejfdickinson I've identified the bug and am working on a fix. For now, a very hacky workaround is to make sure y or z is in the returned function so that the discretisation identifies the shape correctly. E.g. import pybamm
import numpy as np
times = np.arange(0, 1810, 10)
tmax = max(times)
experiment = pybamm.Experiment([f"Discharge at 1C for {tmax} s"])
def temp_drive_cycle(y, z, t):
return 1e-32 * y + pybamm.Interpolant(times, 298.15 + 20 * (times / tmax), t)
parameter_values = pybamm.ParameterValues("Chen2020")
parameter_values.update(
{"Initial temperature [K]": 298.15, "Ambient temperature [K]": temp_drive_cycle}
)
sim = pybamm.Simulation(
model=pybamm.lithium_ion.DFN(),
parameter_values=parameter_values,
experiment=experiment,
)
sol = sim.solve()
sol.plot(["Voltage [V]", "Volume-averaged cell temperature [K]"]) |
* Bump to v23.9rc0 * Merge pull request #3412 from agriyakhetarpal/drop-i686-manylinux2014-support Drop support for i686 manylinux * Merge pull request #3413 from Saransh-cpp/improve-release-workflow Improve release workflow, add a note, bump version manually * Merge pull request #3436 from Saransh-cpp/fortnightly-wheels Build wheels on the 1st and 15th of every month * Merge pull request #3445 from pybamm-team/issue-3428-rename-exchange #3428 exchange-current density error * Merge pull request #3449 from pybamm-team/i3431-windows-wheels Fix failing windows wheel builds * Merge pull request #3456 from abillscmu/issue-3224-initial_soc make initial soc work with half cell models * Merge pull request #3467 from abillscmu/bugfix/initial_soh * Merge pull request #3423 from jsbrittain/jax_gpu JaxSolver fails when using GPU support with no input parameters * Fix changelog * Merge pull request #3475 from arjxn-py/fix-default-imports Resolve default imports for optional dependencies * Bump - `v23.9rc1` * Fix date in CHANGELOG * Bump version to v23.9 * Fix docs about Jax solver compatibility with Python versions (#3702) * Ensure correct Python versions for Jax solver compatibility * Simplify array of Python versions Co-authored-by: Eric G. Kratz <kratman@users.noreply.github.com> * Use different conjunction Co-authored-by: Eric G. Kratz <kratman@users.noreply.github.com> --------- Co-authored-by: Eric G. Kratz <kratman@users.noreply.github.com> * Merge pull request #3706 from agriyakhetarpal/fix-pybamm-install-odes Make `pybamm_install_odes` a bit more robust * #3690 fix issue with skipped steps (#3708) * #3690 fix issue with skipped steps * #3690 changelog * #3690 add test * #3611 use actual cell volume for average total heating (#3707) * #3611 use actual cell volume for average total heating * #3611 changelog * #3611 account for number of electrode pairs * #3611 update variable names * Improve the release workflow (#3737) * Try fixing the release workflow * Turn off safety * Fix CHANGELOG * Add OS * Use regex for better matches * Update instructions, add safety checks * checkout to the version branch for the final release * Bump to v24.1rc1 * #3630 fix interpolant shape error (#3761) * #3630 fix interpolant shape error * #3630 changelog * Bump to v24.1rc2 * Bump to v24.1 * Fix doctests failures in scheduled tests (#3784) Closes #3781 * Resolve broken `scikits.odes` installation on self-hosted M-series runner (#3785) * Try fixing M-series runner tests This is being done by adding SuiteSparse and SUNDIALS installations which might have been missing on the runner, which broke `scikits.odes`. * Don't use Homebrew SUNDIALS, use LD_LIBRARY_PATH * Don't use Homebrew to install SUNDIALS * Force remove pip cache for `scikits.odes` --------- Co-authored-by: Eric G. Kratz <kratman@users.noreply.github.com> * add temperature dependence to MSMR model * changelog * fix tests * fix example * rob comments * update notebook --------- Co-authored-by: Ferran Brosa Planella <Ferran.Brosa-Planella@warwick.ac.uk> Co-authored-by: Saransh Chopra <saransh0701@gmail.com> Co-authored-by: Martin Robinson <martinjrobins@gmail.com> Co-authored-by: Agriya Khetarpal <74401230+agriyakhetarpal@users.noreply.github.com> Co-authored-by: Eric G. Kratz <kratman@users.noreply.github.com> Co-authored-by: Robert Timms <43040151+rtimms@users.noreply.github.com> Co-authored-by: Saransh-cpp <Saransh-cpp@users.noreply.github.com>
* pybamm-team#3630 fix interpolant shape error * pybamm-team#3630 changelog
* Bump to v23.9rc0 * Merge pull request pybamm-team#3412 from agriyakhetarpal/drop-i686-manylinux2014-support Drop support for i686 manylinux * Merge pull request pybamm-team#3413 from Saransh-cpp/improve-release-workflow Improve release workflow, add a note, bump version manually * Merge pull request pybamm-team#3436 from Saransh-cpp/fortnightly-wheels Build wheels on the 1st and 15th of every month * Merge pull request pybamm-team#3445 from pybamm-team/issue-3428-rename-exchange pybamm-team#3428 exchange-current density error * Merge pull request pybamm-team#3449 from pybamm-team/i3431-windows-wheels Fix failing windows wheel builds * Merge pull request pybamm-team#3456 from abillscmu/issue-3224-initial_soc make initial soc work with half cell models * Merge pull request pybamm-team#3467 from abillscmu/bugfix/initial_soh * Merge pull request pybamm-team#3423 from jsbrittain/jax_gpu JaxSolver fails when using GPU support with no input parameters * Fix changelog * Merge pull request pybamm-team#3475 from arjxn-py/fix-default-imports Resolve default imports for optional dependencies * Bump - `v23.9rc1` * Fix date in CHANGELOG * Bump version to v23.9 * Fix docs about Jax solver compatibility with Python versions (pybamm-team#3702) * Ensure correct Python versions for Jax solver compatibility * Simplify array of Python versions Co-authored-by: Eric G. Kratz <kratman@users.noreply.github.com> * Use different conjunction Co-authored-by: Eric G. Kratz <kratman@users.noreply.github.com> --------- Co-authored-by: Eric G. Kratz <kratman@users.noreply.github.com> * Merge pull request pybamm-team#3706 from agriyakhetarpal/fix-pybamm-install-odes Make `pybamm_install_odes` a bit more robust * pybamm-team#3690 fix issue with skipped steps (pybamm-team#3708) * pybamm-team#3690 fix issue with skipped steps * pybamm-team#3690 changelog * pybamm-team#3690 add test * pybamm-team#3611 use actual cell volume for average total heating (pybamm-team#3707) * pybamm-team#3611 use actual cell volume for average total heating * pybamm-team#3611 changelog * pybamm-team#3611 account for number of electrode pairs * pybamm-team#3611 update variable names * Improve the release workflow (pybamm-team#3737) * Try fixing the release workflow * Turn off safety * Fix CHANGELOG * Add OS * Use regex for better matches * Update instructions, add safety checks * checkout to the version branch for the final release * Bump to v24.1rc1 * pybamm-team#3630 fix interpolant shape error (pybamm-team#3761) * pybamm-team#3630 fix interpolant shape error * pybamm-team#3630 changelog * Bump to v24.1rc2 * Bump to v24.1 * Fix doctests failures in scheduled tests (pybamm-team#3784) Closes pybamm-team#3781 * Resolve broken `scikits.odes` installation on self-hosted M-series runner (pybamm-team#3785) * Try fixing M-series runner tests This is being done by adding SuiteSparse and SUNDIALS installations which might have been missing on the runner, which broke `scikits.odes`. * Don't use Homebrew SUNDIALS, use LD_LIBRARY_PATH * Don't use Homebrew to install SUNDIALS * Force remove pip cache for `scikits.odes` --------- Co-authored-by: Eric G. Kratz <kratman@users.noreply.github.com> * add temperature dependence to MSMR model * changelog * fix tests * fix example * rob comments * update notebook --------- Co-authored-by: Ferran Brosa Planella <Ferran.Brosa-Planella@warwick.ac.uk> Co-authored-by: Saransh Chopra <saransh0701@gmail.com> Co-authored-by: Martin Robinson <martinjrobins@gmail.com> Co-authored-by: Agriya Khetarpal <74401230+agriyakhetarpal@users.noreply.github.com> Co-authored-by: Eric G. Kratz <kratman@users.noreply.github.com> Co-authored-by: Robert Timms <43040151+rtimms@users.noreply.github.com> Co-authored-by: Saransh-cpp <Saransh-cpp@users.noreply.github.com>
PyBaMM Version
23.9
Python Version
3.9.13
Describe the bug
As of 23.9, using a
pybamm.Interpolant
to specify the"Ambient temperature [K]"
, to run a spatially isothermal model with a specified transient temperature profile, raises aShapeError
withinDiscretisation.process_dict()
acting on the equation with key"Electrolyte current density [A.m-2]"
.This parameter definition pattern was supported and functional in 23.5.
Steps to Reproduce
Works in 23.5. Fails in 23.9.
Relevant log output
The text was updated successfully, but these errors were encountered: