Skip to content

Commit

Permalink
Merge pull request #48 from CADLabs/before_subset_fix
Browse files Browse the repository at this point in the history
before_subset() hook fix for params argument
  • Loading branch information
BenSchZA authored Jun 14, 2022
2 parents fe7f641 + 6348be3 commit c084625
Show file tree
Hide file tree
Showing 5 changed files with 23 additions and 43 deletions.
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,12 @@ All notable changes to this project will be documented in this file.
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

## [0.9.0] - 2022-06-14
### Changed
- `Context` passed to `before_subset(context)` hook will now correctly receive a single parameter subset and not all subsets
- This could be a breaking change for anyone that relied on the `before_subset()` hook - the `before_run()` hook will still receive all subsets, as at that point of simulation the specific subset is unknown
- See "NOTE" in `engine.py`: Each parameter is a list of all subsets in before_run() method and a single subset in before_subset()

## [0.8.4] - 2021-09-04
### Added
= Overide for `__deepcopy__` method of Executable class to enable deepcopy after a simulation/experiment has been run
Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[tool.poetry]
name = "radcad"
version = "0.8.4"
version = "0.9.0"
description = "A Python package for dynamical systems modelling & simulation, inspired by and compatible with cadCAD"
authors = ["CADLabs <[email protected]>"]
packages = [
Expand Down
2 changes: 1 addition & 1 deletion radcad/__init__.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
__version__ = "0.8.4"
__version__ = "0.9.0"

from radcad.wrappers import Context, Model, Simulation, Experiment
from radcad.engine import Engine
Expand Down
1 change: 0 additions & 1 deletion radcad/core.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import copy
from functools import reduce, partial
import logging
import pickle
Expand Down
55 changes: 15 additions & 40 deletions radcad/engine.py
Original file line number Diff line number Diff line change
Expand Up @@ -109,63 +109,38 @@ def _run_stream(self, configs):

# NOTE Hook allows mutation of RunArgs
for run_index in range(0, runs):
if param_sweep:
context = wrappers.Context(
simulation_index,
run_index,
None,
timesteps,
initial_state,
params # NOTE Each parameter is a list of all subsets in before_run() method and a single subset in before_subset()
)
self.executable._before_run(context=context)
for subset_index, param_set in enumerate(param_sweep if param_sweep else [params]):
context = wrappers.Context(
simulation_index,
run_index,
None,
subset_index,
timesteps,
initial_state,
params
param_set
)
self.executable._before_run(context=context)
for subset_index, param_set in enumerate(param_sweep):
context = wrappers.Context(
simulation_index,
run_index,
subset_index,
timesteps,
initial_state,
params
)
self.executable._before_subset(context=context)
yield wrappers.RunArgs(
simulation_index,
timesteps,
run_index,
subset_index,
copy.deepcopy(initial_state),
state_update_blocks,
copy.deepcopy(param_set),
self.deepcopy,
self.drop_substeps,
)
self.executable._after_subset(context=context)
self.executable._after_run(context=context)
else:
context = wrappers.Context(
simulation_index,
run_index,
0,
timesteps,
initial_state,
params
)
self.executable._before_run(context=context)
self.executable._before_subset(context=context)
yield wrappers.RunArgs(
simulation_index,
timesteps,
run_index,
0,
subset_index,
copy.deepcopy(initial_state),
state_update_blocks,
copy.deepcopy(params),
copy.deepcopy(param_set),
self.deepcopy,
self.drop_substeps,
)
self.executable._after_subset(context=context)
self.executable._after_run(context=context)
self.executable._after_run(context=context)

self.executable._after_simulation(
simulation=simulation
Expand Down

0 comments on commit c084625

Please sign in to comment.