diff --git a/neurolib/optimize/exploration/exploration.py b/neurolib/optimize/exploration/exploration.py index 717577f4..c39db0b4 100644 --- a/neurolib/optimize/exploration/exploration.py +++ b/neurolib/optimize/exploration/exploration.py @@ -281,6 +281,8 @@ def getModelFromTraj(self, traj): """ model = self.model runParams = self.getParametersFromTraj(traj) + if self.parameterSpace.star: + runParams = flatten_nested_dict(flat_dict_to_nested(runParams)["parameters"]) model.params.update(runParams) return model diff --git a/neurolib/utils/stimulus.py b/neurolib/utils/stimulus.py index 60febf7f..8e72e57e 100644 --- a/neurolib/utils/stimulus.py +++ b/neurolib/utils/stimulus.py @@ -80,9 +80,20 @@ def update_params(self, params_dict): :param params_dict: New parameters for this input :type params_dict: dict """ + + def _sanitize(value): + """ + Change string `None` to actual None - can happen with Exploration or + Evolution, since `pypet` does None -> "None". + """ + if value == "None": + return None + else: + return value + for param, value in params_dict.items(): if hasattr(self, param): - setattr(self, param, value) + setattr(self, param, _sanitize(value)) def _get_times(self, duration, dt): """ diff --git a/tests/test_exploration.py b/tests/test_exploration.py index 68bc8464..b20c648a 100644 --- a/tests/test_exploration.py +++ b/tests/test_exploration.py @@ -20,7 +20,7 @@ def randomString(stringLength=10): - """Generate a random string of fixed length """ + """Generate a random string of fixed length""" letters = string.ascii_lowercase return "".join(random.choice(letters) for i in range(stringLength)) diff --git a/tests/test_stimulus.py b/tests/test_stimulus.py index 7ccbec76..82ad5ca1 100644 --- a/tests/test_stimulus.py +++ b/tests/test_stimulus.py @@ -238,7 +238,7 @@ def test_set_params(self): n=2, seed=42, ) - UPDATE = {"amplitude": 43.0, "seed": 12} + UPDATE = {"amplitude": 43.0, "seed": 12, "start": "None"} sin.update_params(UPDATE) params = sin.get_params() params.pop("type") @@ -249,10 +249,10 @@ def test_set_params(self): "seed": 42, "frequency": self.FREQUENCY, "amplitude": self.AMPLITUDE, - "start": STIM_START, "dc_bias": False, "end": STIM_END, **UPDATE, + "start": None, }, ) @@ -318,7 +318,7 @@ def test_set_params(self): n=2, seed=42, ) - UPDATE = {"amplitude": 43.0, "seed": 12} + UPDATE = {"amplitude": 43.0, "seed": 12, "start": "None"} sq.update_params(UPDATE) params = sq.get_params() params.pop("type") @@ -329,10 +329,10 @@ def test_set_params(self): "seed": 42, "frequency": self.FREQUENCY, "amplitude": self.AMPLITUDE, - "start": STIM_START, "end": STIM_END, "dc_bias": False, **UPDATE, + "start": None, }, )