merge etc

This commit is contained in:
Sander Land committed 2020-06-22 19:19:26 +02:00
commit a333ca7142
22 files changed
+101 -37

No files matched your search

+1
View File
@@ -10,6 +10,7 @@
* Alternatively download and install [Python 3.7.5](https://www.python.org/downloads/release/python-375/)
* Install Katago using [Homebrew](https://brew.sh/) by executing `brew install katago`
* You can also follow instructions [here](https://github.com/lightvector/KataGo) to compile KataGo yourself.
* If you encounter SSL errors on downloading model files, you may need to follow [these](https://stackoverflow.com/questions/52805115/certificate-verify-failed-unable-to-get-local-issuer-certificate) instructions to fix your certificates.
## Installation and running KaTrain from PyPi
* Run `pip3 install katrain`
+1 -1
View File
@@ -145,7 +145,7 @@ In addition to shortcuts mentioned above and those shown in the main menu:
* Ideas, feedback, and contributions to code or translations are all very welcome.
* For suggestions and planned improvements, see [open issues](https://github.com/sanderland/katrain/issues) on github to check if the functionality is already planned.
* I am looking for contributors of more translations of both this manual and the program itself. The best way to help with this is to contact me on discord.
* You also can contact me on [discord](https://discord.gg/AjTPFpN) (Sander#3278), [KakaoTalk](https://open.kakao.com/o/gTsMJCac)
* You can contact me on [discord](https://discord.gg/AjTPFpN) (Sander#3278), [KakaoTalk](https://open.kakao.com/o/gTsMJCac)
or [Reddit](http://reddit.com/u/sanderbaduk) to get help, discuss improvements, or simply show your appreciation.
* You can also donate to the project through [Liberapay](https://liberapay.com/KaTrain/) or [Github Sponsors](https://github.com/sponsors/sanderland).
+1 -1
View File
@@ -16,7 +16,7 @@
"anim_pv_time": 0.5,
"debug_level": 0,
"lang": "en",
"version": "1.2.0"
"version": "1.3.0"
},
"timer": {
"byo_length": 30,
+5 -2
View File
@@ -85,13 +85,16 @@ class KaTrainBase:
config_file = user_config_file
self.log(f"Copied package config to local file {config_file}", OUTPUT_INFO)
else: # user file exists
version = JsonStore(user_config_file, indent=4).get("general")["version"]
try:
version = JsonStore(user_config_file).get("general")["version"]
except Exception: # broken file etc
version = "0.0.0"
if version < CONFIG_MIN_VERSION:
backup = user_config_file + f".{version}.backup"
shutil.copyfile(user_config_file, backup)
shutil.copyfile(package_config_file, user_config_file)
self.log(
f"Copied package config file to {user_config_file} as user file is outdated (<{CONFIG_MIN_VERSION}). Old version stored as {backup}",
f"Copied package config file to {user_config_file} as user file is outdated or broken ({version}<{CONFIG_MIN_VERSION}). Old version stored as {backup}",
OUTPUT_INFO,
)
config_file = user_config_file
+1 -1
View File
@@ -37,7 +37,7 @@ class KataGoEngine:
self.query_counter = 0
self.katago_process = None
self.base_priority = 0
self.override_settings = {'reportAnalysisWinratesAs':'BLACK'} # force these settings
self.override_settings = {"reportAnalysisWinratesAs": "BLACK"} # force these settings
self._lock = threading.Lock()
self.analysis_thread = None
self.stderr_thread = None
+22 -11
View File
@@ -5,6 +5,7 @@ from typing import Any, Dict, List, Tuple, Union
from kivy.clock import Clock
from kivy.properties import BooleanProperty, NumericProperty, StringProperty, ListProperty
from kivy.metrics import dp
from kivy.uix.anchorlayout import AnchorLayout
from kivy.uix.boxlayout import BoxLayout
from kivy.uix.label import Label
@@ -25,7 +26,7 @@ from katrain.core.constants import (
)
from katrain.core.engine import KataGoEngine
from katrain.core.lang import i18n
from katrain.core.utils import find_package_resource, PATHS
from katrain.core.utils import PATHS, find_package_resource
from katrain.gui.kivyutils import BackgroundMixin, I18NSpinner
from katrain.gui.style import DEFAULT_FONT, EVAL_COLORS
from katrain.gui.widgets.progress_loader import ProgressLoader
@@ -335,12 +336,12 @@ class ConfigAIPopup(QuickConfigGui):
for _ in range((self.max_options - len(mode_settings)) * 2):
self.options_grid.add_widget(Label(size_hint_x=None))
class ConfigPopup(QuickConfigGui):
def __init__(self, katrain):
super().__init__(katrain)
self.paths = [self.katrain.config("engine/model"), "katrain/models", "~/.katrain"]
def build_and_set_properties(self, *_args):
super().build_and_set_properties()
@@ -371,12 +372,9 @@ class ConfigPopup(QuickConfigGui):
self.model_files.text = models_available_msg
MODELS = {
# "pure 20b": "https://github.com/lightvector/KataGo/releases/download/v1.4.0/g170-b20c256x2-s4384473088-d968438914.bin.gz",
# "pure 30b": "https://github.com/lightvector/KataGo/releases/download/v1.4.0/g170-b30c320x2-s3530176512-d968463914.bin.gz",
# "pure 40b": "https://github.com/lightvector/KataGo/releases/download/v1.4.0/g170-b40c256x2-s3708042240-d967973220.bin.gz",
"final 20b":"https://github.com/lightvector/KataGo/releases/download/v1.4.5/g170e-b20c256x2-s5303129600-d1228401921.bin.gz",
"final 30b": "https://github.com/lightvector/KataGo/releases/download/v1.4.5/g170-b30c320x2-s4824661760-d1229536699.bin.gz",
"final 40b":"https://github.com/lightvector/KataGo/releases/download/v1.4.5/g170-b40c256x2-s5095420928-d1229425124.bin.gz"
"latest 20b": "https://github.com/lightvector/KataGo/releases/download/v1.4.5/g170e-b20c256x2-s5303129600-d1228401921.bin.gz",
"latest 30b": "https://github.com/lightvector/KataGo/releases/download/v1.4.5/g170-b30c320x2-s4824661760-d1229536699.bin.gz",
"latest 40b": "https://github.com/lightvector/KataGo/releases/download/v1.4.5/g170-b40c256x2-s5095420928-d1229425124.bin.gz",
}
def download_models(self, *_largs):
@@ -388,6 +386,11 @@ class ConfigPopup(QuickConfigGui):
self.katrain.log(f"Download of {model} model complete, but could not move file: {e}", OUTPUT_ERROR)
self.check_models()
for c in self.download_progress_box.children:
if isinstance(c, ProgressLoader) and c.request:
c.request.cancel()
self.download_progress_box.clear_widgets()
downloading = False
for name, url in self.MODELS.items():
filename = os.path.split(url)[1]
if not any(os.path.split(f)[1] == filename for f in self.model_files.values):
@@ -397,15 +400,23 @@ class ConfigPopup(QuickConfigGui):
progress = ProgressLoader(
download_url=url,
path_to_file=savepath_tmp,
downloading_text=f"Downloading {name} model: " + "{}%",
downloading_text=f"Downloading {name} model: " + "{}",
label_downloading_text=f"Starting download for {name} model",
download_complete=lambda req, tmp=savepath_tmp, path=savepath, model=name: download_complete(
req, tmp, path, model
),
download_redirected=lambda req: self.katrain.log(
f"Download {name} redirected {req.resp_headers}", OUTPUT_DEBUG
download_redirected=lambda req, mname=name: self.katrain.log(
f"Download {mname} redirected {req.resp_headers}", OUTPUT_DEBUG
),
download_error=lambda req, error, mname=name: self.katrain.log(
f"Download of {mname} failed or cancelled ({error})", OUTPUT_ERROR
),
)
progress.start(self.download_progress_box)
downloading = True
if not downloading:
self.download_progress_box.add_widget(Label(text=i18n._("All models downloaded"), text_size=(None, dp(50))))
print("x")
def update_config(self, save_to_file=True):
updated = super().update_config(save_to_file=save_to_file)
+36 -16
View File
@@ -1,9 +1,9 @@
# From KivyMD which will remove it in their next version, with some fixes
from kivy.clock import Clock
from kivy.animation import Animation
from kivy.network.urlrequest import UrlRequest
from kivy.clock import Clock
from kivy.lang import Builder
from kivy.properties import StringProperty, ObjectProperty
from kivy.network.urlrequest import UrlRequest
from kivy.properties import ObjectProperty, StringProperty
from kivy.uix.boxlayout import BoxLayout
Builder.load_string(
@@ -14,18 +14,22 @@ Builder.load_string(
<ProgressLoader>
opacity: 0
spacing: 10
size_hint_y: None
height: dp(25)
MDSpinner
id: spinner
size_hint: None, 0.8
width: dp(32)
size: dp(23), dp(23)
color: 0.95,0.95,0.95,1
MDLabel:
id: label_download
max_lines: 2
shorten: True
max_lines: 1
shorten_from: 'right'
halign: 'left'
valign: 'center'
text_size: self.size
height: dp(23)
color: 0.95,0.95,0.95,1
text: root.label_downloading_text
"""
@@ -47,6 +51,8 @@ class ProgressLoader(BoxLayout):
download_complete = ObjectProperty()
"""Function, called after a successful file upload."""
download_error = ObjectProperty()
"""Function, called after an error in downloading."""
download_redirected = ObjectProperty()
"""Function, called after a redirect event."""
@@ -56,6 +62,7 @@ class ProgressLoader(BoxLayout):
def __init__(self, **kwargs):
super().__init__(**kwargs)
self.root_instance = None
self.request = None
def start(self, root_instance):
self.root_instance = root_instance
@@ -81,29 +88,42 @@ class ProgressLoader(BoxLayout):
file_path=path,
chunk_size=102400,
on_progress=self.update_progress,
on_success=self.on_success,
on_redirect=self.redirected,
on_error=self.download_error,
on_success=self.handle_success,
on_redirect=self.handle_redirect,
on_error=lambda req, error: self.handle_error(req, error),
on_failure=lambda req, res: self.handle_error(req, "Failure"),
on_cancel=lambda req: self.handle_error(req, "Cancelled"),
)
def redirected(self, request, *_args):
new_url = request.resp_headers.get("location")
def handle_redirect(self, request, *_args):
new_url = request.resp_headers.get("location") or request.resp_headers.get("Location")
if new_url:
self.download_url = new_url
self.request_download_file(self.download_url, self.path_to_file)
else:
self.handle_error()
if self.download_redirected:
self.download_redirected(request)
def download_error(self, request, *_args):
pass
def cleanup(self):
self.root_instance.remove_widget(self)
def handle_error(self, request, error):
status = f"Error: {error}"
if request.resp_status:
status += f" ({request.resp_status})"
self.label_downloading_text = self.downloading_text.format(status)
self.ids.spinner.active = False
if self.download_error:
self.download_error(request, error)
def update_progress(self, request, current_size, total_size):
if total_size < 1e4:
current_size = 0
percent = current_size * 100 // max(total_size, 1)
self.label_downloading_text = self.downloading_text.format(percent)
percent = current_size / max(total_size, 1)
self.label_downloading_text = self.downloading_text.format(f"{percent:.1%}")
def on_success(self, request, result):
self.root_instance.remove_widget(self)
def handle_success(self, request, result):
self.cleanup()
if self.download_complete:
self.download_complete(request)
Binary file not shown.
@@ -564,3 +564,7 @@ msgstr "{num} available model(s) found"
#. TODO
msgid "download models button"
msgstr "Download Models"
#. TODO
msgid "All models downloaded"
msgstr "All available models already downloaded"
Binary file not shown.
@@ -607,3 +607,7 @@ msgstr "{num} available model(s) found"
#. TODO
msgid "download models button"
msgstr "Download Models"
#. TODO
msgid "All models downloaded"
msgstr "All available models already downloaded"
Binary file not shown.
@@ -598,3 +598,6 @@ msgstr "Download Models"
msgid "models available"
msgstr "{num} available model(s) found"
msgid "All models downloaded"
msgstr "All available models already downloaded"
Binary file not shown.
@@ -497,7 +497,7 @@ msgstr ""
" cuantas jugadas en la apertura son al azar."
msgid "ai:p:weighted"
msgstr "Intuición debilitada"
msgstr "Parcial"
msgid "aihelp:p:weighted"
msgstr ""
@@ -602,3 +602,7 @@ msgstr "{num} available model(s) found"
#. TODO
msgid "download models button"
msgstr "Download Models"
#. TODO
msgid "All models downloaded"
msgstr "All available models already downloaded"
Binary file not shown.
@@ -641,3 +641,7 @@ msgstr "{num} available model(s) found"
#. TODO
msgid "download models button"
msgstr "Download Models"
#. TODO
msgid "All models downloaded"
msgstr "All available models already downloaded"
Binary file not shown.
@@ -579,3 +579,7 @@ msgstr "{num} available model(s) found"
#. TODO
msgid "download models button"
msgstr "Download Models"
#. TODO
msgid "All models downloaded"
msgstr "All available models already downloaded"
Binary file not shown.
@@ -604,3 +604,7 @@ msgstr "{num} available model(s) found"
#. TODO
msgid "download models button"
msgstr "Download Models"
#. TODO
msgid "All models downloaded"
msgstr "All available models already downloaded"
+6 -4
View File
@@ -198,18 +198,20 @@
LabelledFloatInput:
input_property: "engine/wide_root_noise"
hint_text: i18n._("engine:wide_root_noise:hint")
BoxLayout:
MDBoxLayout:
orientation: 'horizontal'
size_hint: 1,1.5
BoxLayout:
MDBoxLayout:
size_hint_x: 4 if self.children else 0.0001
orientation: 'vertical'
id: download_progress_box
AnchorLayout:
AutoSizedRoundedRectangleButton:
padding_x: 15
size_hint: None,0.5
size_hint: None,None
height: dp(40)
text: i18n._("update settings")
on_press: root.update_config(True)
Widget: # for centering
<ConfigTeacherPopup>
options_grid: options_grid