From 8a0584e747a0bd745cffd14f92fdbed316743969 Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Tue, 12 Mar 2024 23:19:36 +0000 Subject: [PATCH 1/3] chore: update pre-commit hooks MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit updates: - [github.com/astral-sh/ruff-pre-commit: v0.2.2 → v0.3.2](https://github.com/astral-sh/ruff-pre-commit/compare/v0.2.2...v0.3.2) --- .pre-commit-config.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index c5ba024f06..f78b0e424b 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -4,7 +4,7 @@ ci: repos: - repo: https://github.com/astral-sh/ruff-pre-commit - rev: "v0.2.2" + rev: "v0.3.2" hooks: - id: ruff args: [--fix, --show-fixes] From f395819d1c874071b7e76e32ec4f0bbe42462b48 Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Tue, 12 Mar 2024 23:19:51 +0000 Subject: [PATCH 2/3] style: pre-commit fixes --- .../notebooks/models/using-submodels.ipynb | 78 +++---- .../spatial_methods/finite-volumes.ipynb | 4 +- examples/scripts/custom_model.py | 70 +++---- pybamm/citations.py | 1 - pybamm/discretisations/discretisation.py | 24 +-- pybamm/expression_tree/binary_operators.py | 4 +- pybamm/expression_tree/input_parameter.py | 4 +- .../operations/convert_to_casadi.py | 6 +- .../operations/evaluate_python.py | 8 +- pybamm/expression_tree/symbol.py | 8 +- pybamm/expression_tree/unary_operators.py | 4 +- pybamm/expression_tree/vector.py | 4 +- pybamm/geometry/battery_geometry.py | 4 +- pybamm/meshes/one_dimensional_submeshes.py | 12 +- pybamm/meshes/scikit_fem_submeshes.py | 14 +- pybamm/models/base_model.py | 28 +-- .../full_battery_models/base_battery_model.py | 28 ++- .../equivalent_circuit/thevenin.py | 14 +- .../lead_acid/base_lead_acid_model.py | 30 +-- .../full_battery_models/lead_acid/full.py | 48 +++-- .../full_battery_models/lead_acid/loqs.py | 190 +++++++++--------- .../lithium_ion/base_lithium_ion_model.py | 118 +++++------ .../full_battery_models/lithium_ion/dfn.py | 22 +- .../lithium_ion/newman_tobias.py | 14 +- .../full_battery_models/lithium_ion/spm.py | 44 ++-- .../full_battery_models/lithium_ion/spme.py | 22 +- .../effective_resistance_current_collector.py | 4 +- .../constant_concentration.py | 6 +- .../electrolyte_diffusion/full_diffusion.py | 6 +- pybamm/parameters/bpx.py | 38 ++-- pybamm/parameters/parameter_sets.py | 6 +- pybamm/parameters/parameter_values.py | 18 +- pybamm/plotting/quick_plot.py | 11 +- pybamm/simulation.py | 14 +- pybamm/solvers/algebraic_solver.py | 4 +- pybamm/solvers/base_solver.py | 39 +--- pybamm/solvers/casadi_algebraic_solver.py | 8 +- pybamm/solvers/solution.py | 4 +- pybamm/spatial_methods/spectral_volume.py | 12 +- scripts/install_KLU_Sundials.py | 6 +- .../test_operations/test_latexify.py | 1 + .../test_printing/test_print_name.py | 1 + .../test_printing/test_sympy_overrides.py | 1 + .../test_parameters/test_base_parameters.py | 1 + 44 files changed, 454 insertions(+), 529 deletions(-) diff --git a/docs/source/examples/notebooks/models/using-submodels.ipynb b/docs/source/examples/notebooks/models/using-submodels.ipynb index 5c00de05da..cce32fcefd 100644 --- a/docs/source/examples/notebooks/models/using-submodels.ipynb +++ b/docs/source/examples/notebooks/models/using-submodels.ipynb @@ -142,10 +142,12 @@ "metadata": {}, "outputs": [], "source": [ - "model.submodels[\n", - " \"negative primary particle\"\n", - "] = pybamm.particle.XAveragedPolynomialProfile(\n", - " model.param, \"negative\", options={**model.options, \"particle\": \"uniform profile\"}\n", + "model.submodels[\"negative primary particle\"] = (\n", + " pybamm.particle.XAveragedPolynomialProfile(\n", + " model.param,\n", + " \"negative\",\n", + " options={**model.options, \"particle\": \"uniform profile\"},\n", + " )\n", ")" ] }, @@ -431,19 +433,19 @@ "outputs": [], "source": [ "options = {**model.options, \"particle\": \"uniform profile\"}\n", - "model.submodels[\n", - " \"negative primary particle\"\n", - "] = pybamm.particle.XAveragedPolynomialProfile(model.param, \"negative\", options)\n", - "model.submodels[\n", - " \"positive primary particle\"\n", - "] = pybamm.particle.XAveragedPolynomialProfile(model.param, \"positive\", options)\n", + "model.submodels[\"negative primary particle\"] = (\n", + " pybamm.particle.XAveragedPolynomialProfile(model.param, \"negative\", options)\n", + ")\n", + "model.submodels[\"positive primary particle\"] = (\n", + " pybamm.particle.XAveragedPolynomialProfile(model.param, \"positive\", options)\n", + ")\n", "\n", - "model.submodels[\n", - " \"negative total particle concentration\"\n", - "] = pybamm.particle.TotalConcentration(model.param, \"negative\", options)\n", - "model.submodels[\n", - " \"positive total particle concentration\"\n", - "] = pybamm.particle.TotalConcentration(model.param, \"positive\", options)" + "model.submodels[\"negative total particle concentration\"] = (\n", + " pybamm.particle.TotalConcentration(model.param, \"negative\", options)\n", + ")\n", + "model.submodels[\"positive total particle concentration\"] = (\n", + " pybamm.particle.TotalConcentration(model.param, \"positive\", options)\n", + ")" ] }, { @@ -459,15 +461,15 @@ "metadata": {}, "outputs": [], "source": [ - "model.submodels[\n", - " \"negative open-circuit potential\"\n", - "] = pybamm.open_circuit_potential.SingleOpenCircuitPotential(\n", - " model.param, \"negative\", \"lithium-ion main\", options=model.options\n", + "model.submodels[\"negative open-circuit potential\"] = (\n", + " pybamm.open_circuit_potential.SingleOpenCircuitPotential(\n", + " model.param, \"negative\", \"lithium-ion main\", options=model.options\n", + " )\n", ")\n", - "model.submodels[\n", - " \"positive open-circuit potential\"\n", - "] = pybamm.open_circuit_potential.SingleOpenCircuitPotential(\n", - " model.param, \"positive\", \"lithium-ion main\", options=model.options\n", + "model.submodels[\"positive open-circuit potential\"] = (\n", + " pybamm.open_circuit_potential.SingleOpenCircuitPotential(\n", + " model.param, \"positive\", \"lithium-ion main\", options=model.options\n", + " )\n", ")\n", "model.submodels[\"negative interface\"] = pybamm.kinetics.InverseButlerVolmer(\n", " model.param, \"negative\", \"lithium-ion main\", options=model.options\n", @@ -475,15 +477,15 @@ "model.submodels[\"positive interface\"] = pybamm.kinetics.InverseButlerVolmer(\n", " model.param, \"positive\", \"lithium-ion main\", options=model.options\n", ")\n", - "model.submodels[\n", - " \"negative interface current\"\n", - "] = pybamm.kinetics.CurrentForInverseButlerVolmer(\n", - " model.param, \"negative\", \"lithium-ion main\"\n", + "model.submodels[\"negative interface current\"] = (\n", + " pybamm.kinetics.CurrentForInverseButlerVolmer(\n", + " model.param, \"negative\", \"lithium-ion main\"\n", + " )\n", ")\n", - "model.submodels[\n", - " \"positive interface current\"\n", - "] = pybamm.kinetics.CurrentForInverseButlerVolmer(\n", - " model.param, \"positive\", \"lithium-ion main\"\n", + "model.submodels[\"positive interface current\"] = (\n", + " pybamm.kinetics.CurrentForInverseButlerVolmer(\n", + " model.param, \"positive\", \"lithium-ion main\"\n", + " )\n", ")\n", "model.submodels[\"negative interface utilisation\"] = pybamm.interface_utilisation.Full(\n", " model.param, \"negative\", model.options\n", @@ -545,12 +547,12 @@ "metadata": {}, "outputs": [], "source": [ - "model.submodels[\n", - " \"electrolyte diffusion\"\n", - "] = pybamm.electrolyte_diffusion.ConstantConcentration(model.param)\n", - "model.submodels[\n", - " \"electrolyte conductivity\"\n", - "] = pybamm.electrolyte_conductivity.LeadingOrder(model.param)" + "model.submodels[\"electrolyte diffusion\"] = (\n", + " pybamm.electrolyte_diffusion.ConstantConcentration(model.param)\n", + ")\n", + "model.submodels[\"electrolyte conductivity\"] = (\n", + " pybamm.electrolyte_conductivity.LeadingOrder(model.param)\n", + ")" ] }, { diff --git a/docs/source/examples/notebooks/spatial_methods/finite-volumes.ipynb b/docs/source/examples/notebooks/spatial_methods/finite-volumes.ipynb index 849f1bdf47..78e1a161b4 100644 --- a/docs/source/examples/notebooks/spatial_methods/finite-volumes.ipynb +++ b/docs/source/examples/notebooks/spatial_methods/finite-volumes.ipynb @@ -920,9 +920,7 @@ "int_v_over_r2 = pybamm.Integral(v / r_var**2, r_var)\n", "int_v_over_r2_disc = disc.process_symbol(int_v_over_r2)\n", "print(\n", - " \"int(v/r^2) = {} is approximately equal to 4 * pi * sin(1), {}\".format(\n", - " int_v_over_r2_disc.evaluate(y=y), 4 * np.pi * np.sin(1)\n", - " )\n", + " f\"int(v/r^2) = {int_v_over_r2_disc.evaluate(y=y)} is approximately equal to 4 * pi * sin(1), {4 * np.pi * np.sin(1)}\"\n", ")" ] }, diff --git a/examples/scripts/custom_model.py b/examples/scripts/custom_model.py index 4c6dcf3fad..a0e7ef2b80 100644 --- a/examples/scripts/custom_model.py +++ b/examples/scripts/custom_model.py @@ -17,61 +17,61 @@ model.submodels["current collector"] = pybamm.current_collector.Uniform(model.param) model.submodels["thermal"] = pybamm.thermal.isothermal.Isothermal(model.param) model.submodels["porosity"] = pybamm.porosity.Constant(model.param, model.options) -model.submodels[ - "electrolyte diffusion" -] = pybamm.electrolyte_diffusion.ConstantConcentration(model.param) -model.submodels[ - "electrolyte conductivity" -] = pybamm.electrolyte_conductivity.LeadingOrder(model.param) +model.submodels["electrolyte diffusion"] = ( + pybamm.electrolyte_diffusion.ConstantConcentration(model.param) +) +model.submodels["electrolyte conductivity"] = ( + pybamm.electrolyte_conductivity.LeadingOrder(model.param) +) # Loop over negative and positive electrode domains for some submodels for domain in ["negative", "positive"]: model.submodels[f"{domain} active material"] = pybamm.active_material.Constant( model.param, domain, model.options ) - model.submodels[ - f"{domain} electrode potential" - ] = pybamm.electrode.ohm.LeadingOrder(model.param, domain) + model.submodels[f"{domain} electrode potential"] = ( + pybamm.electrode.ohm.LeadingOrder(model.param, domain) + ) model.submodels[f"{domain} particle"] = pybamm.particle.XAveragedPolynomialProfile( model.param, domain, options={**model.options, "particle": "uniform profile"}, phase="primary", ) - model.submodels[ - f"{domain} total particle concentration" - ] = pybamm.particle.TotalConcentration( - model.param, domain, model.options, phase="primary" + model.submodels[f"{domain} total particle concentration"] = ( + pybamm.particle.TotalConcentration( + model.param, domain, model.options, phase="primary" + ) ) - model.submodels[ - f"{domain} open-circuit potential" - ] = pybamm.open_circuit_potential.SingleOpenCircuitPotential( - model.param, - domain, - "lithium-ion main", - options=model.options, - phase="primary", + model.submodels[f"{domain} open-circuit potential"] = ( + pybamm.open_circuit_potential.SingleOpenCircuitPotential( + model.param, + domain, + "lithium-ion main", + options=model.options, + phase="primary", + ) ) model.submodels[f"{domain} interface"] = pybamm.kinetics.InverseButlerVolmer( model.param, domain, "lithium-ion main", options=model.options ) - model.submodels[ - f"{domain} interface utilisation" - ] = pybamm.interface_utilisation.Full(model.param, domain, model.options) - model.submodels[ - f"{domain} interface current" - ] = pybamm.kinetics.CurrentForInverseButlerVolmer( - model.param, domain, "lithium-ion main" + model.submodels[f"{domain} interface utilisation"] = ( + pybamm.interface_utilisation.Full(model.param, domain, model.options) ) - model.submodels[ - f"{domain} surface potential difference [V]" - ] = pybamm.electrolyte_conductivity.surface_potential_form.Explicit( - model.param, domain, model.options + model.submodels[f"{domain} interface current"] = ( + pybamm.kinetics.CurrentForInverseButlerVolmer( + model.param, domain, "lithium-ion main" + ) + ) + model.submodels[f"{domain} surface potential difference [V]"] = ( + pybamm.electrolyte_conductivity.surface_potential_form.Explicit( + model.param, domain, model.options + ) + ) + model.submodels[f"{domain} particle mechanics"] = ( + pybamm.particle_mechanics.NoMechanics(model.param, domain, model.options) ) - model.submodels[ - f"{domain} particle mechanics" - ] = pybamm.particle_mechanics.NoMechanics(model.param, domain, model.options) model.submodels[f"{domain} sei"] = pybamm.sei.NoSEI( model.param, domain, model.options ) diff --git a/pybamm/citations.py b/pybamm/citations.py index 74f477c117..c2930e5826 100644 --- a/pybamm/citations.py +++ b/pybamm/citations.py @@ -11,7 +11,6 @@ class Citations: - """Entry point to citations management. This object may be used to record BibTeX citation information and then register that a particular citation is relevant for a particular simulation. diff --git a/pybamm/discretisations/discretisation.py b/pybamm/discretisations/discretisation.py index 7be3b2bc53..90814ea508 100644 --- a/pybamm/discretisations/discretisation.py +++ b/pybamm/discretisations/discretisation.py @@ -458,9 +458,7 @@ def process_boundary_conditions(self, model): if bcs["left"][0].value != 0 or bcs["left"][1] != "Neumann": raise pybamm.ModelError( "Boundary condition at r = 0 must be a homogeneous " - "Neumann condition for {} coordinates".format( - self.mesh[subdomain].coord_sys - ) + f"Neumann condition for {self.mesh[subdomain].coord_sys} coordinates" ) # Handle any boundary conditions applied on the tabs @@ -890,11 +888,11 @@ def _process_symbol(self, symbol): y_slices = self.y_slices[symbol] except KeyError: raise pybamm.ModelError( - """ - No key set for variable '{}'. Make sure it is included in either + f""" + No key set for variable '{symbol.name}'. Make sure it is included in either model.rhs or model.algebraic in an unmodified form (e.g. not Broadcasted) - """.format(symbol.name) + """ ) # Add symbol's reference and multiply by the symbol's scale # so that the state vector is of order 1 @@ -1033,20 +1031,14 @@ def check_initial_conditions(self, model): raise pybamm.ModelError( "rhs and initial conditions must have the same shape after " "discretisation but rhs.shape = " - "{} and initial_conditions.shape = {} for variable '{}'.".format( - model.rhs[var].shape, model.initial_conditions[var].shape, var - ) + f"{model.rhs[var].shape} and initial_conditions.shape = {model.initial_conditions[var].shape} for variable '{var}'." ) for var in model.algebraic.keys(): if model.algebraic[var].shape != model.initial_conditions[var].shape: raise pybamm.ModelError( "algebraic and initial conditions must have the same shape after " "discretisation but algebraic.shape = " - "{} and initial_conditions.shape = {} for variable '{}'.".format( - model.algebraic[var].shape, - model.initial_conditions[var].shape, - var, - ) + f"{model.algebraic[var].shape} and initial_conditions.shape = {model.initial_conditions[var].shape} for variable '{var}'." ) def check_variables(self, model): @@ -1080,9 +1072,7 @@ def check_variables(self, model): raise pybamm.ModelError( "variable and its eqn must have the same shape after " "discretisation but variable.shape = " - "{} and rhs.shape = {} for variable '{}'. ".format( - var.shape, model.rhs[rhs_var].shape, var - ) + f"{var.shape} and rhs.shape = {model.rhs[rhs_var].shape} for variable '{var}'. " ) def is_variable_independent(self, var, all_vars_in_eqns): diff --git a/pybamm/expression_tree/binary_operators.py b/pybamm/expression_tree/binary_operators.py index a8086ebdd1..2088d890b9 100644 --- a/pybamm/expression_tree/binary_operators.py +++ b/pybamm/expression_tree/binary_operators.py @@ -36,9 +36,7 @@ def _preprocess_binary( # Check both left and right are pybamm Symbols if not (isinstance(left, pybamm.Symbol) and isinstance(right, pybamm.Symbol)): raise NotImplementedError( - """BinaryOperator not implemented for symbols of type {} and {}""".format( - type(left), type(right) - ) + f"""BinaryOperator not implemented for symbols of type {type(left)} and {type(right)}""" ) # Do some broadcasting in special cases, to avoid having to do this manually diff --git a/pybamm/expression_tree/input_parameter.py b/pybamm/expression_tree/input_parameter.py index a1ee00a47b..110aff89c1 100644 --- a/pybamm/expression_tree/input_parameter.py +++ b/pybamm/expression_tree/input_parameter.py @@ -116,9 +116,7 @@ def _base_evaluate( return input_eval else: raise ValueError( - "Input parameter '{}' was given an object of size '{}'".format( - self.name, input_size - ) + f"Input parameter '{self.name}' was given an object of size '{input_size}'" + f" but was expecting an object of size '{self._expected_size}'." ) diff --git a/pybamm/expression_tree/operations/convert_to_casadi.py b/pybamm/expression_tree/operations/convert_to_casadi.py index 084b587721..196da9dec9 100644 --- a/pybamm/expression_tree/operations/convert_to_casadi.py +++ b/pybamm/expression_tree/operations/convert_to_casadi.py @@ -215,8 +215,8 @@ def _convert(self, symbol, t, y, y_dot, inputs): else: raise TypeError( - """ - Cannot convert symbol of type '{}' to CasADi. Symbols must all be + f""" + Cannot convert symbol of type '{type(symbol)}' to CasADi. Symbols must all be 'linear algebra' at this stage. - """.format(type(symbol)) + """ ) diff --git a/pybamm/expression_tree/operations/evaluate_python.py b/pybamm/expression_tree/operations/evaluate_python.py index 3582db13aa..6d13761756 100644 --- a/pybamm/expression_tree/operations/evaluate_python.py +++ b/pybamm/expression_tree/operations/evaluate_python.py @@ -362,9 +362,7 @@ def find_symbols( else: raise NotImplementedError( - "Conversion to python not implemented for a symbol of type '{}'".format( - type(symbol) - ) + f"Conversion to python not implemented for a symbol of type '{type(symbol)}'" ) variable_symbols[symbol.id] = symbol_str @@ -406,9 +404,7 @@ def to_python( if debug: # pragma: no cover variable_lines = [ - "print('{}'); ".format( - line_format.format(id_to_python_variable(symbol_id, False), symbol_line) - ) + f"print('{line_format.format(id_to_python_variable(symbol_id, False), symbol_line)}'); " + line_format.format(id_to_python_variable(symbol_id, False), symbol_line) + "; print(type({0}),np.shape({0}))".format( id_to_python_variable(symbol_id, False) diff --git a/pybamm/expression_tree/symbol.py b/pybamm/expression_tree/symbol.py index e68e436749..cb53e6a787 100644 --- a/pybamm/expression_tree/symbol.py +++ b/pybamm/expression_tree/symbol.py @@ -570,13 +570,7 @@ def __str__(self): def __repr__(self): """returns the string `__class__(id, name, children, domain)`""" - return ("{!s}({}, {!s}, children={!s}, domains={!s})").format( - self.__class__.__name__, - hex(self.id), - self._name, - [str(child) for child in self.children], - {k: v for k, v in self.domains.items() if v != []}, - ) + return f"{self.__class__.__name__!s}({hex(self.id)}, {self._name!s}, children={[str(child) for child in self.children]!s}, domains={({k: v for k, v in self.domains.items() if v != []})!s})" def __add__(self, other: ChildSymbol) -> pybamm.Addition: """return an :class:`Addition` object.""" diff --git a/pybamm/expression_tree/unary_operators.py b/pybamm/expression_tree/unary_operators.py index 9669c2596a..2a2bb36640 100644 --- a/pybamm/expression_tree/unary_operators.py +++ b/pybamm/expression_tree/unary_operators.py @@ -757,9 +757,7 @@ class BackwardIndefiniteIntegral(BaseIndefiniteIntegral): def __init__(self, child, integration_variable): super().__init__(child, integration_variable) # Overwrite the name - self.name = "{} integrated backward w.r.t {}".format( - child.name, self.integration_variable[0].name - ) + self.name = f"{child.name} integrated backward w.r.t {self.integration_variable[0].name}" if isinstance(integration_variable, pybamm.SpatialVariable): self.name += f" on {self.integration_variable[0].domain}" diff --git a/pybamm/expression_tree/vector.py b/pybamm/expression_tree/vector.py index a1d8052c94..6dc358afb0 100644 --- a/pybamm/expression_tree/vector.py +++ b/pybamm/expression_tree/vector.py @@ -29,9 +29,9 @@ def __init__( entries = entries[:, np.newaxis] if entries.shape[1] != 1: raise ValueError( + f""" + Entries must have 1 dimension or be column vector, not have shape {entries.shape} """ - Entries must have 1 dimension or be column vector, not have shape {} - """.format(entries.shape) ) if name is None: name = f"Column vector of length {entries.shape[0]!s}" diff --git a/pybamm/geometry/battery_geometry.py b/pybamm/geometry/battery_geometry.py index e15c358128..9be08ff619 100644 --- a/pybamm/geometry/battery_geometry.py +++ b/pybamm/geometry/battery_geometry.py @@ -135,8 +135,8 @@ def battery_geometry( } else: raise pybamm.GeometryError( - "Invalid current collector dimension '{}' (should be 0 or 1 for " - "a 'cylindrical' battery geometry)".format(current_collector_dimension) + f"Invalid current collector dimension '{current_collector_dimension}' (should be 0 or 1 for " + "a 'cylindrical' battery geometry)" ) else: raise pybamm.GeometryError( diff --git a/pybamm/meshes/one_dimensional_submeshes.py b/pybamm/meshes/one_dimensional_submeshes.py index d6c3c7f78e..be4fa0d156 100644 --- a/pybamm/meshes/one_dimensional_submeshes.py +++ b/pybamm/meshes/one_dimensional_submeshes.py @@ -299,10 +299,10 @@ def __init__(self, lims, npts, edges=None): # check that npts + 1 equals number of user-supplied edges if (npts + 1) != len(edges): raise pybamm.GeometryError( - """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 ", " ") + f"""User-suppled edges has should have length (npts + 1) but has length + {len(edges)}.Number of points (npts) for domain {spatial_var.domain} is {npts}.""".replace( + "\n ", " " + ) ) # check end points of edges agree with spatial_lims @@ -360,9 +360,7 @@ def __init__(self, lims, npts, edges=None, order=2): elif (npts + 1) != len(edges): raise pybamm.GeometryError( "User-suppled edges should have length (npts + 1) but has len" - "gth {}. Number of points (npts) for domain {} is {}.".format( - len(edges), spatial_var.domain, npts - ) + f"gth {len(edges)}. Number of points (npts) for domain {spatial_var.domain} is {npts}." ) # check end points of edges agree with spatial_lims diff --git a/pybamm/meshes/scikit_fem_submeshes.py b/pybamm/meshes/scikit_fem_submeshes.py index e52f58f069..ba624c7f48 100644 --- a/pybamm/meshes/scikit_fem_submeshes.py +++ b/pybamm/meshes/scikit_fem_submeshes.py @@ -92,10 +92,8 @@ def read_lims(self, lims): # check coordinate system agrees if spatial_vars[0].coord_sys != spatial_vars[1].coord_sys: raise pybamm.DomainError( - """spatial variables should have the same coordinate system, - but have coordinate systems {} and {}""".format( - spatial_vars[0].coord_sys, spatial_vars[1].coord_sys - ) + f"""spatial variables should have the same coordinate system, + but have coordinate systems {spatial_vars[0].coord_sys} and {spatial_vars[1].coord_sys}""" ) return spatial_vars, tabs @@ -362,11 +360,9 @@ def __init__(self, lims, npts, y_edges=None, z_edges=None): # check that npts equals number of user-supplied edges if npts[var.name] != len(edges[var.name]): raise pybamm.GeometryError( - """User-suppled edges has should have length npts but has length {}. - Number of points (npts) for variable {} in - domain {} is {}.""".format( - len(edges[var.name]), var.name, var.domain, npts[var.name] - ) + f"""User-suppled edges has should have length npts but has length {len(edges[var.name])}. + Number of points (npts) for variable {var.name} in + domain {var.domain} is {npts[var.name]}.""" ) # check end points of edges agree with spatial_lims diff --git a/pybamm/models/base_model.py b/pybamm/models/base_model.py index 007897370f..48ff1bb364 100644 --- a/pybamm/models/base_model.py +++ b/pybamm/models/base_model.py @@ -557,9 +557,7 @@ def build_fundamental(self): # Get the fundamental variables for submodel_name, submodel in self.submodels.items(): pybamm.logger.debug( - "Getting fundamental variables for {} submodel ({})".format( - submodel_name, self.name - ) + f"Getting fundamental variables for {submodel_name} submodel ({self.name})" ) self.variables.update(submodel.get_fundamental_variables()) @@ -580,9 +578,7 @@ def build_coupled_variables(self): for submodel_name, submodel in self.submodels.items(): if submodel_name in submodels: pybamm.logger.debug( - "Getting coupled variables for {} submodel ({})".format( - submodel_name, self.name - ) + f"Getting coupled variables for {submodel_name} submodel ({self.name})" ) try: self.variables.update( @@ -593,9 +589,7 @@ def build_coupled_variables(self): if len(submodels) == 1 or count == 100: # no more submodels to try raise pybamm.ModelError( - "Missing variable for submodel '{}': {}.\n".format( - submodel_name, key - ) + f"Missing variable for submodel '{submodel_name}': {key}.\n" + "Check the selected " "submodels provide all of the required variables." ) @@ -621,9 +615,7 @@ def build_model_equations(self): submodel.set_algebraic(self.variables) pybamm.logger.verbose( - "Setting boundary conditions for {} submodel ({})".format( - submodel_name, self.name - ) + f"Setting boundary conditions for {submodel_name} submodel ({self.name})" ) submodel.set_boundary_conditions(self.variables) @@ -967,9 +959,7 @@ def check_no_repeated_keys(self): if not rhs_keys.isdisjoint(alg_keys): raise pybamm.ModelError( - "Multiple equations specified for variables {}".format( - rhs_keys.intersection(alg_keys) - ) + f"Multiple equations specified for variables {rhs_keys.intersection(alg_keys)}" ) def info(self, symbol_name): @@ -1341,9 +1331,7 @@ def check_and_convert_equations(self, equations): variable_in_equation = next(iter(unpacker.unpack_symbol(eqn))) raise TypeError( "Initial conditions cannot contain 'Variable' objects, " - "but '{!r}' found in initial conditions for '{}'".format( - variable_in_equation, var - ) + f"but '{variable_in_equation!r}' found in initial conditions for '{var}'" ) return equations @@ -1374,9 +1362,9 @@ def check_and_convert_bcs(self, boundary_conditions): # Check types if bc[1] not in ["Dirichlet", "Neumann"]: raise pybamm.ModelError( + f""" + boundary condition types must be Dirichlet or Neumann, not '{bc[1]}' """ - boundary condition types must be Dirichlet or Neumann, not '{}' - """.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 1ac618ddde..4fcae6a1d8 100644 --- a/pybamm/models/full_battery_models/base_battery_model.py +++ b/pybamm/models/full_battery_models/base_battery_model.py @@ -435,9 +435,7 @@ def __init__(self, extra_options): ) else: raise pybamm.OptionError( - "Option '{}' not recognised. Best matches are {}".format( - name, options.get_best_matches(name) - ) + f"Option '{name}' not recognised. Best matches are {options.get_best_matches(name)}" ) # If any of "open-circuit potential", "particle" or "intercalation kinetics" is @@ -922,9 +920,9 @@ def default_spatial_methods(self): } if self.options["dimensionality"] == 0: # 0D submesh - use base spatial method - base_spatial_methods[ - "current collector" - ] = pybamm.ZeroDimensionalSpatialMethod() + base_spatial_methods["current collector"] = ( + pybamm.ZeroDimensionalSpatialMethod() + ) elif self.options["dimensionality"] == 1: base_spatial_methods["current collector"] = pybamm.FiniteVolume() elif self.options["dimensionality"] == 2: @@ -1038,9 +1036,7 @@ def build_model_equations(self): submodel.set_algebraic(self.variables) pybamm.logger.verbose( - "Setting boundary conditions for {} submodel ({})".format( - submodel_name, self.name - ) + f"Setting boundary conditions for {submodel_name} submodel ({self.name})" ) submodel.set_boundary_conditions(self.variables) @@ -1168,14 +1164,14 @@ def set_external_circuit_submodel(self): self.submodels["external circuit"] = model def set_transport_efficiency_submodels(self): - self.submodels[ - "electrolyte transport efficiency" - ] = pybamm.transport_efficiency.Bruggeman( - self.param, "Electrolyte", self.options + self.submodels["electrolyte transport efficiency"] = ( + pybamm.transport_efficiency.Bruggeman( + self.param, "Electrolyte", self.options + ) + ) + self.submodels["electrode transport efficiency"] = ( + pybamm.transport_efficiency.Bruggeman(self.param, "Electrode", self.options) ) - self.submodels[ - "electrode transport efficiency" - ] = pybamm.transport_efficiency.Bruggeman(self.param, "Electrode", self.options) def set_thermal_submodel(self): if self.options["thermal"] == "isothermal": diff --git a/pybamm/models/full_battery_models/equivalent_circuit/thevenin.py b/pybamm/models/full_battery_models/equivalent_circuit/thevenin.py index 9d01f89ffd..14f3381f29 100644 --- a/pybamm/models/full_battery_models/equivalent_circuit/thevenin.py +++ b/pybamm/models/full_battery_models/equivalent_circuit/thevenin.py @@ -89,17 +89,13 @@ def set_options(self, extra_options=None): options[name] = opt else: raise pybamm.OptionError( - "Option '{}' not recognised. Best matches are {}".format( - name, options.get_best_matches(name) - ) + f"Option '{name}' not recognised. Best matches are {options.get_best_matches(name)}" ) for opt, value in options.items(): if value not in possible_options[opt]: raise pybamm.OptionError( - "Option '{}' must be one of {}. Got '{}' instead.".format( - opt, possible_options[opt], value - ) + f"Option '{opt}' must be one of {possible_options[opt]}. Got '{value}' instead." ) self.options = options @@ -148,9 +144,9 @@ def set_external_circuit_submodel(self): self.submodels["external circuit"] = model def set_ocv_submodel(self): - self.submodels[ - "Open-circuit voltage" - ] = pybamm.equivalent_circuit_elements.OCVElement(self.param, self.options) + self.submodels["Open-circuit voltage"] = ( + pybamm.equivalent_circuit_elements.OCVElement(self.param, self.options) + ) def set_resistor_submodel(self): name = "Element-0 (Resistor)" diff --git a/pybamm/models/full_battery_models/lead_acid/base_lead_acid_model.py b/pybamm/models/full_battery_models/lead_acid/base_lead_acid_model.py index c0b5d1935c..1e6105be0f 100644 --- a/pybamm/models/full_battery_models/lead_acid/base_lead_acid_model.py +++ b/pybamm/models/full_battery_models/lead_acid/base_lead_acid_model.py @@ -77,23 +77,23 @@ def set_soc_variables(self): def set_open_circuit_potential_submodel(self): for domain in ["negative", "positive"]: - self.submodels[ - f"{domain} open-circuit potential" - ] = pybamm.open_circuit_potential.SingleOpenCircuitPotential( - self.param, domain, "lead-acid main", self.options, "primary" + self.submodels[f"{domain} open-circuit potential"] = ( + pybamm.open_circuit_potential.SingleOpenCircuitPotential( + self.param, domain, "lead-acid main", self.options, "primary" + ) ) - self.submodels[ - f"{domain} oxygen open-circuit potential" - ] = pybamm.open_circuit_potential.SingleOpenCircuitPotential( - self.param, domain, "lead-acid oxygen", self.options, "primary" + self.submodels[f"{domain} oxygen open-circuit potential"] = ( + pybamm.open_circuit_potential.SingleOpenCircuitPotential( + self.param, domain, "lead-acid oxygen", self.options, "primary" + ) ) def set_active_material_submodel(self): for domain in ["negative", "positive"]: - self.submodels[ - f"{domain} active material" - ] = pybamm.active_material.Constant( - self.param, domain, self.options, "primary" + self.submodels[f"{domain} active material"] = ( + pybamm.active_material.Constant( + self.param, domain, self.options, "primary" + ) ) def set_sei_submodel(self): @@ -104,9 +104,9 @@ def set_sei_submodel(self): def set_lithium_plating_submodel(self): for domain in ["negative", "positive"]: - self.submodels[ - f"{domain} lithium plating" - ] = pybamm.lithium_plating.NoPlating(self.param, domain) + self.submodels[f"{domain} lithium plating"] = ( + pybamm.lithium_plating.NoPlating(self.param, domain) + ) def set_total_interface_submodel(self): self.submodels["total interface"] = pybamm.interface.TotalInterfacialCurrent( diff --git a/pybamm/models/full_battery_models/lead_acid/full.py b/pybamm/models/full_battery_models/lead_acid/full.py index 927f9a2028..b5b561e6dd 100644 --- a/pybamm/models/full_battery_models/lead_acid/full.py +++ b/pybamm/models/full_battery_models/lead_acid/full.py @@ -45,24 +45,24 @@ def set_porosity_submodel(self): def set_convection_submodel(self): if self.options["convection"] == "none": - self.submodels[ - "transverse convection" - ] = pybamm.convection.transverse.NoConvection(self.param) - self.submodels[ - "through-cell convection" - ] = pybamm.convection.through_cell.NoConvection(self.param) + self.submodels["transverse convection"] = ( + pybamm.convection.transverse.NoConvection(self.param) + ) + self.submodels["through-cell convection"] = ( + pybamm.convection.through_cell.NoConvection(self.param) + ) else: if self.options["convection"] == "uniform transverse": - self.submodels[ - "transverse convection" - ] = pybamm.convection.transverse.Uniform(self.param) + self.submodels["transverse convection"] = ( + pybamm.convection.transverse.Uniform(self.param) + ) elif self.options["convection"] == "full transverse": - self.submodels[ - "transverse convection" - ] = pybamm.convection.transverse.Full(self.param) - self.submodels[ - "through-cell convection" - ] = pybamm.convection.through_cell.Full(self.param) + self.submodels["transverse convection"] = ( + pybamm.convection.transverse.Full(self.param) + ) + self.submodels["through-cell convection"] = ( + pybamm.convection.through_cell.Full(self.param) + ) def set_intercalation_kinetics_submodel(self): for domain in ["negative", "positive"]: @@ -90,9 +90,9 @@ def set_electrolyte_submodel(self): ) if self.options["surface form"] == "false": - self.submodels[ - "electrolyte conductivity" - ] = pybamm.electrolyte_conductivity.Full(self.param) + self.submodels["electrolyte conductivity"] = ( + pybamm.electrolyte_conductivity.Full(self.param) + ) surf_model = surf_form.Explicit elif self.options["surface form"] == "differential": surf_model = surf_form.FullDifferential @@ -112,10 +112,14 @@ def set_side_reaction_submodels(self): self.submodels["positive oxygen interface"] = pybamm.kinetics.ForwardTafel( self.param, "positive", "lead-acid oxygen", self.options, "primary" ) - self.submodels[ - "negative oxygen interface" - ] = pybamm.kinetics.DiffusionLimited( - self.param, "negative", "lead-acid oxygen", self.options, order="full" + self.submodels["negative oxygen interface"] = ( + pybamm.kinetics.DiffusionLimited( + self.param, + "negative", + "lead-acid oxygen", + self.options, + order="full", + ) ) else: self.submodels["oxygen diffusion"] = pybamm.oxygen_diffusion.NoOxygen( diff --git a/pybamm/models/full_battery_models/lead_acid/loqs.py b/pybamm/models/full_battery_models/lead_acid/loqs.py index 953be55c9c..c63c9cd11b 100644 --- a/pybamm/models/full_battery_models/lead_acid/loqs.py +++ b/pybamm/models/full_battery_models/lead_acid/loqs.py @@ -47,22 +47,22 @@ def set_external_circuit_submodel(self): e.g. (not necessarily constant-) current, voltage, etc """ if self.options["operating mode"] == "current": - self.submodels[ - "external circuit" - ] = pybamm.external_circuit.ExplicitCurrentControl(self.param, self.options) + self.submodels["external circuit"] = ( + pybamm.external_circuit.ExplicitCurrentControl(self.param, self.options) + ) elif self.options["operating mode"] == "voltage": - self.submodels[ - "external circuit" - ] = pybamm.external_circuit.VoltageFunctionControl(self.param, self.options) + self.submodels["external circuit"] = ( + pybamm.external_circuit.VoltageFunctionControl(self.param, self.options) + ) elif self.options["operating mode"] == "power": - self.submodels[ - "external circuit" - ] = pybamm.external_circuit.PowerFunctionControl(self.param, self.options) + self.submodels["external circuit"] = ( + pybamm.external_circuit.PowerFunctionControl(self.param, self.options) + ) elif callable(self.options["operating mode"]): - self.submodels[ - "external circuit" - ] = pybamm.external_circuit.FunctionControl( - self.param, self.options["operating mode"], self.options + self.submodels["external circuit"] = ( + pybamm.external_circuit.FunctionControl( + self.param, self.options["operating mode"], self.options + ) ) def set_current_collector_submodel(self): @@ -85,58 +85,58 @@ def set_porosity_submodel(self): def set_convection_submodel(self): if self.options["convection"] == "none": - self.submodels[ - "leading-order transverse convection" - ] = pybamm.convection.transverse.NoConvection(self.param) - self.submodels[ - "leading-order through-cell convection" - ] = pybamm.convection.through_cell.NoConvection(self.param) + self.submodels["leading-order transverse convection"] = ( + pybamm.convection.transverse.NoConvection(self.param) + ) + self.submodels["leading-order through-cell convection"] = ( + pybamm.convection.through_cell.NoConvection(self.param) + ) else: if self.options["convection"] == "uniform transverse": - self.submodels[ - "leading-order transverse convection" - ] = pybamm.convection.transverse.Uniform(self.param) + self.submodels["leading-order transverse convection"] = ( + pybamm.convection.transverse.Uniform(self.param) + ) elif self.options["convection"] == "full transverse": - self.submodels[ - "leading-order transverse convection" - ] = pybamm.convection.transverse.Full(self.param) - self.submodels[ - "leading-order through-cell convection" - ] = pybamm.convection.through_cell.Explicit(self.param) + self.submodels["leading-order transverse convection"] = ( + pybamm.convection.transverse.Full(self.param) + ) + self.submodels["leading-order through-cell convection"] = ( + pybamm.convection.through_cell.Explicit(self.param) + ) def set_intercalation_kinetics_submodel(self): if self.options["surface form"] == "false": - self.submodels[ - "leading-order negative interface" - ] = pybamm.kinetics.InverseButlerVolmer( - self.param, "negative", "lead-acid main", self.options - ) - self.submodels[ - "leading-order positive interface" - ] = pybamm.kinetics.InverseButlerVolmer( - self.param, "positive", "lead-acid main", self.options - ) - self.submodels[ - "negative interface current" - ] = pybamm.kinetics.CurrentForInverseButlerVolmer( - self.param, "negative", "lead-acid main" - ) - self.submodels[ - "positive interface current" - ] = pybamm.kinetics.CurrentForInverseButlerVolmer( - self.param, "positive", "lead-acid main" + self.submodels["leading-order negative interface"] = ( + pybamm.kinetics.InverseButlerVolmer( + self.param, "negative", "lead-acid main", self.options + ) + ) + self.submodels["leading-order positive interface"] = ( + pybamm.kinetics.InverseButlerVolmer( + self.param, "positive", "lead-acid main", self.options + ) + ) + self.submodels["negative interface current"] = ( + pybamm.kinetics.CurrentForInverseButlerVolmer( + self.param, "negative", "lead-acid main" + ) + ) + self.submodels["positive interface current"] = ( + pybamm.kinetics.CurrentForInverseButlerVolmer( + self.param, "positive", "lead-acid main" + ) ) else: - self.submodels[ - "leading-order negative interface" - ] = pybamm.kinetics.SymmetricButlerVolmer( - self.param, "negative", "lead-acid main", self.options, "primary" + self.submodels["leading-order negative interface"] = ( + pybamm.kinetics.SymmetricButlerVolmer( + self.param, "negative", "lead-acid main", self.options, "primary" + ) ) - self.submodels[ - "leading-order positive interface" - ] = pybamm.kinetics.SymmetricButlerVolmer( - self.param, "positive", "lead-acid main", self.options, "primary" + self.submodels["leading-order positive interface"] = ( + pybamm.kinetics.SymmetricButlerVolmer( + self.param, "positive", "lead-acid main", self.options, "primary" + ) ) # always use forward Butler-Volmer for the reaction submodel to be passed to the # higher order model @@ -154,20 +154,20 @@ def set_intercalation_kinetics_submodel(self): } def set_electrode_submodels(self): - self.submodels[ - "leading-order negative electrode potential" - ] = pybamm.electrode.ohm.LeadingOrder(self.param, "negative") - self.submodels[ - "leading-order positive electrode potential" - ] = pybamm.electrode.ohm.LeadingOrder(self.param, "positive") + self.submodels["leading-order negative electrode potential"] = ( + pybamm.electrode.ohm.LeadingOrder(self.param, "negative") + ) + self.submodels["leading-order positive electrode potential"] = ( + pybamm.electrode.ohm.LeadingOrder(self.param, "positive") + ) def set_electrolyte_submodel(self): surf_form = pybamm.electrolyte_conductivity.surface_potential_form if self.options["surface form"] == "false": - self.submodels[ - "leading-order electrolyte conductivity" - ] = pybamm.electrolyte_conductivity.LeadingOrder(self.param) + self.submodels["leading-order electrolyte conductivity"] = ( + pybamm.electrolyte_conductivity.LeadingOrder(self.param) + ) surf_model = surf_form.Explicit elif self.options["surface form"] == "differential": surf_model = surf_form.LeadingOrderDifferential @@ -179,42 +179,42 @@ def set_electrolyte_submodel(self): self.param, domain, self.options ) - self.submodels[ - "electrolyte diffusion" - ] = pybamm.electrolyte_diffusion.LeadingOrder(self.param) + self.submodels["electrolyte diffusion"] = ( + pybamm.electrolyte_diffusion.LeadingOrder(self.param) + ) def set_side_reaction_submodels(self): if self.options["hydrolysis"] == "true": - self.submodels[ - "leading-order oxygen diffusion" - ] = pybamm.oxygen_diffusion.LeadingOrder(self.param) - self.submodels[ - "leading-order positive oxygen interface" - ] = pybamm.kinetics.ForwardTafel( - self.param, "positive", "lead-acid oxygen", self.options, "primary" - ) - self.submodels[ - "leading-order negative oxygen interface" - ] = pybamm.kinetics.DiffusionLimited( - self.param, - "negative", - "lead-acid oxygen", - self.options, - order="leading", + self.submodels["leading-order oxygen diffusion"] = ( + pybamm.oxygen_diffusion.LeadingOrder(self.param) + ) + self.submodels["leading-order positive oxygen interface"] = ( + pybamm.kinetics.ForwardTafel( + self.param, "positive", "lead-acid oxygen", self.options, "primary" + ) + ) + self.submodels["leading-order negative oxygen interface"] = ( + pybamm.kinetics.DiffusionLimited( + self.param, + "negative", + "lead-acid oxygen", + self.options, + order="leading", + ) ) else: - self.submodels[ - "leading-order oxygen diffusion" - ] = pybamm.oxygen_diffusion.NoOxygen(self.param) - self.submodels[ - "leading-order negative oxygen interface" - ] = pybamm.kinetics.NoReaction( - self.param, "negative", "lead-acid oxygen", "primary" - ) - self.submodels[ - "leading-order positive oxygen interface" - ] = pybamm.kinetics.NoReaction( - self.param, "positive", "lead-acid oxygen", "primary" + self.submodels["leading-order oxygen diffusion"] = ( + pybamm.oxygen_diffusion.NoOxygen(self.param) + ) + self.submodels["leading-order negative oxygen interface"] = ( + pybamm.kinetics.NoReaction( + self.param, "negative", "lead-acid oxygen", "primary" + ) + ) + self.submodels["leading-order positive oxygen interface"] = ( + pybamm.kinetics.NoReaction( + self.param, "positive", "lead-acid oxygen", "primary" + ) ) self.reaction_submodels["negative"].append( self.submodels["leading-order negative oxygen interface"] diff --git a/pybamm/models/full_battery_models/lithium_ion/base_lithium_ion_model.py b/pybamm/models/full_battery_models/lithium_ion/base_lithium_ion_model.py index fbe19b0d42..d6f80b3cc5 100644 --- a/pybamm/models/full_battery_models/lithium_ion/base_lithium_ion_model.py +++ b/pybamm/models/full_battery_models/lithium_ion/base_lithium_ion_model.py @@ -318,10 +318,10 @@ def set_sei_on_cracks_submodel(self): ) self.submodels[f"{domain} {phase} sei on cracks"] = submodel if len(phases) > 1: - self.submodels[ - f"{domain} total sei on cracks" - ] = pybamm.sei.TotalSEI( - self.param, domain, self.options, cracks=True + self.submodels[f"{domain} total sei on cracks"] = ( + pybamm.sei.TotalSEI( + self.param, domain, self.options, cracks=True + ) ) def set_lithium_plating_submodel(self): @@ -332,17 +332,17 @@ def set_lithium_plating_submodel(self): domain = domain.split()[0].lower() lithium_plating_opt = getattr(self.options, domain)["lithium plating"] if lithium_plating_opt == "none": - self.submodels[ - f"{domain} lithium plating" - ] = pybamm.lithium_plating.NoPlating( - self.param, domain, self.options + self.submodels[f"{domain} lithium plating"] = ( + pybamm.lithium_plating.NoPlating( + self.param, domain, self.options + ) ) else: x_average = self.options["x-average side reactions"] == "true" - self.submodels[ - f"{domain} lithium plating" - ] = pybamm.lithium_plating.Plating( - self.param, domain, x_average, self.options + self.submodels[f"{domain} lithium plating"] = ( + pybamm.lithium_plating.Plating( + self.param, domain, x_average, self.options + ) ) def set_total_interface_submodel(self): @@ -356,26 +356,26 @@ def set_crack_submodel(self): domain = domain.split()[0].lower() crack = getattr(self.options, domain)["particle mechanics"] if crack == "none": - self.submodels[ - f"{domain} particle mechanics" - ] = pybamm.particle_mechanics.NoMechanics( - self.param, domain, options=self.options, phase="primary" + self.submodels[f"{domain} particle mechanics"] = ( + pybamm.particle_mechanics.NoMechanics( + self.param, domain, options=self.options, phase="primary" + ) ) elif crack == "swelling only": - self.submodels[ - f"{domain} particle mechanics" - ] = pybamm.particle_mechanics.SwellingOnly( - self.param, domain, options=self.options, phase="primary" + self.submodels[f"{domain} particle mechanics"] = ( + pybamm.particle_mechanics.SwellingOnly( + self.param, domain, options=self.options, phase="primary" + ) ) elif crack == "swelling and cracking": - self.submodels[ - f"{domain} particle mechanics" - ] = pybamm.particle_mechanics.CrackPropagation( - self.param, - domain, - self.x_average, - options=self.options, - phase="primary", + self.submodels[f"{domain} particle mechanics"] = ( + pybamm.particle_mechanics.CrackPropagation( + self.param, + domain, + self.x_average, + options=self.options, + phase="primary", + ) ) def set_active_material_submodel(self): @@ -396,9 +396,9 @@ def set_active_material_submodel(self): # Submodel for the total active material, summing up each phase if len(phases) > 1: - self.submodels[ - f"{domain} total active material" - ] = pybamm.active_material.Total(self.param, domain, self.options) + self.submodels[f"{domain} total active material"] = ( + pybamm.active_material.Total(self.param, domain, self.options) + ) def set_porosity_submodel(self): if ( @@ -427,41 +427,45 @@ def set_li_metal_counter_electrode_submodels(self): and self.options["surface form"] == "false" ): # only symmetric Butler-Volmer can be inverted - self.submodels[ - f"{domain} electrode potential" - ] = pybamm.electrode.ohm.LithiumMetalExplicit( - self.param, domain, self.options + self.submodels[f"{domain} electrode potential"] = ( + pybamm.electrode.ohm.LithiumMetalExplicit( + self.param, domain, self.options + ) ) - self.submodels[ - f"{domain} electrode interface" - ] = pybamm.kinetics.InverseButlerVolmer( - self.param, domain, "lithium metal plating", self.options + self.submodels[f"{domain} electrode interface"] = ( + pybamm.kinetics.InverseButlerVolmer( + self.param, domain, "lithium metal plating", self.options + ) ) # assuming symmetric reaction for now so we can take the inverse - self.submodels[ - f"{domain} electrode interface current" - ] = pybamm.kinetics.CurrentForInverseButlerVolmerLithiumMetal( - self.param, domain, "lithium metal plating", self.options + self.submodels[f"{domain} electrode interface current"] = ( + pybamm.kinetics.CurrentForInverseButlerVolmerLithiumMetal( + self.param, domain, "lithium metal plating", self.options + ) ) else: - self.submodels[ - f"{domain} electrode potential" - ] = pybamm.electrode.ohm.LithiumMetalSurfaceForm( - self.param, domain, self.options + self.submodels[f"{domain} electrode potential"] = ( + pybamm.electrode.ohm.LithiumMetalSurfaceForm( + self.param, domain, self.options + ) ) neg_intercalation_kinetics = self.get_intercalation_kinetics(domain) - self.submodels[ - f"{domain} electrode interface" - ] = neg_intercalation_kinetics( - self.param, domain, "lithium metal plating", self.options, "primary" + self.submodels[f"{domain} electrode interface"] = ( + neg_intercalation_kinetics( + self.param, + domain, + "lithium metal plating", + self.options, + "primary", + ) ) def set_convection_submodel(self): - self.submodels[ - "transverse convection" - ] = pybamm.convection.transverse.NoConvection(self.param, self.options) - self.submodels[ - "through-cell convection" - ] = pybamm.convection.through_cell.NoConvection(self.param, self.options) + self.submodels["transverse convection"] = ( + pybamm.convection.transverse.NoConvection(self.param, self.options) + ) + self.submodels["through-cell convection"] = ( + pybamm.convection.through_cell.NoConvection(self.param, self.options) + ) def insert_reference_electrode(self, position=None): """ diff --git a/pybamm/models/full_battery_models/lithium_ion/dfn.py b/pybamm/models/full_battery_models/lithium_ion/dfn.py index db4e0282d8..345cd7d962 100644 --- a/pybamm/models/full_battery_models/lithium_ion/dfn.py +++ b/pybamm/models/full_battery_models/lithium_ion/dfn.py @@ -41,10 +41,10 @@ def set_intercalation_kinetics_submodel(self): self.submodels[f"{domain} {phase} interface"] = submod if len(phases) > 1: - self.submodels[ - f"total {domain} interface" - ] = pybamm.kinetics.TotalMainKinetics( - self.param, domain, "lithium-ion main", self.options + self.submodels[f"total {domain} interface"] = ( + pybamm.kinetics.TotalMainKinetics( + self.param, domain, "lithium-ion main", self.options + ) ) def set_particle_submodel(self): @@ -70,10 +70,10 @@ def set_particle_submodel(self): self.param, domain, self.options, phase=phase, x_average=False ) self.submodels[f"{domain} {phase} particle"] = submod - self.submodels[ - f"{domain} {phase} total particle concentration" - ] = pybamm.particle.TotalConcentration( - self.param, domain, self.options, phase + self.submodels[f"{domain} {phase} total particle concentration"] = ( + pybamm.particle.TotalConcentration( + self.param, domain, self.options, phase + ) ) def set_solid_submodel(self): @@ -104,9 +104,9 @@ def set_electrolyte_potential_submodel(self): ) if self.options["surface form"] == "false": - self.submodels[ - "electrolyte conductivity" - ] = pybamm.electrolyte_conductivity.Full(self.param, self.options) + self.submodels["electrolyte conductivity"] = ( + pybamm.electrolyte_conductivity.Full(self.param, self.options) + ) if self.options["surface form"] == "false": surf_model = surf_form.Explicit diff --git a/pybamm/models/full_battery_models/lithium_ion/newman_tobias.py b/pybamm/models/full_battery_models/lithium_ion/newman_tobias.py index a704bd0b33..ae373debc0 100644 --- a/pybamm/models/full_battery_models/lithium_ion/newman_tobias.py +++ b/pybamm/models/full_battery_models/lithium_ion/newman_tobias.py @@ -53,13 +53,13 @@ def set_particle_submodel(self): self.param, domain, self.options, phase=phase, x_average=True ) self.submodels[f"{domain} {phase} particle"] = submod - self.submodels[ - f"{domain} {phase} total particle concentration" - ] = pybamm.particle.TotalConcentration( - self.param, domain, self.options, phase + self.submodels[f"{domain} {phase} total particle concentration"] = ( + pybamm.particle.TotalConcentration( + self.param, domain, self.options, phase + ) ) def set_electrolyte_concentration_submodel(self): - self.submodels[ - "electrolyte diffusion" - ] = pybamm.electrolyte_diffusion.ConstantConcentration(self.param) + self.submodels["electrolyte diffusion"] = ( + pybamm.electrolyte_diffusion.ConstantConcentration(self.param) + ) diff --git a/pybamm/models/full_battery_models/lithium_ion/spm.py b/pybamm/models/full_battery_models/lithium_ion/spm.py index 386c55ded9..e0a7dcd8f2 100644 --- a/pybamm/models/full_battery_models/lithium_ion/spm.py +++ b/pybamm/models/full_battery_models/lithium_ion/spm.py @@ -65,10 +65,10 @@ def set_intercalation_kinetics_submodel(self): self.submodels[f"{domain} interface"] = inverse_intercalation_kinetics( self.param, domain, "lithium-ion main", self.options ) - self.submodels[ - f"{domain} interface current" - ] = pybamm.kinetics.CurrentForInverseButlerVolmer( - self.param, domain, "lithium-ion main", self.options + self.submodels[f"{domain} interface current"] = ( + pybamm.kinetics.CurrentForInverseButlerVolmer( + self.param, domain, "lithium-ion main", self.options + ) ) else: intercalation_kinetics = self.get_intercalation_kinetics(domain) @@ -79,10 +79,10 @@ def set_intercalation_kinetics_submodel(self): ) self.submodels[f"{domain} {phase} interface"] = submod if len(phases) > 1: - self.submodels[ - f"total {domain} interface" - ] = pybamm.kinetics.TotalMainKinetics( - self.param, domain, "lithium-ion main", self.options + self.submodels[f"total {domain} interface"] = ( + pybamm.kinetics.TotalMainKinetics( + self.param, domain, "lithium-ion main", self.options + ) ) def set_particle_submodel(self): @@ -109,24 +109,24 @@ def set_particle_submodel(self): self.param, domain, self.options, phase=phase, x_average=True ) self.submodels[f"{domain} {phase} particle"] = submod - self.submodels[ - f"{domain} {phase} total particle concentration" - ] = pybamm.particle.TotalConcentration( - self.param, domain, self.options, phase + self.submodels[f"{domain} {phase} total particle concentration"] = ( + pybamm.particle.TotalConcentration( + self.param, domain, self.options, phase + ) ) def set_solid_submodel(self): for domain in ["negative", "positive"]: if self.options.electrode_types[domain] == "planar": continue - self.submodels[ - f"{domain} electrode potential" - ] = pybamm.electrode.ohm.LeadingOrder(self.param, domain, self.options) + self.submodels[f"{domain} electrode potential"] = ( + pybamm.electrode.ohm.LeadingOrder(self.param, domain, self.options) + ) def set_electrolyte_concentration_submodel(self): - self.submodels[ - "electrolyte diffusion" - ] = pybamm.electrolyte_diffusion.ConstantConcentration(self.param, self.options) + self.submodels["electrolyte diffusion"] = ( + pybamm.electrolyte_diffusion.ConstantConcentration(self.param, self.options) + ) def set_electrolyte_potential_submodel(self): surf_form = pybamm.electrolyte_conductivity.surface_potential_form @@ -142,10 +142,10 @@ def set_electrolyte_potential_submodel(self): self.options["surface form"] == "false" or self.options.electrode_types["negative"] == "planar" ): - self.submodels[ - "leading-order electrolyte conductivity" - ] = pybamm.electrolyte_conductivity.LeadingOrder( - self.param, options=self.options + self.submodels["leading-order electrolyte conductivity"] = ( + pybamm.electrolyte_conductivity.LeadingOrder( + self.param, options=self.options + ) ) if self.options["surface form"] == "false": surf_model = surf_form.Explicit diff --git a/pybamm/models/full_battery_models/lithium_ion/spme.py b/pybamm/models/full_battery_models/lithium_ion/spme.py index 103f13415a..6e0784ff60 100644 --- a/pybamm/models/full_battery_models/lithium_ion/spme.py +++ b/pybamm/models/full_battery_models/lithium_ion/spme.py @@ -56,16 +56,16 @@ def set_electrolyte_potential_submodel(self): or self.options.electrode_types["negative"] == "planar" ): if self.options["electrolyte conductivity"] in ["default", "composite"]: - self.submodels[ - "electrolyte conductivity" - ] = pybamm.electrolyte_conductivity.Composite( - self.param, options=self.options + self.submodels["electrolyte conductivity"] = ( + pybamm.electrolyte_conductivity.Composite( + self.param, options=self.options + ) ) elif self.options["electrolyte conductivity"] == "integrated": - self.submodels[ - "electrolyte conductivity" - ] = pybamm.electrolyte_conductivity.Integrated( - self.param, options=self.options + self.submodels["electrolyte conductivity"] = ( + pybamm.electrolyte_conductivity.Integrated( + self.param, options=self.options + ) ) if self.options["surface form"] == "false": surf_model = surf_form.Explicit @@ -76,6 +76,6 @@ def set_electrolyte_potential_submodel(self): for domain in ["negative", "positive"]: if self.options.electrode_types[domain] == "porous": - self.submodels[ - f"{domain} surface potential difference [V]" - ] = surf_model(self.param, domain, self.options) + self.submodels[f"{domain} surface potential difference [V]"] = ( + surf_model(self.param, domain, self.options) + ) diff --git a/pybamm/models/submodels/current_collector/effective_resistance_current_collector.py b/pybamm/models/submodels/current_collector/effective_resistance_current_collector.py index 1d50e1be7c..23001b9d02 100644 --- a/pybamm/models/submodels/current_collector/effective_resistance_current_collector.py +++ b/pybamm/models/submodels/current_collector/effective_resistance_current_collector.py @@ -76,9 +76,7 @@ def options(self, extra_options): options[name] = opt else: raise pybamm.OptionError( - "Option '{}' not recognised. Best matches are {}".format( - name, options.get_best_matches(name) - ) + f"Option '{name}' not recognised. Best matches are {options.get_best_matches(name)}" ) if options["dimensionality"] not in [1, 2]: diff --git a/pybamm/models/submodels/electrolyte_diffusion/constant_concentration.py b/pybamm/models/submodels/electrolyte_diffusion/constant_concentration.py index ca8b11e796..eee441446f 100644 --- a/pybamm/models/submodels/electrolyte_diffusion/constant_concentration.py +++ b/pybamm/models/submodels/electrolyte_diffusion/constant_concentration.py @@ -48,9 +48,9 @@ def get_coupled_variables(self, variables): c_e_k = eps_c_e_k / eps_k c_e_dict[domain] = c_e_k - variables[ - "Electrolyte concentration concatenation [mol.m-3]" - ] = pybamm.concatenation(*c_e_dict.values()) + variables["Electrolyte concentration concatenation [mol.m-3]"] = ( + pybamm.concatenation(*c_e_dict.values()) + ) variables.update(self._get_standard_domain_concentration_variables(c_e_dict)) c_e = ( diff --git a/pybamm/models/submodels/electrolyte_diffusion/full_diffusion.py b/pybamm/models/submodels/electrolyte_diffusion/full_diffusion.py index 464d82e4e7..2fdd937966 100644 --- a/pybamm/models/submodels/electrolyte_diffusion/full_diffusion.py +++ b/pybamm/models/submodels/electrolyte_diffusion/full_diffusion.py @@ -51,9 +51,9 @@ def get_coupled_variables(self, variables): c_e_k = eps_c_e_k / eps_k c_e_dict[domain] = c_e_k - variables[ - "Electrolyte concentration concatenation [mol.m-3]" - ] = pybamm.concatenation(*c_e_dict.values()) + variables["Electrolyte concentration concatenation [mol.m-3]"] = ( + pybamm.concatenation(*c_e_dict.values()) + ) variables.update(self._get_standard_domain_concentration_variables(c_e_dict)) c_e = ( diff --git a/pybamm/parameters/bpx.py b/pybamm/parameters/bpx.py index c6037b0f40..d191426f2e 100644 --- a/pybamm/parameters/bpx.py +++ b/pybamm/parameters/bpx.py @@ -157,9 +157,9 @@ def _bpx_to_param_dict(bpx: BPX) -> dict: # BPX is for single cell in series, user can change this later pybamm_dict["Number of cells connected in series to make a battery"] = 1 - pybamm_dict[ - "Number of electrodes connected in parallel to make a cell" - ] = pybamm_dict["Number of electrode pairs connected in parallel to make a cell"] + pybamm_dict["Number of electrodes connected in parallel to make a cell"] = ( + pybamm_dict["Number of electrode pairs connected in parallel to make a cell"] + ) # electrode area equal_len_width = math.sqrt(pybamm_dict["Electrode area [m2]"]) @@ -290,22 +290,22 @@ def _conductivity(c_e, T, Ea, sigma_ref, constant=False): phase_domain_pre_name + "entropic change coefficient [V.K-1]" ] if callable(dUdT): - pybamm_dict[ - phase_domain_pre_name + "OCP entropic change [V.K-1]" - ] = partial(_entropic_change, dUdT=dUdT) + pybamm_dict[phase_domain_pre_name + "OCP entropic change [V.K-1]"] = ( + partial(_entropic_change, dUdT=dUdT) + ) elif isinstance(dUdT, tuple): - pybamm_dict[ - phase_domain_pre_name + "OCP entropic change [V.K-1]" - ] = partial( - _entropic_change, - dUdT=partial( - _interpolant_func, name=dUdT[0], x=dUdT[1][0], y=dUdT[1][1] - ), + pybamm_dict[phase_domain_pre_name + "OCP entropic change [V.K-1]"] = ( + partial( + _entropic_change, + dUdT=partial( + _interpolant_func, name=dUdT[0], x=dUdT[1][0], y=dUdT[1][1] + ), + ) ) else: - pybamm_dict[ - phase_domain_pre_name + "OCP entropic change [V.K-1]" - ] = partial(_entropic_change, dUdT=dUdT, constant=True) + pybamm_dict[phase_domain_pre_name + "OCP entropic change [V.K-1]"] = ( + partial(_entropic_change, dUdT=dUdT, constant=True) + ) # reaction rate c_max = pybamm_dict[ @@ -326,9 +326,9 @@ def _conductivity(c_e, T, Ea, sigma_ref, constant=False): # *sinh(), # and in PyBaMM j = 2*k*sqrt(ce*c*(c_max - c))*sinh() k = k_norm * F / (c_max * c_e**0.5) - pybamm_dict[ - phase_domain_pre_name + "exchange-current density [A.m-2]" - ] = partial(_exchange_current_density, k_ref=k, Ea=Ea_k) + pybamm_dict[phase_domain_pre_name + "exchange-current density [A.m-2]"] = ( + partial(_exchange_current_density, k_ref=k, Ea=Ea_k) + ) # diffusivity Ea_D = pybamm_dict.get( diff --git a/pybamm/parameters/parameter_sets.py b/pybamm/parameters/parameter_sets.py index 7a517af418..e7872f8a28 100644 --- a/pybamm/parameters/parameter_sets.py +++ b/pybamm/parameters/parameter_sets.py @@ -89,9 +89,9 @@ def __getattribute__(self, name): # parameter set as before when passed to `ParameterValues` if name in self: msg = ( - "Parameter sets should be called directly by their name ({0}), " - "instead of via pybamm.parameter_sets (pybamm.parameter_sets.{0})." - ).format(name) + f"Parameter sets should be called directly by their name ({name}), " + f"instead of via pybamm.parameter_sets (pybamm.parameter_sets.{name})." + ) warnings.warn(msg, DeprecationWarning) return name raise error diff --git a/pybamm/parameters/parameter_values.py b/pybamm/parameters/parameter_values.py index 85c8f02b53..5a2c61b1d5 100644 --- a/pybamm/parameters/parameter_values.py +++ b/pybamm/parameters/parameter_values.py @@ -125,12 +125,12 @@ def create_from_bpx(filename, target_soc=1): ) else: c_n_init, c_p_init = get_electrode_concentrations(target_soc, bpx) - pybamm_dict[ - "Initial concentration in negative electrode [mol.m-3]" - ] = c_n_init - pybamm_dict[ - "Initial concentration in positive electrode [mol.m-3]" - ] = c_p_init + pybamm_dict["Initial concentration in negative electrode [mol.m-3]"] = ( + c_n_init + ) + pybamm_dict["Initial concentration in positive electrode [mol.m-3]"] = ( + c_p_init + ) return pybamm.ParameterValues(pybamm_dict) @@ -570,9 +570,9 @@ def process_and_check(sym): if spatial_variable == "tabs": for tab, position_size in spatial_limits.items(): for position_size, sym in position_size.items(): - geometry[domain]["tabs"][tab][ - position_size - ] = process_and_check(sym) + geometry[domain]["tabs"][tab][position_size] = ( + process_and_check(sym) + ) else: for lim, sym in spatial_limits.items(): geometry[domain][spatial_variable][lim] = process_and_check(sym) diff --git a/pybamm/plotting/quick_plot.py b/pybamm/plotting/quick_plot.py index dbb8f37555..7780f092bf 100644 --- a/pybamm/plotting/quick_plot.py +++ b/pybamm/plotting/quick_plot.py @@ -116,9 +116,7 @@ def __init__( else: if len(labels) != len(models): raise ValueError( - "labels '{}' have different length to models '{}'".format( - labels, [model.name for model in models] - ) + f"labels '{labels}' have different length to models '{[model.name for model in models]}'" ) self.labels = labels @@ -297,12 +295,7 @@ def set_output_variables(self, output_variables, solutions): if variable.domain != domain: raise ValueError( "Mismatching variable domains. " - "'{}' has domain '{}', but '{}' has domain '{}'".format( - variable_tuple[0], - domain, - variable_tuple[idx], - variable.domain, - ) + f"'{variable_tuple[0]}' has domain '{domain}', but '{variable_tuple[idx]}' has domain '{variable.domain}'" ) self.spatial_variable_dict[variable_tuple] = {} diff --git a/pybamm/simulation.py b/pybamm/simulation.py index aa58022b6d..493c0069b2 100644 --- a/pybamm/simulation.py +++ b/pybamm/simulation.py @@ -279,9 +279,9 @@ def set_up_and_parameterise_model_for_experiment(self): parameterised_model = new_parameter_values.process_model( new_model, inplace=False ) - self.experiment_unique_steps_to_model[ - "Rest for padding" - ] = parameterised_model + self.experiment_unique_steps_to_model["Rest for padding"] = ( + parameterised_model + ) def update_new_model_events(self, new_model, op): for term in op.termination: @@ -571,14 +571,14 @@ def solve( dt_eval_max = np.max(np.diff(t_eval)) if dt_eval_max > dt_data_min + sys.float_info.epsilon: warnings.warn( - """ - The largest timestep in t_eval ({}) is larger than - the smallest timestep in the data ({}). The returned + f""" + The largest timestep in t_eval ({dt_eval_max}) is larger than + the smallest timestep in the data ({dt_data_min}). The returned solution may not have the correct resolution to accurately 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), + """, pybamm.SolverWarning, ) diff --git a/pybamm/solvers/algebraic_solver.py b/pybamm/solvers/algebraic_solver.py index d241d5b24c..fed2f4a1c0 100644 --- a/pybamm/solvers/algebraic_solver.py +++ b/pybamm/solvers/algebraic_solver.py @@ -106,9 +106,7 @@ def root_fun(y_alg): y = np.concatenate([y0_diff, y_alg]) out = algebraic(t, y) pybamm.logger.debug( - "Evaluating algebraic equations at t={}, L2-norm is {}".format( - t, np.linalg.norm(out) - ) + f"Evaluating algebraic equations at t={t}, L2-norm is {np.linalg.norm(out)}" ) return out diff --git a/pybamm/solvers/base_solver.py b/pybamm/solvers/base_solver.py index 69de3be968..5a636b89bb 100644 --- a/pybamm/solvers/base_solver.py +++ b/pybamm/solvers/base_solver.py @@ -844,9 +844,9 @@ def solve( # If the new initial conditions are different # and cannot be evaluated directly, set up again self.set_up(model, model_inputs_list[0], t_eval, ics_only=True) - self._model_set_up[model][ - "initial conditions" - ] = model.concatenated_initial_conditions + self._model_set_up[model]["initial conditions"] = ( + model.concatenated_initial_conditions + ) set_up_time = timer.time() timer.reset() @@ -892,10 +892,7 @@ def solve( solutions = None for start_index, end_index in zip(start_indices, end_indices): pybamm.logger.verbose( - "Calling solver for {} < t < {}".format( - t_eval[start_index], - t_eval[end_index - 1], - ) + f"Calling solver for {t_eval[start_index]} < t < {t_eval[end_index - 1]}" ) ninputs = len(model_inputs_list) if ninputs == 1: @@ -972,24 +969,13 @@ def solve( if len(solutions) == 1: pybamm.logger.info(f"Finish solving {model.name} ({termination})") pybamm.logger.info( - ( - "Set-up time: {}, Solve time: {} (of which integration time: {}), " - "Total time: {}" - ).format( - solutions[0].set_up_time, - solutions[0].solve_time, - solutions[0].integration_time, - solutions[0].total_time, - ) + f"Set-up time: {solutions[0].set_up_time}, Solve time: {solutions[0].solve_time} (of which integration time: {solutions[0].integration_time}), " + f"Total time: {solutions[0].total_time}" ) else: pybamm.logger.info(f"Finish solving {model.name} for all inputs") pybamm.logger.info( - ("Set-up time: {}, Solve time: {}, Total time: {}").format( - solutions[0].set_up_time, - solutions[0].solve_time, - solutions[0].total_time, - ) + f"Set-up time: {solutions[0].set_up_time}, Solve time: {solutions[0].solve_time}, Total time: {solutions[0].total_time}" ) # Raise error if solutions[0] only contains one timestep (except for algebraic @@ -1248,15 +1234,8 @@ def step( # Report times pybamm.logger.verbose(f"Finish stepping {model.name} ({termination})") pybamm.logger.verbose( - ( - "Set-up time: {}, Step time: {} (of which integration time: {}), " - "Total time: {}" - ).format( - solution.set_up_time, - solution.solve_time, - solution.integration_time, - solution.total_time, - ) + f"Set-up time: {solution.set_up_time}, Step time: {solution.solve_time} (of which integration time: {solution.integration_time}), " + f"Total time: {solution.total_time}" ) # Return solution diff --git a/pybamm/solvers/casadi_algebraic_solver.py b/pybamm/solvers/casadi_algebraic_solver.py index ec7305906a..40cb2130ca 100644 --- a/pybamm/solvers/casadi_algebraic_solver.py +++ b/pybamm/solvers/casadi_algebraic_solver.py @@ -149,11 +149,11 @@ def _integrate(self, model, t_eval, inputs_dict=None): ) else: raise pybamm.SolverError( - """ + f""" Could not find acceptable solution: solver terminated - successfully, but maximum solution error ({}) - above tolerance ({}) - """.format(casadi.mmax(casadi.fabs(fun)), self.tol) + successfully, but maximum solution error ({casadi.mmax(casadi.fabs(fun))}) + above tolerance ({self.tol}) + """ ) # Concatenate differential part diff --git a/pybamm/solvers/solution.py b/pybamm/solvers/solution.py index a3b3e9e6ef..735dd8e396 100644 --- a/pybamm/solvers/solution.py +++ b/pybamm/solvers/solution.py @@ -710,9 +710,7 @@ def save_data( for name, var in data.items(): if var.ndim >= 2: raise ValueError( - "only 0D variables can be saved to csv, but '{}' is {}D".format( - name, var.ndim - 1 - ) + f"only 0D variables can be saved to csv, but '{name}' is {var.ndim - 1}D" ) df = pd.DataFrame(data) return df.to_csv(filename, index=False) diff --git a/pybamm/spatial_methods/spectral_volume.py b/pybamm/spatial_methods/spectral_volume.py index 50e1cadf25..b8bee93b1d 100644 --- a/pybamm/spatial_methods/spectral_volume.py +++ b/pybamm/spatial_methods/spectral_volume.py @@ -342,12 +342,12 @@ def gradient_matrix(self, domain, domains): sub_matrix[i * d, i * (d + 1) : (i + 1) * (d + 1)] = ( f * sub_matrix_raw[i * (d + 1), i * (d + 1) : (i + 1) * (d + 1)] ) - sub_matrix[ - i * d + 1 : (i + 1) * d, i * (d + 1) : (i + 1) * (d + 1) - ] = sub_matrix_raw[ - i * (d + 1) + 1 : (i + 1) * (d + 1) - 1, - i * (d + 1) : (i + 1) * (d + 1), - ] + sub_matrix[i * d + 1 : (i + 1) * d, i * (d + 1) : (i + 1) * (d + 1)] = ( + sub_matrix_raw[ + i * (d + 1) + 1 : (i + 1) * (d + 1) - 1, + i * (d + 1) : (i + 1) * (d + 1), + ] + ) sub_matrix[(i + 1) * d, i * (d + 1) : (i + 1) * (d + 1)] = ( f * sub_matrix_raw[i * (d + 1) + d, i * (d + 1) : (i + 1) * (d + 1)] ) diff --git a/scripts/install_KLU_Sundials.py b/scripts/install_KLU_Sundials.py index 546d7a313c..620480273e 100755 --- a/scripts/install_KLU_Sundials.py +++ b/scripts/install_KLU_Sundials.py @@ -72,9 +72,9 @@ def install_suitesparse(download_dir): # INSTALL RPATH in order to ensure that the dynamic libraries are found # at runtime just once. Otherwise, delocate complains about multiple # references to the SuiteSparse_config dynamic library (auditwheel does not). - env[ - "CMAKE_OPTIONS" - ] = f"-DCMAKE_INSTALL_PREFIX={install_dir} -DCMAKE_INSTALL_RPATH={install_dir}/lib -DCMAKE_INSTALL_RPATH_USE_LINK_PATH=FALSE -DCMAKE_BUILD_WITH_INSTALL_RPATH=FALSE" + env["CMAKE_OPTIONS"] = ( + f"-DCMAKE_INSTALL_PREFIX={install_dir} -DCMAKE_INSTALL_RPATH={install_dir}/lib -DCMAKE_INSTALL_RPATH_USE_LINK_PATH=FALSE -DCMAKE_BUILD_WITH_INSTALL_RPATH=FALSE" + ) subprocess.run(make_cmd, cwd=build_dir, env=env, shell=True, check=True) subprocess.run(install_cmd, cwd=build_dir, check=True) diff --git a/tests/unit/test_expression_tree/test_operations/test_latexify.py b/tests/unit/test_expression_tree/test_operations/test_latexify.py index 7e0703534e..0340a1d53f 100644 --- a/tests/unit/test_expression_tree/test_operations/test_latexify.py +++ b/tests/unit/test_expression_tree/test_operations/test_latexify.py @@ -1,6 +1,7 @@ """ Tests for the latexify.py """ + from tests import TestCase import os import platform diff --git a/tests/unit/test_expression_tree/test_printing/test_print_name.py b/tests/unit/test_expression_tree/test_printing/test_print_name.py index 554e6567f1..e1c8ec13e1 100644 --- a/tests/unit/test_expression_tree/test_printing/test_print_name.py +++ b/tests/unit/test_expression_tree/test_printing/test_print_name.py @@ -1,6 +1,7 @@ """ Tests for the print_name.py """ + from tests import TestCase import unittest diff --git a/tests/unit/test_expression_tree/test_printing/test_sympy_overrides.py b/tests/unit/test_expression_tree/test_printing/test_sympy_overrides.py index ed029d73c6..4b19c7d822 100644 --- a/tests/unit/test_expression_tree/test_printing/test_sympy_overrides.py +++ b/tests/unit/test_expression_tree/test_printing/test_sympy_overrides.py @@ -1,6 +1,7 @@ """ Tests for the sympy_overrides.py """ + from tests import TestCase import unittest diff --git a/tests/unit/test_parameters/test_base_parameters.py b/tests/unit/test_parameters/test_base_parameters.py index 11879f01ce..5ca21b1c7c 100644 --- a/tests/unit/test_parameters/test_base_parameters.py +++ b/tests/unit/test_parameters/test_base_parameters.py @@ -1,6 +1,7 @@ """ Tests for the base_parameters.py """ + from tests import TestCase import pybamm import unittest From a59c033a0973b82c0b82192fbb27ba1cafdcaf98 Mon Sep 17 00:00:00 2001 From: Agriya Khetarpal <74401230+agriyakhetarpal@users.noreply.github.com> Date: Wed, 13 Mar 2024 10:56:16 +0530 Subject: [PATCH 3/3] Update .git-blame-ignore-revs --- .git-blame-ignore-revs | 2 ++ 1 file changed, 2 insertions(+) diff --git a/.git-blame-ignore-revs b/.git-blame-ignore-revs index b38e6697cb..97a8d33089 100644 --- a/.git-blame-ignore-revs +++ b/.git-blame-ignore-revs @@ -10,3 +10,5 @@ a63e49ece0f9336d1f5c2562f7459e555c6e6693 ff6d81c01331c7d269303b4a8321d9881bdf98fa # migrated to ruff-format - https://github.com/pybamm-team/PyBaMM/pull/3655 60ebd4148059a95428a496f4f55c1175ead362d3 +# implemented cleaner string formatting via f-strings - https://github.com/pybamm-team/PyBaMM/pull/3890 +f395819d1c874071b7e76e32ec4f0bbe42462b48