valanga 0.1.5__py3-none-any.whl → 0.1.6__py3-none-any.whl

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/evaluations.py CHANGED
@@ -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(self) -> ContentRepresentation | None:
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
 
@@ -1,76 +1,50 @@
1
1
  """
2
- Factory class for creating state representations.
2
+ Factory for creating content representations from game states and state modifications.
3
3
  """
4
4
 
5
5
  from dataclasses import dataclass
6
- from typing import Protocol
6
+ from typing import Callable, TypeVar
7
7
 
8
8
  from .game import State, StateModifications
9
9
  from .represention_for_evaluation import ContentRepresentation
10
10
 
11
+ StateT = TypeVar("StateT", bound=State)
12
+ EvalIn = TypeVar("EvalIn")
11
13
 
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: ...
14
+ CreateFromState = Callable[[StateT], ContentRepresentation[StateT, EvalIn]]
15
+ CreateFromStateAndMods = Callable[
16
+ [StateT, StateModifications, ContentRepresentation[StateT, EvalIn]],
17
+ ContentRepresentation[StateT, EvalIn],
18
+ ]
33
19
 
34
20
 
35
21
  @dataclass
36
- class RepresentationFactory[StateT: State, RepT: ContentRepresentation]:
37
- """
38
- Factory class for creating state representations.
22
+ class RepresentationFactory[StateT: State, EvalIn]:
23
+ """Factory for creating content representations from states and state modifications.
24
+ Attributes:
25
+ create_from_state: Function to create a content representation from a state.
26
+ create_from_state_and_modifications: Function to create a content representation from a state and state modifications.
39
27
  """
40
28
 
41
- create_from_state: CreateFromState[StateT, RepT]
42
- create_from_state_and_modifications: CreateFromStateAndModifications[StateT, RepT]
29
+ create_from_state: CreateFromState[StateT, EvalIn]
30
+ create_from_state_and_modifications: CreateFromStateAndMods[StateT, EvalIn]
43
31
 
44
32
  def create_from_transition(
45
33
  self,
46
34
  state: StateT,
47
- previous_state_representation: RepT | None,
35
+ previous_state_representation: ContentRepresentation[StateT, EvalIn] | None,
48
36
  modifications: StateModifications | None,
49
- ) -> RepT:
50
- """
51
- Create a Generic T_StateRepresentation object from a transition.
52
-
37
+ ) -> ContentRepresentation[StateT, EvalIn]:
38
+ """Creates a content representation from a state transition.
53
39
  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
-
40
+ state: The current state of the game.
41
+ previous_state_representation: The content representation of the previous state, or None if not available.
42
+ modifications: The modifications applied to the previous state to reach the current state, or None if not available.
58
43
  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
44
+ ContentRepresentation[StateT, EvalIn]: The content representation of the current state.
63
45
  """
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
46
+ if previous_state_representation is None or modifications is None:
47
+ return self.create_from_state(state)
48
+ return self.create_from_state_and_modifications(
49
+ state, modifications, previous_state_representation
50
+ )
@@ -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 Any, Protocol, TypeVar
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=Any)
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(Protocol[StateT_contra]):
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) -> EvaluatorInput:
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,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: valanga
3
- Version: 0.1.5
3
+ Version: 0.1.6
4
4
  Summary: Shared types and utilities for evaluation
5
5
  Author-email: Victor Gabillon <victorgabillon@gmail.com>
6
6
  License: GNU GENERAL PUBLIC LICENSE
@@ -1,15 +1,15 @@
1
1
  valanga/__init__.py,sha256=EFoB5P_lGQCXM1tLTc9ZvO5mt_Ui_MXStEpcPwptwd8,945
2
- valanga/evaluations.py,sha256=Csy6z_npeHA5ipUYCR1QVHazvLGIq3StZ6mRv2Bpqxk,1370
2
+ valanga/evaluations.py,sha256=kGq8oU6cV-dlMvX_lSU_AAAWCXlvEGhsXdRt_CmuYvc,1461
3
3
  valanga/evaluator_types.py,sha256=dRNY297Up2BSIM2557jy6cz0cINzfUHOpqkr1T6SSQM,344
4
4
  valanga/game.py,sha256=7vFLJL0AhG9EqG_Po0hpyFU685YVMWnKYXn-QR2yiOo,6086
5
5
  valanga/over_event.py,sha256=jUqN3CXq3e55TvDZatZKFlEOzJfho7M1Zr7VjZUhP6M,7908
6
6
  valanga/policy.py,sha256=TkqcOSePRhHqtuoMbCKe5qZbizvF5H9uG1_oEcIZsuA,1229
7
7
  valanga/progress_messsage.py,sha256=3LnOXSgyU84UkwcpsakcbPt_d3el2ojRSUClAwoPyEk,361
8
8
  valanga/py.typed,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
9
- valanga/representation_factory.py,sha256=zTZEo_sfUYY6fnMHU1U_ToWIIpvXVCs707JKDH2cEKw,2556
10
- valanga/represention_for_evaluation.py,sha256=4ZJhcmAcEAB2CkED9blu6RX3sY5LgVxHJ0p40Sujwn8,1010
11
- valanga-0.1.5.dist-info/licenses/LICENSE,sha256=OXLcl0T2SZ8Pmy2_dmlvKuetivmyPd5m1q-Gyd-zaYY,35149
12
- valanga-0.1.5.dist-info/METADATA,sha256=7ZrF2SDwCyuXDXDTx98w8oLAmoLwx1vQpulXTxXVxQw,44645
13
- valanga-0.1.5.dist-info/WHEEL,sha256=qELbo2s1Yzl39ZmrAibXA2jjPLUYfnVhUNTlyF1rq0Y,92
14
- valanga-0.1.5.dist-info/top_level.txt,sha256=cKFLhxKDTqygHnc0xc_L8jDx6oNu5hSHqZ4UExU4xPo,8
15
- valanga-0.1.5.dist-info/RECORD,,
9
+ valanga/representation_factory.py,sha256=w1RKwuDec-imp5NmB3rg-e5iiuEScbHCX8tnBeXeVgQ,2117
10
+ valanga/represention_for_evaluation.py,sha256=9yCCOuN-h9FnoLJrffKGQ-oXiiXzZT3rP4e5wwMYfys,1135
11
+ valanga-0.1.6.dist-info/licenses/LICENSE,sha256=OXLcl0T2SZ8Pmy2_dmlvKuetivmyPd5m1q-Gyd-zaYY,35149
12
+ valanga-0.1.6.dist-info/METADATA,sha256=cMwv58HEFZHTEmRujAzCRcnU0uL24voleiQV7OVCZDE,44645
13
+ valanga-0.1.6.dist-info/WHEEL,sha256=qELbo2s1Yzl39ZmrAibXA2jjPLUYfnVhUNTlyF1rq0Y,92
14
+ valanga-0.1.6.dist-info/top_level.txt,sha256=cKFLhxKDTqygHnc0xc_L8jDx6oNu5hSHqZ4UExU4xPo,8
15
+ valanga-0.1.6.dist-info/RECORD,,