From 3759eadee4c466248ff0ab6efcb7def21224ffc8 Mon Sep 17 00:00:00 2001 From: Sander Land Date: Sun, 3 May 2020 22:44:02 +0200 Subject: [PATCH] reduce installer size --- README.md | 4 +- core/ai.py | 6 +-- gui/popups.py | 4 +- img/flaticon/bar.svg | 1 - img/flaticon/gears.svg | 114 --------------------------------------- img/flaticon/go-game.svg | 60 --------------------- spec/KaTrain.spec | 8 ++- 7 files changed, 13 insertions(+), 184 deletions(-) delete mode 100644 img/flaticon/bar.svg delete mode 100644 img/flaticon/gears.svg delete mode 100644 img/flaticon/go-game.svg diff --git a/README.md b/README.md index 7335f0c..41d6f01 100644 --- a/README.md +++ b/README.md @@ -36,14 +36,14 @@ but has since grown to include a wide range of features, including: * Download the repository by clicking the green *Clone or download* on this page and *Download zip*. Extract the contents. * Make sure you have a python installation, I will assume Anaconda (Python 3.7), available [here](https://www.anaconda.com/distribution/#download-section). * Open 'Anaconda prompt' from the start menu and navigate to where you extracted the zip file using the `cd ` command. -* Execute the command `pip install numpy kivy_deps.glew kivy_deps.sdl2 kivy_deps.gstreamer kivy` +* Execute the command `pip install kivy_deps.glew kivy_deps.sdl2 kivy_deps.gstreamer kivy` * Start the app by running `python katrain.py` in the directory where you downloaded the scripts. Note that the program can be slow to initialize the first time, due to kata's gpu tuning. ### Installation for Linux/Mac users * This assumed you have a working Python 3.6/3.7 installation as a default. If your default is python 2, use pip3/python3. Kivy currently does not have a release for Python 3.8. * Git clone or download the repository. -* `pip install kivy numpy` +* `pip install kivy` * A binary for KataGo is included, but if you have compiled your own, point the 'engine/katago' setting to the relevant KataGo v1.3.5+ binary. * Start the app by running `python katrain.py`. Note that the program can be slow to initialize the first time, due to KataGo's GPU tuning. diff --git a/core/ai.py b/core/ai.py index 83e7eb8..bf420f2 100644 --- a/core/ai.py +++ b/core/ai.py @@ -4,8 +4,6 @@ import random import time from typing import Dict, List, Tuple -import numpy as np - from core.common import OUTPUT_DEBUG, OUTPUT_ERROR, OUTPUT_INFO, var_to_grid from core.engine import EngineDiedException from core.game import Game, GameNode, IllegalMoveException, Move @@ -18,7 +16,9 @@ def weighted_selection_without_replacement(items: List[Tuple[float, float, int, def dirichlet_noise(num, dir_alpha=0.3): - return np.random.dirichlet([dir_alpha] * num) + sample = [random.gammavariate(dir_alpha, 1) for _ in range(num)] + sum_sample = sum(sample) + return [s / sum_sample for s in sample] def fmt_moves(moves: List[Tuple[float, Move]]): diff --git a/gui/popups.py b/gui/popups.py index 5934c69..bb9e8dd 100644 --- a/gui/popups.py +++ b/gui/popups.py @@ -133,7 +133,7 @@ class ConfigPopup(QuickConfigGui): col_container.add_widget(cols[0]) col_container.add_widget(cols[1]) self.add_widget(col_container) - self.info_label = Label(halign='center') + self.info_label = Label(halign="center") self.apply_button = StyledButton(text="Apply", on_press=lambda _: self.update_config()) self.save_button = StyledButton(text="Apply and Save", on_press=lambda _: self.update_config(save_to_file=True)) btn_container = BoxLayout(orientation="horizontal", size_hint=(1, 0.1), spacing=1, padding=1) @@ -170,7 +170,7 @@ class ConfigPopup(QuickConfigGui): def restart_engine(_dt): old_engine = self.katrain.engine # type: KataGoEngine - old_proc =old_engine.katago_process + old_proc = old_engine.katago_process if old_proc: old_engine.shutdown(finish=True) diff --git a/img/flaticon/bar.svg b/img/flaticon/bar.svg deleted file mode 100644 index 55c00c2..0000000 --- a/img/flaticon/bar.svg +++ /dev/null @@ -1 +0,0 @@ - \ No newline at end of file diff --git a/img/flaticon/gears.svg b/img/flaticon/gears.svg deleted file mode 100644 index 20018d4..0000000 --- a/img/flaticon/gears.svg +++ /dev/null @@ -1,114 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/img/flaticon/go-game.svg b/img/flaticon/go-game.svg deleted file mode 100644 index 92bd494..0000000 --- a/img/flaticon/go-game.svg +++ /dev/null @@ -1,60 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/spec/KaTrain.spec b/spec/KaTrain.spec index 481e14c..00706fd 100644 --- a/spec/KaTrain.spec +++ b/spec/KaTrain.spec @@ -3,7 +3,7 @@ from kivy_deps import sdl2, glew block_cipher = None -# build with "pyinstaller spec/katrain.spec --noconfirm" +# pyinstaller spec/katrain.spec --upx-dir my --noconfirm a = Analysis(['..\\katrain.py'], pathex=['C:\\Users\\sande\\Desktop\\katrain\\spec'], @@ -12,7 +12,7 @@ a = Analysis(['..\\katrain.py'], hiddenimports=["win32file","win32timezone"], # FileChooser in kivy loads this conditionally hookspath=[], runtime_hooks=[], - excludes=['..\\bots'], + excludes=['scipy','pandas','numpy','matplotlib','docutils','mkl'], win_no_prefer_redirects=False, win_private_assemblies=False, cipher=block_cipher, @@ -32,6 +32,10 @@ exe = EXE(pyz, strip=False, upx=True, console=True) # , icon='..\\icon.png' + +EXCLUDE_SUFFIX = ['katago-bs','b10-1.3.txt.gz','katago.exe','screenshot_analyze.png','screenshot_play.png'] +EXCLUDE = ['KataGoData'] +a.datas = [(ff,ft,tp) for ff,ft,tp in a.datas if not any(ff.endswith(suffix) for suffix in EXCLUDE_SUFFIX) and not any(kw in ff for kw in EXCLUDE)] coll = COLLECT(exe, a.binaries, a.zipfiles,