From 9bca0cb417290a4c65c7c49aaad174d8d9bb0e5e Mon Sep 17 00:00:00 2001 From: Theo Wolf Date: Thu, 22 May 2025 13:28:42 +0100 Subject: [PATCH 1/5] Make deepcopy of config before modifying --- src/rejax/algos/algorithm.py | 1 + tests/test_configs.py | 16 ++++++++++++++++ 2 files changed, 17 insertions(+) diff --git a/src/rejax/algos/algorithm.py b/src/rejax/algos/algorithm.py index 42cfa33..63d105a 100644 --- a/src/rejax/algos/algorithm.py +++ b/src/rejax/algos/algorithm.py @@ -35,6 +35,7 @@ class Algorithm(struct.PyTreeNode): @classmethod def create(cls, **config): + config = deepcopy(config) env, env_params = cls.create_env(config) agent = cls.create_agent(config, env, env_params) diff --git a/tests/test_configs.py b/tests/test_configs.py index 49248a7..1ab6615 100644 --- a/tests/test_configs.py +++ b/tests/test_configs.py @@ -31,3 +31,19 @@ def test_configs(self) -> None: f"Failed to create {algo} with config '{config_path}': " f"{type(e).__name__}: {str(e)}" ) + + def test_create_algo_with_same_config(self) -> None: + for config_path, configs_env in self.configs.items(): + for algo, config in configs_env.items(): + if config.get("env", "").startswith("navix"): + continue + with self.subTest(config_opath=config_path, algo=algo): + try: + algo_cls = get_algo(algo) + algo_cls.create(**config) + algo_cls.create(**config) + except Exception as e: + self.fail( + f"Failed to create {algo} with config '{config_path}': " + f"{type(e).__name__}: {str(e)}" + ) \ No newline at end of file From 22fd7d678e0b2cb652ebe55d8d880591a75e7ff3 Mon Sep 17 00:00:00 2001 From: Theo Wolf Date: Thu, 22 May 2025 13:38:07 +0100 Subject: [PATCH 2/5] Add line break at EOF --- tests/test_configs.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/tests/test_configs.py b/tests/test_configs.py index 1ab6615..c49539c 100644 --- a/tests/test_configs.py +++ b/tests/test_configs.py @@ -46,4 +46,5 @@ def test_create_algo_with_same_config(self) -> None: self.fail( f"Failed to create {algo} with config '{config_path}': " f"{type(e).__name__}: {str(e)}" - ) \ No newline at end of file + ) + \ No newline at end of file From 99d0d5806f9c4ec0880f943d2046273207c48cba Mon Sep 17 00:00:00 2001 From: Theo Wolf Date: Thu, 22 May 2025 13:49:53 +0100 Subject: [PATCH 3/5] Compare dicts directly in test case --- tests/test_configs.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/tests/test_configs.py b/tests/test_configs.py index c49539c..0a3f87d 100644 --- a/tests/test_configs.py +++ b/tests/test_configs.py @@ -1,6 +1,6 @@ import os import unittest - +from copy import deepcopy from yaml import safe_load from rejax import get_algo @@ -39,9 +39,10 @@ def test_create_algo_with_same_config(self) -> None: continue with self.subTest(config_opath=config_path, algo=algo): try: + original_config = deepcopy(config) algo_cls = get_algo(algo) algo_cls.create(**config) - algo_cls.create(**config) + self.assertEqual(config, original_config) except Exception as e: self.fail( f"Failed to create {algo} with config '{config_path}': " From e4e2bae5a5f2521005de48ad5b315cc9384a5a0c Mon Sep 17 00:00:00 2001 From: Theo Wolf Date: Thu, 22 May 2025 13:50:52 +0100 Subject: [PATCH 4/5] Change test name --- tests/test_configs.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/test_configs.py b/tests/test_configs.py index 0a3f87d..f8b7d2b 100644 --- a/tests/test_configs.py +++ b/tests/test_configs.py @@ -32,7 +32,7 @@ def test_configs(self) -> None: f"{type(e).__name__}: {str(e)}" ) - def test_create_algo_with_same_config(self) -> None: + def test_create_does_not_modify_config(self) -> None: for config_path, configs_env in self.configs.items(): for algo, config in configs_env.items(): if config.get("env", "").startswith("navix"): From f288520fa05069450e75da5d60d48fa7592d6341 Mon Sep 17 00:00:00 2001 From: Theo Wolf Date: Thu, 22 May 2025 13:54:45 +0100 Subject: [PATCH 5/5] Fix error output and test title --- tests/test_configs.py | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/tests/test_configs.py b/tests/test_configs.py index f8b7d2b..d18d04e 100644 --- a/tests/test_configs.py +++ b/tests/test_configs.py @@ -45,7 +45,6 @@ def test_create_does_not_modify_config(self) -> None: self.assertEqual(config, original_config) except Exception as e: self.fail( - f"Failed to create {algo} with config '{config_path}': " + f"Config '{config_path}' for {algo} has been modified: " f"{type(e).__name__}: {str(e)}" ) - \ No newline at end of file