Skip to content

Commit

Permalink
merge develop, remove autoinstall
Browse files Browse the repository at this point in the history
  • Loading branch information
valentinsulzer committed Sep 26, 2024
2 parents abac35f + 62a7ee8 commit ad0faa1
Show file tree
Hide file tree
Showing 39 changed files with 1,281 additions and 535 deletions.
3 changes: 2 additions & 1 deletion .all-contributorsrc
Original file line number Diff line number Diff line change
Expand Up @@ -747,7 +747,8 @@
"profile": "https://github.com/AbhishekChaudharii",
"contributions": [
"doc",
"code"
"code",
"test"
]
},
{
Expand Down
2 changes: 1 addition & 1 deletion .github/CODEOWNERS
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ src/pybamm/meshes/ @martinjrobins @rtimms @valentinsulzer @rtimms
src/pybamm/models/ @brosaplanella @DrSOKane @rtimms @valentinsulzer @TomTranter @rtimms
src/pybamm/parameters/ @brosaplanella @DrSOKane @rtimms @valentinsulzer @TomTranter @rtimms @kratman
src/pybamm/plotting/ @martinjrobins @rtimms @Saransh-cpp @valentinsulzer @rtimms @kratman @agriyakhetarpal
src/pybamm/solvers/ @martinjrobins @rtimms @valentinsulzer @TomTranter @rtimms
src/pybamm/solvers/ @martinjrobins @rtimms @valentinsulzer @TomTranter @rtimms @MarcBerliner
src/pybamm/spatial_methods/ @martinjrobins @rtimms @valentinsulzer @rtimms
src/pybamm/* @pybamm-team/maintainers # the files directly under /pybamm/, will not recurse

Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/scorecard.yml
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,6 @@ jobs:
# Upload the results to GitHub's code scanning dashboard (optional).
# Commenting out will disable upload of results to your repo's Code Scanning dashboard
- name: "Upload to code-scanning"
uses: github/codeql-action/upload-sarif@4dd16135b69a43b6c8efb853346f8437d92d3c93 # v3.26.6
uses: github/codeql-action/upload-sarif@294a9d92911152fe08befb9ec03e240add280cb3 # v3.26.8
with:
sarif_file: results.sarif
2 changes: 1 addition & 1 deletion .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ ci:

repos:
- repo: https://github.com/astral-sh/ruff-pre-commit
rev: "v0.6.4"
rev: "v0.6.7"
hooks:
- id: ruff
args: [--fix, --show-fixes]
Expand Down
11 changes: 8 additions & 3 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,21 +4,26 @@

- Added basic telemetry to record which functions are being run. See [Telemetry section in the User Guide](https://docs.pybamm.org/en/latest/source/user_guide/index.html#telemetry) for more information. ([#4441](https://github.com/pybamm-team/PyBaMM/pull/4441))
- Added sensitivity calculation support for `pybamm.Simulation` and `pybamm.Experiment` ([#4415](https://github.com/pybamm-team/PyBaMM/pull/4415))
- Added OpenMP parallelization to IDAKLU solver for lists of input parameters ([#4449](https://github.com/pybamm-team/PyBaMM/pull/4449))
- Added phase-dependent particle options to LAM ([#4369](https://github.com/pybamm-team/PyBaMM/pull/4369))
- Added a lithium ion equivalent circuit model with split open circuit voltages for each electrode (`SplitOCVR`). ([#4330](https://github.com/pybamm-team/PyBaMM/pull/4330))

## Optimizations

- Performance refactor of JAX BDF Solver with default Jax method set to `"BDF"`. ([#4456](https://github.com/pybamm-team/PyBaMM/pull/4456))
- Improved performance of initialization and reinitialization of ODEs in the (`IDAKLUSolver`). ([#4453](https://github.com/pybamm-team/PyBaMM/pull/4453))
- Removed the `start_step_offset` setting and disabled minimum `dt` warnings for drive cycles with the (`IDAKLUSolver`). ([#4416](https://github.com/pybamm-team/PyBaMM/pull/4416))

## Features
## Bug Fixes

- Added phase-dependent particle options to LAM #4369
- Fixed bug where IDAKLU solver failed when `output variables` were specified and an extrapolation event is present. ([#4440](https://github.com/pybamm-team/PyBaMM/pull/4440))

## Breaking changes

- Removed the deprecation warning for the chemistry argument in ParameterValues ([#4466](https://github.com/pybamm-team/PyBaMM/pull/4466))
- The parameters "... electrode OCP entropic change [V.K-1]" and "... electrode volume change" are now expected to be functions of stoichiometry only instead of functions of both stoichiometry and maximum concentration ([#4427](https://github.com/pybamm-team/PyBaMM/pull/4427))
- Renamed `set_events` function to `add_events_from` to better reflect its purpose. ([#4421](https://github.com/pybamm-team/PyBaMM/pull/4421))


# [v24.9.0](https://github.com/pybamm-team/PyBaMM/tree/v24.9.0) - 2024-09-03

## Features
Expand Down
23 changes: 22 additions & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ endif()

project(idaklu)

set(CMAKE_CXX_STANDARD 14)
set(CMAKE_CXX_STANDARD 17)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
set(CMAKE_CXX_EXTENSIONS OFF)
set(CMAKE_EXPORT_COMPILE_COMMANDS 1)
Expand Down Expand Up @@ -82,6 +82,8 @@ pybind11_add_module(idaklu
src/pybamm/solvers/c_solvers/idaklu/idaklu_solver.hpp
src/pybamm/solvers/c_solvers/idaklu/IDAKLUSolver.cpp
src/pybamm/solvers/c_solvers/idaklu/IDAKLUSolver.hpp
src/pybamm/solvers/c_solvers/idaklu/IDAKLUSolverGroup.cpp
src/pybamm/solvers/c_solvers/idaklu/IDAKLUSolverGroup.hpp
src/pybamm/solvers/c_solvers/idaklu/IDAKLUSolverOpenMP.inl
src/pybamm/solvers/c_solvers/idaklu/IDAKLUSolverOpenMP.hpp
src/pybamm/solvers/c_solvers/idaklu/IDAKLUSolverOpenMP_solvers.cpp
Expand All @@ -94,6 +96,8 @@ pybind11_add_module(idaklu
src/pybamm/solvers/c_solvers/idaklu/common.cpp
src/pybamm/solvers/c_solvers/idaklu/Solution.cpp
src/pybamm/solvers/c_solvers/idaklu/Solution.hpp
src/pybamm/solvers/c_solvers/idaklu/SolutionData.cpp
src/pybamm/solvers/c_solvers/idaklu/SolutionData.hpp
src/pybamm/solvers/c_solvers/idaklu/Options.hpp
src/pybamm/solvers/c_solvers/idaklu/Options.cpp
# IDAKLU expressions / function evaluation [abstract]
Expand Down Expand Up @@ -138,6 +142,23 @@ set_target_properties(
INSTALL_RPATH_USE_LINK_PATH TRUE
)

# openmp
if (${CMAKE_SYSTEM_NAME} MATCHES "Darwin")
execute_process(
COMMAND "brew" "--prefix"
OUTPUT_VARIABLE HOMEBREW_PREFIX
OUTPUT_STRIP_TRAILING_WHITESPACE)
if (OpenMP_ROOT)
set(OpenMP_ROOT "${OpenMP_ROOT}:${HOMEBREW_PREFIX}/opt/libomp")
else()
set(OpenMP_ROOT "${HOMEBREW_PREFIX}/opt/libomp")
endif()
endif()
find_package(OpenMP)
if(OpenMP_CXX_FOUND)
target_link_libraries(idaklu PRIVATE OpenMP::OpenMP_CXX)
endif()

set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} ${PROJECT_SOURCE_DIR})
# Sundials
find_package(SUNDIALS REQUIRED)
Expand Down
2 changes: 1 addition & 1 deletion all_contributors.md
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ Thanks goes to these wonderful people ([emoji key](https://allcontributors.org/d
<td align="center" valign="top" width="14.28%"><a href="https://github.com/Agnik7"><img src="https://avatars.githubusercontent.com/u/77234005?v=4?s=100" width="100px;" alt="Agnik Bakshi"/><br /><sub><b>Agnik Bakshi</b></sub></a><br /><a href="https://github.com/pybamm-team/PyBaMM/commits?author=Agnik7" title="Documentation">📖</a></td>
<td align="center" valign="top" width="14.28%"><a href="https://github.com/RuiheLi"><img src="https://avatars.githubusercontent.com/u/84007676?v=4?s=100" width="100px;" alt="RuiheLi"/><br /><sub><b>RuiheLi</b></sub></a><br /><a href="https://github.com/pybamm-team/PyBaMM/commits?author=RuiheLi" title="Code">💻</a> <a href="https://github.com/pybamm-team/PyBaMM/commits?author=RuiheLi" title="Tests">⚠️</a></td>
<td align="center" valign="top" width="14.28%"><a href="https://github.com/chmabaur"><img src="https://avatars.githubusercontent.com/u/127507466?v=4?s=100" width="100px;" alt="chmabaur"/><br /><sub><b>chmabaur</b></sub></a><br /><a href="https://github.com/pybamm-team/PyBaMM/issues?q=author%3Achmabaur" title="Bug reports">🐛</a> <a href="https://github.com/pybamm-team/PyBaMM/commits?author=chmabaur" title="Code">💻</a></td>
<td align="center" valign="top" width="14.28%"><a href="https://github.com/AbhishekChaudharii"><img src="https://avatars.githubusercontent.com/u/91185083?v=4?s=100" width="100px;" alt="Abhishek Chaudhari"/><br /><sub><b>Abhishek Chaudhari</b></sub></a><br /><a href="https://github.com/pybamm-team/PyBaMM/commits?author=AbhishekChaudharii" title="Documentation">📖</a> <a href="https://github.com/pybamm-team/PyBaMM/commits?author=AbhishekChaudharii" title="Code">💻</a></td>
<td align="center" valign="top" width="14.28%"><a href="https://github.com/AbhishekChaudharii"><img src="https://avatars.githubusercontent.com/u/91185083?v=4?s=100" width="100px;" alt="Abhishek Chaudhari"/><br /><sub><b>Abhishek Chaudhari</b></sub></a><br /><a href="https://github.com/pybamm-team/PyBaMM/commits?author=AbhishekChaudharii" title="Documentation">📖</a> <a href="https://github.com/pybamm-team/PyBaMM/commits?author=AbhishekChaudharii" title="Code">💻</a> <a href="https://github.com/pybamm-team/PyBaMM/commits?author=AbhishekChaudharii" title="Tests">⚠️</a></td>
<td align="center" valign="top" width="14.28%"><a href="https://github.com/shubhambhar007"><img src="https://avatars.githubusercontent.com/u/32607282?v=4?s=100" width="100px;" alt="Shubham Bhardwaj"/><br /><sub><b>Shubham Bhardwaj</b></sub></a><br /><a href="#infra-shubhambhar007" title="Infrastructure (Hosting, Build-Tools, etc)">🚇</a></td>
<td align="center" valign="top" width="14.28%"><a href="https://github.com/jlauber18"><img src="https://avatars.githubusercontent.com/u/28939653?v=4?s=100" width="100px;" alt="Jonathan Lauber"/><br /><sub><b>Jonathan Lauber</b></sub></a><br /><a href="#infra-jlauber18" title="Infrastructure (Hosting, Build-Tools, etc)">🚇</a></td>
</tr>
Expand Down
7 changes: 7 additions & 0 deletions docs/source/api/models/lithium_ion/ecm_split_ocv.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
Equivalent Circuit Model with Split OCV (SplitOCVR)
=====================================================

.. autoclass:: pybamm.lithium_ion.SplitOCVR
:members:

.. footbibliography::
1 change: 1 addition & 0 deletions docs/source/api/models/lithium_ion/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -12,3 +12,4 @@ Lithium-ion Models
msmr
yang2017
electrode_soh
ecm_split_ocv
57 changes: 57 additions & 0 deletions examples/scripts/multiprocess_jax_solver.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
import pybamm
import time
import numpy as np


# This script provides an example for massively vectorised
# model solves using the JAX BDF solver. First,
# we set up the model and process parameters
model = pybamm.lithium_ion.SPM()
model.convert_to_format = "jax"
model.events = [] # remove events (not supported in jax)
geometry = model.default_geometry
param = pybamm.ParameterValues("Chen2020")
param.update({"Current function [A]": "[input]"})
param.process_geometry(geometry)
param.process_model(model)

# Discretise and setup solver
mesh = pybamm.Mesh(geometry, model.default_submesh_types, model.default_var_pts)
disc = pybamm.Discretisation(mesh, model.default_spatial_methods)
disc.process_model(model)
t_eval = np.linspace(0, 3600, 100)
solver = pybamm.JaxSolver(atol=1e-6, rtol=1e-6, method="BDF")

# Set number of vectorised solves
values = np.linspace(0.01, 1.0, 1000)
inputs = [{"Current function [A]": value} for value in values]

# Run solve for all inputs, with a just-in-time compilation
# occurring on the first solve. All sequential solves will
# use the compiled code, with a large performance improvement.
start_time = time.time()
sol = solver.solve(model, t_eval, inputs=inputs)
print(f"Time taken: {time.time() - start_time}") # 1.3s

# Rerun the vectorised solve, showing performance improvement
start_time = time.time()
compiled_sol = solver.solve(model, t_eval, inputs=inputs)
print(f"Compiled time taken: {time.time() - start_time}") # 0.42s

# Plot one of the solves
plot = pybamm.QuickPlot(
sol[5],
[
"Negative particle concentration [mol.m-3]",
"Electrolyte concentration [mol.m-3]",
"Positive particle concentration [mol.m-3]",
"Current [A]",
"Negative electrode potential [V]",
"Electrolyte potential [V]",
"Positive electrode potential [V]",
"Voltage [V]",
],
time_unit="seconds",
spatial_unit="um",
)
plot.dynamic_plot()
2 changes: 1 addition & 1 deletion noxfile.py
Original file line number Diff line number Diff line change
Expand Up @@ -222,7 +222,7 @@ def run_scripts(session):
# https://bitbucket.org/pybtex-devs/pybtex/issues/169/replace-pkg_resources-with
# is fixed
session.install("setuptools", silent=False)
session.install("-e", ".[all,dev]", silent=False)
session.install("-e", ".[all,dev,jax]", silent=False)
session.run("python", "-m", "pytest", "-m", "scripts")


Expand Down
3 changes: 0 additions & 3 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -281,6 +281,3 @@ module = [
"pybamm.models.full_battery_models.base_battery_model.*"
]
disable_error_code = "attr-defined"

[tool.poetry.scripts]
post-install = "scripts.post_install:run"
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,9 @@
from .Yang2017 import Yang2017
from .mpm import MPM
from .msmr import MSMR
from .basic_splitOCVR import SplitOCVR

__all__ = ['Yang2017', 'base_lithium_ion_model', 'basic_dfn',
'basic_dfn_composite', 'basic_dfn_half_cell', 'basic_spm', 'dfn',
'electrode_soh', 'electrode_soh_half_cell', 'mpm', 'msmr',
'newman_tobias', 'spm', 'spme']
'newman_tobias', 'spm', 'spme', 'basic_splitOCVR']
100 changes: 100 additions & 0 deletions src/pybamm/models/full_battery_models/lithium_ion/basic_splitOCVR.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,100 @@
#
# Equivalent Circuit Model with split OCV
#
import pybamm


class SplitOCVR(pybamm.BaseModel):
"""Basic Equivalent Circuit Model that uses two OCV functions
for each electrode. This model is easily parameterizable with minimal parameters.
This class differs from the :class: pybamm.equivalent_circuit.Thevenin() due
to dual OCV functions to make up the voltage from each electrode.
Parameters
----------
name: str, optional
The name of the model.
"""

def __init__(self, name="ECM with split OCV"):
super().__init__(name)

######################
# Variables
######################
# All variables are only time-dependent
# No domain definition needed

theta_n = pybamm.Variable("Negative particle stoichiometry")
theta_p = pybamm.Variable("Positive particle stoichiometry")
Q = pybamm.Variable("Discharge capacity [A.h]")
V = pybamm.Variable("Voltage [V]")

# model is isothermal
I = pybamm.FunctionParameter("Current function [A]", {"Time [s]": pybamm.t})

# Capacity equation
self.rhs[Q] = I / 3600
self.initial_conditions[Q] = pybamm.Scalar(0)

# Capacity in each electrode
Q_n = pybamm.Parameter("Negative electrode capacity [A.h]")
Q_p = pybamm.Parameter("Positive electrode capacity [A.h]")

# State of charge electrode equations
theta_n_0 = pybamm.Parameter("Negative electrode initial stoichiometry")
theta_p_0 = pybamm.Parameter("Positive electrode initial stoichiometry")
self.rhs[theta_n] = -I / Q_n / 3600
self.rhs[theta_p] = I / Q_p / 3600
self.initial_conditions[theta_n] = theta_n_0
self.initial_conditions[theta_p] = theta_p_0

# Resistance for IR expression
R = pybamm.Parameter("Ohmic resistance [Ohm]")

# Open-circuit potential for each electrode
Un = pybamm.FunctionParameter(
"Negative electrode OCP [V]", {"Negative particle stoichiometry": theta_n}
)
Up = pybamm.FunctionParameter(
"Positive electrode OCP [V]", {"Positive particle stoichiometry": theta_p}
)

# Voltage expression
V = Up - Un - I * R

# Parameters for Voltage cutoff
voltage_high_cut = pybamm.Parameter("Upper voltage cut-off [V]")
voltage_low_cut = pybamm.Parameter("Lower voltage cut-off [V]")

self.variables = {
"Negative particle stoichiometry": theta_n,
"Positive particle stoichiometry": theta_p,
"Current [A]": I,
"Discharge capacity [A.h]": Q,
"Voltage [V]": V,
"Times [s]": pybamm.t,
"Positive electrode OCP [V]": Up,
"Negative electrode OCP [V]": Un,
"Current function [A]": I,
}

# Events specify points at which a solution should terminate
self.events += [
pybamm.Event("Minimum voltage [V]", V - voltage_low_cut),
pybamm.Event("Maximum voltage [V]", voltage_high_cut - V),
pybamm.Event("Maximum Negative Electrode stoichiometry", 0.999 - theta_n),
pybamm.Event("Maximum Positive Electrode stoichiometry", 0.999 - theta_p),
pybamm.Event("Minimum Negative Electrode stoichiometry", theta_n - 0.0001),
pybamm.Event("Minimum Positive Electrode stoichiometry", theta_p - 0.0001),
]

@property
def default_quick_plot_variables(self):
return [
"Voltage [V]",
["Negative particle stoichiometry", "Positive particle stoichiometry"],
"Negative electrode OCP [V]",
"Positive electrode OCP [V]",
"Current [A]",
]
16 changes: 7 additions & 9 deletions src/pybamm/parameters/parameter_values.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,15 +35,7 @@ class ParameterValues:
"""

def __init__(self, values, chemistry=None):
if chemistry is not None:
raise ValueError(
"The 'chemistry' keyword argument has been deprecated. "
"Call `ParameterValues` with a dictionary dictionary of "
"parameter values, or the name of a parameter set (string), "
"as the single argument, e.g. `ParameterValues('Chen2020')`.",
)

def __init__(self, values):
# add physical constants as default values
self._dict_items = pybamm.FuzzyDict(
{
Expand Down Expand Up @@ -930,3 +922,9 @@ def print_evaluated_parameters(self, evaluated_parameters, output_file):
file.write((s + " : {:10.4g}\n").format(name, value))
else:
file.write((s + " : {:10.3E}\n").format(name, value))

def __contains__(self, key):
return key in self._dict_items

def __iter__(self):
return iter(self._dict_items)
Loading

0 comments on commit ad0faa1

Please sign in to comment.