Skip to content

Commit

Permalink
#3176 fix failing tests
Browse files Browse the repository at this point in the history
  • Loading branch information
brosaplanella committed Aug 10, 2023
1 parent 7ebb1e2 commit af9e45a
Show file tree
Hide file tree
Showing 2 changed files with 0 additions and 96 deletions.
43 changes: 0 additions & 43 deletions pybamm/simulation.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,6 @@
import pybamm
import numpy as np
import copy
import warnings
import sys
from functools import lru_cache
from datetime import timedelta
import tqdm
Expand Down Expand Up @@ -541,47 +539,6 @@ def solve(
"\tsim.solve([0, 3700])\n\n"
"for a 1C discharge."
)
# For drive cycles (current provided as data) we perform additional
# tests on t_eval (if provided) to ensure the returned solution
# captures the input.
time_data = self._parameter_values["Current function [A]"].x[0]
# If no t_eval is provided, we use the times provided in the data.
if t_eval is None:
pybamm.logger.info("Setting t_eval as specified by the data")
t_eval = time_data
# If t_eval is provided we first check if it contains all of the
# times in the data to within 10-12. If it doesn't, we then check
# that the largest gap in t_eval is smaller than the smallest gap in
# the time data (to ensure the resolution of t_eval is fine enough).
# We only raise a warning here as users may genuinely only want
# the solution returned at some specified points.
elif (
set(np.round(time_data, 12)).issubset(set(np.round(t_eval, 12)))
) is False:
warnings.warn(
"""
t_eval does not contain all of the time points in the data
set. Note: passing t_eval = None automatically sets t_eval
to be the points in the data.
""",
pybamm.SolverWarning,
)
dt_data_min = np.min(np.diff(time_data))
dt_eval_max = np.max(np.diff(t_eval))
if dt_eval_max > dt_data_min + sys.float_info.epsilon:
warnings.warn(
"""
The largest timestep in t_eval ({}) is larger than
the smallest timestep in the data ({}). The returned
solution may not have the correct resolution to accurately
capture the input. Try refining t_eval. Alternatively,
passing t_eval = None automatically sets t_eval to be the
points in the data.
""".format(
dt_eval_max, dt_data_min
),
pybamm.SolverWarning,
)

self._solution = solver.solve(self.built_model, t_eval, **kwargs)

Expand Down
53 changes: 0 additions & 53 deletions tests/unit/test_simulation.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import pybamm
import numpy as np
import pandas as pd
from tests import TestCase
import os
import sys
Expand Down Expand Up @@ -184,20 +183,6 @@ def test_solve_with_initial_soc(self):
sim.solve(initial_soc=0.8)
self.assertEqual(sim._built_initial_soc, 0.8)

# test with drive cycle
drive_cycle = pd.read_csv(
os.path.join("pybamm", "input", "drive_cycles", "US06.csv"),
comment="#",
header=None,
).to_numpy()
current_interpolant = pybamm.Interpolant(
drive_cycle[:, 0], drive_cycle[:, 1], pybamm.t
)
param["Current function [A]"] = current_interpolant
sim = pybamm.Simulation(model, parameter_values=param)
sim.solve(initial_soc=0.8)
self.assertEqual(sim._built_initial_soc, 0.8)

# Test that build works with initial_soc
sim = pybamm.Simulation(model, parameter_values=param)
sim.build(initial_soc=0.5)
Expand Down Expand Up @@ -345,44 +330,6 @@ def test_create_gif(self):

os.remove("plot.gif")

def test_drive_cycle_interpolant(self):
model = pybamm.lithium_ion.SPM()
param = model.default_parameter_values
# Import drive cycle from file
drive_cycle = pd.read_csv(
pybamm.get_parameters_filepath(
os.path.join("input", "drive_cycles", "US06.csv")
),
comment="#",
skip_blank_lines=True,
header=None,
).to_numpy()

current_interpolant = pybamm.Interpolant(
drive_cycle[:, 0], drive_cycle[:, 1], pybamm.t
)

param["Current function [A]"] = current_interpolant

time_data = drive_cycle[:, 0]

sim = pybamm.Simulation(model, parameter_values=param)

# check solution is returned at the times in the data
sim.solve()
np.testing.assert_array_almost_equal(sim.solution.t, time_data)

# check warning raised if the largest gap in t_eval is bigger than the
# smallest gap in the data
with self.assertWarns(pybamm.SolverWarning):
sim.solve(t_eval=np.linspace(0, 10, 3))

# check warning raised if t_eval doesnt contain time_data , but has a finer
# resolution (can still solve, but good for users to know they dont have
# the solution returned at the data points)
with self.assertWarns(pybamm.SolverWarning):
sim.solve(t_eval=np.linspace(0, time_data[-1], 800))

def test_discontinuous_current(self):
def car_current(t):
current = (
Expand Down

0 comments on commit af9e45a

Please sign in to comment.