Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Issue 1673 import parameters chemistry error #1675

Merged
merged 3 commits into from
Sep 16, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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