Skip to content

Commit

Permalink
Merge pull request #4245 from pybamm-team/fix-batch-study-test
Browse files Browse the repository at this point in the history
Fix batch study test
  • Loading branch information
valentinsulzer authored Jul 5, 2024
2 parents f270232 + 10b7412 commit 4486522
Showing 1 changed file with 35 additions and 26 deletions.
61 changes: 35 additions & 26 deletions tests/unit/test_batch_study.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down Expand Up @@ -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])

Expand Down

0 comments on commit 4486522

Please sign in to comment.