-
Notifications
You must be signed in to change notification settings - Fork 25
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add support for parameters dataclass (#57)
* Add support for parameter dataclasses * Update test * Update version * Update README * Update typing * Allow single value parameters * Update changelog
- Loading branch information
Showing
8 changed files
with
240 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,6 @@ | ||
[tool.poetry] | ||
name = "radcad" | ||
version = "0.11.0" | ||
version = "0.11.1" | ||
description = "A Python package for dynamical systems modelling & simulation, inspired by and compatible with cadCAD" | ||
authors = ["CADLabs <[email protected]>"] | ||
packages = [ | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
from dataclasses import dataclass | ||
from typing import List | ||
from radcad import Model, Simulation, Experiment, Backend | ||
from radcad.utils import default | ||
|
||
|
||
# NOTE To pickle a dataclass, it must be defined in module and not function scope | ||
@dataclass | ||
class P1: | ||
subset: List[int] = default([0, 1, 2]) | ||
a: List[int] = default([0, 1]) | ||
|
||
|
||
def policy(params: P1, substep, state_history, previous_state): | ||
subset = previous_state['subset'] | ||
assert subset == params.subset | ||
assert params.a == params.subset if subset < 2 else params.a == 1 | ||
return {} | ||
|
||
|
||
def test_basic_state_update(): | ||
initial_state = {} | ||
|
||
state_update_blocks = [ | ||
{ | ||
'policies': { | ||
'p': policy | ||
}, | ||
'variables': {} | ||
}, | ||
] | ||
|
||
params = P1() | ||
|
||
TIMESTEPS = 10 | ||
RUNS = 3 | ||
|
||
model = Model(initial_state=initial_state, state_update_blocks=state_update_blocks, params=params) | ||
simulation = Simulation(model=model, timesteps=TIMESTEPS, runs=RUNS) | ||
experiment = Experiment(simulation) | ||
_result = experiment.run() |