Skip to content

Commit

Permalink
#1329 Rob and Ferran comments
Browse files Browse the repository at this point in the history
  • Loading branch information
valentinsulzer committed Jan 21, 2021
1 parent f4ea0e7 commit 2542734
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 13 deletions.
3 changes: 2 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,8 @@

## Optimizations

- If solver method `solve()` is passed a list of inputs as the `inputs` keyword argument, the resolution of the model for each input set is spread acrosss several Python processes, usually running in parallel on different processors. The default number of processes is the number of processors available. `solve()` takes a new keyword argument `nproc` which can be used to set this number a manually.
- The `Solution` class now only creates the concatenated `y` when the user asks for it. This is an optimization step as the concatenation can be slow, especially with larger experiments ([#1331](https://github.com/pybamm-team/PyBaMM/pull/1331))
- If solver method `solve()` is passed a list of inputs as the `inputs` keyword argument, the resolution of the model for each input set is spread across several Python processes, usually running in parallel on different processors. The default number of processes is the number of processors available. `solve()` takes a new keyword argument `nproc` which can be used to set this number a manually.
- Variables are now post-processed using CasADi ([#1316](https://github.com/pybamm-team/PyBaMM/pull/1316))
- Operations such as `1*x` and `0+x` now directly return `x` ([#1252](https://github.com/pybamm-team/PyBaMM/pull/1252))

Expand Down
18 changes: 9 additions & 9 deletions pybamm/simulation.py
Original file line number Diff line number Diff line change
Expand Up @@ -443,7 +443,7 @@ def solve(self, t_eval=None, solver=None, check_model=True, **kwargs):
pybamm.logger.info("Start running experiment")
timer = pybamm.Timer()

phases = []
steps = []
for idx, (exp_inputs, dt) in enumerate(
zip(self._experiment_inputs, self._experiment_times)
):
Expand All @@ -454,13 +454,13 @@ def solve(self, t_eval=None, solver=None, check_model=True, **kwargs):
npts = max(int(round(dt / exp_inputs["period"])) + 1, 2)
self.step(dt, solver=solver, npts=npts, **kwargs)

# Extract the new parts of the solution to construct the entire "phase"
# Extract the new parts of the solution to construct the entire "step"
sol = self.solution
new_num_subsolutions = len(sol.sub_solutions)
diff_num_subsolutions = new_num_subsolutions - previous_num_subsolutions
previous_num_subsolutions = new_num_subsolutions

phase_solution = pybamm.Solution(
step_solution = pybamm.Solution(
sol.all_ts[-diff_num_subsolutions:],
sol.all_ys[-diff_num_subsolutions:],
sol.model,
Expand All @@ -469,9 +469,9 @@ def solve(self, t_eval=None, solver=None, check_model=True, **kwargs):
sol.y_event,
sol.termination,
)
phase_solution.solve_time = 0
phase_solution.integration_time = 0
phases.append(phase_solution)
step_solution.solve_time = 0
step_solution.integration_time = 0
steps.append(step_solution)
# Only allow events specified by experiment
if not (
self._solution.termination == "final time"
Expand All @@ -493,10 +493,10 @@ def solve(self, t_eval=None, solver=None, check_model=True, **kwargs):
self.solution.cycles = []
for cycle_num, cycle_length in enumerate(self.experiment.cycle_lengths):
cycle_start_idx = sum(self.experiment.cycle_lengths[0:cycle_num])
cycle_solution = phases[cycle_start_idx]
cycle_solution = steps[cycle_start_idx]
for idx in range(cycle_length - 1):
cycle_solution = cycle_solution + phases[cycle_start_idx + idx + 1]
cycle_solution.phases = phases[
cycle_solution = cycle_solution + steps[cycle_start_idx + idx + 1]
cycle_solution.steps = steps[
cycle_start_idx : cycle_start_idx + cycle_length
]
self.solution.cycles.append(cycle_solution)
Expand Down
5 changes: 2 additions & 3 deletions pybamm/solvers/solution.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,8 @@

class Solution(object):
"""
(Semi-private) class containing the solution of, and various attributes associated
with, a PyBaMM model. This class is automatically created by the `Solution` class,
and should never be called from outside the `Solution` class.
Class containing the solution of, and various attributes associated with, a PyBaMM
model.
Parameters
----------
Expand Down

0 comments on commit 2542734

Please sign in to comment.