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

Migrate to PyBaMM 22.10 #105

Merged
merged 3 commits into from
Nov 2, 2022
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
4 changes: 3 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,6 @@ plot.png
tempCodeRunnerFile.py
plot.gif
.coverage
.ipynb_checkpoints
.ipynb_checkpoints
plot*.png
.DS_Store
4 changes: 2 additions & 2 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,9 @@ This will install all the dependencies in your local system including the latest

4. To check if the installation worked, execute (this will take some time) -
```bash
python -m unittest
python -m unittest -v
# or if you haven't completed the pre-installation process, this -
python -m unittest discover ./test/without_keys/
python -m unittest discover ./test/without_keys/ -v
```
**Note: The tests written in `with_keys` subdirectory will fail if you haven't completed the pre-installation process, again, you don't necessarily need the `Twitter Developer Account` to contribute to this repository.**

Expand Down
8 changes: 4 additions & 4 deletions bot/plotting/comparison_generator.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@ class ComparisonGenerator:
}
Provide only 1 model for "parameter comparison" and 2 or more models for
"model comparison".
chemistry : dict
Chemistry for the models.
chemistry : str
A PyBaMM chemistry.
is_experiment : bool
If the comparison includes an experiment.
params : pybamm.ParameterValues
Expand Down Expand Up @@ -163,7 +163,7 @@ def model_comparison(self, testing=False):
)

if self.is_experiment:
if self.chemistry == pybamm.parameter_sets.Ai2020:
if self.chemistry == "Ai2020":
batch_study.solve(calc_esoh=False)
else:
batch_study.solve()
Expand Down Expand Up @@ -254,7 +254,7 @@ def parameter_comparison(self, testing=False):
)

if self.is_experiment:
if self.chemistry == pybamm.parameter_sets.Ai2020:
if self.chemistry == "Ai2020":
batch_study.solve(calc_esoh=False)
else:
batch_study.solve()
Expand Down
14 changes: 7 additions & 7 deletions bot/plotting/config_generator.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,10 @@

# possible chemistries for the bot
chemistries = [
pybamm.parameter_sets.Ai2020,
pybamm.parameter_sets.Chen2020,
pybamm.parameter_sets.Marquis2019,
pybamm.parameter_sets.OKane2022
"Ai2020",
"Chen2020",
"Marquis2019",
"OKane2022"
]

