Skip to content

Commit

Permalink
Resolve conflicts
Browse files Browse the repository at this point in the history
  • Loading branch information
Saransh-cpp committed Jul 24, 2023
2 parents a7dedf1 + cb38ed5 commit 901cf5d
Show file tree
Hide file tree
Showing 10 changed files with 189 additions and 197 deletions.
4 changes: 2 additions & 2 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@ repos:
hooks:
- id: black

- repo: https://github.com/charliermarsh/ruff-pre-commit
rev: "v0.0.260"
- repo: https://github.com/astral-sh/ruff-pre-commit
rev: "v0.0.276"
hooks:
- id: ruff
args: [--ignore=E741, --exclude=__init__.py]
18 changes: 17 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,23 @@

- ([#PR](link))

# [v0.3.5](https://github.com/pybamm-team/liionpack/) - 2023-04-05
# [v0.3.7](https://github.com/pybamm-team/liionpack/tree/v0.3.7) - 2023-07-05


## Bug fixes

- Update to PyBaMM 23.5 with small chages to protocols ([#265](https://github.com/pybamm-team/liionpack/pull/265))


# [v0.3.6](https://github.com/pybamm-team/liionpack/tree/v0.3.6) - 2023-05-26


## Bug fixes

- Fix a RunTimeError introduced by change to latest version of casadi that PyBaMM now supports. Solution returned by casadi no longer contains initial state. ([#259](https://github.com/pybamm-team/liionpack/pull/259))


# [v0.3.5](https://github.com/pybamm-team/liionpack/tree/v0.3.5) - 2023-04-05

## Features

Expand Down
144 changes: 24 additions & 120 deletions docs/examples/03 Experiments.ipynb

Large diffs are not rendered by default.

117 changes: 60 additions & 57 deletions docs/examples/05 Drive cycles.ipynb

Large diffs are not rendered by default.

3 changes: 2 additions & 1 deletion environment.yml
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,11 @@ dependencies:
- sympy
- pip
- pip:
- pybamm>=23.3
- pybamm>=23.5
- ipdb
- ruff
- mkdocstrings-python-legacy
- mkdocs-material
- mkdocs-jupyter
- nbconvert
- -e .
70 changes: 70 additions & 0 deletions examples/mixed_capacity.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
"""
Example of running a simulation with batteries of different size.
"""

import liionpack as lp
import pybamm
import numpy as np

lp.logger.setLevel("NOTICE")

# Define parameters
Np = 2
Ns = 3
Iapp = 10

# Generate the netlist and output variables
netlist = lp.setup_circuit(
Np=Np,
Ns=Ns,
Rb=1.5e-3,
Rc=1e-2,
Ri=5e-2,
V=4.0,
I=Iapp,
configuration="series-groups",
)

lp.draw_circuit(netlist)

# Cycling experiment
experiment = pybamm.Experiment(
[
f"Discharge at {Iapp} A for 30 minutes",
"Rest for 30 minutes",
],
period="10 seconds",
)

# PyBaMM parameters
param = pybamm.ParameterValues("Chen2020")

w_original = param["Electrode width [m]"]

param.update(
{
"Electrode width [m]": "[input]",
}
)

new_widths = np.ones(Np * Ns) * w_original

# Divide the capacity by 2 for 1 half of the batteries
new_widths[:3] = w_original / 2

inputs = {
"Electrode width [m]": new_widths,
}

# Solve pack
output = lp.solve(
netlist=netlist,
parameter_values=param,
experiment=experiment,
initial_soc=None,
inputs=inputs,
)

# Plot results
lp.plot_output(output)
lp.show_plots()
17 changes: 8 additions & 9 deletions liionpack/protocols.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,26 +19,25 @@ def generate_protocol_from_experiment(experiment, flatten=True):
"""
protocol = []
for i, op in enumerate(experiment.operating_conditions):
for i, step in enumerate(experiment.operating_conditions_steps):
proto = []
t = op["time"]
dt = op["period"]
t = step.duration
dt = step.period
if t % dt != 0:
raise ValueError("Time must be an integer multiple of the period")
typ = op["type"]
typ = step.type
if typ not in ["current"]:
raise ValueError("Only constant current operations are supported")
else:
if typ == "current":
if "Current input [A]" in op.keys():
I = op["Current input [A]"]
if not step.is_drive_cycle:
I = step.value
proto.extend([I] * int(t / dt))
if i == 0:
# Include initial state when not drive cycle, first op
proto = [proto[0]] + proto
elif "dc_data" in op.keys():
dc_data = op["dc_data"]
proto.extend(dc_data[:, 1].tolist())
else:
proto.extend(step.value.y.tolist())

if flatten:
protocol.extend(proto)
Expand Down
6 changes: 3 additions & 3 deletions liionpack/solver_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ def _serial_step(model, solutions, inputs_dict, integrator, variables, t_eval, e
ninputs = len(temp.values())
# Call the integrator once, with the grid
casadi_sol = integrator(x0=x0, z0=z0, p=inputs)
xf = casadi_sol["xf"]
xf = casadi.horzcat(x0, casadi_sol["xf"])
zf = casadi_sol["zf"]
if zf.is_empty():
y_sol = xf
Expand Down Expand Up @@ -215,15 +215,15 @@ def _mapped_step(model, solutions, inputs_dict, integrator, variables, t_eval, e
tic = timer.time()
casadi_sol = integrator(x0=x0, z0=z0, p=inputs)
integration_time = timer.time()
nt = len(t_eval)
nt = len(t_eval[1:])
xf = casadi_sol["xf"]
zf = casadi_sol["zf"]
sol = []
xend = []
events_eval = []
for i in range(N):
start = i * nt
y_diff = xf[:, start : start + nt]
y_diff = casadi.horzcat(x0[:, i], xf[:, start : start + nt])
if zf.is_empty():
y_sol = y_diff
else:
Expand Down
3 changes: 2 additions & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -35,13 +35,14 @@ dependencies = [
"openpyxl",
"pandas",
"plotly",
"pybamm>=23.3",
"pybamm>=23.5",
"ray",
"redis",
"scikit-spatial",
"scipy",
"textwrapper",
"tqdm",
"nbconvert",
]
dynamic = [
"version",
Expand Down
4 changes: 1 addition & 3 deletions tests/unit/test_protocols.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,9 +41,7 @@ def test_generate_protocol_from_drive_cycle(self):
).to_numpy()

experiment = pybamm.Experiment(
operating_conditions=["Run US06 (A)"],
period="1 minute",
drive_cycles={"US06": drive_cycle},
[pybamm.step.current(drive_cycle)], period="1 second"
)
p = lp.generate_protocol_from_experiment(experiment)
assert len(p) == 601
Expand Down

0 comments on commit 901cf5d

Please sign in to comment.