The Mrbdzz Novelty Grinder!

April 2, 2024 Matthew Sadler 4 comments

Leela’s wonderful new WDL Contempt feature – discussed in earlier posts and also in a series of videos on my Silicon Road YouTube channel (https://youtube.com/playlist?list=PLxhvNMc95Uo9N6W48TUAyIwkjK0w1wHKj&si=IK9OpgsfWB-wktZ1) – continues to inspire new avenues of chess investigation. One event that created a stir was the fascinating David Navara – Leela match at knight odds on which I commentated here: https://www.youtube.com/live/b04MPlCSL24?si=ybsivb7HM3HnosEa I’ll most likely dedicate some blog space to that match in the future, but this blog post focuses on a lovely little programming project by grizzled veteran TCEC chatter mrbdzz who many of you will know from my streams as “Leela’s Greatest Fan”!

A while back we chatted about the ideal tooling for opening exploration by engines. We both agreed that the current available tooling (especially the commercial tools) is very limited and that someone should do something about it! I’m not a programmer so it was never going to be me 😉 so it’s cool that mrbdzz has started the ball rolling with this 0.1 dev version of his “Novelty Grinder”! It is freely downloadable from https://github.com/skiminki/novelty-grinder?tab=readme-ov-file Since it’s a 0.1 dev version, it requires a tiny bit of tweaking to get things working on Windows. However, with just a bit of effort you have the makings of some really great opening tooling.

Note that this is really hot off the press – it was released just a couple of days ago! I haven’t tried all the different permutations, just tried to get it working on Windows as quickly as possible. There’ll probably be more tips and tricks coming in the next weeks!

The idea is to let an engine find novelties / unusual ideas in the opening for you in automated fashion. The way this happens is described by mrbdzz in his introduction (with a few comments added by me here):

Novelty Grinder is a tool to find potential surprise moves. This is done by analyzing games (or lines) as follows:

A position is analyzed with an engine for candidate moves

Leela works “out of the box” in this version, though you could adjust things to point to another engine.

A game database is queried for popular moves

The Lichess database is used in this case to see which engine suggestions are the most popular (we’re not interested in those of course – we only want the sexy stuff!)

Popular moves are removed from the candidate moves set

The remaining candidate moves are the potential surprise moves

A pgn file is then produced with annotations.

Arrows are added in the PGN annotation for visualization. Red arrow = novelty; green arrow = unpopular engine suggestion.

The cool thing of course is combining this powerful mechanism with “Contemptla” (Leela with WDL Contempt) to generate crazy ideas!

The output pgn file ends up looking like this:

The green arrows show unpopular moves and the red ones are novelties (in the Lichess database) And all that within a few seconds!

In the next paragraphs, I’m going to explain how I got this working on Windows as mrbdzz shared this as a Linux tool. However, the beauty of Python – the programming language used by mrbdzz – is that it works on anything and everything. Even a rather uncertain user like myself can fiddle around to get things working!

I am assuming in all this that you already have a working Leela and Nibbler configuration. If not, take a look at my earlier blog posts to see how to do this!

Python

The first thing you need is a working Python environment on your Windows machine. You can download everything you need from python.org but the simplest is to go to the Microsoft Store and let Windows install Python for you. That way all the correct paths and variables for your system get configured automatically.

I am using 3.11 but I’m sure 3.12 would be fine too. Just click on Get and let Microsoft work its magic

Installing the required modules

Mrbdzz has used the python-chess and Berserk modules which are not in the standard Python download.

After installing python, you should be able to open up a command prompt on your Windows machine and install them through the pip package manager tool.

The command line Pip install python-chess berserk (asalso specified in the https://github.com/skiminki/novelty-grinder/blob/main/setup-python-venv.sh file provided by mrbdzz) will get you what you need!

Downloading

Download the Novelty Grinder from https://github.com/skiminki/novelty-grinder/blob/main/src/noveltygrinder.py The highlighted button will download the file for you.

Copy the file to a directory (I put mine into D:\NoveltyGrinder\src) and then navigate with your command prompt to that location.

The command line

The sample command line provided by mrbdzz is

./novelty-grinder –engine=/usr/local/bin/lc0 –nodes=100000 –eval-threshold=100 –arrows –first-move=4 –book-cutoff=40 input-games.pgn | tee annotated-games.pgn

This has a few Linux-specific things in it so we need to change that. First of all however, let’s hear from mrbdzz what the command actually does (with a few additions from me)

This command uses engine /usr/local/bin/lc0 to analyze the game:

100 kN per move, starting from move 4

That’s a good amount of analysis, particularly when using the Leela WDL Contempt feature

Moves less than 1% from the top move are considered candidate moves

Default popularity cutoff is used. That is, moves with at most 5% popularity are considered for surprises

Analysis is stopped when less than 40 games are in the database.

Obviously, you can tweak all these parameter values based on what you want to analyse. There are a couple of things that must be changed however to get things working on Windows.

The –engine path

This path obviously refers to a Linux location. In principle it should be perfectly possible to specify a Windows location, but every syntax I tried failed. In the end, I removed this option from the command line and added a default value to the appropriate section in noveltygrinder.py

BEFORE

AFTER

This equates to a Leela installation in C:\Users\gmmat\Leela\lc0.exe

Note that I also defined this Leela installation in Nibbler with appropriate contempt settings:

The engines.json path

There is one sneaky thing in noveltygrinder.py: it really does expect you to have a Nibbler installation! And you need to point noveltygrinder.py to the appropriate path for your Nibbler engines.json file. It’s not too complicated:

BEFORE

AFTER

As you can see, this ends up pointing the noveltygrinder.py file to this standard location for the Nibbler configuration files:

If you need any help on the syntax of the path function in Python then this is one of many Internet articles:

https://medium.com/@ageitgey/python-3-quick-tip-the-easy-way-to-deal-with-file-paths-on-windows-mac-and-linux-11a072b58d5f

The tee command

The last piped command tee annotated-games.pgn outputs Leela’s analysis to the annotated-games.pgn file. In Windows, it’s simpler just to use >> filename.

Putting it all together

So what do we get? Well this was the sample (Linux-friendly) command line from mrbdzz once again

./novelty-grinder –engine=/usr/local/bin/lc0 –nodes=100000 –eval-threshold=100 –arrows –first-move=4 –book-cutoff=40 input-games.pgn | tee annotated-games.pgn

This is the Windows-friendly one INCLUDING the necessary alterations to the noveltygrinder.py file as detailed above

python noveltygrinder.py –nodes=100000 –eval-threshold=100 –arrows –first-move=4 –book-cutoff=40 inputgame.pgn >> output2.pgn

As you can see, you execute python in Windows by putting python in front of the noveltygrinder.py filename

The input was this simple pgn file

And the output was this:

Finally, mrbdzz has given his personal assurance – swearing solemnly on Leela’s name – that he will work day and night to add extra features! Follow his progress here: https://github.com/skiminki/novelty-grinder/issues

4 Comments on “The Mrbdzz Novelty Grinder!

  1. I really like this idea – it feels very natural, making you wonder if seconds already prepare novelties using similar tools. Maybe part of the challenge is telling if a move has a new idea to it, vs merely a very slightly worse version of a popular move? As a relatively bad chess player who hasn’t played around with Leela contempt or anything, no clue, but it looks interesting. It would be cool to try this in a browser, either in its own page or through Lichess somehow (bot?).

    1. Thanks! Yes it’s a lovely idea! I’d discussed it quite a few times in the TCEC chat with mrbdzz so I’m really glad he decided to take on the programming himself and go for it! I wouldn’t think that anyone is using anything like this (yet!) but it may change. Tbh, if I was an elite player, I would have hired in a programmer to do something like this for me but I don’t have the impression that anyone has done that… Best Wishes, Matthew

  2. I don’t have a windows installation and I can programme, so I should be good to go!
    What can I use as `input_games.pgn`? This is the missing piece, I think not mentioned in this blog post…

    1. Pretty much any pgn is good! Try first with a simple pgn of 1 game and then you’ll see how it works! There’s a 0.1 version in the make as well that outputs the main Leela line (as well as the individual move suggestions) which should be a nice addition!

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.