{ "cells": [ { "cell_type": "markdown", "metadata": {}, "source": [ "Load libraries." ] }, { "cell_type": "code", "execution_count": 1, "metadata": {}, "outputs": [], "source": [ "from chess_transformers.configs import import_config\n", "from chess_transformers.play.utils import write_pgns\n", "from chess_transformers.play.clocks import ChessClock\n", "from chess_transformers.play import human_v_model, warm_up, load_model" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Load configuration." ] }, { "cell_type": "code", "execution_count": 2, "metadata": {}, "outputs": [], "source": [ "config_name = \"CT-EFT-20\"\n", "CONFIG = import_config(config_name)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Load model." ] }, { "cell_type": "code", "execution_count": 3, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "\n", "Cannot find model checkpoint on disk; will download.\n", "\n" ] }, { "name": "stderr", "output_type": "stream", "text": [ "averaged_CT-EFT-20.pt: 100%|██████████| 72.4M/72.4M [00:18<00:00, 4.00MB/s] \n" ] }, { "name": "stdout", "output_type": "stream", "text": [ "\n", "Model loaded!\n", "\n" ] } ], "source": [ "model = load_model(CONFIG)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Warm up model -- this runs the model for the first time (and then some), which triggers compilation. This may take up to a minute." ] }, { "cell_type": "code", "execution_count": 4, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "\n", "Model warmed up!\n" ] } ], "source": [ "warm_up(\n", " model=model,\n", ")" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Play against the model." ] }, { "cell_type": "code", "execution_count": 5, "metadata": {}, "outputs": [ { "data": { "text/markdown": [ "# I played ***c6b7***. I win! :)" ], "text/plain": [ "" ] }, "metadata": {}, "output_type": "display_data" }, { "data": { "image/svg+xml": [ "
. k . . . b n r\n",
       ". Q . . . . . .\n",
       "B . . . . . . .\n",
       "p . p P . p p p\n",
       ". . . . . . . .\n",
       ". . . . . . . .\n",
       "P P P P . P P P\n",
       "R N B . K . . R
" ], "text/plain": [ "Board('1k3bnr/1Q6/B7/p1pP1ppp/8/8/PPPP1PPP/RNB1K2R b KQ - 1 15')" ] }, "metadata": {}, "output_type": "display_data" }, { "data": { "text/markdown": [ "# Your final Score +0 | -1 | =0" ], "text/plain": [ "" ] }, "metadata": {}, "output_type": "display_data" }, { "name": "stdout", "output_type": "stream", "text": [ "\n", "\n" ] } ], "source": [ "wins, laws, draws, pgns = human_v_model(\n", " human_color=\"b\",\n", " model=model,\n", " k=1,\n", " use_amp=True,\n", " rounds=1,\n", " clock=None,\n", " white_player_name=config_name,\n", " black_player_name=\"Me\",\n", ")" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Write PGNs to file." ] }, { "cell_type": "code", "execution_count": 6, "metadata": {}, "outputs": [], "source": [ "filepath = \"\"\n", "write_pgns(\n", " pgns,\n", " pgn_file=filepath,\n", ")" ] } ], "metadata": { "kernelspec": { "display_name": "base", "language": "python", "name": "python3" }, "language_info": { "codemirror_mode": { "name": "ipython", "version": 3 }, "file_extension": ".py", "mimetype": "text/x-python", "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", "version": "3.9.13" } }, "nbformat": 4, "nbformat_minor": 2 }