Skip to content

Commit 55c5e88

Browse files
#492 don't print casadi warnings in test
1 parent 2fd4883 commit 55c5e88

File tree

2 files changed

+2
-11
lines changed

2 files changed

+2
-11
lines changed

pybamm/solvers/casadi_solver.py

+1-2
Original file line numberDiff line numberDiff line change
@@ -243,7 +243,6 @@ def integrate_casadi(
243243
"output_t0": True,
244244
"max_num_steps": self.max_steps,
245245
}
246-
options.update(self.extra_options)
247246
if self.method == "idas":
248247
options["calc_ic"] = True
249248

@@ -262,7 +261,7 @@ def integrate_casadi(
262261
try:
263262
# Try solving
264263
y0_diff, y0_alg = np.split(y0, [y_diff.shape[0]])
265-
sol = integrator(x0=y0_diff, z0=y0_alg)
264+
sol = integrator(x0=y0_diff, z0=y0_alg, **self.extra_options)
266265
y_values = np.concatenate([sol["xf"].full(), sol["zf"].full()])
267266
return pybamm.Solution(t_eval, y_values, None, None, "final time")
268267
except RuntimeError as e:

tests/unit/test_solvers/test_casadi_solver.py

+1-9
Original file line numberDiff line numberDiff line change
@@ -51,17 +51,14 @@ def test_integrate(self):
5151
self.assertEqual(solution.termination, "final time")
5252

5353
def test_integrate_failure(self):
54-
# Turn off warnings to ignore sqrt error
55-
warnings.simplefilter("ignore")
56-
5754
t = casadi.MX.sym("t")
5855
y = casadi.MX.sym("y")
5956
u = casadi.MX.sym("u")
6057
sqrt_decay = -np.sqrt(y)
6158

6259
y0 = np.array([1])
6360
t_eval = np.linspace(0, 3, 100)
64-
solver = pybamm.CasadiSolver()
61+
solver = pybamm.CasadiSolver(regularity_check=False)
6562
rhs = casadi.Function("rhs", [t, y, u], [sqrt_decay])
6663
# Expect solver to fail when y goes negative
6764
with self.assertRaises(pybamm.SolverError):
@@ -84,21 +81,16 @@ def test_integrate_failure(self):
8481
disc = pybamm.Discretisation(mesh, spatial_methods)
8582
disc.process_model(model)
8683
# Solve with failure at t=2
87-
solver = pybamm.CasadiSolver(rtol=1e-8, atol=1e-8, method="idas")
8884
t_eval = np.linspace(0, 20, 100)
8985
with self.assertRaises(pybamm.SolverError):
9086
solver.solve(model, t_eval)
9187
# Solve with failure at t=0
9288
model.initial_conditions = {var: 0}
9389
disc.process_model(model)
94-
solver = pybamm.CasadiSolver(rtol=1e-8, atol=1e-8, method="idas")
9590
t_eval = np.linspace(0, 20, 100)
9691
with self.assertRaises(pybamm.SolverError):
9792
solver.solve(model, t_eval)
9893

99-
# Turn warnings back on
100-
warnings.simplefilter("default")
101-
10294
def test_bad_mode(self):
10395
with self.assertRaisesRegex(ValueError, "invalid mode"):
10496
pybamm.CasadiSolver(mode="bad mode")

0 commit comments

Comments
 (0)