# possible "particle mechanics" for the bot, to be used with Ai2020 parameters
Expand Down Expand Up @@ -101,7 +101,7 @@ def config_generator(
chemistry = test_config["chemistry"]
# use only Mohtat2020 and SPM till others are fixed
elif choice == "degradation comparison":
chemistry = pybamm.parameter_sets.Mohtat2020
chemistry = "Mohtat2020"
else:
chemistry = random.choice(chemistries)
parameter_values = pybamm.ParameterValues(chemistry)
Expand All @@ -110,15 +110,15 @@ def config_generator(
if choice == "degradation comparison":

# add degradation / update model options
if chemistry == pybamm.parameter_sets.Ai2020:
if chemistry == "Ai2020":
degradation_value = particle_mechanics_list[0]
degradation_mode = "particle mechanics"
model_options.update(
{
degradation_mode: degradation_value,
}
)
elif chemistry == pybamm.parameter_sets.Mohtat2020:
elif chemistry == "Mohtat2020":
if test_config["degradation_mode"] is None:
degradation_mode = random.choice(["SEI", "particle mechanics"])
else:
Expand Down
12 changes: 6 additions & 6 deletions bot/plotting/degradation_comparison_generator.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@ class DegradationComparisonGenerator:
----------
model : :class:`pybamm.BaseBatteryModel`
Model to be used in the comparison.
chemistry : dict
Chemistry to be used in the comparison.
chemistry : str
A PyBaMM chemistry.
param_values : list
Parameter values with one degradation parameter varied. Should be of the
form -
Expand Down Expand Up @@ -75,9 +75,9 @@ def create_simulation(self, experiment):
experiment=experiment,
parameter_values=self.param_values[i],
)
if self.chemistry == pybamm.parameter_sets.Ai2020: # pragma: no cover
if self.chemistry == "Ai2020": # pragma: no cover
sim.solve(calc_esoh=False)
elif self.chemistry == pybamm.parameter_sets.Mohtat2020:
elif self.chemistry == "Mohtat2020":
sim.solve(initial_soc=1)
else: # pragma: no cover
sim.solve()
Expand All @@ -99,7 +99,7 @@ def solve(self):
"""
Solves an experiment with the given configuration.
"""
if self.chemistry == pybamm.parameter_sets.Ai2020: # pragma: no cover
if self.chemistry == "Ai2020": # pragma: no cover
experiment = pybamm.Experiment(self.cycle * self.number)
else:
experiment = pybamm.Experiment(
Expand All @@ -121,7 +121,7 @@ def generate_summary_variables(self):
"""
Creates and saves a picture of summary variable comparison plot.
"""
if self.chemistry == pybamm.parameter_sets.Ai2020: # pragma: no cover
if self.chemistry == "Ai2020": # pragma: no cover
vars_to_plot = [
"Measured capacity [A.h]",
"Loss of lithium inventory [%]",
Expand Down
20 changes: 10 additions & 10 deletions bot/run-simulation.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,7 @@
"if config[\"is_experiment\"] and not config[\"is_comparison\"]:\n",
"\n",
" # don't terminate early if Ai2020 parameter sets were used\n",
" if config[\"chemistry\"] == pybamm.parameter_sets.Ai2020:\n",
" if config[\"chemistry\"] == \"Ai2020\":\n",
" experiment = pybamm.Experiment(\n",
" config[\"cycle\"] * config[\"number\"]\n",
" )\n",
Expand All @@ -163,7 +163,7 @@
" parameter_values = pybamm.ParameterValues(config[\"chemistry\"])\n",
"\n",
" # update parameter sets for Mohtat2020 chemistry\n",
" if config[\"chemistry\"] == pybamm.parameter_sets.Mohtat2020:\n",
" if config[\"chemistry\"] == \"Mohtat2020\":\n",
" def lico2_volume_change_Ai2020(sto):\n",
" omega = pybamm.Parameter(\"Positive electrode partial molar volume [m3.mol-1]\")\n",
" c_p_max = pybamm.Parameter(\"Maximum concentration in positive electrode [mol.m-3]\")\n",
Expand Down Expand Up @@ -251,17 +251,17 @@
" parameter_values=param_list[i],\n",
" )\n",
"\n",
" if config[\"chemistry\"] == pybamm.parameter_sets.Ai2020:\n",
" if config[\"chemistry\"] == \"Ai2020\":\n",
" sim.solve(calc_esoh=False)\n",
" elif config[\"chemistry\"] == pybamm.parameter_sets.Mohtat2020:\n",
" elif config[\"chemistry\"] == \"Mohtat2020\":\n",
" sim.solve(initial_soc=1)\n",
" else:\n",
" sim.solve()\n",
" solution = sim.solution\n",
" solutions.append(solution)\n",
"\n",
" # defining the summary variables\n",
" if config[\"chemistry\"] == pybamm.parameter_sets.Ai2020:\n",
" if config[\"chemistry\"] == \"Ai2020\":\n",
" vars_to_plot = [\n",
" \"Measured capacity [A.h]\",\n",
" \"Loss of lithium inventory [%]\",\n",
Expand Down Expand Up @@ -406,7 +406,7 @@
" t_end = 3700\n",
"\n",
" # solving\n",
" if config[\"chemistry\"] == pybamm.parameter_sets.Ai2020:\n",
" if config[\"chemistry\"] == \"Ai2020\":\n",
" s.solve([0, t_end], calc_esoh=False)\n",
" else:\n",
" s.solve([0, t_end])\n",
Expand Down Expand Up @@ -489,7 +489,7 @@
" )\n",
"\n",
" # solving\n",
" if config[\"chemistry\"] == pybamm.parameter_sets.Ai2020:\n",
" if config[\"chemistry\"] == \"Ai2020\":\n",
" s.solve(calc_esoh=False)\n",
" else:\n",
" s.solve()\n",
Expand Down Expand Up @@ -526,7 +526,7 @@
],
"metadata": {
"kernelspec": {
"display_name": "Python 3",
"display_name": "Python 3 (ipykernel)",
"language": "python",
"name": "python3"
},
Expand All @@ -540,9 +540,9 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.9.0"
"version": "3.9.6"
}
},
"nbformat": 4,
"nbformat_minor": 2
}
}
2 changes: 1 addition & 1 deletion bot/twitter_api/tweet_plot.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ def __init__(self, testing=False, choice=None):
"""
Defines video tweet properties
"""
super().__init__()
# super().__init__()
# create a random GIF
while True:
manager = multiprocessing.Manager()
Expand Down
6 changes: 3 additions & 3 deletions bot/twitter_api/tweet_reply.py
Original file line number Diff line number Diff line change
Expand Up @@ -127,11 +127,11 @@ def generate_reply(self, tweet_text, testing=False):
models_for_comp = dict(list(enumerate(models)))

