From 61021599a7b54b906d358cfcae3cd2b4ccbd6001 Mon Sep 17 00:00:00 2001 From: Steve Bachmeier <23350991+stevebachmeier@users.noreply.github.com> Date: Thu, 20 Jun 2024 14:43:27 -0600 Subject: [PATCH] stop writing seed/draw to simulation results (#436) * stop writing seed/draw to simulation results * pin numpy<2.0.0 --- src/vivarium/framework/results/observer.py | 10 ---------- tests/framework/results/helpers.py | 13 ++++--------- tests/framework/results/test_observer.py | 12 ++++-------- tests/framework/test_engine.py | 3 --- 4 files changed, 8 insertions(+), 30 deletions(-) diff --git a/src/vivarium/framework/results/observer.py b/src/vivarium/framework/results/observer.py index 463e9074b..6a3aef36c 100644 --- a/src/vivarium/framework/results/observer.py +++ b/src/vivarium/framework/results/observer.py @@ -16,8 +16,6 @@ class Observer(Component, ABC): def __init__(self) -> None: super().__init__() self.results_dir = None - self.input_draw = None - self.random_seed = None @abstractmethod def register_observations(self, builder: Builder) -> None: @@ -36,14 +34,6 @@ def get_formatter_attributes(self, builder: Builder) -> None: .get("output_data", {}) .get("results_directory", None) ) - self.input_draw = ( - builder.configuration.to_dict() - .get("input_data", {}) - .get("input_draw_number", None) - ) - self.random_seed = ( - builder.configuration.to_dict().get("randomness", {}).get("random_seed", None) - ) class StratifiedObserver(Observer): diff --git a/tests/framework/results/helpers.py b/tests/framework/results/helpers.py index fc7e30fa9..e32b607ce 100644 --- a/tests/framework/results/helpers.py +++ b/tests/framework/results/helpers.py @@ -1,5 +1,4 @@ import itertools -from functools import partial from typing import List import numpy as np @@ -122,7 +121,7 @@ def register_observations(self, builder: Builder) -> None: requires_columns=[ "house_points", ], - results_formatter=partial(formatter, self.random_seed, self.input_draw), + results_formatter=results_formatter, ) @@ -154,7 +153,7 @@ def register_observations(self, builder: Builder) -> None: requires_columns=[ "quidditch_wins", ], - results_formatter=partial(formatter, self.random_seed, self.input_draw), + results_formatter=results_formatter, ) @@ -170,7 +169,7 @@ def register_observations(self, builder: Builder) -> None: requires_columns=[ "quidditch_wins", ], - results_formatter=partial(formatter, self.random_seed, self.input_draw), + results_formatter=results_formatter, ) @@ -266,17 +265,13 @@ def setup(self, builder: Builder) -> None: ################## -def formatter( - random_seed: str, - input_draw: str, +def results_formatter( measure: str, results: pd.DataFrame, ) -> pd.DataFrame: """An test use case of an observer's report method that writes a DataFrame to a CSV file.""" # Add extra cols results["measure"] = measure - results["random_seed"] = random_seed - results["input_draw"] = input_draw # Sort the columns such that the stratifications (index) are first # and VALUE_COLUMN is last and sort the rows by the stratifications. other_cols = [c for c in results.columns if c != VALUE_COLUMN] diff --git a/tests/framework/results/test_observer.py b/tests/framework/results/test_observer.py index e5d979787..41f190e9d 100644 --- a/tests/framework/results/test_observer.py +++ b/tests/framework/results/test_observer.py @@ -29,13 +29,13 @@ def test_observer_instantiation(): @pytest.mark.parametrize( - "is_interactive, results_dir, draw, seed", + "is_interactive, results_dir", [ - (False, "/some/results/dir", 111, 222), - (True, None, None, None), + (False, "/some/results/dir"), + (True, None), ], ) -def test_get_formatter_attributes(is_interactive, results_dir, draw, seed, mocker): +def test_get_formatter_attributes(is_interactive, results_dir, mocker): builder = mocker.Mock() if is_interactive: builder.configuration = LayeredConfigTree() @@ -43,8 +43,6 @@ def test_get_formatter_attributes(is_interactive, results_dir, draw, seed, mocke builder.configuration = LayeredConfigTree( { "output_data": {"results_directory": results_dir}, - "input_data": {"input_draw_number": draw}, - "randomness": {"random_seed": seed}, } ) @@ -52,8 +50,6 @@ def test_get_formatter_attributes(is_interactive, results_dir, draw, seed, mocke observer.get_formatter_attributes(builder) assert observer.results_dir == results_dir - assert observer.input_draw == draw - assert observer.random_seed == seed @pytest.mark.parametrize( diff --git a/tests/framework/test_engine.py b/tests/framework/test_engine.py index 201344847..8520e244e 100644 --- a/tests/framework/test_engine.py +++ b/tests/framework/test_engine.py @@ -393,9 +393,6 @@ def test_get_results_formatting(SimulationContext, base_config): df = eval(measure) # Check that metrics col matches name of dataset assert (df["measure"] == measure).all() - # Check for other cols - assert "random_seed" in df.columns - assert "input_draw" in df.columns # We do enforce a col order, but most importantly ensure VALUE_COLUMN is at the end assert df.columns[-1] == VALUE_COLUMN # Check values