algorhino-anemone 0.1.2__py3-none-any.whl → 0.1.3__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.
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: algorhino-anemone
3
- Version: 0.1.2
3
+ Version: 0.1.3
4
4
  Summary: anemone searches trees
5
5
  Author-email: Victor Gabillon <victorgabillon@gmail.com>
6
6
  License-Expression: GPL-3.0-only
@@ -12,8 +12,8 @@ Classifier: Operating System :: OS Independent
12
12
  Requires-Python: >=3.13
13
13
  Description-Content-Type: text/markdown
14
14
  License-File: LICENSE
15
- Requires-Dist: valanga
16
- Requires-Dist: atomheart
15
+ Requires-Dist: valanga>=0.1.4
16
+ Requires-Dist: atomheart>=0.1.2
17
17
  Requires-Dist: rich
18
18
  Requires-Dist: sortedcollections>=2.1.0
19
19
  Requires-Dist: graphviz
@@ -1,10 +1,10 @@
1
- algorhino_anemone-0.1.2.dist-info/licenses/LICENSE,sha256=OXLcl0T2SZ8Pmy2_dmlvKuetivmyPd5m1q-Gyd-zaYY,35149
1
+ algorhino_anemone-0.1.3.dist-info/licenses/LICENSE,sha256=OXLcl0T2SZ8Pmy2_dmlvKuetivmyPd5m1q-Gyd-zaYY,35149
2
2
  anemone/__init__.py,sha256=iKX9OGJxbyIqe9Fy-xxZY6sdH7WcG4RFyPR0WBai7Ls,942
3
- anemone/basics.py,sha256=jMKY9mFLbbMZ_xNvtBVlbZI_vP15rg2tUGUf9ZQ-9tw,1023
3
+ anemone/basics.py,sha256=plCN-SfAcCj4TPDVD3r19Q36UFjiKmNvuEyPH0kQ7Qs,574
4
4
  anemone/factory.py,sha256=Nmx84UrSqED3R9891XoBTX56jKlINvZn4DLYduSbHgo,6020
5
5
  anemone/state_transition.py,sha256=fxvHZOYRtWV5ExXRIoehdRg9qV6zhgiE5uiCeOc80Dc,1418
6
- anemone/tree_and_value_branch_selector.py,sha256=bervTIx03h79g-Qu1npGpcA5YlSzZKRk0xA86l69jX4,3480
7
- anemone/tree_exploration.py,sha256=Fb6mNw0UxbaaFtbBAhxjjKJQbClbRPzhrEG2pWHQkjY,10378
6
+ anemone/tree_and_value_branch_selector.py,sha256=7s_Tz3JeG0rFYfFLSEUegMSb-av7vKg_9jM2AANUbig,3474
7
+ anemone/tree_exploration.py,sha256=cg1iTp3j9p9jUNjm07ogbflX8VC15AV8GEhGz3g1YNU,10529
8
8
  anemone/indices/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
9
9
  anemone/indices/index_manager/__init__.py,sha256=P49ofGrnP_Nfmv63Rg_-Zvwn5NFvFFDQ3MD3GMeWNWw,515
10
10
  anemone/indices/index_manager/factory.py,sha256=Fti6PTnLOEg0g5cqqRBMsmGGNZw6uVFiKpjv0B766qE,1783
@@ -18,8 +18,8 @@ anemone/node_evaluation/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG
18
18
  anemone/node_evaluation/node_direct_evaluation/__init__.py,sha256=2_YwJ3oe0KBfIc3Hs-FLz093RLZsTG-VaNmecLceoiY,898
19
19
  anemone/node_evaluation/node_direct_evaluation/factory.py,sha256=lpFmBJkIGAnar5-pQ1vMze9jUFKFchp5Pg2S8eK-ABM,470
20
20
  anemone/node_evaluation/node_direct_evaluation/node_direct_evaluator.py,sha256=jM-gkNeaOOXBXS4JNAAVeXJ5K2bAOppQwV7wpTBX1Ck,5787
