• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

sisl / astra-rl / 18339483451

03 Oct 2025 08:38PM UTC coverage: 38.778%. Remained the same
18339483451

push

github

web-flow
Merge pull request #24 from sisl/de/ux_improvements

User Experience Naming Improvements

61 of 143 new or added lines in 18 files covered. (42.66%)

58 existing lines in 6 files now uncovered.

311 of 802 relevant lines covered (38.78%)

0.78 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

80.77
/src/astra_rl/core/sampler.py
1
"""
2
sampler.py
3
Roll out a system, and specify how its sampler behaves.
4
"""
5

6
from abc import abstractmethod, ABC
2✔
7
from dataclasses import dataclass
2✔
8
from typing import Sequence, Generic, Self, Optional, Any
2✔
9

10
from astra_rl.core.common import StateT, ActionT
2✔
11
from astra_rl.core.system import System
2✔
12

13

14
@dataclass
2✔
15
class Node(Generic[StateT, ActionT]):
2✔
16
    """A node in the rollout graph.
17

18
    Represents a single leaf in the rollout process, containing the context,
19
    the action taken, the response received, the reward for that action,
20
    and any children nodes that follow this action in this rollout.
21

22
    Attributes:
23
        context (StateT): The initial state before the action.
24
        probe (ActionT): The action taken in this node.
25
        response (StateT): The resulting state after the action.
26
        reward (float): The reward received for taking the action.
27
        children (Sequence[Node[StateT, ActionT]]): Subsequent nodes that follow this action.
28

29
    Generics:
30
        StateT (type): The type of the state in the sampler.
31
        ActionT (type): The type of the action in the sampler.
32
    """
33

34
    context: StateT
2✔
35
    probe: ActionT
2✔
36
    response: StateT
2✔
37
    reward: float
2✔
38

39
    children: Sequence[Self]
2✔
40

41

42
@dataclass
2✔
43
class Graph(Generic[StateT, ActionT]):
2✔
44
    """A graph representing the rollout (history + actions) of a system.
45

46
    Attributes:
47
        context (StateT): The initial state of the sampler.
48
        children (Sequence[Node[StateT, ActionT]]): The sequence of nodes representing actions and responses.
49
    """
50

51
    context: StateT
2✔
52
    children: Sequence[Node[StateT, ActionT]]
2✔
53

54

55
class Sampler(ABC, Generic[StateT, ActionT]):
2✔
56
    """A Sampler used for rolling out a system.
57

58
    The primary point of this class is to make a `Graph` of the system
59
    by calling the `rollout` method. The sampler can keep/sample
60
    initial state, but should not have global state that persists
61
    across rollouts.
62

63
    Attributes:
64
        system (System[StateT, ActionT]): The system instance that defines the sampler and actions.
65

66
    Generics:
67
        StateT (type): The type of the state in the sampler.
68
        ActionT (type): The type of the action in the sampler.
69
    """
70

71
    def __init__(self, system: System[StateT, ActionT]):
2✔
NEW
72
        self.system = system
×
73

74
    @abstractmethod
2✔
75
    def rollout(self, seed: Optional[int] = None) -> Graph[StateT, ActionT]:
2✔
76
        """Roll out a system and return a graph of the actions taken.
77

78
        Args:
79
            seed (Optional[int]): An optional seed; the same seed should produce the same graph.
80

81
        Returns:
82
            Graph[StateT, ActionT]: A graph representing the rollout of the system.
83
        """
84

85
        pass
×
86

87
    def eval_rollout(self, seed: Optional[Any] = None) -> Graph[StateT, ActionT]:
2✔
88
        """Roll out for evaluation, by default just the standard rollout
89

90
        Notes:
91
            This can be customized to whatever the user desires in terms of rollout for eval.
92
            For instance, for evaluation the seed maybe StateT instead of int since there may
93
            be another evaluation dataset.
94

95
            However, if the seed given is None or an int, a default implementation exists
96
            which just calls `self.rollout(seed)` and so evaluation can be done without
97
            needing to override this method.
98

99
        Args:
100
            seed (Optional[Any]): An optional seed; the same seed should produce the same graph.
101

102
        Returns:
103
            Graph[StateT, ActionT]: A graph representing the rollout of the system.
104
        """
105

106
        if seed is None or isinstance(seed, int):
×
107
            return self.rollout(seed)
×
108

109
        raise NotImplementedError(
×
110
            "eval_rollout not implemented for non-int seeds; please override this method."
111
        )
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc