From 359dec633f893e4f583120c62181042f8c85be87 Mon Sep 17 00:00:00 2001 From: Valentin Sulzer Date: Fri, 5 Jul 2024 11:21:54 -0400 Subject: [PATCH] move batch study setup into test so it isn't run first by other tests --- tests/unit/test_batch_study.py | 61 +++++++++++++++++++--------------- 1 file changed, 35 insertions(+), 26 deletions(-) diff --git a/tests/unit/test_batch_study.py b/tests/unit/test_batch_study.py index ab7370a193..2713a3f35b 100644 --- a/tests/unit/test_batch_study.py +++ b/tests/unit/test_batch_study.py @@ -8,34 +8,38 @@ import unittest from tempfile import TemporaryDirectory -spm = pybamm.lithium_ion.SPM() -spm_uniform = pybamm.lithium_ion.SPM({"particle": "uniform profile"}) -casadi_safe = pybamm.CasadiSolver(mode="safe") -casadi_fast = pybamm.CasadiSolver(mode="fast") -exp1 = pybamm.Experiment([("Discharge at C/5 for 10 minutes", "Rest for 1 hour")]) -exp2 = pybamm.Experiment([("Discharge at C/20 for 10 minutes", "Rest for 1 hour")]) - -bs_false_only_models = pybamm.BatchStudy( - models={"SPM": spm, "SPM uniform": spm_uniform} -) -bs_true_only_models = pybamm.BatchStudy( - models={"SPM": spm, "SPM uniform": spm_uniform}, permutations=True -) -bs_false = pybamm.BatchStudy( - models={"SPM": spm, "SPM uniform": spm_uniform}, - solvers={"casadi safe": casadi_safe, "casadi fast": casadi_fast}, - experiments={"exp1": exp1, "exp2": exp2}, -) -bs_true = pybamm.BatchStudy( - models={"SPM": spm, "SPM uniform": spm_uniform}, - solvers={"casadi safe": casadi_safe, "casadi fast": casadi_fast}, - experiments={"exp2": exp2}, - permutations=True, -) - class TestBatchStudy(TestCase): def test_solve(self): + spm = pybamm.lithium_ion.SPM() + spm_uniform = pybamm.lithium_ion.SPM({"particle": "uniform profile"}) + casadi_safe = pybamm.CasadiSolver(mode="safe") + casadi_fast = pybamm.CasadiSolver(mode="fast") + exp1 = pybamm.Experiment( + [("Discharge at C/5 for 10 minutes", "Rest for 1 hour")] + ) + exp2 = pybamm.Experiment( + [("Discharge at C/20 for 10 minutes", "Rest for 1 hour")] + ) + + bs_false_only_models = pybamm.BatchStudy( + models={"SPM": spm, "SPM uniform": spm_uniform} + ) + bs_true_only_models = pybamm.BatchStudy( + models={"SPM": spm, "SPM uniform": spm_uniform}, permutations=True + ) + bs_false = pybamm.BatchStudy( + models={"SPM": spm, "SPM uniform": spm_uniform}, + solvers={"casadi safe": casadi_safe, "casadi fast": casadi_fast}, + experiments={"exp1": exp1, "exp2": exp2}, + ) + bs_true = pybamm.BatchStudy( + models={"SPM": spm, "SPM uniform": spm_uniform}, + solvers={"casadi safe": casadi_safe, "casadi fast": casadi_fast}, + experiments={"exp2": exp2}, + permutations=True, + ) + # Tests for exceptions for name in pybamm.BatchStudy.INPUT_LIST: with self.assertRaises(ValueError): @@ -96,7 +100,12 @@ def test_create_gif(self): ValueError, "The simulations have not been solved yet." ): pybamm.BatchStudy( - models={"SPM": spm, "SPM uniform": spm_uniform} + models={ + "SPM": pybamm.lithium_ion.SPM(), + "SPM uniform": pybamm.lithium_ion.SPM( + {"particle": "uniform profile"} + ), + } ).create_gif() bs.solve([0, 10])