Skip to content

Commit

Permalink
Merge pull request #1675 from pybamm-team/issue-1673-import-parameter…
Browse files Browse the repository at this point in the history
…s-chemistry-error

Issue 1673 import parameters chemistry error
  • Loading branch information
brosaplanella committed Sep 16, 2021
2 parents d5e818a + aa81375 commit 261f6c4
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 1 deletion.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ example notebook ([#1602](https://github.com/pybamm-team/PyBaMM/pull/1602))

## Bug fixes

- Fixed bug with `load_function` ([#1675](https://github.com/pybamm-team/PyBaMM/pull/1675))
- Updated documentation to include some previously missing functions, such as `erf` and `tanh` ([#1628](https://github.com/pybamm-team/PyBaMM/pull/1628))
- Fixed reading citation file without closing ([#1620](https://github.com/pybamm-team/PyBaMM/pull/1620))
- Porosity variation for SEI and plating models is calculated from the film thickness rather than from a separate ODE ([#1617](https://github.com/pybamm-team/PyBaMM/pull/1617))
Expand Down
5 changes: 4 additions & 1 deletion pybamm/util.py
Original file line number Diff line number Diff line change
Expand Up @@ -273,9 +273,12 @@ def load_function(filename):
# Assign path to _ and filename to tail
_, tail = os.path.split(filename)

# Strip absolute path to pybamm/input/exapmle.py
# Strip absolute path to pybamm/input/example.py
if "pybamm" in filename:
root_path = filename[filename.rfind("pybamm") :]
elif os.getcwd() in filename:
root_path = filename.replace(os.getcwd(), "")
root_path = root_path[1:]
else:
root_path = filename

Expand Down
13 changes: 13 additions & 0 deletions tests/unit/test_parameters/test_parameter_values.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

import os
import tempfile
import subprocess
import unittest

import numpy as np
Expand Down Expand Up @@ -71,6 +72,18 @@ def test_update_from_chemistry(self):
with self.assertRaisesRegex(KeyError, "must provide 'cell' parameters"):
pybamm.ParameterValues(chemistry={"chemistry": "lithium_ion"})

def test_update_from_chemistry_local(self):
# Copy parameters
cmd = ["pybamm_edit_parameter", "-f", "lithium_ion"]
subprocess.run(cmd)

# Import parameters from chemistry
pybamm.ParameterValues(chemistry=pybamm.parameter_sets.Chen2020)

# Clean up parameter files
cmd = ["rm", "-r", "lithium_ion"]
subprocess.run(cmd)

def test_update(self):
# converts to dict if not
param = pybamm.ParameterValues(chemistry=pybamm.parameter_sets.Chen2020)
Expand Down

0 comments on commit 261f6c4

Please sign in to comment.