Skip to content

Commit

Permalink
Merge pull request #2844 from pybamm-team/issue-2833-random-tests
Browse files Browse the repository at this point in the history
Fix random seed on tests
  • Loading branch information
martinjrobins authored Apr 17, 2023
2 parents 7c69f1d + 6f1a384 commit 1d6bd48
Show file tree
Hide file tree
Showing 146 changed files with 371 additions and 186 deletions.
3 changes: 2 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,12 +29,13 @@

## Bug fixes

- Fix non-deteministic outcome of some tests in the test suite ([#2844](https://github.com/pybamm-team/PyBaMM/pull/2844))
- Fixed excessive RAM consumption when running multiple simulations ([#2823](https://github.com/pybamm-team/PyBaMM/pull/2823))
- Fixed use of last_state as starting_solution in Simulation.solve() ([#2822](https://github.com/pybamm-team/PyBaMM/pull/2822))
- Fixed a bug where variable bounds could not contain `InputParameters` ([#2795](https://github.com/pybamm-team/PyBaMM/pull/2795))
- Improved `model.latexify()` to have a cleaner and more readable output ([#2764](https://github.com/pybamm-team/PyBaMM/pull/2764))
- Fixed electrolyte conservation in the case of concentration-dependent transference number ([#2758](https://github.com/pybamm-team/PyBaMM/pull/2758))
- Fixed `plot_voltage_components` so that the sum of overpotentials is now equal to the voltage ([#2740](https://github.com/pybamm-team/PyBaMM/pull/2740))
- Fixed use of last_state as starting_solution in Simulation.solve() ([#2822](https://github.com/pybamm-team/PyBaMM/pull/2822))

## Optimizations

Expand Down
3 changes: 2 additions & 1 deletion tests/integration/test_experiments.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
#
# Test some experiments
#
from tests import TestCase
import pybamm
import numpy as np
import unittest


class TestExperiments(unittest.TestCase):
class TestExperiments(TestCase):
def test_discharge_rest_charge(self):
experiment = pybamm.Experiment(
[
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
import pybamm
import unittest
import tests
from tests import TestCase


class TestThevenin(unittest.TestCase):
class TestThevenin(TestCase):
def test_basic_processing(self):
model = pybamm.equivalent_circuit.Thevenin()
modeltest = tests.StandardModelTest(model)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
#
# Tests for the asymptotic convergence of the simplified models
#
from tests import TestCase
import pybamm

import numpy as np
import unittest


class TestAsymptoticConvergence(unittest.TestCase):
class TestAsymptoticConvergence(TestCase):
def test_leading_order_convergence(self):
"""
Check that the leading-order model solution converges linearly in C_e to the
Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
#
# Compare basic models with full models
#
from tests import TestCase
import pybamm

import numpy as np
import unittest


class TestCompareBasicModels(unittest.TestCase):
class TestCompareBasicModels(TestCase):
def test_compare_full(self):
basic_full = pybamm.lead_acid.BasicFull()
full = pybamm.lead_acid.Full()
Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
#
# Tests for the asymptotic convergence of the simplified models
#
from tests import TestCase
import pybamm
import numpy as np
import unittest
from tests import StandardOutputComparison


class TestCompareOutputs(unittest.TestCase):
class TestCompareOutputs(TestCase):
def test_compare_averages_asymptotics(self):
"""
Check that the average value of certain variables is constant across submodels
Expand Down
Original file line number Diff line number Diff line change
@@ -1,14 +1,15 @@
#
# Tests for the lead-acid Full model
#
from tests import TestCase
import pybamm
import tests

import unittest
import numpy as np


class TestLeadAcidFull(unittest.TestCase):
class TestLeadAcidFull(TestCase):
def test_basic_processing(self):
options = {"thermal": "isothermal"}
model = pybamm.lead_acid.Full(options)
Expand Down Expand Up @@ -55,7 +56,7 @@ def test_basic_processing_1plus1D(self):
modeltest.test_all(skip_output_tests=True)


class TestLeadAcidFullSurfaceForm(unittest.TestCase):
class TestLeadAcidFullSurfaceForm(TestCase):
def test_basic_processing_differential(self):
options = {"surface form": "differential"}
model = pybamm.lead_acid.Full(options)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,14 +1,15 @@
#
# Tests for the lead-acid LOQS model
#
from tests import TestCase
import pybamm
import tests

import unittest
import numpy as np


class TestLOQS(unittest.TestCase):
class TestLOQS(TestCase):
def test_basic_processing(self):
model = pybamm.lead_acid.LOQS()
modeltest = tests.StandardModelTest(model)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#
# Tests for the lead-acid LOQS model with capacitance
#
from tests import TestCase
import pybamm
import tests

Expand All @@ -9,7 +10,7 @@
import numpy as np


class TestLeadAcidLoqsSurfaceForm(unittest.TestCase):
class TestLeadAcidLoqsSurfaceForm(TestCase):
def test_basic_processing(self):
options = {"surface form": "algebraic"}
model = pybamm.lead_acid.LOQS(options)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,14 +1,15 @@
#
# Tests for the lead-acid Full model
#
from tests import TestCase
import pybamm
import tests

import unittest
import numpy as np


class TestLeadAcidFullSideReactions(unittest.TestCase):
class TestLeadAcidFullSideReactions(TestCase):
def test_basic_processing(self):
options = {"hydrolysis": "true"}
model = pybamm.lead_acid.Full(options)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
#
# Tests for the lead-acid LOQS model
#
from tests import TestCase
import pybamm
import tests
import unittest


class TestLeadAcidLOQSWithSideReactions(unittest.TestCase):
class TestLeadAcidLOQSWithSideReactions(TestCase):
def test_discharge_differential(self):
options = {"surface form": "differential", "hydrolysis": "true"}
model = pybamm.lead_acid.LOQS(options)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
#
# Test basic half-cell model with different parameter values
#
from tests import TestCase
import pybamm

import numpy as np
import unittest


class TestBasicHalfCellModels(unittest.TestCase):
class TestBasicHalfCellModels(TestCase):
def test_runs_Xu2019(self):
options = {"working electrode": "positive"}
model = pybamm.lithium_ion.BasicDFNHalfCell(options=options)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
#
# Compare basic models with full models
#
from tests import TestCase
import pybamm

import numpy as np
import unittest


class TestCompareBasicModels(unittest.TestCase):
class TestCompareBasicModels(TestCase):
def test_compare_dfns(self):
basic_dfn = pybamm.lithium_ion.BasicDFN()
dfn = pybamm.lithium_ion.DFN()
Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
#
# Tests for the surface formulation
#
from tests import TestCase
import pybamm
import numpy as np
import unittest
from tests import StandardOutputComparison


class TestCompareOutputs(unittest.TestCase):
class TestCompareOutputs(TestCase):
def test_compare_outputs_surface_form(self):
# load models
options = [
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,10 @@
import pybamm
import numpy as np
import unittest
from tests import TestCase


class TestCompareOutputsTwoPhase(unittest.TestCase):
class TestCompareOutputsTwoPhase(TestCase):
def compare_outputs_two_phase_graphite_graphite(self, model_class):
"""
Check that a two-phase graphite-graphite model gives the same results as a
Expand Down
Original file line number Diff line number Diff line change
@@ -1,14 +1,15 @@
#
# Tests for the lithium-ion DFN model
#
from tests import TestCase
import pybamm
import tests
import numpy as np
import unittest
from tests import BaseIntegrationTestLithiumIon


class TestDFN(BaseIntegrationTestLithiumIon, unittest.TestCase):
class TestDFN(BaseIntegrationTestLithiumIon, TestCase):
def setUp(self):
self.model = pybamm.lithium_ion.DFN

Expand Down Expand Up @@ -38,7 +39,7 @@ def positive_radius(x):
self.run_basic_processing_test({}, parameter_values=param)


class TestDFNWithSizeDistribution(unittest.TestCase):
class TestDFNWithSizeDistribution(TestCase):
def setUp(self):
params = pybamm.ParameterValues("Marquis2019")
self.params = pybamm.get_size_distribution_parameters(params)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
#
# Tests for the lithium-ion DFN half-cell model
#
from tests import TestCase
import pybamm
import unittest
from tests import BaseIntegrationTestLithiumIonHalfCell


class TestDFNHalfCell(BaseIntegrationTestLithiumIonHalfCell, unittest.TestCase):
class TestDFNHalfCell(BaseIntegrationTestLithiumIonHalfCell, TestCase):
def setUp(self):
self.model = pybamm.lithium_ion.DFN

Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
#
# Tests for inputting a temperature profile
#
from tests import TestCase
import pybamm
import unittest
import numpy as np


class TestInputLumpedTemperature(unittest.TestCase):
class TestInputLumpedTemperature(TestCase):
def test_input_lumped_temperature(self):
model = pybamm.lithium_ion.SPMe()
parameter_values = model.default_parameter_values
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
#
# Test edge cases for initial SOC
#
from tests import TestCase
import pybamm
import unittest


class TestInitialSOC(unittest.TestCase):
class TestInitialSOC(TestCase):
def test_interpolant_parameter_sets(self):
model = pybamm.lithium_ion.SPM()
params = [
Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
#
# Tests for the lithium-ion MPM model
#
from tests import TestCase
import pybamm
import tests
import numpy as np
import unittest


class TestMPM(unittest.TestCase):
class TestMPM(TestCase):
def test_basic_processing(self):
options = {"thermal": "isothermal"}
model = pybamm.lithium_ion.MPM(options)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
#
# Tests for the lithium-ion Newman-Tobias model
#
from tests import TestCase
import pybamm
import unittest
from tests import BaseIntegrationTestLithiumIon


class TestNewmanTobias(BaseIntegrationTestLithiumIon, unittest.TestCase):
class TestNewmanTobias(BaseIntegrationTestLithiumIon, TestCase):
def setUp(self):
self.model = pybamm.lithium_ion.NewmanTobias

Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
#
# Tests for the lithium-ion SPM model
#
from tests import TestCase
import pybamm
import unittest
from tests import BaseIntegrationTestLithiumIon


class TestSPM(BaseIntegrationTestLithiumIon, unittest.TestCase):
class TestSPM(BaseIntegrationTestLithiumIon, TestCase):
def setUp(self):
self.model = pybamm.lithium_ion.SPM

Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
#
# Tests for the half-cell lithium-ion SPM model
#
from tests import TestCase
import pybamm
import unittest
from tests import BaseIntegrationTestLithiumIonHalfCell


class TestSPMHalfCell(BaseIntegrationTestLithiumIonHalfCell, unittest.TestCase):
class TestSPMHalfCell(BaseIntegrationTestLithiumIonHalfCell, TestCase):
def setUp(self):
self.model = pybamm.lithium_ion.SPM

Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
#
# Tests for the lithium-ion SPMe model
#
from tests import TestCase
import pybamm
import unittest
from tests import BaseIntegrationTestLithiumIon


class TestSPMe(BaseIntegrationTestLithiumIon, unittest.TestCase):
class TestSPMe(BaseIntegrationTestLithiumIon, TestCase):
def setUp(self):
self.model = pybamm.lithium_ion.SPMe

Expand Down
Loading

0 comments on commit 1d6bd48

Please sign in to comment.