diff --git a/examples/word_ladder/main.py b/examples/word_ladder/main.py index 1157c093..640059f7 100644 --- a/examples/word_ladder/main.py +++ b/examples/word_ladder/main.py @@ -9,7 +9,7 @@ main.py – Orchestrates the overall flow: import sys import uuid from pathlib import Path -from typing import Any, Dict +from typing import Any from examples.word_ladder.utils import create_word_ladders, generate_reasoning diff --git a/notebooks/test_generator_files.py b/notebooks/test_generator_files.py index a41bed3b..ab1e0862 100644 --- a/notebooks/test_generator_files.py +++ b/notebooks/test_generator_files.py @@ -1,7 +1,6 @@ import importlib.util import os from datetime import datetime -from typing import Any, Dict def test_generator_files(directory_path: str) -> None: diff --git a/reasoning_gym/algebra/intermediate_integration.py b/reasoning_gym/algebra/intermediate_integration.py index b4fb28ea..c967c7be 100644 --- a/reasoning_gym/algebra/intermediate_integration.py +++ b/reasoning_gym/algebra/intermediate_integration.py @@ -1,6 +1,6 @@ import random from dataclasses import dataclass -from typing import Any, Dict, Optional +from typing import Any, Optional import sympy diff --git a/reasoning_gym/algebra/simple_integration.py b/reasoning_gym/algebra/simple_integration.py index 019cdf90..a45dc3ff 100644 --- a/reasoning_gym/algebra/simple_integration.py +++ b/reasoning_gym/algebra/simple_integration.py @@ -1,7 +1,7 @@ import random from dataclasses import dataclass from fractions import Fraction -from typing import Any, Dict, Optional +from typing import Any, Optional import sympy diff --git a/reasoning_gym/algorithmic/cryptarithm.py b/reasoning_gym/algorithmic/cryptarithm.py index e04516a1..bfa9baa8 100644 --- a/reasoning_gym/algorithmic/cryptarithm.py +++ b/reasoning_gym/algorithmic/cryptarithm.py @@ -13,7 +13,7 @@ No leading letter can be zero (unless allow_leading_zero=True). from dataclasses import dataclass from random import Random -from typing import Any, Dict, Optional +from typing import Any, Optional from ..factory import ProceduralDataset, register_dataset diff --git a/reasoning_gym/algorithmic/jugs.py b/reasoning_gym/algorithmic/jugs.py index a09893d0..134ac068 100644 --- a/reasoning_gym/algorithmic/jugs.py +++ b/reasoning_gym/algorithmic/jugs.py @@ -4,12 +4,12 @@ from collections import deque from dataclasses import dataclass from functools import reduce from random import Random -from typing import Dict, List, Optional, Tuple +from typing import Any, Optional from ..factory import ProceduralDataset, register_dataset -def min_moves_n(jug_capacities: List[int], target: int) -> Optional[int]: +def min_moves_n(jug_capacities: list[int], target: int) -> Optional[int]: """ Compute the minimum number of moves required to have exactly `target` gallons in any one jug for a puzzle with multiple jugs. @@ -73,7 +73,7 @@ def min_moves_n(jug_capacities: List[int], target: int) -> Optional[int]: return None -def generate_puzzle(rng: Random, num_jugs: int = 3, difficulty: int = 6, max_attempts: int = 10000) -> Dict[str, any]: +def generate_puzzle(rng: Random, num_jugs: int = 3, difficulty: int = 6, max_attempts: int = 10000) -> dict[str, Any]: """ Generate a multi-jug water puzzle. @@ -181,7 +181,7 @@ def verify_solution(puzzle, moves): return (any(w == target for w in state), states) -def generate_jug_solution(jug_capacities: Tuple[int, int, int], target: int) -> List[str]: +def generate_jug_solution(jug_capacities: tuple[int, int, int], target: int) -> list[str]: """Solves the jug puzzle and returns a sequence of formatted steps.""" capacities = list(jug_capacities) initial_state = (0, 0, 0) @@ -283,14 +283,14 @@ Reply as a JSON-parsable list of moves which result in any of the jugs being fil "metadata": {"puzzle": puzzle}, } - def score_answer(self, answer: Optional[str], entry: Dict[str, any]) -> float: + def score_answer(self, answer: Optional[str], entry: dict[str, Any]) -> float: """Determine if the solution provided solves the Jugs task. The function awards 1.0 for a correct answer. Args: answer (Optional[str]): The user's answer. - entry (Dict[str, any]): The original dataset entry containing the correct answer. + entry (dict[str, Any]): The original dataset entry containing the correct answer. Returns: float: The computed score between 0.0 and 1.0. diff --git a/reasoning_gym/algorithmic/palindrome_generation.py b/reasoning_gym/algorithmic/palindrome_generation.py index 2eca2693..0e54579a 100644 --- a/reasoning_gym/algorithmic/palindrome_generation.py +++ b/reasoning_gym/algorithmic/palindrome_generation.py @@ -1,7 +1,7 @@ import random import string from dataclasses import dataclass -from typing import Any, Dict, Optional +from typing import Any, Optional from ..factory import ProceduralDataset, register_dataset diff --git a/reasoning_gym/algorithmic/rotten_oranges.py b/reasoning_gym/algorithmic/rotten_oranges.py index ca7f8817..92e35a20 100644 --- a/reasoning_gym/algorithmic/rotten_oranges.py +++ b/reasoning_gym/algorithmic/rotten_oranges.py @@ -7,7 +7,7 @@ https://leetcode.com/problems/rotting-oranges/description/ from collections import deque from dataclasses import dataclass from random import Random -from typing import Dict, Optional +from typing import Optional from ..factory import ProceduralDataset, register_dataset diff --git a/reasoning_gym/algorithmic/sentence_reordering.py b/reasoning_gym/algorithmic/sentence_reordering.py index b96fe8a4..9caae762 100644 --- a/reasoning_gym/algorithmic/sentence_reordering.py +++ b/reasoning_gym/algorithmic/sentence_reordering.py @@ -3,7 +3,7 @@ import re from dataclasses import dataclass from random import Random -from typing import Any, Dict, Optional +from typing import Any, Optional from ..data import read_data_file from ..factory import ProceduralDataset, register_dataset diff --git a/reasoning_gym/algorithmic/spell_backward.py b/reasoning_gym/algorithmic/spell_backward.py index 9a978372..57825d84 100644 --- a/reasoning_gym/algorithmic/spell_backward.py +++ b/reasoning_gym/algorithmic/spell_backward.py @@ -3,7 +3,7 @@ import re from dataclasses import dataclass from random import Random -from typing import Any, Dict, Optional +from typing import Any, Optional from ..data import read_data_file from ..factory import ProceduralDataset, register_dataset diff --git a/reasoning_gym/arc/rearc.py b/reasoning_gym/arc/rearc.py index 35712705..fe4a9aa5 100644 --- a/reasoning_gym/arc/rearc.py +++ b/reasoning_gym/arc/rearc.py @@ -1,6 +1,6 @@ from dataclasses import dataclass, field from random import Random -from typing import Any, Callable, Dict, Optional +from typing import Any, Callable, Optional from ..factory import ProceduralDataset, register_dataset from .board_format import ARC_PROMPT_TEMPLATE, BoardFormattingOptions, format_board, format_board_pair, parse_board diff --git a/reasoning_gym/arc/rearc_utils/dsl.py b/reasoning_gym/arc/rearc_utils/dsl.py index a42b4a49..46497189 100644 --- a/reasoning_gym/arc/rearc_utils/dsl.py +++ b/reasoning_gym/arc/rearc_utils/dsl.py @@ -1,23 +1,23 @@ # types -from typing import Any, Callable, Container, FrozenSet, Tuple, Union +from typing import Any, Callable, Container, FrozenSet, Union Boolean = bool Integer = int -IntegerTuple = Tuple[Integer, Integer] -Numerical = Union[Integer, IntegerTuple] +Integertuple = tuple[Integer, Integer] +Numerical = Union[Integer, Integertuple] IntegerSet = FrozenSet[Integer] -Grid = Tuple[Tuple[Integer]] -Cell = Tuple[Integer, IntegerTuple] +Grid = tuple[tuple[Integer]] +Cell = tuple[Integer, Integertuple] Object = FrozenSet[Cell] Objects = FrozenSet[Object] -Indices = FrozenSet[IntegerTuple] +Indices = FrozenSet[Integertuple] IndicesSet = FrozenSet[Indices] Patch = Union[Object, Indices] Element = Union[Object, Grid] Piece = Union[Grid, Patch] -TupleTuple = Tuple[Tuple] +tupletuple = tuple[tuple] ContainerContainer = Container[Container] @@ -160,17 +160,17 @@ def difference(a: Container, b: Container) -> Container: return type(a)(e for e in a if e not in b) -def dedupe(iterable: Tuple) -> Tuple: +def dedupe(iterable: tuple) -> tuple: """remove duplicates""" return tuple(e for i, e in enumerate(iterable) if iterable.index(e) == i) -def order(container: Container, compfunc: Callable) -> Tuple: +def order(container: Container, compfunc: Callable) -> tuple: """order container by custom key""" return tuple(sorted(container, key=compfunc)) -def repeat(item: Any, num: Integer) -> Tuple: +def repeat(item: Any, num: Integer) -> tuple: """repetition of item within vector""" return tuple(item for i in range(num)) @@ -277,12 +277,12 @@ def positive(x: Integer) -> Boolean: return x > 0 -def toivec(i: Integer) -> IntegerTuple: +def toivec(i: Integer) -> Integertuple: """vector pointing vertically""" return (i, 0) -def tojvec(j: Integer) -> IntegerTuple: +def tojvec(j: Integer) -> Integertuple: """vector pointing horizontally""" return (0, j) @@ -302,7 +302,7 @@ def extract(container: Container, condition: Callable) -> Any: return next(e for e in container if condition(e)) -def totuple(container: FrozenSet) -> Tuple: +def totuple(container: FrozenSet) -> tuple: """conversion to tuple""" return tuple(container) @@ -332,12 +332,12 @@ def other(container: Container, value: Any) -> Any: return first(remove(value, container)) -def interval(start: Integer, stop: Integer, step: Integer) -> Tuple: +def interval(start: Integer, stop: Integer, step: Integer) -> tuple: """range""" return tuple(range(start, stop, step)) -def astuple(a: Integer, b: Integer) -> IntegerTuple: +def astuple(a: Integer, b: Integer) -> Integertuple: """constructs a tuple""" return (a, b) @@ -347,7 +347,7 @@ def product(a: Container, b: Container) -> FrozenSet: return frozenset((i, j) for j in b for i in a) -def pair(a: Tuple, b: Tuple) -> TupleTuple: +def pair(a: tuple, b: tuple) -> tupletuple: """zipping of two tuples""" return tuple(zip(a, b)) @@ -421,12 +421,12 @@ def mapply(function: Callable, container: ContainerContainer) -> FrozenSet: return merge(apply(function, container)) -def papply(function: Callable, a: Tuple, b: Tuple) -> Tuple: +def papply(function: Callable, a: tuple, b: tuple) -> tuple: """apply function on two vectors""" return tuple(function(i, j) for i, j in zip(a, b)) -def mpapply(function: Callable, a: Tuple, b: Tuple) -> Tuple: +def mpapply(function: Callable, a: tuple, b: tuple) -> tuple: """apply function on two vectors and merge""" return merge(papply(function, a, b)) @@ -466,7 +466,7 @@ def width(piece: Piece) -> Integer: return rightmost(piece) - leftmost(piece) + 1 -def shape(piece: Piece) -> IntegerTuple: +def shape(piece: Piece) -> Integertuple: """height and width of grid or patch""" return (height(piece), width(piece)) @@ -503,27 +503,27 @@ def ofcolor(grid: Grid, value: Integer) -> Indices: return frozenset((i, j) for i, r in enumerate(grid) for j, v in enumerate(r) if v == value) -def ulcorner(patch: Patch) -> IntegerTuple: +def ulcorner(patch: Patch) -> Integertuple: """index of upper left corner""" return tuple(map(min, zip(*toindices(patch)))) -def urcorner(patch: Patch) -> IntegerTuple: +def urcorner(patch: Patch) -> Integertuple: """index of upper right corner""" return tuple(map(lambda ix: {0: min, 1: max}[ix[0]](ix[1]), enumerate(zip(*toindices(patch))))) -def llcorner(patch: Patch) -> IntegerTuple: +def llcorner(patch: Patch) -> Integertuple: """index of lower left corner""" return tuple(map(lambda ix: {0: max, 1: min}[ix[0]](ix[1]), enumerate(zip(*toindices(patch))))) -def lrcorner(patch: Patch) -> IntegerTuple: +def lrcorner(patch: Patch) -> Integertuple: """index of lower right corner""" return tuple(map(max, zip(*toindices(patch)))) -def crop(grid: Grid, start: IntegerTuple, dims: IntegerTuple) -> Grid: +def crop(grid: Grid, start: Integertuple, dims: Integertuple) -> Grid: """subgrid specified by start and dimension""" return tuple(r[start[1] : start[1] + dims[1]] for r in grid[start[0] : start[0] + dims[0]]) @@ -542,7 +542,7 @@ def recolor(value: Integer, patch: Patch) -> Object: return frozenset((value, index) for index in toindices(patch)) -def shift(patch: Patch, directions: IntegerTuple) -> Patch: +def shift(patch: Patch, directions: Integertuple) -> Patch: """shift patch""" if len(patch) == 0: return patch @@ -559,19 +559,19 @@ def normalize(patch: Patch) -> Patch: return shift(patch, (-uppermost(patch), -leftmost(patch))) -def dneighbors(loc: IntegerTuple) -> Indices: +def dneighbors(loc: Integertuple) -> Indices: """directly adjacent indices""" return frozenset({(loc[0] - 1, loc[1]), (loc[0] + 1, loc[1]), (loc[0], loc[1] - 1), (loc[0], loc[1] + 1)}) -def ineighbors(loc: IntegerTuple) -> Indices: +def ineighbors(loc: Integertuple) -> Indices: """diagonally adjacent indices""" return frozenset( {(loc[0] - 1, loc[1] - 1), (loc[0] - 1, loc[1] + 1), (loc[0] + 1, loc[1] - 1), (loc[0] + 1, loc[1] + 1)} ) -def neighbors(loc: IntegerTuple) -> Indices: +def neighbors(loc: Integertuple) -> Indices: """adjacent indices""" return dneighbors(loc) | ineighbors(loc) @@ -690,7 +690,7 @@ def bordering(patch: Patch, grid: Grid) -> Boolean: ) -def centerofmass(patch: Patch) -> IntegerTuple: +def centerofmass(patch: Patch) -> Integertuple: """center of mass""" return tuple(map(lambda x: sum(x) // len(patch), zip(*toindices(patch)))) @@ -895,14 +895,14 @@ def subgrid(patch: Patch, grid: Grid) -> Grid: return crop(grid, ulcorner(patch), shape(patch)) -def hsplit(grid: Grid, n: Integer) -> Tuple: +def hsplit(grid: Grid, n: Integer) -> tuple: """split grid horizontally""" h, w = len(grid), len(grid[0]) // n offset = len(grid[0]) % n != 0 return tuple(crop(grid, (0, w * i + i * offset), (h, w)) for i in range(n)) -def vsplit(grid: Grid, n: Integer) -> Tuple: +def vsplit(grid: Grid, n: Integer) -> tuple: """split grid vertically""" h, w = len(grid) // n, len(grid[0]) offset = len(grid) % n != 0 @@ -933,12 +933,12 @@ def switch(grid: Grid, a: Integer, b: Integer) -> Grid: return tuple(tuple(v if (v != a and v != b) else {a: b, b: a}[v] for v in r) for r in grid) -def center(patch: Patch) -> IntegerTuple: +def center(patch: Patch) -> Integertuple: """center of the patch""" return (uppermost(patch) + height(patch) // 2, leftmost(patch) + width(patch) // 2) -def position(a: Patch, b: Patch) -> IntegerTuple: +def position(a: Patch, b: Patch) -> Integertuple: """relative position between two patches""" ia, ja = center(toindices(a)) ib, jb = center(toindices(b)) @@ -952,7 +952,7 @@ def position(a: Patch, b: Patch) -> IntegerTuple: return (-1, 1 if ja < jb else -1) -def index(grid: Grid, loc: IntegerTuple) -> Integer: +def index(grid: Grid, loc: Integertuple) -> Integer: """color at location""" i, j = loc h, w = len(grid), len(grid[0]) @@ -961,7 +961,7 @@ def index(grid: Grid, loc: IntegerTuple) -> Integer: return grid[loc[0]][loc[1]] -def canvas(value: Integer, dimensions: IntegerTuple) -> Grid: +def canvas(value: Integer, dimensions: Integertuple) -> Grid: """grid construction""" return tuple(tuple(value for j in range(dimensions[1])) for i in range(dimensions[0])) @@ -971,7 +971,7 @@ def corners(patch: Patch) -> Indices: return frozenset({ulcorner(patch), urcorner(patch), llcorner(patch), lrcorner(patch)}) -def connect(a: IntegerTuple, b: IntegerTuple) -> Indices: +def connect(a: Integertuple, b: Integertuple) -> Indices: """line between two points""" ai, aj = a bi, bj = b @@ -1000,7 +1000,7 @@ def trim(grid: Grid) -> Grid: return tuple(r[1:-1] for r in grid[1:-1]) -def move(grid: Grid, obj: Object, offset: IntegerTuple) -> Grid: +def move(grid: Grid, obj: Object, offset: Integertuple) -> Grid: """move object on grid""" return paint(cover(grid, obj), shift(obj, offset)) @@ -1025,12 +1025,12 @@ def righthalf(grid: Grid) -> Grid: return rot270(bottomhalf(rot90(grid))) -def vfrontier(location: IntegerTuple) -> Indices: +def vfrontier(location: Integertuple) -> Indices: """vertical frontier""" return frozenset((i, location[1]) for i in range(30)) -def hfrontier(location: IntegerTuple) -> Indices: +def hfrontier(location: Integertuple) -> Indices: """horizontal frontier""" return frozenset((location[0], j) for j in range(30)) @@ -1052,7 +1052,7 @@ def delta(patch: Patch) -> Indices: return backdrop(patch) - toindices(patch) -def gravitate(source: Patch, destination: Patch) -> IntegerTuple: +def gravitate(source: Patch, destination: Patch) -> Integertuple: """direction to move source until adjacent to destination""" source_i, source_j = center(source) destination_i, destination_j = center(destination) @@ -1108,7 +1108,7 @@ def box(patch: Patch) -> Indices: return frozenset(vlines | hlines) -def shoot(start: IntegerTuple, direction: IntegerTuple) -> Indices: +def shoot(start: Integertuple, direction: Integertuple) -> Indices: """line from starting point and direction""" return connect(start, (start[0] + 42 * direction[0], start[1] + 42 * direction[1])) diff --git a/reasoning_gym/arithmetic/decimal_chain_sum.py b/reasoning_gym/arithmetic/decimal_chain_sum.py index 8e20ed59..de22bb29 100644 --- a/reasoning_gym/arithmetic/decimal_chain_sum.py +++ b/reasoning_gym/arithmetic/decimal_chain_sum.py @@ -1,7 +1,7 @@ import random from dataclasses import dataclass from decimal import Decimal -from typing import Any, Dict, Optional +from typing import Any, Optional from ..coaching import AttributeType, BaseCurriculum, RangeAttributeDefinition from ..factory import ProceduralDataset, register_dataset diff --git a/reasoning_gym/arithmetic/gsm_symbolic/generators_00_49.py b/reasoning_gym/arithmetic/gsm_symbolic/generators_00_49.py index eea9429b..95d78a22 100644 --- a/reasoning_gym/arithmetic/gsm_symbolic/generators_00_49.py +++ b/reasoning_gym/arithmetic/gsm_symbolic/generators_00_49.py @@ -1,7 +1,7 @@ import math from fractions import Fraction from random import Random -from typing import Any, Dict +from typing import Any from reasoning_gym.utils import format_number, is_integer diff --git a/reasoning_gym/arithmetic/gsm_symbolic/generators_50_99.py b/reasoning_gym/arithmetic/gsm_symbolic/generators_50_99.py index 960e023a..0f862e17 100644 --- a/reasoning_gym/arithmetic/gsm_symbolic/generators_50_99.py +++ b/reasoning_gym/arithmetic/gsm_symbolic/generators_50_99.py @@ -1,6 +1,6 @@ from fractions import Fraction from random import Random -from typing import Any, Dict +from typing import Any from reasoning_gym.utils import format_number, is_integer diff --git a/reasoning_gym/arithmetic/leg_counting.py b/reasoning_gym/arithmetic/leg_counting.py index b8a15191..f7da2d35 100644 --- a/reasoning_gym/arithmetic/leg_counting.py +++ b/reasoning_gym/arithmetic/leg_counting.py @@ -2,7 +2,7 @@ from dataclasses import dataclass from random import Random -from typing import Dict, Optional +from typing import Optional from ..factory import ProceduralDataset, register_dataset diff --git a/reasoning_gym/cognition/needle_haystack.py b/reasoning_gym/cognition/needle_haystack.py index a8cd1cf4..f83318b8 100644 --- a/reasoning_gym/cognition/needle_haystack.py +++ b/reasoning_gym/cognition/needle_haystack.py @@ -1,7 +1,6 @@ -import re from dataclasses import dataclass from random import Random -from typing import Any, Dict, List, Optional +from typing import Any, Optional from ..factory import ProceduralDataset, register_dataset @@ -20,7 +19,7 @@ class NeedleHaystackConfig: assert self.num_statements < 168387000, f"num_statements must be less than {168387000}" -def generate_unique_triplets(names: List[str], verbs: List[str], subjects: List[str], n: int, rng) -> Dict[str, Any]: +def generate_unique_triplets(names: list[str], verbs: list[str], subjects: list[str], n: int, rng) -> dict[str, Any]: """ Generate n unique random triplets (name, verb, subject) without generating the full Cartesian product in memory. @@ -29,14 +28,14 @@ def generate_unique_triplets(names: List[str], verbs: List[str], subjects: List[ randomly chosen as the 'needle'. Args: - names (List[str]): List of names. - verbs (List[str]): List of verbs. - subjects (List[str]): List of subjects. + names (list[str]): List of names. + verbs (list[str]): List of verbs. + subjects (list[str]): List of subjects. n (int): Number of unique triplets to generate. rng (random.Random): A pre-seeded random number generator. Returns: - Dict[str, Any]: A dictionary with: + dict[str, Any]: A dictionary with: - "triplets": a list of n unique triplets (tuples of (name, verb, subject)), - "needle": one triplet randomly chosen from the list. @@ -47,7 +46,7 @@ def generate_unique_triplets(names: List[str], verbs: List[str], subjects: List[ # Use a range for memory efficiency and sample n unique indices. indices = rng.sample(range(total_possible), n) - triplets: List[Tuple[str, str, str]] = [] + triplets: list[tuple[str, str, str]] = [] num_verbs = len(verbs) num_subjects = len(subjects) @@ -101,12 +100,12 @@ class NeedleHaystackDataset(ProceduralDataset): "metadata": {"question": question}, } - def score_answer(self, answer: Optional[str], entry: Dict[str, any]) -> float: + def score_answer(self, answer: Optional[str], entry: dict[str, Any]) -> float: """Determine if the solution provided solves the task. Args: answer (Optional[str]): The user's answer. - entry (Dict[str, any]): The original dataset entry containing the correct answer. + entry (dict[str, Any]): The original dataset entry containing the correct answer. Returns: float: The computed score between 0.0 and 1.0. diff --git a/reasoning_gym/games/emoji_mystery.py b/reasoning_gym/games/emoji_mystery.py index 31659863..59b20b16 100644 --- a/reasoning_gym/games/emoji_mystery.py +++ b/reasoning_gym/games/emoji_mystery.py @@ -1,7 +1,7 @@ import re from dataclasses import dataclass from random import Random -from typing import Any, Dict, List, Optional, Tuple +from typing import Any, Optional from ..data import read_data_file from ..factory import ProceduralDataset, register_dataset @@ -181,7 +181,7 @@ class EmojiMysteryDataset(ProceduralDataset): <= self.config.max_words_in_sentence ] - def __getitem__(self, idx: int) -> Dict[str, Any]: + def __getitem__(self, idx: int) -> dict[str, Any]: rng = Random(self.seed + idx) secret_emoji = rng.choice(self.emojis) secret_sentence = rng.choice(self.sentences).strip().replace("\n", " ") @@ -216,7 +216,7 @@ class EmojiMysteryDataset(ProceduralDataset): encoded_bytes = sentence.encode("utf-8") return base + "".join(self.byte_to_variance_selector(b) for b in encoded_bytes) - def score_answer(self, answer: str | None, entry: Dict[str, Any]) -> int: + def score_answer(self, answer: str | None, entry: dict[str, Any]) -> int: reward = 0.0 if answer is not None: try: diff --git a/reasoning_gym/induction/list_functions/generators.py b/reasoning_gym/induction/list_functions/generators.py index 3e1966b8..b8844488 100644 --- a/reasoning_gym/induction/list_functions/generators.py +++ b/reasoning_gym/induction/list_functions/generators.py @@ -1,6 +1,6 @@ import random from random import Random -from typing import Any, Dict +from typing import Any NUM_OF_PAIRS_GENERATED = 5 @@ -65,7 +65,7 @@ def create_numbers_divisible_by_five_or_ten(rng: Random): return result -def generate_0(rng: Random) -> Dict[str, Any]: +def generate_0(rng: Random) -> dict[str, Any]: """Generate input and output pairs where input remains unchanged""" pairs = {} @@ -78,7 +78,7 @@ def generate_0(rng: Random) -> Dict[str, Any]: return pairs -def generate_1(rng: Random) -> Dict[str, Any]: +def generate_1(rng: Random) -> dict[str, Any]: """Generate input and output pairs where output is a list of the third element after removing all other elements """ @@ -95,7 +95,7 @@ def generate_1(rng: Random) -> Dict[str, Any]: return pairs -def generate_2(rng: Random) -> Dict[str, Any]: +def generate_2(rng: Random) -> dict[str, Any]: """Generate input and output pairs where output is a reversed list of the input""" pairs = {} for _ in range(NUM_OF_PAIRS_GENERATED): @@ -108,7 +108,7 @@ def generate_2(rng: Random) -> Dict[str, Any]: return pairs -def generate_3(rng: Random) -> Dict[str, Any]: +def generate_3(rng: Random) -> dict[str, Any]: """Generate input and output pairs where output is the sum of unique elements in the list less than 30""" pairs = {} for _ in range(NUM_OF_PAIRS_GENERATED): @@ -127,7 +127,7 @@ def generate_3(rng: Random) -> Dict[str, Any]: return pairs -def generate_4(rng: Random) -> Dict[str, Any]: +def generate_4(rng: Random) -> dict[str, Any]: """Generate input and output pairs where output is the count of elements equal to 5""" pairs = {} for i in range(NUM_OF_PAIRS_GENERATED): @@ -151,7 +151,7 @@ def generate_4(rng: Random) -> Dict[str, Any]: return pairs -def generate_5(rng: Random) -> Dict[str, Any]: +def generate_5(rng: Random) -> dict[str, Any]: """Generate input and output pairs where output is a list of elements that are followed by an even number NOTE: This is suppose to be a relatively hard problem @@ -173,7 +173,7 @@ def generate_5(rng: Random) -> Dict[str, Any]: return pairs -def generate_6(rng: Random) -> Dict[str, Any]: +def generate_6(rng: Random) -> dict[str, Any]: """Generate input and output pairs where output is a list of elements where each element in input is added to its position(Using zero-indexing)""" pairs = {} for i in range(NUM_OF_PAIRS_GENERATED): @@ -190,7 +190,7 @@ def generate_6(rng: Random) -> Dict[str, Any]: return pairs -def generate_7(rng: Random) -> Dict[str, Any]: +def generate_7(rng: Random) -> dict[str, Any]: """Generate input and output pairs where output is a list of element whose position is indicated by the last element in the input EXAMPLE: @@ -213,7 +213,7 @@ def generate_7(rng: Random) -> Dict[str, Any]: return pairs -def generate_8(rng: Random) -> Dict[str, Any]: +def generate_8(rng: Random) -> dict[str, Any]: """Generate input and output pairs where output is count of elements in the input""" pairs = {} for _ in range(NUM_OF_PAIRS_GENERATED): @@ -227,7 +227,7 @@ def generate_8(rng: Random) -> Dict[str, Any]: return pairs -def generate_9(rng: Random) -> Dict[str, Any]: +def generate_9(rng: Random) -> dict[str, Any]: """Generate input and output pairs where output is sum total of elements in the input""" pairs = {} for _ in range(NUM_OF_PAIRS_GENERATED): @@ -241,7 +241,7 @@ def generate_9(rng: Random) -> Dict[str, Any]: return pairs -def generate_10(rng: Random) -> Dict[str, Any]: +def generate_10(rng: Random) -> dict[str, Any]: """Generate input and output pairs where output is a list of the elements in ascending order""" pairs = {} for _ in range(NUM_OF_PAIRS_GENERATED): @@ -255,7 +255,7 @@ def generate_10(rng: Random) -> Dict[str, Any]: return pairs -def generate_11(rng: Random) -> Dict[str, Any]: +def generate_11(rng: Random) -> dict[str, Any]: """Generate input and output pairs where output is a list of the elements in descending order""" pairs = {} for _ in range(NUM_OF_PAIRS_GENERATED): @@ -269,7 +269,7 @@ def generate_11(rng: Random) -> Dict[str, Any]: return pairs -def generate_12(rng: Random) -> Dict[str, Any]: +def generate_12(rng: Random) -> dict[str, Any]: """Generate input and output pairs where output is a list of the elements where the first and last element in input are replaced by their successor. Example, for an integer 4, successor is 5 """ @@ -288,7 +288,7 @@ def generate_12(rng: Random) -> Dict[str, Any]: return pairs -def generate_13(rng: Random) -> Dict[str, Any]: +def generate_13(rng: Random) -> dict[str, Any]: """Generate input and output pairs where output is [1] if list of input elements is in ascending order, [0] in descending order""" pairs = {} for i in range(NUM_OF_PAIRS_GENERATED): @@ -307,7 +307,7 @@ def generate_13(rng: Random) -> Dict[str, Any]: return pairs -def generate_14(rng: Random) -> Dict[str, Any]: +def generate_14(rng: Random) -> dict[str, Any]: """Generate input and output pairs where output is [1] if input element is divisible by 10, [0] if divisible by 5""" pairs = {} @@ -327,7 +327,7 @@ def generate_14(rng: Random) -> Dict[str, Any]: return pairs -def generate_15(rng: Random) -> Dict[str, Any]: +def generate_15(rng: Random) -> dict[str, Any]: """Generate input and output pairs where output is a twice the amount of last element in the input""" pairs = {} for _ in range(NUM_OF_PAIRS_GENERATED): @@ -348,7 +348,7 @@ def generate_15(rng: Random) -> Dict[str, Any]: return pairs -def generate_16(rng: Random) -> Dict[str, Any]: +def generate_16(rng: Random) -> dict[str, Any]: """Generate input and output pairs where output is built from a function 2x - 4 NOTE: This is suppose to be amazingly hard for the LLM. """