Skip to content

Commit

Permalink
Merge branch 'master' into master
Browse files Browse the repository at this point in the history
  • Loading branch information
psygo authored Aug 28, 2024
2 parents d7229b4 + dd089f7 commit 21b0e5c
Show file tree
Hide file tree
Showing 39 changed files with 1,164 additions and 173 deletions.
3 changes: 2 additions & 1 deletion .flake8
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
[flake8]
ignore = E501, E203, W503, E402 # line length, space before binary op, line break before binary op, import not at top
# line length, space before binary op, line break before binary op, import not at top
ignore = E501, E203, W503, E402
exclude = .git,__pycache__,build,dist
36 changes: 19 additions & 17 deletions .github/workflows/osxbuild.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -9,19 +9,19 @@ jobs:
osx_app:
runs-on: macos-latest
steps:
- uses: actions/checkout@v3
- uses: actions/checkout@v4
- name: Set up Python
uses: actions/setup-python@v3
uses: actions/setup-python@v5
with:
python-version: 3.8
python-version: 3.9

- name: Install dependencies
run: |
brew update
brew install libzip
- name: Build KataGo
run: |
export OPENSSL_ROOT_DIR=$(brew --prefix openssl@1.1)
export OPENSSL_LIBRARIES="${OPENSSL_ROOT_DIR}/lib"
echo $OPENSSL_ROOT_DIR
ls $OPENSSL_ROOT_DIR
echo $OPENSSL_LIBRARIES
ls $OPENSSL_LIBRARIES
rm katrain/KataGo/katago
rm katrain/KataGo/*.dll
rm katrain/KataGo/katago.exe
Expand All @@ -37,14 +37,15 @@ jobs:
unzip "platypus.zip"
gunzip Platypus.app/Contents/Resources/platypus_clt.gz
gunzip Platypus.app/Contents/Resources/ScriptExec.gz
mkdir -p /usr/local/bin
mkdir -p /usr/local/share/platypus
cp Platypus.app/Contents/Resources/platypus_clt /usr/local/bin/platypus
cp Platypus.app/Contents/Resources/ScriptExec /usr/local/share/platypus/ScriptExec
cp -a Platypus.app/Contents/Resources/MainMenu.nib /usr/local/share/platypus/MainMenu.nib
chmod -R 755 /usr/local/share/platypus
sudo mkdir -p /usr/local/bin
sudo mkdir -p /usr/local/share/platypus
sudo cp Platypus.app/Contents/Resources/platypus_clt /usr/local/bin/platypus
sudo cp Platypus.app/Contents/Resources/ScriptExec /usr/local/share/platypus/ScriptExec
sudo cp -a Platypus.app/Contents/Resources/MainMenu.nib /usr/local/share/platypus/MainMenu.nib
sudo chmod -R 755 /usr/local/share/platypus
- name: Get Kivy dependencies
run: |
brew install ninja
cd ..
git clone https://github.com/kivy/kivy-sdk-packager.git
cd kivy-sdk-packager/osx
Expand All @@ -54,7 +55,8 @@ jobs:
pushd ../kivy-sdk-packager/osx/build/KaTrain.app/Contents/Resources/venv/bin
source activate
popd
python -m pip install .
python -m pip install poetry
poetry install
- name: Finalize KaTrain bundle
run: |
export KATRAIN_VERSION=`python -c 'from katrain.core.constants import VERSION;print(VERSION)' `
Expand All @@ -74,7 +76,7 @@ jobs:
mkdir osx_app
cp ../kivy-sdk-packager/osx/KaTrain.dmg osx_app/
- name: Upload app as artifact
uses: actions/upload-artifact@v2
uses: actions/upload-artifact@v4
with:
name: KaTrainOSX
path: osx_app
23 changes: 11 additions & 12 deletions .github/workflows/release.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -9,31 +9,30 @@ jobs:
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v2
- uses: actions/checkout@v4

- name: Set up Python
uses: actions/setup-python@v3
uses: actions/setup-python@v5
with:
python-version: 3.8
python-version: 3.12

- name: Install dependencies
run: |
pip3 install -e .
pip3 install pytest wheel twine polib
pip3 install poetry
poetry self add "poetry-dynamic-versioning[plugin]"
poetry install --with dev,test
- name: Run tests
run: pytest -v -s tests
run: poetry run pytest -v -s tests

- name: Run I18N conversion
run: python i18n.py
run: poetry run python i18n.py

- name: Build
run: |
python3 setup.py sdist
python3 setup.py bdist_wheel
poetry build
- name: Release to PyPI
env:
TWINE_USERNAME: ${{ secrets.PYPI_USER }}
TWINE_PASSWORD: ${{ secrets.PYPI_PASSWORD }}
run: twine upload --verbose dist/* || echo 'File exists'
POETRY_PYPI_TOKEN_PYPI: ${{ secrets.PYPI_TOKEN }}
run: poetry publish --verbose
21 changes: 21 additions & 0 deletions .github/workflows/stale.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
name: "Close stale issues and PRs"
on:
schedule:
- cron: "30 1 * * *"

jobs:
stale:
runs-on: ubuntu-latest
permissions:
pull-requests: write
issues: write
steps:
- uses: actions/stale@v8
with:
operations-per-run: 200
stale-issue-message: "This issue is stale because it has been open 90 days with no activity. Remove stale label or comment or this will be closed in 10 days."
close-issue-message: "This issue was closed because it has been stalled for 30 days with no activity."
days-before-stale: 90
days-before-close: 30
stale-pr-message: "This PR is stale because it has been open 90 days with no activity. Remove stale label or comment or this will be closed in 10 days."
close-pr-message: "This PR was closed because it has been stalled for 30 days with no activity."
18 changes: 9 additions & 9 deletions .github/workflows/test.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -11,28 +11,28 @@ jobs:
strategy:
fail-fast: false
matrix:
python-version: ['3.7', '3.11'] # '3.8', '3.9',
python-version: ['3.9', '3.12'] # '3.11',

steps:
- uses: actions/checkout@v2
- uses: actions/checkout@v4

- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v1
uses: actions/setup-python@v5
with:
python-version: ${{ matrix.python-version }}

- name: Install dependencies
run: |
pip3 install -e .
pip3 install pytest wheel polib
pip3 install poetry
poetry self add "poetry-dynamic-versioning[plugin]"
poetry install --with dev,test
- name: Run tests
run: pytest tests
run: poetry run pytest tests

- name: Run I18N conversion
run: python i18n.py -todo
run: poetry run python i18n.py -todo

- name: Build
run: |
python3 setup.py sdist
python3 setup.py bdist_wheel
poetry build
11 changes: 6 additions & 5 deletions INSTALL.md
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ Simply download and run, everything is included.
### <a name="WindowsSources"></a>Installation from sources

* 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/3.8), available [here](https://www.anaconda.com/products/individual#download-section).
* Make sure you have a python installation, I will assume Anaconda (Python 3.9 or later), available [here](https://www.anaconda.com/products/individual#download-section).
* Open 'Anaconda prompt' from the start menu and navigate to where you extracted the zip file using the `cd <folder>` command.
* Execute the command `pip3 install .`
* Start the app by running `katrain` in the command prompt.
Expand All @@ -63,7 +63,7 @@ Simply download and run, everything is included.

### <a name="LinuxQuick"></a>Quick install guide

If you have a working Python 3.6-3.8 available, you should be able to simply:
If you have a working Python 3.9 or later available, you should be able to simply:

* Run `pip3 install -U katrain` to install or upgrade.
* Run the program by executing `katrain` in a terminal.
Expand All @@ -72,15 +72,15 @@ If you have a working Python 3.6-3.8 available, you should be able to simply:

This section describes how to install KaTrain from sources,
in case you want to run it in a local directory or have more control over the process.
It assumes you have a working Python 3.6+ installation.
It assumes you have a working Python 3.9+ installation.

* Open a terminal.
* Run the command `git clone https://github.com/sanderland/katrain.git` to download the repository and
change directory using `cd katrain`
* Run the command `pip3 install .` to install the package globally, or use `--user` to install locally.
* Run the program by typing `katrain` in the terminal.
* If you prefer not to install, run without installing using `python3 -m katrain` after installing the
dependencies from `requirements.txt`.
dependencies from `poetry.lock` with `poetry install`.

A binary for KataGo is included, but if you have compiled your own, press F8 to open general settings and change the
KataGo executable path to the relevant KataGo v1.4+ binary.
Expand All @@ -101,7 +101,8 @@ sudo apt-get install python3-pip build-essential git python3 python3-dev ffmpeg
```
Then, try installing python package dependencies using:
```bash
pip3 install -r requirements.txt
pip3 install poetry
poetry install
pip3 install screeninfo # Skip on MacOS, not working
```
In case the sound is not working, or there is no available wheel for your OS or Python version, try building kivy locally using:
Expand Down
1 change: 1 addition & 0 deletions katrain/KataGo/analysis_config.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@ maxVisits = 500
# But there's no substitute for experimenting and seeing what's best for your hardware and your usage case.
# Keep in mind that the number of threads you want doesn't necessarily have much to do with how many cores you
# have on your system, and could easily exceed the number of cores. GPU batching is (usually) the dominant consideration.
numAnalysisThreads = 12
numSearchThreads = 8

# nnMaxBatchSize is the max number of positions to send to a single GPU at once. Generally, it should be the case that:
Expand Down
Binary file modified katrain/KataGo/katago
Binary file not shown.
Binary file modified katrain/KataGo/katago.exe
Binary file not shown.
Binary file added katrain/KataGo/libcrypto-3-x64.dll
Binary file not shown.
Binary file added katrain/KataGo/libssl-3-x64.dll
Binary file not shown.
Binary file modified katrain/KataGo/libz.dll
Binary file not shown.
Binary file modified katrain/KataGo/libzip.dll
Binary file not shown.
Binary file modified katrain/KataGo/msvcp140.dll
Binary file not shown.
Binary file modified katrain/KataGo/msvcp140_1.dll
Binary file not shown.
Binary file modified katrain/KataGo/msvcp140_2.dll
Binary file not shown.
Binary file added katrain/KataGo/msvcp140_atomic_wait.dll
Binary file not shown.
Binary file added katrain/KataGo/msvcp140_codecvt_ids.dll
Binary file not shown.
Binary file modified katrain/KataGo/vcruntime140.dll
Binary file not shown.
Binary file added katrain/KataGo/vcruntime140_1.dll
Binary file not shown.
9 changes: 9 additions & 0 deletions katrain/__main__.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
"""isort:skip_file"""

# first, logging level lower
import os
import sys
Expand Down Expand Up @@ -124,6 +125,8 @@ def __init__(self, **kwargs):
self.contribute_popup = None

self.pondering = False
self.show_move_num = False

self.animate_contributing = False
self.message_queue = Queue()

Expand Down Expand Up @@ -173,6 +176,10 @@ def toggle_continuous_analysis(self, quiet=False):
self.pondering = not self.pondering
self.update_state()

def toggle_move_num(self):
self.show_move_num = not self.show_move_num
self.update_state()

def start(self):
if self.engine:
return
Expand Down Expand Up @@ -740,6 +747,8 @@ def _on_keyboard_down(self, _keyboard, keycode, _text, modifiers):

if keycode[1] == Theme.KEY_TOGGLE_CONTINUOUS_ANALYSIS:
self.toggle_continuous_analysis(quiet=shift_pressed)
elif keycode[1] == Theme.KEY_TOGGLE_MOVENUM:
self.toggle_move_num()
elif keycode[1] == Theme.KEY_TOGGLE_COORDINATES:
self.board_gui.toggle_coordinates()
elif keycode[1] in Theme.KEY_PAUSE_TIMER and not ctrl_pressed:
Expand Down
5 changes: 2 additions & 3 deletions katrain/config.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,8 @@
"engine": {
"katago": "",
"altcommand": "",
"model": "katrain/models/kata1-b18c384nbt-s6582191360-d3422816034.bin.gz",
"model": "katrain/models/kata1-b18c384nbt-s9996604416-d4316597426.bin.gz",
"config": "katrain/KataGo/analysis_config.cfg",
"threads": 12,
"max_visits": 500,
"fast_visits": 25,
"max_time": 8.0,
Expand All @@ -28,7 +27,7 @@
"anim_pv_time": 0.5,
"debug_level": 0,
"lang": "en",
"version": "1.14.0",
"version": "1.15.0",
"load_fast_analysis": false,
"load_sgf_rewind": true
},
Expand Down
22 changes: 12 additions & 10 deletions katrain/core/ai.py
Original file line number Diff line number Diff line change
Expand Up @@ -142,16 +142,18 @@ def game_report(game, thresholds, depth_filter=None):
for bw in "BW"
}
sum_stats = {
bw: {
"accuracy": 100 * 0.75 ** wt_loss[bw],
"complexity": sum(w for w, aw in weights[bw]) / len(player_ptloss[bw]),
"mean_ptloss": sum(player_ptloss[bw]) / len(player_ptloss[bw]),
"weighted_ptloss": wt_loss[bw],
"ai_top_move": ai_top_move_count[bw] / len(player_ptloss[bw]),
"ai_top5_move": ai_approved_move_count[bw] / len(player_ptloss[bw]),
}
if len(player_ptloss[bw]) > 0
else {}
bw: (
{
"accuracy": 100 * 0.75 ** wt_loss[bw],
"complexity": sum(w for w, aw in weights[bw]) / len(player_ptloss[bw]),
"mean_ptloss": sum(player_ptloss[bw]) / len(player_ptloss[bw]),
"weighted_ptloss": wt_loss[bw],
"ai_top_move": ai_top_move_count[bw] / len(player_ptloss[bw]),
"ai_top5_move": ai_approved_move_count[bw] / len(player_ptloss[bw]),
}
if len(player_ptloss[bw]) > 0
else {}
)
for bw in "BW"
}
return sum_stats, histogram, player_ptloss
Expand Down
4 changes: 2 additions & 2 deletions katrain/core/constants.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
PROGRAM_NAME = "KaTrain"
VERSION = "1.14.0"
VERSION = "1.15.0"
HOMEPAGE = "https://github.com/sanderland/katrain"
CONFIG_MIN_VERSION = "1.14.0" # keep config files from this version
CONFIG_MIN_VERSION = "1.15.0" # keep config files from this version
ANALYSIS_FORMAT_VERSION = "1.0"
DATA_FOLDER = "~/.katrain"

Expand Down
2 changes: 1 addition & 1 deletion katrain/core/contribute_engine.py
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ def __init__(self, katrain):
self.max_buffer_games = 2 * settings_dict["maxSimultaneousGames"]
settings = {f"{k}={v}" for k, v in settings_dict.items()}
self.command = shlex.split(
f'"{exe}" contribute -config "{cfg}" -base-dir "{base_dir}" -override-config "{",".join(settings)}"'
f'"{exe}" contribute -config "{cfg}" -base-dir "{base_dir}" -override-config {shlex.quote(",".join(settings))}'
)
self.start()

Expand Down
2 changes: 1 addition & 1 deletion katrain/core/engine.py
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ def __init__(self, katrain, config):
self.on_error(i18n._("Kata config not found").format(config=cfg), code="KATAGO-FILES")
return # don't start
self.command = shlex.split(
f'"{exe}" analysis -model "{model}" -config "{cfg}" -analysis-threads {config["threads"]} -override-config "homeDataDir={os.path.expanduser(DATA_FOLDER)}"'
f'"{exe}" analysis -model "{model}" -config "{cfg}" -override-config "homeDataDir={os.path.expanduser(DATA_FOLDER)}"'
)
self.start()

Expand Down
2 changes: 1 addition & 1 deletion katrain/core/sgf_parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -577,7 +577,7 @@ def parse_ngf(cls, ngf):
key = line[4]
raw_move = line[5:7].lower()
if raw_move == "aa":
value = "" # pass
value = "" # pass
else:
value = chr(ord(raw_move[0]) - 1) + chr(ord(raw_move[1]) - 1)

Expand Down
15 changes: 6 additions & 9 deletions katrain/core/utils.py
Original file line number Diff line number Diff line change
@@ -1,15 +1,13 @@
import heapq
import math
import os
from pathlib import Path
import random
import struct
import sys
from typing import List, Tuple, TypeVar

try:
import importlib.resources as pkg_resources
except ImportError:
import importlib_resources as pkg_resources
import importlib.resources as pkg_resources


T = TypeVar("T")

Expand Down Expand Up @@ -49,14 +47,13 @@ def find_package_resource(path, silent_errors=False):
if path.startswith("katrain"):
if not PATHS.get("PACKAGE"):
try:
with pkg_resources.path("katrain", "gui.kv") as p:
PATHS["PACKAGE"] = os.path.split(str(p))[0]
PATHS["PACKAGE"] = str(pkg_resources.files("katrain").absolute())
except (ModuleNotFoundError, FileNotFoundError, ValueError) as e:
print(f"Package path not found, installation possibly broken. Error: {e}", file=sys.stderr)
return f"FILENOTFOUND/{path}"
return os.path.join(PATHS["PACKAGE"], path.replace("katrain\\", "katrain/").replace("katrain/", ""))
return str(Path(PATHS["PACKAGE"]) / path.replace("katrain\\", "katrain/").replace("katrain/", ""))
else:
return os.path.abspath(os.path.expanduser(path)) # absolute path
return str(Path(path).expanduser().absolute())


def pack_floats(float_list):
Expand Down
Loading

0 comments on commit 21b0e5c

Please sign in to comment.