Skip to content

Commit

Permalink
Merge branch 'develop' into issue-1886-order-of-sensitivities
Browse files Browse the repository at this point in the history
  • Loading branch information
Scottmar93 committed Jan 17, 2022
2 parents 1ce6f53 + 751c18d commit 2396ed3
Show file tree
Hide file tree
Showing 8 changed files with 69 additions and 8 deletions.
10 changes: 5 additions & 5 deletions .github/workflows/test_on_push.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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/[email protected]

- name: Run integration tests for GNU/Linux
Expand Down
5 changes: 4 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -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
Expand Down
8 changes: 8 additions & 0 deletions pybamm/models/submodels/interface/kinetics/base_kinetics.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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()
Expand Down
2 changes: 1 addition & 1 deletion pybamm/models/submodels/interface/sei/sei_growth.py
Original file line number Diff line number Diff line change
Expand Up @@ -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}
5 changes: 5 additions & 0 deletions pybamm/parameters/parameter_values.py
Original file line number Diff line number Diff line change
Expand Up @@ -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))
19 changes: 19 additions & 0 deletions pybamm/util.py
Original file line number Diff line number Diff line change
Expand Up @@ -283,19 +283,38 @@ 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:
root_path = 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)


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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(
Expand Down
12 changes: 12 additions & 0 deletions tests/unit/test_parameters/test_parameter_values.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down

0 comments on commit 2396ed3

Please sign in to comment.