21
- anemone/node_evaluation/node_tree_evaluation/node_minmax_evaluation.py,sha256=npqy9r7ZKHGMJsDhSY7bZZbRvakwoTyABpwQOVTQ-ww,35126
22
- anemone/node_evaluation/node_tree_evaluation/node_tree_evaluation.py,sha256=-fiuTO0nWKKiKWAdgFi-L8kKxIjH0A_0yeUKrp4fk34,4260
21
+ anemone/node_evaluation/node_tree_evaluation/node_minmax_evaluation.py,sha256=KfU781UnaD9P2qibIKHXXnc8q7Rd2eJJl5NzKKsntsc,35126
22
+ anemone/node_evaluation/node_tree_evaluation/node_tree_evaluation.py,sha256=x5fnbf6NhKGouBgU0rNVNSmusmNovbcnQ3eLH6JV7Ow,4260
23
23
  anemone/node_evaluation/node_tree_evaluation/node_tree_evaluation_factory.py,sha256=UY1glqflqMOqOPAHhtuzJ8QhGOp55Y9InqdhCMt9KJ8,1279
24
24
  anemone/node_factory/__init__.py,sha256=qhbX58hu8-TdFof5zo3ibfPFvF-OWNSgJf3RDMrtyTQ,553
25
25
  anemone/node_factory/algorithm_node_factory.py,sha256=eHsyZ6_no8i9ACfZV8VSKefV3kXiQHvdMNEighDn8Lc,3947
@@ -40,16 +40,16 @@ anemone/node_selector/sequool/sequool.py,sha256=NSGwIQk8KxD-TSzdw2LvFIOPUlNfQX8O
40
40
  anemone/node_selector/uniform/__init__.py,sha256=fRGC0FL_fnXXeNoj3QeMQmNoESrFfSDaiHp-zHpF_zw,366
41
41
  anemone/node_selector/uniform/uniform.py,sha256=Frxyik7Vx2-vF0CcMWclPqymj7XEl08nILtMv4Wjxj8,3745
42
42
  anemone/nodes/__init__.py,sha256=XWTr9wZGGX9XHp-bw3zjKfCVdKnNEgVGL1wFWW-ozzI,393
43
- anemone/nodes/itree_node.py,sha256=ywQIvF8LIihf-7p8OgzMjfTg6S39GRbY3u1b4Ka4JoM,3536
44
- anemone/nodes/tree_node.py,sha256=DxsFJw5Y8vromLu-oZL8D5F9aLME4FjI1d8XF9e3Eq8,7728
43
+ anemone/nodes/itree_node.py,sha256=ZXyux7M2BBEGyraUWLHyYeoLgEHvuRgB0JJb-W-Ln_g,3547
44
+ anemone/nodes/tree_node.py,sha256=C9jKzA62ToYhANYjwhS2qPAHti81l-x-p7RmKe6Sb0Q,7739
45
45
  anemone/nodes/tree_traversal.py,sha256=sE9as_8-74bIUuAYNhk2MK6VvlrN1Y3mFExff_HGpQ8,3958
46
46
  anemone/nodes/utils.py,sha256=_NPGFnjzouFMpepyNPw5D0d3999_F3tmJHa0bafwo7M,4501
47
47
  anemone/nodes/algorithm_node/__init__.py,sha256=8cNk3PmDzd22K78YWiO29Mu5A1FCObzPwEfWE1ym6Jk,116
48
- anemone/nodes/algorithm_node/algorithm_node.py,sha256=VzZsLZ0KmRt92me1U_mwATLu_uyVVafTOA-wtugtyms,6517
48
+ anemone/nodes/algorithm_node/algorithm_node.py,sha256=SlYxmClzIgd6y1yPB3G2vZMoPIzylo8hHqcO2iXJje8,6528
49
49
  anemone/progress_monitor/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
50
50
  anemone/progress_monitor/progress_monitor.py,sha256=ExuvwOntZBwrBjIbNr8ZpeCd2F5s21rsX74FFog7gqY,10896
51
51
  anemone/recommender_rule/__init__.py,sha256=9K73T0bkpvHg0IsQc1OW8QgsUhCNYq9ceqPMkwdqE8c,347
52
- anemone/recommender_rule/recommender_rule.py,sha256=Ck34nf3fw6FZOi-1HR_XJpuEggcCTxGoCJE_ueUNVO4,4587
52
+ anemone/recommender_rule/recommender_rule.py,sha256=yQlIWWWFKJQFSxuDaEBNtUrgDe1PRwNusM2a1ds89hw,4427
53
53
  anemone/search_factory/__init__.py,sha256=ToU88Fa1lBBdf2AYTJ2PNVwWzi5Hzh-78-WOxClVkN4,619
54
54
  anemone/search_factory/search_factory.py,sha256=vCkxJk4cs6i6jjrTrUAsRBtp38N84j_uhyvpYIODoG4,6757
55
55
  anemone/tree_manager/__init__.py,sha256=D3j8emzRNF1fkPTpNUPsXbqAzMM9SyI3Ty_4Y_b2Tas,962
@@ -76,7 +76,7 @@ anemone/utils/dict_of_numbered_dict_with_pointer_on_max.py,sha256=s5Z-O5mBwJUh4P
76
76
  anemone/utils/logger.py,sha256=bJQ8COqdn5obtbi8TuokQHmdHpp57XRksTmfvCLLfyM,2973
77
77
  anemone/utils/my_value_sorted_dict.py,sha256=LbqtpBSCS7VrUTUChWCsi18IKZj65FkTJREqbl-xSVA,619
78
78
  anemone/utils/small_tools.py,sha256=l9dy5Oqvuvg8qQXqJUfyb3uwBHwVGVrKz6WeTHjyLTk,2766
79
- algorhino_anemone-0.1.2.dist-info/METADATA,sha256=BxqVitC0TFU3tWcoxkf_aSsdefABd1flA9_uYBKkgdM,5677
80
- algorhino_anemone-0.1.2.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
81
- algorhino_anemone-0.1.2.dist-info/top_level.txt,sha256=G1vbB-vAevQVde3UZ5X1_Ysy1_6sJDEueHRi2qcDgrY,8
82
- algorhino_anemone-0.1.2.dist-info/RECORD,,
79
+ algorhino_anemone-0.1.3.dist-info/METADATA,sha256=1ky2d5juHL2FQc6VTlRsVJNqej1Pr69dvR0dYX1ZoJA,5691
80
+ algorhino_anemone-0.1.3.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
81
+ algorhino_anemone-0.1.3.dist-info/top_level.txt,sha256=G1vbB-vAevQVde3UZ5X1_Ysy1_6sJDEueHRi2qcDgrY,8
82
+ algorhino_anemone-0.1.3.dist-info/RECORD,,
anemone/basics.py CHANGED
@@ -1,11 +1,8 @@
1
1
  """Basic types and protocols for Anemone."""
2
2
 
3
- from dataclasses import dataclass
4
- from typing import Annotated, Mapping, Protocol
3
+ from typing import Annotated, Protocol
5
4
 
6
- from valanga import BoardEvaluation, BranchKey, Color, HasTurn, State
7
-
8
- from anemone.recommender_rule.recommender_rule import BranchPolicy
5
+ from valanga import Color, HasTurn, State
9
6
 
10
7
  type Seed = Annotated[int, "seed"]
11
8
  type TreeDepth = Annotated[int, "Depth level of a node in a tree structure"]
@@ -17,16 +14,6 @@ class StateWithTurn(State, HasTurn, Protocol):
17
14
  ...
18
15
 
19
16
 
20
- @dataclass(frozen=True, slots=True)
21
- class BranchRecommendation:
22
- """A recommendation for a specific branch in a tree node."""
23
-
24
- branch_key: BranchKey
25
- evaluation: BoardEvaluation | None = None
26
- policy: BranchPolicy | None = None
27
- child_evals: Mapping[BranchKey, BoardEvaluation] | None = None
28
-
29
-
30
17
  class HasBlackAndWhiteTurn(Protocol):
31
18
  """Protocol for state that has black and white turns."""
32
19
 
@@ -21,12 +21,12 @@ from random import choice
21
21
  from typing import Any, Protocol, Self, runtime_checkable
22
22
 
23
23
  from valanga import (
24
- BoardEvaluation,
25
24
  BranchKey,
26
25
  Color,
27
26
  FloatyStateEvaluation,
28
27
  ForcedOutcome,
29
28
  OverEvent,
29
+ StateEvaluation,
30
30
  TurnState,
31
31
  )
32
32
 
