valanga 0.1.5__tar.gz → 0.1.7__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- {valanga-0.1.5 → valanga-0.1.7}/PKG-INFO +1 -1
- {valanga-0.1.5 → valanga-0.1.7}/pyproject.toml +1 -1
- {valanga-0.1.5 → valanga-0.1.7}/src/valanga/evaluations.py +5 -1
- valanga-0.1.7/src/valanga/representation_factory.py +64 -0
- {valanga-0.1.5 → valanga-0.1.7}/src/valanga/represention_for_evaluation.py +11 -5
- {valanga-0.1.5 → valanga-0.1.7}/src/valanga.egg-info/PKG-INFO +1 -1
- valanga-0.1.5/src/valanga/representation_factory.py +0 -76
- {valanga-0.1.5 → valanga-0.1.7}/LICENSE +0 -0
- {valanga-0.1.5 → valanga-0.1.7}/README.md +0 -0
- {valanga-0.1.5 → valanga-0.1.7}/setup.cfg +0 -0
- {valanga-0.1.5 → valanga-0.1.7}/src/valanga/__init__.py +0 -0
- {valanga-0.1.5 → valanga-0.1.7}/src/valanga/evaluator_types.py +0 -0
- {valanga-0.1.5 → valanga-0.1.7}/src/valanga/game.py +0 -0
- {valanga-0.1.5 → valanga-0.1.7}/src/valanga/over_event.py +0 -0
- {valanga-0.1.5 → valanga-0.1.7}/src/valanga/policy.py +0 -0
- {valanga-0.1.5 → valanga-0.1.7}/src/valanga/progress_messsage.py +0 -0
- {valanga-0.1.5 → valanga-0.1.7}/src/valanga/py.typed +0 -0
- {valanga-0.1.5 → valanga-0.1.7}/src/valanga.egg-info/SOURCES.txt +0 -0
- {valanga-0.1.5 → valanga-0.1.7}/src/valanga.egg-info/dependency_links.txt +0 -0
- {valanga-0.1.5 → valanga-0.1.7}/src/valanga.egg-info/requires.txt +0 -0
- {valanga-0.1.5 → valanga-0.1.7}/src/valanga.egg-info/top_level.txt +0 -0
- {valanga-0.1.5 → valanga-0.1.7}/tests/test_over_event.py +0 -0
- {valanga-0.1.5 → valanga-0.1.7}/tests/test_placeholder.py +0 -0
- {valanga-0.1.5 → valanga-0.1.7}/tests/test_representation_factory.py +0 -0
|
@@ -5,6 +5,8 @@ Evaluation-related classes and types.
|
|
|
5
5
|
from dataclasses import dataclass
|
|
6
6
|
from typing import Protocol
|
|
7
7
|
|
|
8
|
+
from valanga.evaluator_types import EvaluatorInput
|
|
9
|
+
|
|
8
10
|
from .game import BranchKey, State
|
|
9
11
|
from .over_event import OverEvent
|
|
10
12
|
from .represention_for_evaluation import ContentRepresentation
|
|
@@ -22,7 +24,9 @@ class EvalItem[StateT: State](Protocol):
|
|
|
22
24
|
...
|
|
23
25
|
|
|
24
26
|
@property
|
|
25
|
-
def state_representation(
|
|
27
|
+
def state_representation(
|
|
28
|
+
self,
|
|
29
|
+
) -> ContentRepresentation[StateT, EvaluatorInput] | None:
|
|
26
30
|
"""The representation of the state associated with this evaluation item, if available."""
|
|
27
31
|
...
|
|
28
32
|
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
"""
|
|
2
|
+
Factory for creating content representations from game states and state modifications.
|
|
3
|
+
"""
|
|
4
|
+
|
|
5
|
+
from dataclasses import dataclass
|
|
6
|
+
from typing import Protocol
|
|
7
|
+
|
|
8
|
+
from .game import State
|
|
9
|
+
from .represention_for_evaluation import ContentRepresentation
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
class CreateFromState[StateT: State, EvalIn](Protocol):
|
|
13
|
+
"""
|
|
14
|
+
Protocol for creating a state representation from a state.
|
|
15
|
+
"""
|
|
16
|
+
|
|
17
|
+
def __call__(self, state: StateT) -> ContentRepresentation[StateT, EvalIn]: ...
|
|
18
|
+
|
|
19
|
+
|
|
20
|
+
class CreateFromStateAndModifications[StateT: State, EvalIn, StateModT](Protocol):
|
|
21
|
+
"""
|
|
22
|
+
Protocol for creating a state representation from a state and modifications.
|
|
23
|
+
"""
|
|
24
|
+
|
|
25
|
+
def __call__(
|
|
26
|
+
self,
|
|
27
|
+
state: StateT,
|
|
28
|
+
state_modifications: StateModT,
|
|
29
|
+
previous_state_representation: ContentRepresentation[StateT, EvalIn],
|
|
30
|
+
) -> ContentRepresentation[StateT, EvalIn]: ...
|
|
31
|
+
|
|
32
|
+
|
|
33
|
+
@dataclass
|
|
34
|
+
class RepresentationFactory[StateT: State, EvalIn, StateModT]:
|
|
35
|
+
"""Factory for creating content representations from states and state modifications.
|
|
36
|
+
Attributes:
|
|
37
|
+
create_from_state: Function to create a content representation from a state.
|
|
38
|
+
create_from_state_and_modifications: Function to create a content representation from a state and state modifications.
|
|
39
|
+
"""
|
|
40
|
+
|
|
41
|
+
create_from_state: CreateFromState[StateT, EvalIn]
|
|
42
|
+
create_from_state_and_modifications: CreateFromStateAndModifications[
|
|
43
|
+
StateT, EvalIn, StateModT
|
|
44
|
+
]
|
|
45
|
+
|
|
46
|
+
def create_from_transition(
|
|
47
|
+
self,
|
|
48
|
+
state: StateT,
|
|
49
|
+
previous_state_representation: ContentRepresentation[StateT, EvalIn] | None,
|
|
50
|
+
modifications: StateModT | None,
|
|
51
|
+
) -> ContentRepresentation[StateT, EvalIn]:
|
|
52
|
+
"""Creates a content representation from a state transition.
|
|
53
|
+
Args:
|
|
54
|
+
state: The current state of the game.
|
|
55
|
+
previous_state_representation: The content representation of the previous state, or None if not available.
|
|
56
|
+
modifications: The modifications applied to the previous state to reach the current state, or None if not available.
|
|
57
|
+
Returns:
|
|
58
|
+
ContentRepresentation[StateT, EvalIn]: The content representation of the current state.
|
|
59
|
+
"""
|
|
60
|
+
if previous_state_representation is None or modifications is None:
|
|
61
|
+
return self.create_from_state(state)
|
|
62
|
+
return self.create_from_state_and_modifications(
|
|
63
|
+
state, modifications, previous_state_representation
|
|
64
|
+
)
|
|
@@ -2,21 +2,26 @@
|
|
|
2
2
|
Contains the definition of the ContentRepresentation protocol for content representations used in evaluations.
|
|
3
3
|
"""
|
|
4
4
|
|
|
5
|
-
from typing import
|
|
5
|
+
from typing import Protocol, TypeVar
|
|
6
|
+
|
|
7
|
+
from valanga.evaluator_types import EvaluatorInput
|
|
6
8
|
|
|
7
|
-
from .evaluator_types import EvaluatorInput
|
|
8
9
|
from .game import State
|
|
9
10
|
|
|
10
|
-
StateT_contra = TypeVar("StateT_contra", bound=State, contravariant=True, default=
|
|
11
|
+
StateT_contra = TypeVar("StateT_contra", bound=State, contravariant=True, default=State)
|
|
12
|
+
|
|
13
|
+
EvalIn_co = TypeVar(
|
|
14
|
+
"EvalIn_co", covariant=True, bound=EvaluatorInput, default=EvaluatorInput
|
|
15
|
+
)
|
|
11
16
|
|
|
12
17
|
|
|
13
|
-
class ContentRepresentation
|
|
18
|
+
class ContentRepresentation[StateT_contra, EvalIn_co](Protocol):
|
|
14
19
|
"""
|
|
15
20
|
Protocol defining the interface for a content representation.
|
|
16
21
|
It is a function returning the proper input for evaluation by the content evaluator.
|
|
17
22
|
"""
|
|
18
23
|
|
|
19
|
-
def get_evaluator_input(self, state: StateT_contra) ->
|
|
24
|
+
def get_evaluator_input(self, state: StateT_contra) -> EvalIn_co:
|
|
20
25
|
"""
|
|
21
26
|
Returns the evaluator input tensor for the content. Content representations have generally a compressed view and complemetary view of state info so to avoid redundancy and have all the necessary info we also give the state as input.
|
|
22
27
|
|
|
@@ -26,3 +31,4 @@ class ContentRepresentation(Protocol[StateT_contra]):
|
|
|
26
31
|
Returns:
|
|
27
32
|
The evaluator input tensor.
|
|
28
33
|
"""
|
|
34
|
+
...
|
|
@@ -1,76 +0,0 @@
|
|
|
1
|
-
"""
|
|
2
|
-
Factory class for creating state representations.
|
|
3
|
-
"""
|
|
4
|
-
|
|
5
|
-
from dataclasses import dataclass
|
|
6
|
-
from typing import Protocol
|
|
7
|
-
|
|
8
|
-
from .game import State, StateModifications
|
|
9
|
-
from .represention_for_evaluation import ContentRepresentation
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
class CreateFromState[StateT: State, RepT: ContentRepresentation](Protocol):
|
|
13
|
-
"""
|
|
14
|
-
Protocol for creating a state representation from a state.
|
|
15
|
-
"""
|
|
16
|
-
|
|
17
|
-
def __call__(self, state: StateT) -> RepT: ...
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
class CreateFromStateAndModifications[StateT: State, RepT: ContentRepresentation](
|
|
21
|
-
Protocol
|
|
22
|
-
):
|
|
23
|
-
"""
|
|
24
|
-
Protocol for creating a state representation from a state and modifications.
|
|
25
|
-
"""
|
|
26
|
-
|
|
27
|
-
def __call__(
|
|
28
|
-
self,
|
|
29
|
-
state: StateT,
|
|
30
|
-
state_modifications: StateModifications,
|
|
31
|
-
previous_state_representation: RepT,
|
|
32
|
-
) -> RepT: ...
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
@dataclass
|
|
36
|
-
class RepresentationFactory[StateT: State, RepT: ContentRepresentation]:
|
|
37
|
-
"""
|
|
38
|
-
Factory class for creating state representations.
|
|
39
|
-
"""
|
|
40
|
-
|
|
41
|
-
create_from_state: CreateFromState[StateT, RepT]
|
|
42
|
-
create_from_state_and_modifications: CreateFromStateAndModifications[StateT, RepT]
|
|
43
|
-
|
|
44
|
-
def create_from_transition(
|
|
45
|
-
self,
|
|
46
|
-
state: StateT,
|
|
47
|
-
previous_state_representation: RepT | None,
|
|
48
|
-
modifications: StateModifications | None,
|
|
49
|
-
) -> RepT:
|
|
50
|
-
"""
|
|
51
|
-
Create a Generic T_StateRepresentation object from a transition.
|
|
52
|
-
|
|
53
|
-
Args:
|
|
54
|
-
state (State): The current state of the game.
|
|
55
|
-
previous_state_representation (Representation364 | None): The representation of the previous state. None if this is the root node.
|
|
56
|
-
modifications (StateModifications | None): The modifications from the parent state to the current state. None if this is the root node.
|
|
57
|
-
|
|
58
|
-
Returns:
|
|
59
|
-
T_StateRepresentation: The created (Generic) Representation object
|
|
60
|
-
|
|
61
|
-
This version is supposed to be faster as it only modifies the previous state
|
|
62
|
-
representation with the last modification
|
|
63
|
-
"""
|
|
64
|
-
if previous_state_representation is None: # this is the root_node
|
|
65
|
-
representation = self.create_from_state(state=state)
|
|
66
|
-
else:
|
|
67
|
-
if modifications is None:
|
|
68
|
-
representation = self.create_from_state(state=state)
|
|
69
|
-
else:
|
|
70
|
-
representation = self.create_from_state_and_modifications(
|
|
71
|
-
state=state,
|
|
72
|
-
state_modifications=modifications,
|
|
73
|
-
previous_state_representation=previous_state_representation,
|
|
74
|
-
)
|
|
75
|
-
|
|
76
|
-
return representation
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|