Skip to content
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 @@ -12,6 +12,7 @@

## Breaking Changes

- [#857](https://github.com/pybop-team/PyBOP/pull/857) - Deprecate the custom PyBaMM model build process for a simulation without an experiment and rename `batch_solve` as `solve_batch` to align with other functions.
- [#839](https://github.com/pybop-team/PyBOP/pull/839) - Renames 'prior' as 'distribution' ``for pybop.Parameter``. Allows construction of a ``pybop.Parameter`` with a distribution of type ``scipy.stats.distributions.rv_frozen``. Removes ``margins``, ``set_bounds``, ``remove_bounds`` from ``pybop.Parameter``.

# [v25.11](https://github.com/pybop-team/PyBOP/tree/v25.11) - 2025-11-24
Expand Down
2 changes: 1 addition & 1 deletion pybop/applications/base_method.py
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ def __init__(self, ocv_value: float):
super().__init__(parameters=parameters)
self.ocv_value = ocv_value

def batch_solve(self, inputs, calculate_sensitivities: bool = False):
def solve_batch(self, inputs, calculate_sensitivities: bool = False):
solutions = []
for x in inputs:
diff = np.abs(ocv_function(x["Root"]) - self.ocv_value)
Expand Down
6 changes: 3 additions & 3 deletions pybop/applications/ocp_methods.py
Original file line number Diff line number Diff line change
Expand Up @@ -182,7 +182,7 @@ def __init__(self, parameters):

if self.allow_stretching:

def batch_solve(self, inputs, calculate_sensitivities: bool = False):
def solve_batch(self, inputs, calculate_sensitivities: bool = False):
solutions = []
for x in inputs:
sol = pybop.Solution()
Expand All @@ -203,7 +203,7 @@ def batch_solve(self, inputs, calculate_sensitivities: bool = False):
return solutions
else:

def batch_solve(self, inputs, calculate_sensitivities: bool = False):
def solve_batch(self, inputs, calculate_sensitivities: bool = False):
solutions = []
for x in inputs:
sol = pybop.Solution()
Expand Down Expand Up @@ -333,7 +333,7 @@ def __init__(self, parameters):
super().__init__(parameters=parameters)
self.domain_data = domain_data

def batch_solve(self, inputs, calculate_sensitivities: bool = False):
def solve_batch(self, inputs, calculate_sensitivities: bool = False):
solutions = []
for x in inputs:
sol = pybop.Solution()
Expand Down
2 changes: 1 addition & 1 deletion pybop/problems/problem.py
Original file line number Diff line number Diff line change
Expand Up @@ -258,7 +258,7 @@ def simulate_batch(
the sensitivities dy/dx(t) for output variable(s) y, domain t and parameter(s) x.
"""
model_inputs = [self.get_model_inputs(x) for x in inputs]
return self._simulator.batch_solve(
return self._simulator.solve_batch(
inputs=model_inputs, calculate_sensitivities=calculate_sensitivities
)

Expand Down
38 changes: 23 additions & 15 deletions pybop/pybamm/eis_simulator.py
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ def __init__(
super().__init__(parameters=parameters)

# Set up a simulation
self._simulation = Simulator(
self._simulator = Simulator(
model,
parameter_values=parameter_values,
initial_state=initial_state,
Expand All @@ -100,7 +100,6 @@ def __init__(
discretisation_kwargs=discretisation_kwargs,
build_every_time=build_every_time,
)

self.debug_mode = False

# Initialise
Expand All @@ -110,7 +109,7 @@ def __init__(

v_scale = getattr(model.variables["Voltage [V]"], "scale", 1)
i_scale = getattr(model.variables["Current [A]"], "scale", 1)
self.z_scale = self._simulation.parameter_values.evaluate(v_scale / i_scale)
self.z_scale = self.parameter_values.evaluate(v_scale / i_scale)

def set_up_for_eis(self, model: pybamm.BaseModel) -> pybamm.BaseModel:
"""
Expand Down Expand Up @@ -184,8 +183,10 @@ def set_up_for_eis(self, model: pybamm.BaseModel) -> pybamm.BaseModel:

def _model_rebuild(self, inputs: "Inputs") -> None:
"""Update the parameter values and rebuild the EIS model."""
if self._simulation.requires_model_rebuild:
self._simulation.rebuild_model(inputs=inputs)
if self._simulator.requires_model_rebuild:
self.parameter_values.update(inputs)
self._simulator.create_simulation()
self.simulation.build(initial_soc=self._simulator.initial_state)
self._initialise_eis_matrices(inputs=inputs)

def _initialise_eis_matrices(self, inputs: "Inputs") -> None:
Expand All @@ -199,9 +200,9 @@ def _initialise_eis_matrices(self, inputs: "Inputs") -> None:
RuntimeError
If the model hasn't been built yet.
"""
built_model = self._simulation.built_model
M = self._simulation.built_model.mass_matrix.entries
self._simulation.solver.set_up(built_model, inputs=inputs)
built_model = self.simulation.built_model
M = built_model.mass_matrix.entries
self.simulation.solver.set_up(built_model, inputs=inputs)

# Convert inputs to casadi format if needed
casadi_inputs = (
Expand Down Expand Up @@ -254,7 +255,7 @@ def solve(

return self._catch_errors(inputs)

def batch_solve(
def solve_batch(
self, inputs: "list[Inputs]" = None, calculate_sensitivities: bool = False
) -> list[Solution | FailedSolution]:
"""
Expand Down Expand Up @@ -287,9 +288,7 @@ def _catch_errors(self, inputs: "list[Inputs]") -> list[Solution | FailedSolutio
for x in inputs:
try:
simulations.append(self._solve(x))
except (ZeroDivisionError, RuntimeError, ValueError) as e:
if isinstance(e, ValueError) and str(e) not in self.exception:
raise # Raise the error if it doesn't match the expected list
except (ZeroDivisionError, RuntimeError, ValueError):
simulations.append(
FailedSolution(["Impedance"], [k for k in x.keys()])
)
Expand Down Expand Up @@ -355,20 +354,29 @@ def calculate_impedance(self, frequency):

@property
def simulation(self):
return self._simulation
return self._simulator._simulation # noqa: SLF001

@property
def parameter_values(self):
return self._simulation.parameter_values
return self._simulator.parameter_values

@property
def input_parameter_names(self):
return self._simulation.input_parameter_names
return self._simulator.input_parameter_names

@property
def has_sensitivities(self):
return False

@property
def debug_mode(self):
return self._debug_mode

@debug_mode.setter
def debug_mode(self, value: bool):
self._debug_mode = value
self._simulator.debug_mode = value

def copy(self):
"""Return a copy of the simulation."""
return copy(self)
Loading