mirror of
https://github.com/open-thought/reasoning-gym.git
synced 2026-04-28 17:29:39 +00:00
feat(env): Group Anagrams Curriculum (#288)
* group anagrams curriculum
This commit is contained in:
parent
07eb434d61
commit
e8601a63b4
4 changed files with 96 additions and 23 deletions
|
|
@ -4,27 +4,35 @@ import json
|
|||
|
||||
import pytest
|
||||
|
||||
from reasoning_gym.algorithmic.group_anagrams import GroupAnagramsConfig, GroupAnagramsDataset
|
||||
from reasoning_gym.algorithmic.group_anagrams import GroupAnagramsConfig, GroupAnagramsCurriculum, GroupAnagramsDataset
|
||||
|
||||
|
||||
def test_group_anagrams_config_validation():
|
||||
"""Test that invalid configs raise appropriate errors"""
|
||||
with pytest.raises(AssertionError):
|
||||
config = GroupAnagramsConfig(anagram_groups=-1) # Negative not allowed
|
||||
config = GroupAnagramsConfig(min_anagram_groups=-1) # Negative not allowed
|
||||
config.validate()
|
||||
|
||||
with pytest.raises(AssertionError):
|
||||
config = GroupAnagramsConfig(anagram_groups=0) # Zero not allowed
|
||||
config = GroupAnagramsConfig(min_anagram_groups=0) # Zero not allowed
|
||||
config.validate()
|
||||
|
||||
with pytest.raises(AssertionError):
|
||||
config = GroupAnagramsConfig(max_words_per_group=-1) # Negative not allowed
|
||||
config = GroupAnagramsConfig(min_anagram_groups=5, max_anagram_groups=4) # Min > Max not allowed
|
||||
config.validate()
|
||||
|
||||
with pytest.raises(AssertionError):
|
||||
config = GroupAnagramsConfig(max_words_per_group=0) # Zero not allowed
|
||||
config = GroupAnagramsConfig(min_words_per_group=-1) # Negative not allowed
|
||||
config.validate()
|
||||
|
||||
with pytest.raises(AssertionError):
|
||||
config = GroupAnagramsConfig(min_words_per_group=0) # Zero not allowed
|
||||
config.validate()
|
||||
|
||||
with pytest.raises(AssertionError):
|
||||
config = GroupAnagramsConfig(min_words_per_group=5, max_words_per_group=4) # Min > Max not allowed
|
||||
config.validate() # Min > Max not allowed
|
||||
|
||||
|
||||
def test_group_anagrams_dataset_deterministic():
|
||||
"""Test that dataset generates same items with same seed"""
|
||||
|
|
@ -38,7 +46,7 @@ def test_group_anagrams_dataset_deterministic():
|
|||
|
||||
def test_group_anagrams_dataset_items():
|
||||
"""Test basic properties of generated items"""
|
||||
config = GroupAnagramsConfig(anagram_groups=5, max_words_per_group=3, size=10, seed=42)
|
||||
config = GroupAnagramsConfig(max_anagram_groups=5, max_words_per_group=3, size=10, seed=42)
|
||||
dataset = GroupAnagramsDataset(config)
|
||||
|
||||
for i in range(len(dataset)):
|
||||
|
|
@ -57,8 +65,8 @@ def test_group_anagrams_dataset_items():
|
|||
solution = item["metadata"]["solution"]
|
||||
|
||||
# Verify list dimensions
|
||||
assert len(words) > 5
|
||||
assert len(solution) == 5
|
||||
assert len(words) >= len(solution)
|
||||
assert len(solution) <= 5
|
||||
assert all(len(group) <= 3 for group in solution)
|
||||
|
||||
|
||||
|
|
@ -119,3 +127,28 @@ def test_group_anagrams_score_answer():
|
|||
answer = '["ate", "eat", "tea"], ["bat"], ["nat", "tan"]'
|
||||
item = {"metadata": {"solution": [["ate", "eat", "tea"], ["bat"], ["nat", "tan"]]}}
|
||||
assert dataset.score_answer(answer, item) == 0
|
||||
|
||||
|
||||
def test_group_anagrams_curriculum():
|
||||
curriculum = GroupAnagramsCurriculum()
|
||||
|
||||
base_value = {"size": 150, "seed": 1}
|
||||
|
||||
base_cfg: GroupAnagramsConfig = curriculum.generate_configuration(base_value)
|
||||
assert base_cfg.seed == 1
|
||||
assert base_cfg.size == 150
|
||||
assert base_cfg.min_anagram_groups == 10 and base_cfg.max_anagram_groups == 10
|
||||
assert base_cfg.min_words_per_group == 2 and base_cfg.max_words_per_group == 2
|
||||
|
||||
# test incrementing attribute levels
|
||||
curriculum.increment_attr_level("anagram_groups")
|
||||
curriculum.increment_attr_level("words_per_group")
|
||||
increased_cfg = curriculum.generate_configuration(base_value)
|
||||
assert increased_cfg.min_anagram_groups == 10 and increased_cfg.max_anagram_groups == 100
|
||||
assert increased_cfg.min_words_per_group == 2 and increased_cfg.max_words_per_group == 5
|
||||
|
||||
# test decrementing attribute level partially
|
||||
curriculum.decrement_attr_level("anagram_groups")
|
||||
partially_decreased_cfg = curriculum.generate_configuration(base_value)
|
||||
assert partially_decreased_cfg.min_anagram_groups == 10 and partially_decreased_cfg.max_anagram_groups == 10
|
||||
assert partially_decreased_cfg.min_words_per_group == 2 and partially_decreased_cfg.max_words_per_group == 5
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue