pv stabilization, fav child

This commit is contained in:
Sander Land committed 2020-05-13 20:14:53 +02:00
1 parent 23f8cc97ca
commit 872de528d9
8 files changed
+31 -11

No files matched your search

+1 -1
View File
@@ -53,7 +53,7 @@ class KaTrainGui(BoxLayout):
self._keyboard.bind(on_key_down=self._on_keyboard_down)
def log(self, message, level=OUTPUT_INFO):
if level == OUTPUT_KATAGO_STDERR and 'ERROR' not in self.controls.status.text:
if level == OUTPUT_KATAGO_STDERR and "ERROR" not in self.controls.status.text:
if "starting" in message.lower():
self.controls.set_status(f"KataGo engine starting...")
if message.startswith("Tuning"):
+1 -1
View File
@@ -45,7 +45,7 @@ def find_package_resource(path):
path_obj = pkg_resources.path(".".join(parts[:-1]), parts[-1]).__enter__()
resource_scopes.append(path_obj)
return str(path_obj)
except ModuleNotFoundError as e:
except (ModuleNotFoundError, FileNotFoundError) as e:
print(f"File {path} not found, installation possibly broken")
return "FILENOTFOUND"
else:
+3 -1
View File
@@ -37,7 +37,7 @@ class KataGoEngine:
executable = "katago"
modelfile, configfile = find_package_resource(config["model"]), find_package_resource(config["config"])
self.command = f"{find_package_resource(executable)} analysis -model {modelfile} -config {configfile} -analysis-threads {config['threads']}"
self.command = f'{find_package_resource(executable)} analysis -model "{modelfile}" -config "{configfile}" -analysis-threads {config["threads"]}'
if not sys.platform.startswith("win"):
self.command = shlex.split(self.command)
self.queries = {} # outstanding query id -> start time and callback
@@ -55,6 +55,7 @@ class KataGoEngine:
try:
self.katrain.log(f"Starting KataGo with {self.command}", OUTPUT_DEBUG)
self.katago_process = subprocess.Popen(self.command, stdin=subprocess.PIPE, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
print(self.katago_process, self.katago_process.poll())
except (FileNotFoundError, PermissionError, OSError) as e:
if self.config["katago"].strip():
self.katrain.log(
@@ -111,6 +112,7 @@ class KataGoEngine:
raise EngineDiedException(f"Engine died unexpectedly without sending output, possibly due to out of memory: {e}")
if b"Uncaught exception" in line:
self.katrain.log(f"KataGo Engine Failed: {line.decode()}", OUTPUT_ERROR)
return
if not line:
continue
analysis = json.loads(line)
+2 -1
View File
@@ -136,6 +136,7 @@ class Game:
cn = self.current_node # avoid race conditions
for _ in range(n_times):
if not cn.is_root:
cn.parent.set_favourite_child(cn)
cn = cn.parent
self.set_current_node(cn)
@@ -143,7 +144,7 @@ class Game:
cn = self.current_node # avoid race conditions
for _ in range(n_times):
if cn.children:
cn = cn.children[-1]
cn = cn.favourite_child
self.set_current_node(cn)
def switch_branch(self, direction):
+11
View File
@@ -18,6 +18,7 @@ class GameNode(SGFNode):
self.ai_thoughts = ""
self.move_number = 0
self.undo_threshold = random.random() # for fractional undos, store the random threshold in the move itself for consistency
self._favourite_child = None
def sgf_properties(self, save_comments_player=None, save_comments_class=None, eval_thresholds=None):
properties = copy.copy(super().sgf_properties())
@@ -48,6 +49,16 @@ class GameNode(SGFNode):
def order_children(children):
return sorted(children, key=lambda c: 0.5 if c.auto_undo is None else int(c.auto_undo)) # analyzed/not undone main, non-teach second, undone last
def set_favourite_child(self, c):
self._favourite_child = c
@property
def favourite_child(self) -> Optional["GameNode"]:
if self._favourite_child:
return self._favourite_child
elif self.children:
return self.children[0]
# various analysis functions
def analyze(self, engine, priority=0, visits=None, time_limit=True, refine_move=None, analyze_fast=False):
engine.request_analysis(
+5 -5
View File
@@ -334,22 +334,22 @@ class BadukPanWidget(Widget):
if self.ghost_stone:
self.draw_stone(*self.ghost_stone, (*stone_color[next_player], ghost_alpha))
def animate_pv(self, _dt):
animating_pv = self.animating_pv
if not animating_pv:
return
if animating_pv:
pv, node, start_time, _ = animating_pv
delay = self.ui_config.get("anim_pv_time", 0.5)
up_to_move = (time.time() - start_time) / delay
self.draw_hover_contents()
self.draw_pv(pv, node, up_to_move)
def animate_pv(self, _dt):
if self.animating_pv:
self.draw_hover_contents()
def draw_pv(self, pv, node, up_to_move):
katrain = self.katrain
next_last_player = [node.next_player, node.player]
stone_color = self.ui_config["stones"]
cn = katrain.game.current_node
with self.canvas.after:
if node != cn and node.parent != cn:
hide_node = cn
while hide_node and hide_node.move and hide_node != node:
+1 -1
View File
@@ -278,7 +278,7 @@ class ScoreGraph(Label):
self.nodes = [root]
node = root
while node.children:
node = node.children[0]
node = node.favourite_child
self.nodes.append(node)
self.highlighted_index = 0
+7 -1
View File
@@ -36,7 +36,13 @@ setup(
author_email="sander.land@gmail.com",
url="https://github.com/sanderland/katrain",
license="MIT",
install_requires=["kivy", "kivy_deps.glew;platform_system=='Windows'", "kivy_deps.sdl2;platform_system=='Windows'", "kivy_deps.gstreamer;platform_system=='Windows'","importlib_resources ;python_version<'3.7'",],
install_requires=[
"kivy",
"kivy_deps.glew;platform_system=='Windows'",
"kivy_deps.sdl2;platform_system=='Windows'",
"kivy_deps.gstreamer;platform_system=='Windows'",
"importlib_resources ;python_version<'3.7'",
],
python_requires=">=3.6, <3.8",
entry_points={"console_scripts": ["katrain=katrain.__main__:run_app"]},
classifiers=["Development Status :: 4 - Beta", "Operating System :: Microsoft :: Windows", "Operating System :: POSIX :: Linux", "Programming Language :: Python :: 3"],