diff --git a/.github/workflows/test_on_push.yml b/.github/workflows/test_on_push.yml index f2023326dc..71f4560317 100644 --- a/.github/workflows/test_on_push.yml +++ b/.github/workflows/test_on_push.yml @@ -87,16 +87,16 @@ jobs: if: matrix.os == 'ubuntu-latest' run: tox -e pybamm-requires - - name: Run unit tests for GNU/Linux with Python 3.8 and 3.9 - if: matrix.os == 'ubuntu-latest' && matrix.python-version != 3.7 + - name: Run unit tests for GNU/Linux with Python 3.7 and 3.8 + if: matrix.os == 'ubuntu-latest' && matrix.python-version != 3.9 run: python -m tox -e unit - - name: Run unit tests for GNU/Linux with Python 3.7 and generate coverage report - if: matrix.os == 'ubuntu-latest' && matrix.python-version == 3.7 + - name: Run unit tests for GNU/Linux with Python 3.9 and generate coverage report + if: matrix.os == 'ubuntu-latest' && matrix.python-version == 3.9 run: tox -e coverage - name: Upload coverage report - if: matrix.os == 'ubuntu-latest' && matrix.python-version == 3.7 + if: matrix.os == 'ubuntu-latest' && matrix.python-version == 3.9 uses: codecov/codecov-action@v2.1.0 - name: Run integration tests for GNU/Linux diff --git a/CHANGELOG.md b/CHANGELOG.md index ca544f5903..29d1f3f990 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,6 +1,9 @@ -# unreleased +# [Unreleased](https://github.com/pybamm-team/PyBaMM/) ## Bug fixes + +- Parameters can now be imported from any given path in `Windows` ([#1900](https://github.com/pybamm-team/PyBaMM/pull/1900)) +- Fixed initial conditions for the EC SEI model ([#1895](https://github.com/pybamm-team/PyBaMM/pull/1895)) - Fixed issue in extraction of sensitivites ([#1894](https://github.com/pybamm-team/PyBaMM/pull/1894)) # [v21.12](https://github.com/pybamm-team/PyBaMM/tree/v21.11) - 2021-12-29 diff --git a/pybamm/models/submodels/interface/kinetics/base_kinetics.py b/pybamm/models/submodels/interface/kinetics/base_kinetics.py index 4b0b3ad4b6..1d32ebfe71 100644 --- a/pybamm/models/submodels/interface/kinetics/base_kinetics.py +++ b/pybamm/models/submodels/interface/kinetics/base_kinetics.py @@ -93,6 +93,10 @@ def get_coupled_variables(self, variables): j_tot = variables[ "Total negative electrode interfacial current density variable" ] + + # Override print_name + j_tot.print_name = "j_tot" + eta_sei = -j_tot * L_sei * R_sei else: eta_sei = pybamm.Scalar(0) @@ -203,6 +207,10 @@ def set_algebraic(self, variables): + self.domain.lower() + " electrode interfacial current density variable" ] + + # Override print_name + j_tot_var.print_name = "j_tot" + j_tot = variables[ "Sum of " + self.domain.lower() diff --git a/pybamm/models/submodels/interface/sei/sei_growth.py b/pybamm/models/submodels/interface/sei/sei_growth.py index 1fcabf9975..859180d0d6 100644 --- a/pybamm/models/submodels/interface/sei/sei_growth.py +++ b/pybamm/models/submodels/interface/sei/sei_growth.py @@ -188,6 +188,6 @@ def set_initial_conditions(self, variables): L_inner_0 = self.param.L_inner_0 L_outer_0 = self.param.L_outer_0 if self.options["SEI"] == "ec reaction limited": - self.initial_conditions = {L_outer: L_outer_0} + self.initial_conditions = {L_outer: L_inner_0 + L_outer_0} else: self.initial_conditions = {L_inner: L_inner_0, L_outer: L_outer_0} diff --git a/pybamm/parameters/parameter_values.py b/pybamm/parameters/parameter_values.py index e7182eb47d..bee95d41c2 100644 --- a/pybamm/parameters/parameter_values.py +++ b/pybamm/parameters/parameter_values.py @@ -942,8 +942,13 @@ def find_parameter(path): """Look for parameter file in the different locations in PARAMETER_PATH """ + # Check for absolute path + if os.path.isfile(path) and os.path.isabs(path): + pybamm.logger.verbose(f"Using absolute path: '{path}'") + return path for location in pybamm.PARAMETER_PATH: trial_path = os.path.join(location, path) if os.path.isfile(trial_path): + pybamm.logger.verbose(f"Using path: '{location}' + '{path}'") return trial_path raise FileNotFoundError("Could not find parameter {}".format(path)) diff --git a/pybamm/util.py b/pybamm/util.py index 98e4b79679..5026b468bd 100644 --- a/pybamm/util.py +++ b/pybamm/util.py @@ -283,10 +283,24 @@ def load_function(filename): # Assign path to _ and filename to tail _, tail = os.path.split(filename) + # Store the current working directory + orig_dir = os.getcwd() + # Strip absolute path to pybamm/input/example.py if "pybamm" in filename: root_path = filename[filename.rfind("pybamm") :] + # If the function is in the current working directory elif os.getcwd() in filename: + root_path = filename.replace(os.getcwd(), "") + # getcwd() returns "C:\\" when in the root drive and "C:\\a\\b\\c" otherwise + if root_path[0] == "\\" or root_path[0] == "/": + root_path = root_path[1:] + # If the function is not in the current working directory and the path provided is + # absolute + elif os.path.isabs(filename) and not os.getcwd() in filename: # pragma: no cover + # Change directory to import the function + dir_path = os.path.split(filename)[0] + os.chdir(dir_path) root_path = filename.replace(os.getcwd(), "") root_path = root_path[1:] else: @@ -294,8 +308,13 @@ def load_function(filename): path = root_path.replace("/", ".") path = path.replace("\\", ".") + pybamm.logger.debug( + f"Importing function '{tail}' from file '{filename}' via path '{path}'" + ) module_object = importlib.import_module(path) + # Revert back current working directory if it was changed + os.chdir(orig_dir) return getattr(module_object, tail) diff --git a/tests/unit/test_expression_tree/test_operations/test_convert_to_casadi.py b/tests/unit/test_expression_tree/test_operations/test_convert_to_casadi.py index a74ad7ecd7..32b20ba610 100644 --- a/tests/unit/test_expression_tree/test_operations/test_convert_to_casadi.py +++ b/tests/unit/test_expression_tree/test_operations/test_convert_to_casadi.py @@ -119,7 +119,6 @@ def test_special_functions(self): for np_fun in [ np.sqrt, np.tanh, - np.cosh, np.sinh, np.exp, np.log, @@ -133,6 +132,21 @@ def test_special_functions(self): pybamm.Function(np_fun, c).to_casadi(), casadi.MX(np_fun(3)), evalf=True ) + # A workaround to fix the tests running on GitHub Actions - + # casadi.evalf( + # pybamm.Function(np_fun, c).to_casadi() + # ) - casadi.evalf(casadi.MX(np_fun(3))) + # is not zero, but a small number of the order 10^-15 when np_func is np.cosh + for np_fun in [ + np.cosh + ]: + self.assert_casadi_almost_equal( + pybamm.Function(np_fun, c).to_casadi(), + casadi.MX(np_fun(3)), + decimal=14, + evalf=True, + ) + # test functions with assert_casadi_almost_equal for np_fun in [special.erf]: self.assert_casadi_almost_equal( diff --git a/tests/unit/test_parameters/test_parameter_values.py b/tests/unit/test_parameters/test_parameter_values.py index cb6dbf38c1..b7b2e67176 100644 --- a/tests/unit/test_parameters/test_parameter_values.py +++ b/tests/unit/test_parameters/test_parameter_values.py @@ -60,6 +60,18 @@ def test_init(self): ) self.assertEqual(param["Positive electrode porosity"], 0.3) + # from file, absolute path + param = pybamm.ParameterValues( + os.path.join( + pybamm.root_dir(), + "pybamm", + "input", + "parameters", + "lithium_ion/positive_electrodes/lico2_Marquis2019/parameters.csv", + ) + ) + self.assertEqual(param["Positive electrode porosity"], 0.3) + # values vs chemistry with self.assertRaisesRegex( ValueError, "values and chemistry cannot both be None"