if "chen2020" in text_list:
chemistry = pybamm.parameter_sets.Chen2020
chemistry = "Chen2020"
elif "marquis2019" in text_list:
chemistry = pybamm.parameter_sets.Marquis2019
chemistry = "Marquis2019"
elif "ai2020" in text_list:
chemistry = pybamm.parameter_sets.Ai2020
chemistry = "Ai2020"
else:
# if no chemistry is provided
raise Exception(
Expand Down
6 changes: 3 additions & 3 deletions bot/utils/degradation_parameter_generator.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ def degradation_parameter_generator(

params = pybamm.ParameterValues(chemistry)

if chemistry == pybamm.parameter_sets.Mohtat2020:
if chemistry == "Mohtat2020":
params.update(
{
# mechanical properties
Expand Down Expand Up @@ -93,7 +93,7 @@ def degradation_parameter_generator(
check_already_exists=False,
)
if degradation_mode == "particle mechanics":
if chemistry == pybamm.parameter_sets.Ai2020:
if chemistry == "Ai2020":
degradation_parameters = {
"Negative electrode Paris' law constant b": {
"print_name": None,
Expand Down Expand Up @@ -136,7 +136,7 @@ def degradation_parameter_generator(
"bounds": (None, None),
},
}
elif chemistry == pybamm.parameter_sets.Mohtat2020:
elif chemistry == "Mohtat2020":
degradation_parameters = {
"Positive electrode LAM constant proportional term [s-1]": {
"print_name": None,
Expand Down
23 changes: 14 additions & 9 deletions bot/utils/tweet_text_generator.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
import pybamm


def tweet_text_generator(
chemistry,
model,
Expand All @@ -15,7 +18,7 @@ def tweet_text_generator(

Parameters
----------
chemistry : dict
chemistry : str
model : :class:`pybamm.BaseBatteryModel` or dict
is_experiment : bool
cycle : list or None
Expand All @@ -34,6 +37,8 @@ def tweet_text_generator(
Not none if the tweet text exceeds twitter limit.
"""

param_values = pybamm.ParameterValues(chemistry)

if is_comparison:
# calculate C-rate and Temperature to add in tweet text
c_rate = round(
Expand All @@ -46,7 +51,7 @@ def tweet_text_generator(
# summary variable
if is_experiment and not is_comparison:
tweet_text = (
f"Plotting {model.name} with {chemistry['citation']} "
f"Plotting {model.name} with {param_values['citations'][0]} "
f"parameters and {degradation_value} {degradation_mode} "
f"for the following experiment: {cycle} * {number}"
)
Expand All @@ -58,21 +63,21 @@ def tweet_text_generator(
if len(model) == 2:
tweet_text = (
f"Comparing {model[0].name} and {model[1].name} "
f"with {chemistry['citation']} parameters at {temp}°C for the "
f"following experiment: {cycle} * {number}"
f"with {param_values['citations'][0]} parameters at {temp}°C for "
f"the following experiment: {cycle} * {number}"
)
else:
tweet_text = (
f"Comparing {model[0].name}, {model[1].name}, and "
f"{model[2].name} with {chemistry['citation']} "
f"{model[2].name} with {param_values['citations'][0]} "
f"parameters at {temp}°C for the following experiment: "
f"{cycle} * {number}"
)
# comparing a single model and a single experiment while varying
# a parameter
elif param_to_vary is not None and is_comparison:
tweet_text = (
f"{model[0].name} with {chemistry['citation']} parameters "
f"{model[0].name} with {param_values['citations'][0]} parameters "
f"varying '{param_to_vary}' at {temp}°C for the following experiment: "
f"{cycle} * {number}"
)
Expand All @@ -85,20 +90,20 @@ def tweet_text_generator(
if len(model) == 2:
tweet_text = (
f"Comparing {model[0].name} and {model[1].name} with "
f"{chemistry['citation']} parameters for a {c_rate} C "
f"{param_values['citations'][0]} parameters for a {c_rate} C "
f"discharge at {temp}°C"
)
else:
tweet_text = (
f"Comparing {model[0].name}, {model[1].name}, and "
f"{model[2].name} with {chemistry['citation']} "
f"{model[2].name} with {param_values['citations'][0]} "
f"parameters for a {c_rate} C discharge at {temp}°C"
)

# comparing a single model by varying a parameter value
elif param_to_vary is not None and is_comparison:
tweet_text = (
f"{model[0].name} with {chemistry['citation']} parameters "
f"{model[0].name} with {param_values['citations'][0]} parameters "
f"varying '{param_to_vary}' for a {c_rate} C discharge at "
f"{temp}°C"
)
Expand Down
8 changes: 4 additions & 4 deletions test/with_keys/test_tweet_plot.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ def test_tweet(self):
assert os.path.exists(tweet.plot)
self.assertIsNone(tweet.processing_info)
self.assertIsInstance(tweet.model, pybamm.BaseModel)
self.assertIsInstance(tweet.chemistry, dict)
self.assertIsInstance(tweet.chemistry, str)
self.assertIsInstance(tweet.is_experiment, bool)
self.assertTrue(tweet.is_experiment)
self.assertIsInstance(tweet.cycle, list)
Expand Down Expand Up @@ -48,7 +48,7 @@ def test_tweet(self):
assert os.path.exists(tweet.plot)
self.assertIsNone(tweet.processing_info)
self.assertIsInstance(tweet.model, dict)
self.assertIsInstance(tweet.chemistry, dict)
self.assertIsInstance(tweet.chemistry, str)
self.assertIsInstance(tweet.is_experiment, bool)
self.assertIsInstance(tweet.is_comparison, bool)
self.assertTrue(tweet.is_comparison)
Expand Down Expand Up @@ -79,7 +79,7 @@ def test_tweet(self):
assert os.path.exists(tweet.plot)
self.assertIsNone(tweet.processing_info)
self.assertIsInstance(tweet.model, dict)
self.assertIsInstance(tweet.chemistry, dict)
self.assertIsInstance(tweet.chemistry, str)
self.assertIsInstance(tweet.is_experiment, bool)
self.assertIsInstance(tweet.is_comparison, bool)
self.assertTrue(tweet.is_comparison)
Expand Down Expand Up @@ -113,7 +113,7 @@ def test_tweet(self):
isinstance(tweet.model, dict)
or isinstance(tweet.model, pybamm.BaseModel)
)
self.assertIsInstance(tweet.chemistry, dict)
self.assertIsInstance(tweet.chemistry, str)
self.assertIsInstance(tweet.is_experiment, bool)
self.assertIsInstance(tweet.is_comparison, bool)
self.assertIsInstance(tweet.testing, bool)
Expand Down
Loading