@@ -874,8 +874,8 @@ class NodeMinmaxEvaluation[
874
874
  best_branches.append(branch_key)
875
875
  return best_branches
876
876
 
877
- def evaluate(self) -> BoardEvaluation:
878
- """Build a BoardEvaluation from current minmax state."""
877
+ def evaluate(self) -> StateEvaluation:
878
+ """Build a StateEvaluation from current minmax state."""
879
879
  if self.over_event.is_over():
880
880
  return ForcedOutcome(
881
881
  outcome=self.over_event,
@@ -1,10 +1,10 @@
1
1
  from typing import TYPE_CHECKING, Protocol, Self
2
2
 
3
3
  from valanga import (
4
- BoardEvaluation,
5
4
  BranchKey,
6
5
  OverEvent,
7
6
  State,
7
+ StateEvaluation,
8
8
  )
9
9
 
10
10
  type BranchSortValue = tuple[float, int, int]
@@ -90,8 +90,8 @@ class NodeTreeEvaluation[StateT: State = State](Protocol):
90
90
  """Update terminal state based on updated branches."""
91
91
  ...
92
92
 
93
- def evaluate(self) -> BoardEvaluation:
94
- """Return a board evaluation for this node."""
93
+ def evaluate(self) -> StateEvaluation:
94
+ """Return a state evaluation for this node."""
95
95
  ...
96
96
 
97
97
  def description_tree_visualizer_branch(self, child: "ITreeNode[StateT]") -> str:
@@ -145,7 +145,7 @@ class AlgorithmNode[StateT: State = State]:
145
145
  )
146
146
 
147
147
  @property
148
- def all_branches_keys(self) -> BranchKeyGeneratorP:
148
+ def all_branches_keys(self) -> BranchKeyGeneratorP[BranchKey]:
149
149
  """
150
150
  Returns a generator that yields the branch keys for the current board state.
151
151
 
@@ -108,7 +108,7 @@ class ITreeNode[StateT: State = State](Protocol):
108
108
  """
109
109
 
110
110
  @property
111
- def all_branches_keys(self) -> BranchKeyGeneratorP:
111
+ def all_branches_keys(self) -> BranchKeyGeneratorP[BranchKey]:
112
112
  """
113
113
  Get the available branch keys of the node.
114
114
 
@@ -152,7 +152,7 @@ class TreeNode[
152
152
  return not self.parent_nodes
153
153
 
154
154
  @property
155
- def all_branches_keys(self) -> BranchKeyGeneratorP:
155
+ def all_branches_keys(self) -> BranchKeyGeneratorP[BranchKey]:
156
156
  """
157
157
  Returns a generator that yields the branch keys for the current state.
158
158
 
@@ -16,9 +16,10 @@ Example usage:
16
16
  from dataclasses import dataclass
17
17
  from enum import Enum
18
18
  from random import Random
19
- from typing import Literal, Mapping, Protocol
19
+ from typing import Literal, Protocol
20
20
 
21
21
  from valanga import BranchKey, State
22
+ from valanga.policy import BranchPolicy
22
23
 
23
24
  from anemone.nodes.algorithm_node.algorithm_node import (
24
25
  AlgorithmNode,
@@ -26,15 +27,6 @@ from anemone.nodes.algorithm_node.algorithm_node import (
26
27
  from anemone.utils.small_tools import softmax
27
28
 
28
29
 
29
- @dataclass(frozen=True, slots=True)
30
- class BranchPolicy:
31
- """
32
- Represents a probability distribution over branches.
33
- """
34
-
35
- probs: Mapping[BranchKey, float] # should sum to ~1.0
36
-
37
-
38
30
  def sample_from_policy(policy: BranchPolicy, rng: Random) -> BranchKey:
39
31
  """Sample a branch key from a probability policy using a RNG."""
40
32
  branches = list(policy.probs.keys())
@@ -5,8 +5,9 @@ from queue import Queue
5
5
  from random import Random
6
6
 
7
7
  from valanga import TurnState
8
+ from valanga.policy import Recommendation
8
9
 
9
- from anemone.basics import BranchRecommendation, Seed
10
+ from anemone.basics import Seed
10
11
  from anemone.progress_monitor.progress_monitor import (
11
12
  AllStoppingCriterionArgs,
12
13
  )
@@ -43,9 +44,7 @@ class TreeAndValueBranchSelector[StateT: TurnState = TurnState]:
43
44
  recommend_branch_after_exploration: recommender_rule.AllRecommendFunctionsArgs
44
45
  queue_progress_player: Queue[IsDataclass] | None
45
46
 
46
- def select_branch(
47
- self, state: StateT, selection_seed: Seed
48
- ) -> BranchRecommendation:
47
+ def select_branch(self, state: StateT, selection_seed: Seed) -> Recommendation:
49
48
  """
50
49
  Selects the best branch based on the tree and value strategy.
51
50
 
@@ -59,7 +58,7 @@ class TreeAndValueBranchSelector[StateT: TurnState = TurnState]:
59
58
  tree_exploration: TreeExploration = self.create_tree_exploration(state=state)
60
59
  self.random_generator.seed(selection_seed)
61
60
 
62
- branch_recommendation: BranchRecommendation = tree_exploration.explore(
61
+ branch_recommendation: Recommendation = tree_exploration.explore(
63
62
  random_generator=self.random_generator
64
63
  ).branch_recommendation
65
64
 
@@ -20,9 +20,10 @@ from queue import Queue
20
20
  from random import Random
21
21
  from typing import TYPE_CHECKING, Any, Callable
22
22
 
23
- from valanga import BoardEvaluation, BranchKey, PlayerProgressMessage, State, TurnState
23
+ from valanga import BranchKey, PlayerProgressMessage, State, StateEvaluation, TurnState
24
+ from valanga.game import BranchName
25
+ from valanga.policy import Recommendation
24
26
 
25
- from anemone.basics import BranchRecommendation
26
27
  from anemone.nodes.algorithm_node.algorithm_node import AlgorithmNode
27
28
  from anemone.progress_monitor.progress_monitor import (
28
29
  AllStoppingCriterionArgs,
@@ -39,7 +40,7 @@ from . import tree_manager as tree_man
39
40
  from .trees.factory import ValueTreeFactory
40
41
 
41
42
  if TYPE_CHECKING:
42
- from anemone.recommender_rule.recommender_rule import BranchPolicy
43
+ from valanga.policy import BranchPolicy
43
44
 
44
45
 
45
46
  @dataclass
@@ -48,21 +49,22 @@ class TreeExplorationResult[NodeT: AlgorithmNode[Any] = AlgorithmNode[Any]]:
48
49
  Tree Exploration Result holds the result of a tree exploration.
49
50
  """
50
51
 
51
- branch_recommendation: BranchRecommendation
52
+ branch_recommendation: Recommendation
52
53
  tree: trees.Tree[NodeT]
53
54
 
54
55
 
55
56
  def compute_child_evals[StateT: State](
56
57
  root: AlgorithmNode[StateT],
57
- ) -> dict[BranchKey, BoardEvaluation]:
58
+ ) -> dict[BranchName, StateEvaluation]:
58
59
  """Compute evaluations for each existing child branch."""
59
- evals: dict[BranchKey, BoardEvaluation] = {}
60
+ evals: dict[BranchName, StateEvaluation] = {}
60
61
  for bk, child in root.branches_children.items():
61
62
  if child is None:
62
63
  continue
63
64
 
64
65
  # Use whatever your canonical per-node evaluation is:
65
- evals[bk] = child.tree_evaluation.evaluate()
66
+ bk_name = root.state.branch_name_from_key(bk)
67
+ evals[bk_name] = child.tree_evaluation.evaluate()
66
68
  return evals
67
69
 
68
70
 
@@ -188,15 +190,16 @@ class TreeExploration[NodeT: AlgorithmNode[Any] = AlgorithmNode[Any]]:
188
190
  policy, random_generator
189
191
  )
190
192
 
193
+ best_branch_name = self.tree.root_node.state.branch_name_from_key(best_branch)
191
194
  self.tree_manager.print_best_line(
192
195
  tree=self.tree
193
196
  ) # todo maybe almost best chosen line no?
194
197
 
195
- branch_recommendation = BranchRecommendation(
196
- branch_key=best_branch,
198
+ branch_recommendation = Recommendation(
199
+ recommended_name=best_branch_name,
197
200
  evaluation=self.tree.root_node.tree_evaluation.evaluate(),
198
201
  policy=policy,
199
- child_evals=compute_child_evals(self.tree.root_node),
202
+ branch_evals=compute_child_evals(self.tree.root_node),
200
203
  )
201
204
 
202
205
  tree_exploration_result: TreeExplorationResult[NodeT] = TreeExplorationResult(