Skip to content
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

#1886 added fix within processed variable #1894

Merged
merged 9 commits into from
Jan 17, 2022
2 changes: 1 addition & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

- Parameters can now be imported from any given path in `Windows` ([#1900](https://github.com/pybamm-team/PyBaMM/pull/1900))
- Fixed initial conditions for the EC SEI model ([#1895](https://github.com/pybamm-team/PyBaMM/pull/1895))
- Fixed issue in extraction of sensitivites ([#1894](https://github.com/pybamm-team/PyBaMM/pull/1894))

# [v21.12](https://github.com/pybamm-team/PyBaMM/tree/v21.11) - 2021-12-29

Expand All @@ -14,7 +15,6 @@
- Added cylindrical geometry and finite volume method ([#1824](https://github.com/pybamm-team/PyBaMM/pull/1824))

## Bug fixes

- `PyBaMM` is now importable in `Linux` systems where `jax` is already installed ([#1874](https://github.com/pybamm-team/PyBaMM/pull/1874))
- Simulations with drive cycles now support `initial_soc` ([#1842](https://github.com/pybamm-team/PyBaMM/pull/1842))
- Fixed bug in expression tree simplification ([#1831](https://github.com/pybamm-team/PyBaMM/pull/1831))
Expand Down
7 changes: 6 additions & 1 deletion pybamm/solvers/base_solver.py
Original file line number Diff line number Diff line change
Expand Up @@ -1459,7 +1459,12 @@ def _set_up_ext_and_inputs(
inputs[name] = casadi.MX.sym(name, input_param._expected_size)

external_variables = external_variables or {}
ext_and_inputs = {**external_variables, **inputs}

ordered_inputs_names = list(inputs.keys())
ordered_inputs_names.sort()
ordered_inputs = {name: inputs[name] for name in ordered_inputs_names}

ext_and_inputs = {**external_variables, **ordered_inputs}
return ext_and_inputs


Expand Down
13 changes: 9 additions & 4 deletions pybamm/solvers/processed_variable.py
Original file line number Diff line number Diff line change
Expand Up @@ -351,10 +351,14 @@ def initialise_2D(self):
self.second_dimension = "x"
self.R_sol = first_dim_pts
self.x_sol = second_dim_pts
elif self.domain[0] in [
"negative particle size",
"positive particle size",
] and self.auxiliary_domains["secondary"] == ["current collector"]:
elif (
self.domain[0]
in [
"negative particle size",
"positive particle size",
]
and self.auxiliary_domains["secondary"] == ["current collector"]
):
self.first_dimension = "R"
self.second_dimension = "z"
self.R_sol = first_dim_pts
Expand Down Expand Up @@ -563,6 +567,7 @@ def initialise_sensitivity_explicit_forward(self):
name: casadi.MX.sym(name, value.shape[0])
for name, value in self.all_inputs[0].items()
}

p_casadi_stacked = casadi.vertcat(*[p for p in p_casadi.values()])

# Convert variable to casadi format for differentiating
Expand Down
3 changes: 2 additions & 1 deletion tests/unit/test_solvers/test_casadi_solver.py
Original file line number Diff line number Diff line change
Expand Up @@ -589,9 +589,10 @@ def test_solve_sensitivity_scalar_var_scalar_input(self):
solution = solver.solve(
model,
t_eval,
inputs={"p": 0.1, "q": 2, "r": -1, "s": 0.5},
inputs={"r": -1, "s": 0.5, "q": 2, "p": 0.1},
calculate_sensitivities=True,
)

np.testing.assert_allclose(solution.y[0], -1 + 0.2 * solution.t)
np.testing.assert_allclose(
solution.sensitivities["p"],
Expand Down