diff --git a/.git-blame-ignore-revs b/.git-blame-ignore-revs index 228a76373e..94f9393319 100644 --- a/.git-blame-ignore-revs +++ b/.git-blame-ignore-revs @@ -4,3 +4,5 @@ a63e49ece0f9336d1f5c2562f7459e555c6e6693 # activated standard pre-commits - https://github.com/pybamm-team/PyBaMM/pull/3192 5273214b585c5a4286609aed40e0b092d0e05f42 +# activated standard pre-commits for ruff-format - https://github.com/pybamm-team/PyBaMM/pull/3492 +948030c5eddcae78e5faf2401e16be3080af30fb diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 5d7c85492f..2558a922dd 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -10,6 +10,8 @@ repos: args: [--fix, --show-fixes] types_or: [python, pyi, jupyter] + - id: ruff-format + - repo: https://github.com/adamchainz/blacken-docs rev: "1.16.0" hooks: diff --git a/examples/scripts/compare_comsol/discharge_curve.py b/examples/scripts/compare_comsol/discharge_curve.py index b5cc23d946..effabd1944 100644 --- a/examples/scripts/compare_comsol/discharge_curve.py +++ b/examples/scripts/compare_comsol/discharge_curve.py @@ -53,7 +53,7 @@ plt.grid(True) plt.xlabel(r"Discharge Capacity (Ah)", fontsize=20) plt.ylabel(r"$\vert V - V_{comsol} \vert$", fontsize=20) -colors = iter(plt.cycler(color='bgrcmyk')) +colors = iter(plt.cycler(color="bgrcmyk")) for key, C_rate in C_rates.items(): current = 24 * C_rate diff --git a/noxfile.py b/noxfile.py index 430ad59659..f99010ea06 100644 --- a/noxfile.py +++ b/noxfile.py @@ -17,7 +17,7 @@ "SUNDIALS_INST": f"{homedir}/.local", "LD_LIBRARY_PATH": f"{homedir}/.local/lib:", } -VENV_DIR = Path('./venv').resolve() +VENV_DIR = Path("./venv").resolve() def set_environment_variables(env_dict, session): @@ -122,12 +122,13 @@ def set_dev(session): session.run("virtualenv", os.fsdecode(VENV_DIR), silent=True) python = os.fsdecode(VENV_DIR.joinpath("bin/python")) if sys.platform == "linux": - session.run(python, - "-m", - "pip", - "install", - ".[all,dev,jax,odes]", - external=True, + session.run( + python, + "-m", + "pip", + "install", + ".[all,dev,jax,odes]", + external=True, ) else: session.run(python, "-m", "pip", "install", "-e", ".[all,dev]", external=True) @@ -153,26 +154,26 @@ def build_docs(session): # Local development if session.interactive: session.run( - "sphinx-autobuild", - "-j", - "auto", - "--open-browser", - "-qT", - ".", - f"{envbindir}/../tmp/html", + "sphinx-autobuild", + "-j", + "auto", + "--open-browser", + "-qT", + ".", + f"{envbindir}/../tmp/html", ) # Runs in CI only, treating warnings as errors else: session.run( - "sphinx-build", - "-j", - "auto", - "-b", - "html", - "-W", - "--keep-going", - ".", - f"{envbindir}/../tmp/html", + "sphinx-build", + "-j", + "auto", + "-b", + "html", + "-W", + "--keep-going", + ".", + f"{envbindir}/../tmp/html", ) diff --git a/pybamm/discretisations/discretisation.py b/pybamm/discretisations/discretisation.py index a120adecc0..548953fc3e 100644 --- a/pybamm/discretisations/discretisation.py +++ b/pybamm/discretisations/discretisation.py @@ -514,9 +514,7 @@ def check_tab_conditions(self, symbol, bcs): if domain != "current collector": raise pybamm.ModelError( """Boundary conditions can only be applied on the tabs in the domain - 'current collector', but {} has domain {}""".format( - symbol, domain - ) + 'current collector', but {} has domain {}""".format(symbol, domain) ) # Replace keys with "left" and "right" as appropriate for 1D meshes if isinstance(mesh, pybamm.SubMesh1D): @@ -900,9 +898,7 @@ def _process_symbol(self, symbol): No key set for variable '{}'. Make sure it is included in either model.rhs or model.algebraic in an unmodified form (e.g. not Broadcasted) - """.format( - symbol.name - ) + """.format(symbol.name) ) # Add symbol's reference and multiply by the symbol's scale # so that the state vector is of order 1 diff --git a/pybamm/expression_tree/averages.py b/pybamm/expression_tree/averages.py index e063b16c2a..77f6f87ac5 100644 --- a/pybamm/expression_tree/averages.py +++ b/pybamm/expression_tree/averages.py @@ -189,9 +189,7 @@ def z_average(symbol): if symbol.domain not in [[], ["current collector"]]: raise pybamm.DomainError( """z-average only implemented in the 'current collector' domain, - but symbol has domains {}""".format( - symbol.domain - ) + but symbol has domains {}""".format(symbol.domain) ) # If symbol doesn't have a domain, its average value is itself if symbol.domain == []: @@ -225,9 +223,7 @@ def yz_average(symbol): if symbol.domain not in [[], ["current collector"]]: raise pybamm.DomainError( """y-z-average only implemented in the 'current collector' domain, - but symbol has domains {}""".format( - symbol.domain - ) + but symbol has domains {}""".format(symbol.domain) ) # If symbol doesn't have a domain, its average value is itself if symbol.domain == []: diff --git a/pybamm/expression_tree/binary_operators.py b/pybamm/expression_tree/binary_operators.py index 749384e9bc..f4e18830bb 100644 --- a/pybamm/expression_tree/binary_operators.py +++ b/pybamm/expression_tree/binary_operators.py @@ -312,9 +312,7 @@ def _binary_jac(self, left_jac, right_jac): raise NotImplementedError( """jac of 'MatrixMultiplication' is only implemented for left of type 'pybamm.Array', - not {}""".format( - left.__class__ - ) + not {}""".format(left.__class__) ) def _binary_evaluate(self, left, right): @@ -1341,9 +1339,7 @@ def source(left, right, boundary=False): if left.domain != ["current collector"] or right.domain != ["current collector"]: raise pybamm.DomainError( """'source' only implemented in the 'current collector' domain, - but symbols have domains {} and {}""".format( - left.domain, right.domain - ) + but symbols have domains {} and {}""".format(left.domain, right.domain) ) if boundary: return pybamm.BoundaryMass(right) @ left diff --git a/pybamm/expression_tree/concatenations.py b/pybamm/expression_tree/concatenations.py index 2185a0fad6..c72f4c7830 100644 --- a/pybamm/expression_tree/concatenations.py +++ b/pybamm/expression_tree/concatenations.py @@ -179,7 +179,7 @@ def __init__(self, *children): *children, name="numpy_concatenation", check_domain=False, - concat_fun=np.concatenate + concat_fun=np.concatenate, ) def _concatenation_jac(self, children_jacs): @@ -340,7 +340,7 @@ def __init__(self, *children): *children, name="sparse_stack", check_domain=False, - concat_fun=concatenation_function + concat_fun=concatenation_function, ) def _concatenation_new_copy(self, children): diff --git a/pybamm/expression_tree/functions.py b/pybamm/expression_tree/functions.py index 80c2848ad9..22ca61a82a 100644 --- a/pybamm/expression_tree/functions.py +++ b/pybamm/expression_tree/functions.py @@ -335,7 +335,7 @@ def __init__(self, child): def _function_diff(self, children, idx): """See :meth:`pybamm.Function._function_diff()`.""" - return 2 / np.sqrt(np.pi) * exp(-children[0] ** 2) + return 2 / np.sqrt(np.pi) * exp(-(children[0] ** 2)) def erf(child): diff --git a/pybamm/expression_tree/operations/convert_to_casadi.py b/pybamm/expression_tree/operations/convert_to_casadi.py index b3a048b1f1..78bd650028 100644 --- a/pybamm/expression_tree/operations/convert_to_casadi.py +++ b/pybamm/expression_tree/operations/convert_to_casadi.py @@ -211,7 +211,5 @@ def _convert(self, symbol, t, y, y_dot, inputs): """ Cannot convert symbol of type '{}' to CasADi. Symbols must all be 'linear algebra' at this stage. - """.format( - type(symbol) - ) + """.format(type(symbol)) ) diff --git a/pybamm/expression_tree/symbol.py b/pybamm/expression_tree/symbol.py index 5d28884ed5..de617fa8d5 100644 --- a/pybamm/expression_tree/symbol.py +++ b/pybamm/expression_tree/symbol.py @@ -887,9 +887,7 @@ def create_copy(self): """ raise NotImplementedError( """method self.new_copy() not implemented - for symbol {!s} of type {}""".format( - self, type(self) - ) + for symbol {!s} of type {}""".format(self, type(self)) ) def new_copy(self): diff --git a/pybamm/expression_tree/vector.py b/pybamm/expression_tree/vector.py index 758b988ca7..7600477d21 100644 --- a/pybamm/expression_tree/vector.py +++ b/pybamm/expression_tree/vector.py @@ -29,9 +29,7 @@ def __init__( raise ValueError( """ Entries must have 1 dimension or be column vector, not have shape {} - """.format( - entries.shape - ) + """.format(entries.shape) ) if name is None: name = "Column vector of length {!s}".format(entries.shape[0]) diff --git a/pybamm/input/parameters/lithium_ion/Ai2020.py b/pybamm/input/parameters/lithium_ion/Ai2020.py index abae3087ea..825c34e19b 100644 --- a/pybamm/input/parameters/lithium_ion/Ai2020.py +++ b/pybamm/input/parameters/lithium_ion/Ai2020.py @@ -69,9 +69,7 @@ def graphite_electrolyte_exchange_current_density_Dualfoil1998( E_r = 5000 # activation energy for Temperature Dependent Reaction Constant [J/mol] arrhenius = np.exp(E_r / pybamm.constants.R * (1 / 298.15 - 1 / T)) - return ( - m_ref * arrhenius * c_e**0.5 * c_s_surf**0.5 * (c_s_max - c_s_surf) ** 0.5 - ) + return m_ref * arrhenius * c_e**0.5 * c_s_surf**0.5 * (c_s_max - c_s_surf) ** 0.5 def graphite_entropy_Enertech_Ai2020_function(sto, c_s_max): @@ -272,9 +270,7 @@ def lico2_electrolyte_exchange_current_density_Dualfoil1998(c_e, c_s_surf, c_s_m E_r = 5000 arrhenius = np.exp(E_r / pybamm.constants.R * (1 / 298.15 - 1 / T)) - return ( - m_ref * arrhenius * c_e**0.5 * c_s_surf**0.5 * (c_s_max - c_s_surf) ** 0.5 - ) + return m_ref * arrhenius * c_e**0.5 * c_s_surf**0.5 * (c_s_max - c_s_surf) ** 0.5 def lico2_entropic_change_Ai2020_function(sto, c_s_max): diff --git a/pybamm/input/parameters/lithium_ion/Chen2020.py b/pybamm/input/parameters/lithium_ion/Chen2020.py index e526b480c4..0b5420baaf 100644 --- a/pybamm/input/parameters/lithium_ion/Chen2020.py +++ b/pybamm/input/parameters/lithium_ion/Chen2020.py @@ -70,9 +70,7 @@ def graphite_LGM50_electrolyte_exchange_current_density_Chen2020( E_r = 35000 arrhenius = np.exp(E_r / pybamm.constants.R * (1 / 298.15 - 1 / T)) - return ( - m_ref * arrhenius * c_e**0.5 * c_s_surf**0.5 * (c_s_max - c_s_surf) ** 0.5 - ) + return m_ref * arrhenius * c_e**0.5 * c_s_surf**0.5 * (c_s_max - c_s_surf) ** 0.5 def nmc_LGM50_ocp_Chen2020(sto): @@ -141,9 +139,7 @@ def nmc_LGM50_electrolyte_exchange_current_density_Chen2020(c_e, c_s_surf, c_s_m E_r = 17800 arrhenius = np.exp(E_r / pybamm.constants.R * (1 / 298.15 - 1 / T)) - return ( - m_ref * arrhenius * c_e**0.5 * c_s_surf**0.5 * (c_s_max - c_s_surf) ** 0.5 - ) + return m_ref * arrhenius * c_e**0.5 * c_s_surf**0.5 * (c_s_max - c_s_surf) ** 0.5 def electrolyte_diffusivity_Nyman2008(c_e, T): diff --git a/pybamm/input/parameters/lithium_ion/Chen2020_composite.py b/pybamm/input/parameters/lithium_ion/Chen2020_composite.py index f7e27c8d52..69767cbddf 100644 --- a/pybamm/input/parameters/lithium_ion/Chen2020_composite.py +++ b/pybamm/input/parameters/lithium_ion/Chen2020_composite.py @@ -37,9 +37,7 @@ def graphite_LGM50_electrolyte_exchange_current_density_Chen2020( E_r = 35000 arrhenius = np.exp(E_r / pybamm.constants.R * (1 / 298.15 - 1 / T)) - return ( - m_ref * arrhenius * c_e**0.5 * c_s_surf**0.5 * (c_s_max - c_s_surf) ** 0.5 - ) + return m_ref * arrhenius * c_e**0.5 * c_s_surf**0.5 * (c_s_max - c_s_surf) ** 0.5 def silicon_ocp_lithiation_Mark2016(sto): @@ -167,9 +165,7 @@ def silicon_LGM50_electrolyte_exchange_current_density_Chen2020( E_r = 35000 arrhenius = np.exp(E_r / pybamm.constants.R * (1 / 298.15 - 1 / T)) - return ( - m_ref * arrhenius * c_e**0.5 * c_s_surf**0.5 * (c_s_max - c_s_surf) ** 0.5 - ) + return m_ref * arrhenius * c_e**0.5 * c_s_surf**0.5 * (c_s_max - c_s_surf) ** 0.5 def nmc_LGM50_ocp_Chen2020(sto): @@ -238,9 +234,7 @@ def nmc_LGM50_electrolyte_exchange_current_density_Chen2020(c_e, c_s_surf, c_s_m E_r = 17800 arrhenius = np.exp(E_r / pybamm.constants.R * (1 / 298.15 - 1 / T)) - return ( - m_ref * arrhenius * c_e**0.5 * c_s_surf**0.5 * (c_s_max - c_s_surf) ** 0.5 - ) + return m_ref * arrhenius * c_e**0.5 * c_s_surf**0.5 * (c_s_max - c_s_surf) ** 0.5 def electrolyte_diffusivity_Nyman2008(c_e, T): diff --git a/pybamm/input/parameters/lithium_ion/Ecker2015.py b/pybamm/input/parameters/lithium_ion/Ecker2015.py index 3f37db6e61..28b2ca21e4 100644 --- a/pybamm/input/parameters/lithium_ion/Ecker2015.py +++ b/pybamm/input/parameters/lithium_ion/Ecker2015.py @@ -147,9 +147,7 @@ def graphite_electrolyte_exchange_current_density_Ecker2015(c_e, c_s_surf, c_s_m E_r / (pybamm.constants.R * 296.15) ) - return ( - m_ref * arrhenius * c_e**0.5 * c_s_surf**0.5 * (c_s_max - c_s_surf) ** 0.5 - ) + return m_ref * arrhenius * c_e**0.5 * c_s_surf**0.5 * (c_s_max - c_s_surf) ** 0.5 def nco_diffusivity_Ecker2015(sto, T): @@ -292,9 +290,7 @@ def nco_electrolyte_exchange_current_density_Ecker2015(c_e, c_s_surf, c_s_max, T E_r / (pybamm.constants.R * 296.15) ) - return ( - m_ref * arrhenius * c_e**0.5 * c_s_surf**0.5 * (c_s_max - c_s_surf) ** 0.5 - ) + return m_ref * arrhenius * c_e**0.5 * c_s_surf**0.5 * (c_s_max - c_s_surf) ** 0.5 def electrolyte_diffusivity_Ecker2015(c_e, T): diff --git a/pybamm/input/parameters/lithium_ion/Ecker2015_graphite_halfcell.py b/pybamm/input/parameters/lithium_ion/Ecker2015_graphite_halfcell.py index f6bc8e4d93..441ae95b8b 100644 --- a/pybamm/input/parameters/lithium_ion/Ecker2015_graphite_halfcell.py +++ b/pybamm/input/parameters/lithium_ion/Ecker2015_graphite_halfcell.py @@ -177,9 +177,7 @@ def graphite_electrolyte_exchange_current_density_Ecker2015(c_e, c_s_surf, c_s_m E_r / (pybamm.constants.R * 296.15) ) - return ( - m_ref * arrhenius * c_e**0.5 * c_s_surf**0.5 * (c_s_max - c_s_surf) ** 0.5 - ) + return m_ref * arrhenius * c_e**0.5 * c_s_surf**0.5 * (c_s_max - c_s_surf) ** 0.5 def electrolyte_diffusivity_Ecker2015(c_e, T): diff --git a/pybamm/input/parameters/lithium_ion/Marquis2019.py b/pybamm/input/parameters/lithium_ion/Marquis2019.py index d3bddc6e30..1664e6b1b2 100644 --- a/pybamm/input/parameters/lithium_ion/Marquis2019.py +++ b/pybamm/input/parameters/lithium_ion/Marquis2019.py @@ -90,9 +90,7 @@ def graphite_electrolyte_exchange_current_density_Dualfoil1998( E_r = 37480 arrhenius = np.exp(E_r / pybamm.constants.R * (1 / 298.15 - 1 / T)) - return ( - m_ref * arrhenius * c_e**0.5 * c_s_surf**0.5 * (c_s_max - c_s_surf) ** 0.5 - ) + return m_ref * arrhenius * c_e**0.5 * c_s_surf**0.5 * (c_s_max - c_s_surf) ** 0.5 def graphite_entropic_change_Moura2016(sto, c_s_max): @@ -221,9 +219,7 @@ def lico2_electrolyte_exchange_current_density_Dualfoil1998(c_e, c_s_surf, c_s_m E_r = 39570 arrhenius = np.exp(E_r / pybamm.constants.R * (1 / 298.15 - 1 / T)) - return ( - m_ref * arrhenius * c_e**0.5 * c_s_surf**0.5 * (c_s_max - c_s_surf) ** 0.5 - ) + return m_ref * arrhenius * c_e**0.5 * c_s_surf**0.5 * (c_s_max - c_s_surf) ** 0.5 def lico2_entropic_change_Moura2016(sto, c_s_max): diff --git a/pybamm/input/parameters/lithium_ion/Mohtat2020.py b/pybamm/input/parameters/lithium_ion/Mohtat2020.py index 29535b9f3d..86f14e39a2 100644 --- a/pybamm/input/parameters/lithium_ion/Mohtat2020.py +++ b/pybamm/input/parameters/lithium_ion/Mohtat2020.py @@ -86,9 +86,7 @@ def graphite_electrolyte_exchange_current_density_PeymanMPM(c_e, c_s_surf, c_s_m E_r = 37480 arrhenius = np.exp(E_r / pybamm.constants.R * (1 / 298.15 - 1 / T)) - return ( - m_ref * arrhenius * c_e**0.5 * c_s_surf**0.5 * (c_s_max - c_s_surf) ** 0.5 - ) + return m_ref * arrhenius * c_e**0.5 * c_s_surf**0.5 * (c_s_max - c_s_surf) ** 0.5 def graphite_entropic_change_PeymanMPM(sto, c_s_max): @@ -208,9 +206,7 @@ def NMC_electrolyte_exchange_current_density_PeymanMPM(c_e, c_s_surf, c_s_max, T E_r = 39570 arrhenius = np.exp(E_r / pybamm.constants.R * (1 / 298.15 - 1 / T)) - return ( - m_ref * arrhenius * c_e**0.5 * c_s_surf**0.5 * (c_s_max - c_s_surf) ** 0.5 - ) + return m_ref * arrhenius * c_e**0.5 * c_s_surf**0.5 * (c_s_max - c_s_surf) ** 0.5 def NMC_entropic_change_PeymanMPM(sto, c_s_max): @@ -244,9 +240,9 @@ def NMC_entropic_change_PeymanMPM(sto, c_s_max): - 0.5623 * 10 ** (-4) * np.exp(109.451 * sto - 100.006) ) - du_dT = ( - -800 + 779 * u_eq - 284 * u_eq**2 + 46 * u_eq**3 - 2.8 * u_eq**4 - ) * 10 ** (-3) + du_dT = (-800 + 779 * u_eq - 284 * u_eq**2 + 46 * u_eq**3 - 2.8 * u_eq**4) * 10 ** ( + -3 + ) return du_dT diff --git a/pybamm/input/parameters/lithium_ion/NCA_Kim2011.py b/pybamm/input/parameters/lithium_ion/NCA_Kim2011.py index b5543ea6c2..123714a9da 100644 --- a/pybamm/input/parameters/lithium_ion/NCA_Kim2011.py +++ b/pybamm/input/parameters/lithium_ion/NCA_Kim2011.py @@ -105,11 +105,7 @@ def graphite_electrolyte_exchange_current_density_Kim2011(c_e, c_s_surf, c_s_max arrhenius = np.exp(E_r / pybamm.constants.R * (1 / 298.15 - 1 / T)) return ( - m_ref - * arrhenius - * c_e**alpha - * c_s_surf**alpha - * (c_s_max - c_s_surf) ** alpha + m_ref * arrhenius * c_e**alpha * c_s_surf**alpha * (c_s_max - c_s_surf) ** alpha ) @@ -177,18 +173,12 @@ def nca_electrolyte_exchange_current_density_Kim2011(c_e, c_s_surf, c_s_max, T): c_e_ref = pybamm.Parameter("Initial concentration in electrolyte [mol.m-3]") alpha = 0.5 # charge transfer coefficient - m_ref = i0_ref / ( - c_e_ref**alpha * (c_s_max - c_s_ref) ** alpha * c_s_ref**alpha - ) + m_ref = i0_ref / (c_e_ref**alpha * (c_s_max - c_s_ref) ** alpha * c_s_ref**alpha) E_r = 3e4 arrhenius = np.exp(E_r / pybamm.constants.R * (1 / 298.15 - 1 / T)) return ( - m_ref - * arrhenius - * c_e**alpha - * c_s_surf**alpha - * (c_s_max - c_s_surf) ** alpha + m_ref * arrhenius * c_e**alpha * c_s_surf**alpha * (c_s_max - c_s_surf) ** alpha ) diff --git a/pybamm/input/parameters/lithium_ion/OKane2022.py b/pybamm/input/parameters/lithium_ion/OKane2022.py index e3718fb9ee..930848268f 100644 --- a/pybamm/input/parameters/lithium_ion/OKane2022.py +++ b/pybamm/input/parameters/lithium_ion/OKane2022.py @@ -162,9 +162,7 @@ def graphite_LGM50_electrolyte_exchange_current_density_Chen2020( E_r = 35000 arrhenius = np.exp(E_r / pybamm.constants.R * (1 / 298.15 - 1 / T)) - return ( - m_ref * arrhenius * c_e**0.5 * c_s_surf**0.5 * (c_s_max - c_s_surf) ** 0.5 - ) + return m_ref * arrhenius * c_e**0.5 * c_s_surf**0.5 * (c_s_max - c_s_surf) ** 0.5 def graphite_volume_change_Ai2020(sto, c_s_max): @@ -343,9 +341,7 @@ def nmc_LGM50_electrolyte_exchange_current_density_Chen2020(c_e, c_s_surf, c_s_m E_r = 17800 arrhenius = np.exp(E_r / pybamm.constants.R * (1 / 298.15 - 1 / T)) - return ( - m_ref * arrhenius * c_e**0.5 * c_s_surf**0.5 * (c_s_max - c_s_surf) ** 0.5 - ) + return m_ref * arrhenius * c_e**0.5 * c_s_surf**0.5 * (c_s_max - c_s_surf) ** 0.5 def volume_change_Ai2020(sto, c_s_max): diff --git a/pybamm/input/parameters/lithium_ion/OKane2022_graphite_SiOx_halfcell.py b/pybamm/input/parameters/lithium_ion/OKane2022_graphite_SiOx_halfcell.py index e13d27fad0..31081af14a 100644 --- a/pybamm/input/parameters/lithium_ion/OKane2022_graphite_SiOx_halfcell.py +++ b/pybamm/input/parameters/lithium_ion/OKane2022_graphite_SiOx_halfcell.py @@ -192,9 +192,7 @@ def graphite_LGM50_electrolyte_exchange_current_density_Chen2020( E_r = 35000 arrhenius = pybamm.exp(E_r / pybamm.constants.R * (1 / 298.15 - 1 / T)) - return ( - m_ref * arrhenius * c_e**0.5 * c_s_surf**0.5 * (c_s_max - c_s_surf) ** 0.5 - ) + return m_ref * arrhenius * c_e**0.5 * c_s_surf**0.5 * (c_s_max - c_s_surf) ** 0.5 def graphite_volume_change_Ai2020(sto, c_s_max): diff --git a/pybamm/input/parameters/lithium_ion/Prada2013.py b/pybamm/input/parameters/lithium_ion/Prada2013.py index 2d3d0e7ceb..421256af2a 100644 --- a/pybamm/input/parameters/lithium_ion/Prada2013.py +++ b/pybamm/input/parameters/lithium_ion/Prada2013.py @@ -70,9 +70,7 @@ def graphite_LGM50_electrolyte_exchange_current_density_Chen2020( E_r = 35000 arrhenius = np.exp(E_r / pybamm.constants.R * (1 / 298.15 - 1 / T)) - return ( - m_ref * arrhenius * c_e**0.5 * c_s_surf**0.5 * (c_s_max - c_s_surf) ** 0.5 - ) + return m_ref * arrhenius * c_e**0.5 * c_s_surf**0.5 * (c_s_max - c_s_surf) ** 0.5 def LFP_ocp_Afshar2017(sto): @@ -131,9 +129,7 @@ def LFP_electrolyte_exchange_current_density_kashkooli2017(c_e, c_s_surf, c_s_ma E_r = 39570 arrhenius = np.exp(E_r / pybamm.constants.R * (1 / 298.15 - 1 / T)) - return ( - m_ref * arrhenius * c_e**0.5 * c_s_surf**0.5 * (c_s_max - c_s_surf) ** 0.5 - ) + return m_ref * arrhenius * c_e**0.5 * c_s_surf**0.5 * (c_s_max - c_s_surf) ** 0.5 def electrolyte_conductivity_Prada2013(c_e, T): diff --git a/pybamm/input/parameters/lithium_ion/Ramadass2004.py b/pybamm/input/parameters/lithium_ion/Ramadass2004.py index 13aa86fe8e..4269acf1e9 100644 --- a/pybamm/input/parameters/lithium_ion/Ramadass2004.py +++ b/pybamm/input/parameters/lithium_ion/Ramadass2004.py @@ -89,9 +89,7 @@ def graphite_electrolyte_exchange_current_density_Ramadass2004( E_r = 37480 arrhenius = np.exp(E_r / pybamm.constants.R * (1 / 298.15 - 1 / T)) - return ( - m_ref * arrhenius * c_e**0.5 * c_s_surf**0.5 * (c_s_max - c_s_surf) ** 0.5 - ) + return m_ref * arrhenius * c_e**0.5 * c_s_surf**0.5 * (c_s_max - c_s_surf) ** 0.5 def graphite_entropic_change_Moura2016(sto, c_s_max): @@ -227,9 +225,7 @@ def lico2_electrolyte_exchange_current_density_Ramadass2004(c_e, c_s_surf, c_s_m E_r = 39570 arrhenius = np.exp(E_r / pybamm.constants.R * (1 / 298.15 - 1 / T)) - return ( - m_ref * arrhenius * c_e**0.5 * c_s_surf**0.5 * (c_s_max - c_s_surf) ** 0.5 - ) + return m_ref * arrhenius * c_e**0.5 * c_s_surf**0.5 * (c_s_max - c_s_surf) ** 0.5 def lico2_entropic_change_Moura2016(sto, c_s_max): diff --git a/pybamm/install_odes.py b/pybamm/install_odes.py index 4bf310a0f2..2d78e6bd44 100644 --- a/pybamm/install_odes.py +++ b/pybamm/install_odes.py @@ -102,13 +102,13 @@ def update_LD_LIBRARY_PATH(install_dir): if export_statement not in fh.read(): fh.write(export_statement) print( - "Adding {}/lib to LD_LIBRARY_PATH" - " in {}".format(install_dir, script_path) + "Adding {}/lib to LD_LIBRARY_PATH" " in {}".format( + install_dir, script_path + ) ) def main(arguments=None): - log_format = "%(asctime)s - %(name)s - %(levelname)s - %(message)s" logger = logging.getLogger("scikits.odes setup") diff --git a/pybamm/meshes/one_dimensional_submeshes.py b/pybamm/meshes/one_dimensional_submeshes.py index 2beae6bc3a..8777bebc80 100644 --- a/pybamm/meshes/one_dimensional_submeshes.py +++ b/pybamm/meshes/one_dimensional_submeshes.py @@ -276,9 +276,7 @@ def __init__(self, lims, npts, edges=None): """User-suppled edges has should have length (npts + 1) but has length {}.Number of points (npts) for domain {} is {}.""".format( len(edges), spatial_var.domain, npts - ).replace( - "\n ", " " - ) + ).replace("\n ", " ") ) # check end points of edges agree with spatial_lims diff --git a/pybamm/models/base_model.py b/pybamm/models/base_model.py index 41192dbe1f..df3f74d2f7 100644 --- a/pybamm/models/base_model.py +++ b/pybamm/models/base_model.py @@ -855,9 +855,7 @@ def check_variables(self): No key set for variable '{}'. Make sure it is included in either model.rhs or model.algebraic, in an unmodified form (e.g. not Broadcasted) - """.format( - var - ) + """.format(var) ) def check_no_repeated_keys(self): @@ -1214,9 +1212,7 @@ def check_and_convert_bcs(self, boundary_conditions): raise pybamm.ModelError( """ boundary condition types must be Dirichlet or Neumann, not '{}' - """.format( - bc[1] - ) + """.format(bc[1]) ) return boundary_conditions diff --git a/pybamm/models/full_battery_models/base_battery_model.py b/pybamm/models/full_battery_models/base_battery_model.py index 971bd1a880..94a8f2777e 100644 --- a/pybamm/models/full_battery_models/base_battery_model.py +++ b/pybamm/models/full_battery_models/base_battery_model.py @@ -629,28 +629,26 @@ def __init__(self, extra_options): value = (value,) else: if not ( - ( - option - in [ - "diffusivity", - "exchange-current density", - "intercalation kinetics", - "interface utilisation", - "lithium plating", - "loss of active material", - "number of MSMR reactions", - "open-circuit potential", - "particle", - "particle mechanics", - "particle phases", - "particle size", - "SEI", - "SEI on cracks", - "stress-induced diffusion", - ] - and isinstance(value, tuple) - and len(value) == 2 - ) + option + in [ + "diffusivity", + "exchange-current density", + "intercalation kinetics", + "interface utilisation", + "lithium plating", + "loss of active material", + "number of MSMR reactions", + "open-circuit potential", + "particle", + "particle mechanics", + "particle phases", + "particle size", + "SEI", + "SEI on cracks", + "stress-induced diffusion", + ] + and isinstance(value, tuple) + and len(value) == 2 ): # more possible options that can take 2-tuples to be added # as they come @@ -966,9 +964,7 @@ def options(self, extra_options): ): raise pybamm.OptionError( """must use surface formulation to solve {!s} with hydrolysis - """.format( - self - ) + """.format(self) ) self._options = options diff --git a/pybamm/models/submodels/convection/through_cell/explicit_convection.py b/pybamm/models/submodels/convection/through_cell/explicit_convection.py index 7d83c550ec..33b58e2b23 100644 --- a/pybamm/models/submodels/convection/through_cell/explicit_convection.py +++ b/pybamm/models/submodels/convection/through_cell/explicit_convection.py @@ -39,11 +39,7 @@ def get_coupled_variables(self, variables): x_p = pybamm.standard_spatial_vars.x_p DeltaV_k = param.p.DeltaV p_k = ( - -DeltaV_k - * a_j_k_av - / param.F - * ((x_p - 1) ** 2 - param.p.L**2) - / 2 + -DeltaV_k * a_j_k_av / param.F * ((x_p - 1) ** 2 - param.p.L**2) / 2 + p_s ) v_box_k = -DeltaV_k * a_j_k_av / param.F * (x_p - param.L_x) diff --git a/pybamm/models/submodels/interface/lithium_plating/base_plating.py b/pybamm/models/submodels/interface/lithium_plating/base_plating.py index 5b7a7a5b7f..ebfbe46831 100644 --- a/pybamm/models/submodels/interface/lithium_plating/base_plating.py +++ b/pybamm/models/submodels/interface/lithium_plating/base_plating.py @@ -111,10 +111,14 @@ def _get_standard_concentration_variables(self, c_plated_Li, c_dead_Li): f"X-averaged {domain} lithium plating thickness [m]": L_plated_Li_av, f"{Domain} dead lithium thickness [m]": L_dead_Li, f"X-averaged {domain} dead lithium thickness [m]": L_dead_Li_av, - f"Loss of lithium to {domain} lithium plating " - "[mol]": (Q_plated_Li + Q_dead_Li), - f"Loss of capacity to {domain} lithium plating " - "[A.h]": (Q_plated_Li + Q_dead_Li) * param.F / 3600, + f"Loss of lithium to {domain} lithium plating " "[mol]": ( + Q_plated_Li + Q_dead_Li + ), + f"Loss of capacity to {domain} lithium plating " "[A.h]": ( + Q_plated_Li + Q_dead_Li + ) + * param.F + / 3600, } return variables diff --git a/pybamm/models/submodels/interface/total_interfacial_current.py b/pybamm/models/submodels/interface/total_interfacial_current.py index a9094c4448..79e13e37f6 100644 --- a/pybamm/models/submodels/interface/total_interfacial_current.py +++ b/pybamm/models/submodels/interface/total_interfacial_current.py @@ -110,7 +110,7 @@ def _get_coupled_variables_by_phase_and_domain(self, variables, domain, phase_na new_variables[ f"Sum of {domain} electrode {phase_name}" "electrolyte reaction source terms [A.m-3]" - ] += (s_k * a_j_k) + ] += s_k * a_j_k new_variables[ f"Sum of x-averaged {domain} electrode {phase_name}" "electrolyte reaction source terms [A.m-3]" diff --git a/pybamm/models/submodels/particle/base_particle.py b/pybamm/models/submodels/particle/base_particle.py index ad751c3911..62ad768f6a 100644 --- a/pybamm/models/submodels/particle/base_particle.py +++ b/pybamm/models/submodels/particle/base_particle.py @@ -197,9 +197,7 @@ def _get_distribution_variables(self, R): f_v_dist = R * f_a_dist / pybamm.Integral(R * f_a_dist, R) # [m-1] # Number-based particle-size distribution - f_num_dist = (f_a_dist / R**2) / pybamm.Integral( - f_a_dist / R**2, R - ) # [m-1] + f_num_dist = (f_a_dist / R**2) / pybamm.Integral(f_a_dist / R**2, R) # [m-1] # True mean radii and standard deviations, calculated from the f_a_dist that # was given, all have units [m] diff --git a/pybamm/models/submodels/particle/msmr_diffusion.py b/pybamm/models/submodels/particle/msmr_diffusion.py index 65ab913e97..c53f313ab4 100644 --- a/pybamm/models/submodels/particle/msmr_diffusion.py +++ b/pybamm/models/submodels/particle/msmr_diffusion.py @@ -262,9 +262,7 @@ def get_coupled_variables(self, variables): N_s = c_max * x * (1 - x) * f * D_eff * pybamm.grad(U) variables.update( { - f"{Domain} {phase_name}particle rhs [V.s-1]": -( - 1 / (R_broad_nondim**2) - ) + f"{Domain} {phase_name}particle rhs [V.s-1]": -(1 / (R_broad_nondim**2)) * pybamm.div(N_s) / c_max / dxdU, diff --git a/pybamm/models/submodels/particle/x_averaged_polynomial_profile.py b/pybamm/models/submodels/particle/x_averaged_polynomial_profile.py index 45497c4c54..8b4b7ffe7c 100644 --- a/pybamm/models/submodels/particle/x_averaged_polynomial_profile.py +++ b/pybamm/models/submodels/particle/x_averaged_polynomial_profile.py @@ -203,8 +203,7 @@ def get_coupled_variables(self, variables): # The flux may be computed directly from the polynomial for c N_s_xav = -D_eff_xav * ( (-70 * c_s_surf_xav + 20 * q_s_av * R + 70 * c_s_av) * r / R**2 - + (105 * c_s_surf_xav - 28 * q_s_av * R - 105 * c_s_av) - * (r**3 / R**4) + + (105 * c_s_surf_xav - 28 * q_s_av * R - 105 * c_s_av) * (r**3 / R**4) ) N_s = pybamm.SecondaryBroadcast(N_s_xav, [f"{domain} electrode"]) diff --git a/pybamm/parameters/bpx.py b/pybamm/parameters/bpx.py index 8efd26cd57..a97288b062 100644 --- a/pybamm/parameters/bpx.py +++ b/pybamm/parameters/bpx.py @@ -261,12 +261,12 @@ def _positive_electrode_entropic_change(sto, c_s_max): "Maximum concentration in " + negative_electrode.pre_name.lower() + "[mol.m-3]" ] k_n_norm = pybamm_dict[ - negative_electrode.pre_name - + "reaction rate constant [mol.m-2.s-1]" + negative_electrode.pre_name + "reaction rate constant [mol.m-2.s-1]" ] Ea_k_n = pybamm_dict.get( negative_electrode.pre_name - + "reaction rate constant activation energy [J.mol-1]", 0.0 + + "reaction rate constant activation energy [J.mol-1]", + 0.0, ) # Note that in BPX j = 2*F*k_norm*sqrt((ce/ce0)*(c/c_max)*(1-c/c_max))*sinh(...), # and in PyBaMM j = 2*k*sqrt(ce*c*(c_max - c))*sinh(...) @@ -292,12 +292,12 @@ def _negative_electrode_exchange_current_density(c_e, c_s_surf, c_s_max, T): "Maximum concentration in " + positive_electrode.pre_name.lower() + "[mol.m-3]" ] k_p_norm = pybamm_dict[ - positive_electrode.pre_name - + "reaction rate constant [mol.m-2.s-1]" + positive_electrode.pre_name + "reaction rate constant [mol.m-2.s-1]" ] Ea_k_p = pybamm_dict.get( positive_electrode.pre_name - + "reaction rate constant activation energy [J.mol-1]", 0.0 + + "reaction rate constant activation energy [J.mol-1]", + 0.0, ) # Note that in BPX j = 2*F*k_norm*sqrt((ce/ce0)*(c/c_max)*(1-c/c_max))*sinh(...), # and in PyBaMM j = 2*k*sqrt(ce*c*(c_max - c))*sinh(...) diff --git a/pybamm/parameters/parameter_sets.py b/pybamm/parameters/parameter_sets.py index 6c6201d9af..27c6402683 100644 --- a/pybamm/parameters/parameter_sets.py +++ b/pybamm/parameters/parameter_sets.py @@ -44,7 +44,7 @@ def __init__(self): @staticmethod def get_entries(group_name): # Wrapper for the importlib version logic - if sys.version_info < (3, 10): # pragma: no cover + if sys.version_info < (3, 10): # pragma: no cover return importlib.metadata.entry_points()[group_name] else: return importlib.metadata.entry_points(group=group_name) diff --git a/pybamm/parameters/parameter_values.py b/pybamm/parameters/parameter_values.py index d5f12f362f..2be4948cad 100644 --- a/pybamm/parameters/parameter_values.py +++ b/pybamm/parameters/parameter_values.py @@ -298,8 +298,7 @@ def set_initial_stoichiometry_half_cell( { "Initial concentration in {} electrode [mol.m-3]".format( options["working electrode"] - ): x - * c_max + ): x * c_max } ) return parameter_values diff --git a/pybamm/parameters/process_parameter_data.py b/pybamm/parameters/process_parameter_data.py index 8de8f32ba8..7a6c184f6d 100644 --- a/pybamm/parameters/process_parameter_data.py +++ b/pybamm/parameters/process_parameter_data.py @@ -35,7 +35,7 @@ def process_1D_data(name, path=None): """ filename, name = _process_name(name, path, ".csv") - data = np.genfromtxt(filename, delimiter=',', skip_header=1) + data = np.genfromtxt(filename, delimiter=",", skip_header=1) x = data[:, 0] y = data[:, 1] @@ -88,7 +88,7 @@ def process_2D_data_csv(name, path=None): filename, name = _process_name(name, path, ".csv") - data = np.genfromtxt(filename, delimiter=',',skip_header=1) + data = np.genfromtxt(filename, delimiter=",", skip_header=1) x1 = np.unique(data[:, 0]) x2 = np.unique(data[:, 1]) @@ -135,7 +135,7 @@ def process_3D_data_csv(name, path=None): filename, name = _process_name(name, path, ".csv") - data = np.genfromtxt(filename, delimiter=',',skip_header=1) + data = np.genfromtxt(filename, delimiter=",", skip_header=1) x1 = np.unique(data[:, 0]) x2 = np.unique(data[:, 1]) diff --git a/pybamm/plotting/plot2D.py b/pybamm/plotting/plot2D.py index 80bb5d0ee2..c0e1af7d52 100644 --- a/pybamm/plotting/plot2D.py +++ b/pybamm/plotting/plot2D.py @@ -53,7 +53,7 @@ def plot2D(x, y, z, ax=None, testing=False, **kwargs): z.entries, vmin=ax_min(z.entries), vmax=ax_max(z.entries), - **kwargs + **kwargs, ) plt.colorbar(plot, ax=ax) diff --git a/pybamm/plotting/plot_voltage_components.py b/pybamm/plotting/plot_voltage_components.py index ad0e9a8b71..eb928da5e7 100644 --- a/pybamm/plotting/plot_voltage_components.py +++ b/pybamm/plotting/plot_voltage_components.py @@ -10,7 +10,7 @@ def plot_voltage_components( show_legend=True, split_by_electrode=False, testing=False, - **kwargs_fill + **kwargs_fill, ): """ Generate a plot showing the component overpotentials that make up the voltage @@ -103,14 +103,14 @@ def plot_voltage_components( initial_ocv - delta_ocp_n, initial_ocv, **kwargs_fill, - label="Negative open-circuit potential" + label="Negative open-circuit potential", ) ax.fill_between( time, initial_ocv - delta_ocp_n + delta_ocp_p, initial_ocv - delta_ocp_n, **kwargs_fill, - label="Positive open-circuit potential" + label="Positive open-circuit potential", ) ocv = initial_ocv - delta_ocp_n + delta_ocp_p top = ocv @@ -136,8 +136,9 @@ def plot_voltage_components( ax.set_xlim([time[0], time[-1]]) ax.set_xlabel("Time [h]") - y_min, y_max = 0.98 * min(np.nanmin(V), np.nanmin(ocv)), 1.02 * ( - max(np.nanmax(V), np.nanmax(ocv)) + y_min, y_max = ( + 0.98 * min(np.nanmin(V), np.nanmin(ocv)), + 1.02 * (max(np.nanmax(V), np.nanmax(ocv))), ) ax.set_ylim([y_min, y_max]) diff --git a/pybamm/simulation.py b/pybamm/simulation.py index 380105d215..3a4c91276d 100644 --- a/pybamm/simulation.py +++ b/pybamm/simulation.py @@ -605,9 +605,7 @@ def solve( capture the input. Try refining t_eval. Alternatively, passing t_eval = None automatically sets t_eval to be the points in the data. - """.format( - dt_eval_max, dt_data_min - ), + """.format(dt_eval_max, dt_data_min), pybamm.SolverWarning, ) diff --git a/pybamm/solvers/casadi_algebraic_solver.py b/pybamm/solvers/casadi_algebraic_solver.py index e7983b7f87..97826f3ca2 100644 --- a/pybamm/solvers/casadi_algebraic_solver.py +++ b/pybamm/solvers/casadi_algebraic_solver.py @@ -129,7 +129,7 @@ def _integrate(self, model, t_eval, inputs_dict=None): # If there are no symbolic inputs, check the function is below the tol # Skip this check if there are symbolic inputs if success and ( - (not any(np.isnan(fun)) and np.all(casadi.fabs(fun) < self.tol)) + not any(np.isnan(fun)) and np.all(casadi.fabs(fun) < self.tol) ): # update initial guess for the next iteration y0_alg = y_alg_sol @@ -153,9 +153,7 @@ def _integrate(self, model, t_eval, inputs_dict=None): Could not find acceptable solution: solver terminated successfully, but maximum solution error ({}) above tolerance ({}) - """.format( - casadi.mmax(casadi.fabs(fun)), self.tol - ) + """.format(casadi.mmax(casadi.fabs(fun)), self.tol) ) # Concatenate differential part diff --git a/pybamm/solvers/idaklu_solver.py b/pybamm/solvers/idaklu_solver.py index d9819f1608..6c81bf91e7 100644 --- a/pybamm/solvers/idaklu_solver.py +++ b/pybamm/solvers/idaklu_solver.py @@ -281,10 +281,14 @@ def resfn(t, y, inputs, ydot): # Convert derivative functions for sensitivities if (len(inputs) > 0) and (model.calculate_sensitivities): self.dvar_dy_idaklu_fcns.append( - idaklu.generate_function(self.computed_dvar_dy_fcns[key].serialize()) + idaklu.generate_function( + self.computed_dvar_dy_fcns[key].serialize() + ) ) self.dvar_dp_idaklu_fcns.append( - idaklu.generate_function(self.computed_dvar_dp_fcns[key].serialize()) + idaklu.generate_function( + self.computed_dvar_dp_fcns[key].serialize() + ) ) else: diff --git a/pybamm/solvers/jax_bdf_solver.py b/pybamm/solvers/jax_bdf_solver.py index 2f334ed8ec..1b4b469206 100644 --- a/pybamm/solvers/jax_bdf_solver.py +++ b/pybamm/solvers/jax_bdf_solver.py @@ -217,9 +217,7 @@ def _bdf_init(fun, jac, mass, t0, y0, h0, rtol, atol): state["rtol"] = rtol state["M"] = mass EPS = jnp.finfo(y0.dtype).eps - state["newton_tol"] = jnp.maximum( - 10 * EPS / rtol, jnp.minimum(0.03, rtol**0.5) - ) + state["newton_tol"] = jnp.maximum(10 * EPS / rtol, jnp.minimum(0.03, rtol**0.5)) scale_y0 = atol + rtol * jnp.abs(y0) y0, not_converged = _select_initial_conditions( @@ -645,7 +643,8 @@ def while_body(while_state): # try again (state, updated_jacobian) = tree_map( partial( - jnp.where, not_converged * (updated_jacobian == False) # noqa: E712 + jnp.where, + not_converged * (updated_jacobian == False), # noqa: E712 ), (_update_jacobian(state, jac), True), (state, False + updated_jacobian), diff --git a/pybamm/solvers/scipy_solver.py b/pybamm/solvers/scipy_solver.py index be228e054a..e1ade8adb8 100644 --- a/pybamm/solvers/scipy_solver.py +++ b/pybamm/solvers/scipy_solver.py @@ -123,7 +123,7 @@ def event_fn(t, y): t_eval=t_eval, method=self.method, dense_output=True, - **extra_options + **extra_options, ) integration_time = timer.time() diff --git a/pybamm/solvers/solution.py b/pybamm/solvers/solution.py index d7a27f142c..af504ee54f 100644 --- a/pybamm/solvers/solution.py +++ b/pybamm/solvers/solution.py @@ -321,8 +321,9 @@ def check_ys_are_not_too_large(self): # there will always be a statevector, but just in case if statevector is None: # pragma: no cover raise RuntimeError( - "Cannot find statevector corresponding to variable {}" - .format(var.name) + "Cannot find statevector corresponding to variable {}".format( + var.name + ) ) y_var = y[statevector.y_slices[0]] if np.any(y_var > pybamm.settings.max_y_value): diff --git a/pybamm/spatial_methods/finite_volume.py b/pybamm/spatial_methods/finite_volume.py index ecbae69796..9d7474ad43 100644 --- a/pybamm/spatial_methods/finite_volume.py +++ b/pybamm/spatial_methods/finite_volume.py @@ -1363,8 +1363,9 @@ def upwind_or_downwind(self, symbol, discretised_symbol, bcs, direction): if symbol not in bcs: raise pybamm.ModelError( - "Boundary conditions must be provided for " - "{}ing '{}'".format(direction, symbol) + "Boundary conditions must be provided for " "{}ing '{}'".format( + direction, symbol + ) ) if direction == "upwind": diff --git a/pybamm/spatial_methods/spectral_volume.py b/pybamm/spatial_methods/spectral_volume.py index 7f7cfdb37a..7867bf2053 100644 --- a/pybamm/spatial_methods/spectral_volume.py +++ b/pybamm/spatial_methods/spectral_volume.py @@ -527,8 +527,9 @@ def replace_dirichlet_values(self, symbol, discretised_symbol, bcs): lbc_vector = pybamm.Vector(np.zeros(n * second_dim_repeats)) else: raise ValueError( - "boundary condition must be Dirichlet or Neumann, " - "not '{}'".format(lbc_type) + "boundary condition must be Dirichlet or Neumann, " "not '{}'".format( + lbc_type + ) ) if rbc_type == "Dirichlet": @@ -543,8 +544,9 @@ def replace_dirichlet_values(self, symbol, discretised_symbol, bcs): rbc_vector = pybamm.Vector(np.zeros(n * second_dim_repeats)) else: raise ValueError( - "boundary condition must be Dirichlet or Neumann, " - "not '{}'".format(rbc_type) + "boundary condition must be Dirichlet or Neumann, " "not '{}'".format( + rbc_type + ) ) bcs_vector = lbc_vector + rbc_vector @@ -621,8 +623,9 @@ def replace_neumann_values(self, symbol, discretised_gradient, bcs): lbc_vector = pybamm.Vector(np.zeros(n * second_dim_repeats)) else: raise ValueError( - "boundary condition must be Dirichlet or Neumann, " - "not '{}'".format(lbc_type) + "boundary condition must be Dirichlet or Neumann, " "not '{}'".format( + lbc_type + ) ) if rbc_type == "Neumann": @@ -637,8 +640,9 @@ def replace_neumann_values(self, symbol, discretised_gradient, bcs): rbc_vector = pybamm.Vector(np.zeros(n * second_dim_repeats)) else: raise ValueError( - "boundary condition must be Dirichlet or Neumann, " - "not '{}'".format(rbc_type) + "boundary condition must be Dirichlet or Neumann, " "not '{}'".format( + rbc_type + ) ) bcs_vector = lbc_vector + rbc_vector diff --git a/pybamm/step/_steps_util.py b/pybamm/step/_steps_util.py index e524bc6064..539811eb4c 100644 --- a/pybamm/step/_steps_util.py +++ b/pybamm/step/_steps_util.py @@ -193,10 +193,7 @@ def to_dict(self): } def __eq__(self, other): - return ( - isinstance(other, _Step) - and self.hash_args == other.hash_args - ) + return isinstance(other, _Step) and self.hash_args == other.hash_args def __hash__(self): return hash(self.basic_repr()) diff --git a/pybamm/util.py b/pybamm/util.py index 562352bfac..9ea1cb6e91 100644 --- a/pybamm/util.py +++ b/pybamm/util.py @@ -271,10 +271,9 @@ def have_jax(): def is_jax_compatible(): """Check if the available version of jax and jaxlib are compatible with PyBaMM""" - return ( - importlib.metadata.distribution("jax").version.startswith(JAX_VERSION) - and importlib.metadata.distribution("jaxlib").version.startswith(JAXLIB_VERSION) - ) + return importlib.metadata.distribution("jax").version.startswith( + JAX_VERSION + ) and importlib.metadata.distribution("jaxlib").version.startswith(JAXLIB_VERSION) def is_constant_and_can_evaluate(symbol): diff --git a/scripts/update_version.py b/scripts/update_version.py index fb9b15dd31..156f08e8c6 100644 --- a/scripts/update_version.py +++ b/scripts/update_version.py @@ -19,7 +19,6 @@ def update_version(): release_version = os.getenv("VERSION")[1:] last_day_of_month = date.today() + relativedelta(day=31) - # pybamm/version.py with open(os.path.join(pybamm.root_dir(), "pybamm", "version.py"), "r+") as file: output = file.read() diff --git a/setup.py b/setup.py index f6fd37f75c..57e4bf5f33 100644 --- a/setup.py +++ b/setup.py @@ -252,7 +252,7 @@ def compile_KLU(): "dev": [ # For working with pre-commit hooks "pre-commit", - # For code style checks: linting and auto-formatting + # For code style checks: linting and auto-formatting "ruff", # For running testing sessions "nox", diff --git a/tests/integration/test_models/test_full_battery_models/test_lithium_ion/base_lithium_ion_tests.py b/tests/integration/test_models/test_full_battery_models/test_lithium_ion/base_lithium_ion_tests.py index 6e3beeb1fc..6694248b5d 100644 --- a/tests/integration/test_models/test_full_battery_models/test_lithium_ion/base_lithium_ion_tests.py +++ b/tests/integration/test_models/test_full_battery_models/test_lithium_ion/base_lithium_ion_tests.py @@ -272,10 +272,9 @@ def test_negative_cracking(self): "r_n": 26, # negative particle "r_p": 26, # positive particle } - self.run_basic_processing_test(options, - parameter_values=parameter_values, - var_pts=var_pts - ) + self.run_basic_processing_test( + options, parameter_values=parameter_values, var_pts=var_pts + ) def test_positive_cracking(self): options = {"particle mechanics": ("none", "swelling and cracking")} @@ -287,10 +286,9 @@ def test_positive_cracking(self): "r_n": 26, # negative particle "r_p": 26, # positive particle } - self.run_basic_processing_test(options, - parameter_values=parameter_values, - var_pts=var_pts - ) + self.run_basic_processing_test( + options, parameter_values=parameter_values, var_pts=var_pts + ) def test_both_cracking(self): options = {"particle mechanics": "swelling and cracking"} @@ -302,10 +300,9 @@ def test_both_cracking(self): "r_n": 26, # negative particle "r_p": 26, # positive particle } - self.run_basic_processing_test(options, - parameter_values=parameter_values, - var_pts=var_pts - ) + self.run_basic_processing_test( + options, parameter_values=parameter_values, var_pts=var_pts + ) def test_both_swelling_only(self): options = {"particle mechanics": "swelling only"} diff --git a/tests/integration/test_models/test_full_battery_models/test_lithium_ion/test_mpm.py b/tests/integration/test_models/test_full_battery_models/test_lithium_ion/test_mpm.py index 18d773bed2..e217a11d75 100644 --- a/tests/integration/test_models/test_full_battery_models/test_lithium_ion/test_mpm.py +++ b/tests/integration/test_models/test_full_battery_models/test_lithium_ion/test_mpm.py @@ -56,10 +56,12 @@ def test_current_sigmoid_ocp(self): parameter_values = pybamm.get_size_distribution_parameters(parameter_values) parameter_values.update( { - "Negative electrode lithiation OCP [V]" - "": parameter_values["Negative electrode OCP [V]"], - "Negative electrode delithiation OCP [V]" - "": parameter_values["Negative electrode OCP [V]"], + "Negative electrode lithiation OCP [V]" "": parameter_values[ + "Negative electrode OCP [V]" + ], + "Negative electrode delithiation OCP [V]" "": parameter_values[ + "Negative electrode OCP [V]" + ], }, check_already_exists=False, ) diff --git a/tests/unit/test_expression_tree/test_binary_operators.py b/tests/unit/test_expression_tree/test_binary_operators.py index 6acd7c41b0..0b4e7e1333 100644 --- a/tests/unit/test_expression_tree/test_binary_operators.py +++ b/tests/unit/test_expression_tree/test_binary_operators.py @@ -96,9 +96,7 @@ def test_diff(self): self.assertEqual((a**b).diff(b).evaluate(y=y), 5**3 * np.log(5)) self.assertEqual((a**b).diff(a).evaluate(y=y), 3 * 5**2) self.assertEqual((a**b).diff(a**b).evaluate(), 1) - self.assertEqual( - (a**a).diff(a).evaluate(y=y), 5**5 * np.log(5) + 5 * 5**4 - ) + self.assertEqual((a**a).diff(a).evaluate(y=y), 5**5 * np.log(5) + 5 * 5**4) self.assertEqual((a**a).diff(b).evaluate(y=y), 0) # addition diff --git a/tests/unit/test_expression_tree/test_operations/test_jac.py b/tests/unit/test_expression_tree/test_operations/test_jac.py index c6e04d331f..015857a832 100644 --- a/tests/unit/test_expression_tree/test_operations/test_jac.py +++ b/tests/unit/test_expression_tree/test_operations/test_jac.py @@ -77,9 +77,7 @@ def test_nonlinear(self): np.testing.assert_array_equal(jacobian, dfunc_dy.toarray()) func = 2**v - jacobian = np.array( - [[0, 0, 2**3 * np.log(2), 0], [0, 0, 0, 2**4 * np.log(2)]] - ) + jacobian = np.array([[0, 0, 2**3 * np.log(2), 0], [0, 0, 0, 2**4 * np.log(2)]]) dfunc_dy = func.jac(y).evaluate(y=y0) np.testing.assert_array_equal(jacobian, dfunc_dy.toarray()) diff --git a/tests/unit/test_models/test_full_battery_models/test_base_battery_model.py b/tests/unit/test_models/test_full_battery_models/test_base_battery_model.py index 79c6d8a720..30646f9b6d 100644 --- a/tests/unit/test_models/test_full_battery_models/test_base_battery_model.py +++ b/tests/unit/test_models/test_full_battery_models/test_base_battery_model.py @@ -360,10 +360,7 @@ def test_options(self): # thermal half-cell with self.assertRaisesRegex(pybamm.OptionError, "X-full"): pybamm.BaseBatteryModel( - { - "thermal": "x-full", - "working electrode": "positive" - } + {"thermal": "x-full", "working electrode": "positive"} ) with self.assertRaisesRegex(pybamm.OptionError, "X-lumped"): pybamm.BaseBatteryModel( diff --git a/tests/unit/test_models/test_full_battery_models/test_lithium_ion/test_mpm.py b/tests/unit/test_models/test_full_battery_models/test_lithium_ion/test_mpm.py index 442817e354..88049c0c63 100644 --- a/tests/unit/test_models/test_full_battery_models/test_lithium_ion/test_mpm.py +++ b/tests/unit/test_models/test_full_battery_models/test_lithium_ion/test_mpm.py @@ -21,9 +21,7 @@ def test_default_parameter_values(self): # check default parameters are added correctly model = pybamm.lithium_ion.MPM() self.assertEqual( - model.default_parameter_values[ - "Negative minimum particle radius [m]" - ], + model.default_parameter_values["Negative minimum particle radius [m]"], 0.0, ) diff --git a/tests/unit/test_models/test_full_battery_models/test_lithium_ion/test_mpm_half_cell.py b/tests/unit/test_models/test_full_battery_models/test_lithium_ion/test_mpm_half_cell.py index ebd19ba614..77d51f6cf7 100644 --- a/tests/unit/test_models/test_full_battery_models/test_lithium_ion/test_mpm_half_cell.py +++ b/tests/unit/test_models/test_full_battery_models/test_lithium_ion/test_mpm_half_cell.py @@ -21,9 +21,7 @@ def test_default_parameter_values(self): # check default parameters are added correctly model = pybamm.lithium_ion.MPM({"working electrode": "positive"}) self.assertEqual( - model.default_parameter_values[ - "Positive minimum particle radius [m]" - ], + model.default_parameter_values["Positive minimum particle radius [m]"], 0.0, ) diff --git a/tests/unit/test_parameters/test_bpx.py b/tests/unit/test_parameters/test_bpx.py index 2559641d7e..e131e906c4 100644 --- a/tests/unit/test_parameters/test_bpx.py +++ b/tests/unit/test_parameters/test_bpx.py @@ -9,6 +9,7 @@ import pybamm import copy + class TestBPX(TestCase): def setUp(self): self.base = { @@ -180,7 +181,6 @@ def check_constant_output(func): check_constant_output(kappa) check_constant_output(De) - def test_table_data(self): bpx_obj = copy.copy(self.base) data = {"x": [0, 1], "y": [0, 1]} @@ -255,7 +255,6 @@ def test_bpx_arrhenius(self): pv = pybamm.ParameterValues.create_from_bpx(tmp.name) - def arrhenius_assertion(pv, param_key, Ea_key): sto = 0.5 T = 300 @@ -269,11 +268,10 @@ def arrhenius_assertion(pv, param_key, Ea_key): eval_ratio = ( pv[param_key](c_e, c_s_surf, c_s_max, T).value / pv[param_key](c_e, c_s_surf, c_s_max, T_ref).value - ) + ) else: eval_ratio = ( - pv[param_key](sto, T).value - / pv[param_key](sto, T_ref).value + pv[param_key](sto, T).value / pv[param_key](sto, T_ref).value ) calc_ratio = pybamm.exp(Ea / pybamm.constants.R * (1 / T_ref - 1 / T)).value @@ -301,6 +299,7 @@ def arrhenius_assertion(pv, param_key, Ea_key): for param_key, Ea_key in zip(param_keys, Ea_keys): arrhenius_assertion(pv, param_key, Ea_key) + if __name__ == "__main__": print("Add -v for more debug output") import sys diff --git a/tests/unit/test_parameters/test_parameter_sets/test_Ecker2015.py b/tests/unit/test_parameters/test_parameter_sets/test_Ecker2015.py index a537afc93d..894213f92d 100644 --- a/tests/unit/test_parameters/test_parameter_sets/test_Ecker2015.py +++ b/tests/unit/test_parameters/test_parameter_sets/test_Ecker2015.py @@ -29,7 +29,7 @@ def test_functions(self): "Positive electrode OCP [V]": ([sto], 3.9478), # Electrolyte "Electrolyte diffusivity [m2.s-1]": ([1000, T], 2.593e-10), - "Electrolyte conductivity [S.m-1]": ([1000, T], 0.9738) + "Electrolyte conductivity [S.m-1]": ([1000, T], 0.9738), } for name, value in fun_test.items(): diff --git a/tests/unit/test_parameters/test_parameter_sets/test_Ecker2015_graphite_halfcell.py b/tests/unit/test_parameters/test_parameter_sets/test_Ecker2015_graphite_halfcell.py index 6dde10cd9c..f548030f26 100644 --- a/tests/unit/test_parameters/test_parameter_sets/test_Ecker2015_graphite_halfcell.py +++ b/tests/unit/test_parameters/test_parameter_sets/test_Ecker2015_graphite_halfcell.py @@ -22,7 +22,7 @@ def test_functions(self): "Positive electrode OCP [V]": ([sto], 0.124), # Electrolyte "Electrolyte diffusivity [m2.s-1]": ([1000, T], 2.593e-10), - "Electrolyte conductivity [S.m-1]": ([1000, T], 0.9738) + "Electrolyte conductivity [S.m-1]": ([1000, T], 0.9738), } for name, value in fun_test.items(): diff --git a/tests/unit/test_parameters/test_size_distribution_parameters.py b/tests/unit/test_parameters/test_size_distribution_parameters.py index e633b2764a..5deeaa62be 100644 --- a/tests/unit/test_parameters/test_size_distribution_parameters.py +++ b/tests/unit/test_parameters/test_size_distribution_parameters.py @@ -37,7 +37,6 @@ def test_parameter_values(self): np.testing.assert_almost_equal(values.evaluate(param.n.prim.R_max), 2.5e-5, 3) np.testing.assert_almost_equal(values.evaluate(param.p.prim.R_max), 2.5e-5, 3) - # check function parameters (size distributions) evaluate R_test = pybamm.Scalar(1.0) values.evaluate(param.n.prim.f_a_dist(R_test)) diff --git a/tests/unit/test_plotting/test_quick_plot.py b/tests/unit/test_plotting/test_quick_plot.py index f569f00152..db27ab6bb6 100644 --- a/tests/unit/test_plotting/test_quick_plot.py +++ b/tests/unit/test_plotting/test_quick_plot.py @@ -294,8 +294,9 @@ def test_spm_simulation(self): with TemporaryDirectory() as dir_name: test_stub = os.path.join(dir_name, "spm_sim_test") test_file = f"{test_stub}.gif" - quick_plot.create_gif(number_of_images=3, duration=3, - output_filename=test_file) + quick_plot.create_gif( + number_of_images=3, duration=3, output_filename=test_file + ) assert not os.path.exists(f"{test_stub}*.png") assert os.path.exists(test_file) pybamm.close_plots() diff --git a/tests/unit/test_simulation.py b/tests/unit/test_simulation.py index dac94a2538..5ca3e6fa8d 100644 --- a/tests/unit/test_simulation.py +++ b/tests/unit/test_simulation.py @@ -208,14 +208,14 @@ def test_solve_with_initial_soc(self): options = {"working electrode": "positive"} model = pybamm.lithium_ion.DFN(options) sim = pybamm.Simulation(model) - sim.solve([0,1], initial_soc = 0.9) + sim.solve([0, 1], initial_soc=0.9) self.assertEqual(sim._built_initial_soc, 0.9) # Test whether initial_soc works with half cell (build) options = {"working electrode": "positive"} model = pybamm.lithium_ion.DFN(options) sim = pybamm.Simulation(model) - sim.build(initial_soc = 0.9) + sim.build(initial_soc=0.9) self.assertEqual(sim._built_initial_soc, 0.9) # Test whether initial_soc works with half cell when it is a voltage @@ -227,7 +227,7 @@ def test_solve_with_initial_soc(self): options = {"working electrode": "positive"} parameter_values["Current function [A]"] = 0.0 sim = pybamm.Simulation(model, parameter_values=parameter_values) - sol = sim.solve([0,1], initial_soc = "{} V".format(ucv)) + sol = sim.solve([0, 1], initial_soc="{} V".format(ucv)) voltage = sol["Terminal voltage [V]"].entries self.assertAlmostEqual(voltage[0], ucv, places=5) @@ -302,12 +302,10 @@ def test_save_load(self): sim = pybamm.Simulation(model) sim.solve([0, 600]) with self.assertRaisesRegex( - NotImplementedError, - "Cannot save simulation if model format is python" + NotImplementedError, "Cannot save simulation if model format is python" ): sim.save(test_name) - def test_load_param(self): # Test load_sim for parameters imports filename = f"{uuid.uuid4()}.p" diff --git a/tests/unit/test_solvers/test_idaklu_solver.py b/tests/unit/test_solvers/test_idaklu_solver.py index cc54f3dfd5..604f559049 100644 --- a/tests/unit/test_solvers/test_idaklu_solver.py +++ b/tests/unit/test_solvers/test_idaklu_solver.py @@ -87,7 +87,7 @@ def test_model_events(self): # Check invalid atol type raises an error with self.assertRaises(pybamm.SolverError): - solver._check_atol_type({'key': 'value'}, []) + solver._check_atol_type({"key": "value"}, []) # enforce events that won't be triggered model.events = [pybamm.Event("an event", var + 1)] @@ -566,9 +566,9 @@ def test_with_output_variables(self): t_eval = np.linspace(0, 3600, 100) options = { - 'linear_solver': 'SUNLinSol_KLU', - 'jacobian': 'sparse', - 'num_threads': 4, + "linear_solver": "SUNLinSol_KLU", + "jacobian": "sparse", + "num_threads": 4, } # Use a selection of variables of different types @@ -587,7 +587,8 @@ def test_with_output_variables(self): # Use the full model as comparison (tested separately) solver_all = pybamm.IDAKLUSolver( - atol=1e-8, rtol=1e-8, + atol=1e-8, + rtol=1e-8, options=options, ) sol_all = solver_all.solve( @@ -599,7 +600,8 @@ def test_with_output_variables(self): # Solve for a subset of variables and compare results solver = pybamm.IDAKLUSolver( - atol=1e-8, rtol=1e-8, + atol=1e-8, + rtol=1e-8, options=options, output_variables=output_variables, ) @@ -640,9 +642,9 @@ def test_with_output_variables_and_sensitivities(self): t_eval = np.linspace(0, 3600, 100) options = { - 'linear_solver': 'SUNLinSol_KLU', - 'jacobian': 'sparse', - 'num_threads': 4, + "linear_solver": "SUNLinSol_KLU", + "jacobian": "sparse", + "num_threads": 4, } # Use a selection of variables of different types @@ -656,7 +658,8 @@ def test_with_output_variables_and_sensitivities(self): # Use the full model as comparison (tested separately) solver_all = pybamm.IDAKLUSolver( - atol=1e-8, rtol=1e-8, + atol=1e-8, + rtol=1e-8, options=options, ) sol_all = solver_all.solve( @@ -668,7 +671,8 @@ def test_with_output_variables_and_sensitivities(self): # Solve for a subset of variables and compare results solver = pybamm.IDAKLUSolver( - atol=1e-8, rtol=1e-8, + atol=1e-8, + rtol=1e-8, options=options, output_variables=output_variables, ) diff --git a/tests/unit/test_solvers/test_processed_variable_computed.py b/tests/unit/test_solvers/test_processed_variable_computed.py index e31f51ab1e..142ea27017 100644 --- a/tests/unit/test_solvers/test_processed_variable_computed.py +++ b/tests/unit/test_solvers/test_processed_variable_computed.py @@ -169,11 +169,15 @@ def test_processed_variable_1D(self): np.testing.assert_array_equal(processed_var.unroll(), y_sol) # Check no error when data dimension is transposed vs node/edge - processed_var.mesh.nodes, processed_var.mesh.edges = \ - processed_var.mesh.edges, processed_var.mesh.nodes + processed_var.mesh.nodes, processed_var.mesh.edges = ( + processed_var.mesh.edges, + processed_var.mesh.nodes, + ) processed_var.initialise_1D() - processed_var.mesh.nodes, processed_var.mesh.edges = \ - processed_var.mesh.edges, processed_var.mesh.nodes + processed_var.mesh.nodes, processed_var.mesh.edges = ( + processed_var.mesh.edges, + processed_var.mesh.nodes, + ) # Check that there are no errors with domain-specific attributes # (see ProcessedVariableComputed.initialise_1D() for details) diff --git a/tests/unit/test_solvers/test_solution.py b/tests/unit/test_solvers/test_solution.py index 9fc93dfb26..c7dfb716de 100644 --- a/tests/unit/test_solvers/test_solution.py +++ b/tests/unit/test_solvers/test_solution.py @@ -279,15 +279,16 @@ def test_save(self): solution.save_data(f"{test_stub}.mat", to_format="matlab") # Works if providing alternative name solution.save_data( - f"{test_stub}.mat", to_format="matlab", - short_names={"c + d": "c_plus_d"} + f"{test_stub}.mat", + to_format="matlab", + short_names={"c + d": "c_plus_d"}, ) data_load = loadmat(f"{test_stub}.mat") np.testing.assert_array_equal(solution.data["c + d"], data_load["c_plus_d"]) # to csv with self.assertRaisesRegex( - ValueError, "only 0D variables can be saved to csv" + ValueError, "only 0D variables can be saved to csv" ): solution.save_data(f"{test_stub}.csv", to_format="csv") # only save "c" and "2c" @@ -319,19 +320,23 @@ def test_save(self): np.testing.assert_array_almost_equal(json_data["d"], solution.data["d"]) # raise error if format is unknown - with self.assertRaisesRegex(ValueError, - "format 'wrong_format' not recognised"): + with self.assertRaisesRegex( + ValueError, "format 'wrong_format' not recognised" + ): solution.save_data(f"{test_stub}.csv", to_format="wrong_format") # test save whole solution solution.save(f"{test_stub}.pickle") solution_load = pybamm.load(f"{test_stub}.pickle") - self.assertEqual(solution.all_models[0].name, - solution_load.all_models[0].name) - np.testing.assert_array_equal(solution["c"].entries, - solution_load["c"].entries) - np.testing.assert_array_equal(solution["d"].entries, - solution_load["d"].entries) + self.assertEqual( + solution.all_models[0].name, solution_load.all_models[0].name + ) + np.testing.assert_array_equal( + solution["c"].entries, solution_load["c"].entries + ) + np.testing.assert_array_equal( + solution["d"].entries, solution_load["d"].entries + ) def test_get_data_cycles_steps(self): model = pybamm.BaseModel() diff --git a/tests/unit/test_spatial_methods/test_scikit_finite_element.py b/tests/unit/test_spatial_methods/test_scikit_finite_element.py index 657d896dfd..05b424e053 100644 --- a/tests/unit/test_spatial_methods/test_scikit_finite_element.py +++ b/tests/unit/test_spatial_methods/test_scikit_finite_element.py @@ -203,7 +203,7 @@ def test_manufactured_solution(self): u = np.sin(np.pi * z_vertices) mass = pybamm.Mass(var) mass_disc = disc.process_symbol(mass) - soln = -np.pi**2 * u + soln = -(np.pi**2) * u np.testing.assert_array_almost_equal( eqn_zz_disc.evaluate(None, u), mass_disc.entries @ soln, decimal=3 ) @@ -226,7 +226,7 @@ def test_manufactured_solution(self): u = np.cos(np.pi * y_vertices) * np.sin(np.pi * z_vertices) mass = pybamm.Mass(var) mass_disc = disc.process_symbol(mass) - soln = -np.pi**2 * u + soln = -(np.pi**2) * u np.testing.assert_array_almost_equal( laplace_eqn_disc.evaluate(None, u), mass_disc.entries @ soln, decimal=2 ) @@ -287,7 +287,7 @@ def test_manufactured_solution_cheb_grid(self): u = np.cos(np.pi * y_vertices) * np.sin(np.pi * z_vertices) mass = pybamm.Mass(var) mass_disc = disc.process_symbol(mass) - soln = -np.pi**2 * u + soln = -(np.pi**2) * u np.testing.assert_array_almost_equal( laplace_eqn_disc.evaluate(None, u), mass_disc.entries @ soln, decimal=1 ) @@ -350,7 +350,7 @@ def test_manufactured_solution_exponential_grid(self): u = np.cos(np.pi * y_vertices) * np.sin(np.pi * z_vertices) mass = pybamm.Mass(var) mass_disc = disc.process_symbol(mass) - soln = -np.pi**2 * u + soln = -(np.pi**2) * u np.testing.assert_array_almost_equal( laplace_eqn_disc.evaluate(None, u), mass_disc.entries @ soln, decimal=1 )