diff mbox series

[bug#63088,v2] gnu: Add Lc0.

Message ID 3cc41c81a301fb53c564508d3cbcf92270695d1b.1694082083.git.iyzsong@member.fsf.org
State New
Headers show
Series [bug#63088,v2] gnu: Add Lc0. | expand

Commit Message

vasilii.smirnov--- via Guix-patches" via Sept. 7, 2023, 10:23 a.m. UTC
From: zamfofex <zamfofex@twdb.moe>

* gnu/packages/games.scm (lc0): New variable.

Signed-off-by: 宋文武 <iyzsong@member.fsf.org>
---
 gnu/packages/games.scm | 59 ++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 59 insertions(+)


base-commit: 5ef28595e9dff8b88ec3fcb4d887fbc380c9a8b8
prerequisite-patch-id: 8cee4be3d25dba0dde5c2d0e317f31741c010f50

Comments

Liliana Marie Prikler Sept. 7, 2023, 5:03 p.m. UTC | #1
Am Donnerstag, dem 07.09.2023 um 18:23 +0800 schrieb iyzsong@envs.net:
> From: zamfofex <zamfofex@twdb.moe>
> 
> * gnu/packages/games.scm (lc0): New variable.
Missing the entry for lc0-neural-network.
> 
> Signed-off-by: 宋文武 <iyzsong@member.fsf.org>
> ---
>  gnu/packages/games.scm | 59
> ++++++++++++++++++++++++++++++++++++++++++
>  1 file changed, 59 insertions(+)
> 
> diff --git a/gnu/packages/games.scm b/gnu/packages/games.scm
> index 760234b031..f82f1dcc52 100644
> --- a/gnu/packages/games.scm
> +++ b/gnu/packages/games.scm
> @@ -118,6 +118,7 @@ (define-module (gnu packages games)
>    #:use-module (gnu packages bash)
>    #:use-module (gnu packages bison)
>    #:use-module (gnu packages boost)
> +  #:use-module (gnu packages c)
>    #:use-module (gnu packages check)
>    #:use-module (gnu packages cmake)
>    #:use-module (gnu packages compression)
> @@ -171,6 +172,7 @@ (define-module (gnu packages games)
>    #:use-module (gnu packages linux)
>    #:use-module (gnu packages llvm)
>    #:use-module (gnu packages lua)
> +  #:use-module (gnu packages machine-learning)
>    #:use-module (gnu packages man)
>    #:use-module (gnu packages maths)
>    #:use-module (gnu packages messaging)
> @@ -10409,6 +10411,63 @@ (define-public stockfish
>        (home-page "https://stockfishchess.org/")
>        (license license:gpl3+))))
>  
> +(define lc0-neural-network
> +  (let ((hash
> +        
> "f404e156ceb2882470fd8c032b8754af0fa0b71168328912eaef14671a256e34"))
> +    (origin
> +      (method url-fetch)
> +      (uri (string-append
> "https://storage.lczero.org/files/networks/"
> +                          hash))
> +      (sha256
> +       (base32
> +        "03b9xl9vkiihdilz5dzcpg6g4inb6n4k5gs911i3gbd8h9sh9ixi"))
> +      (file-name "lc0-neural-network"))))
> +
> +(define-public lc0
> +  (package
> +    (name "lc0")
> +    (version "0.30.0")
> +    (source
> +     (origin
> +       (method git-fetch)
> +       (uri (git-reference
> +             (url "https://github.com/LeelaChessZero/lc0")
> +             (commit (string-append "v" version))
> +             (recursive? #t)))
recursive? #t is meh ._.
Can we work around that?
> +       (file-name (git-file-name name version))
> +       (sha256
> +        (base32
> "1m7k8m8iz4pxv3h9g2j1dkgryi4k9c1bcg3fx5j7ii4ysif63kj3"))))
> +    (build-system meson-build-system)
> +    (native-search-paths
> +     (list (search-path-specification
> +            (variable "XDG_DATA_DIRS")
> +            (files '("share")))))
> +    (inputs
> +     `(("neural-network" ,lc0-neural-network)
> +       ("eigen" ,eigen)
> +       ("oneapi-dnnl" ,oneapi-dnnl)
> +       ("zlib" ,zlib)))
Use new-style inputs.
> +    (native-inputs
> +     (list googletest ispc pkg-config python))
> +    (arguments
> +     '(#:phases (modify-phases %standard-phases
> +                  (add-after 'install 'copy-net
> +                    (lambda* (#:key outputs inputs #:allow-other-
> keys)
> +                      (mkdir-p (string-append (assoc-ref outputs
> "out")
> +                                              "/share/lc0"))
> +                      (copy-file (assoc-ref inputs "neural-network")
> +                                 (string-append (assoc-ref outputs
> "out")
> +                                                "/share/lc0/neural-
> network")))))
Can we use search-input-file or the like here?
> +       #:configure-flags (list "-Ddnnl=true"
> +                               (string-append
> +                                "-Ddnnl_dir="
> +                                (assoc-ref %build-inputs "oneapi-
> dnnl")))))
> +    (synopsis "Chess engine using neural networks")
> +    (description "Lc0 is a UCI-compliant chess engine designed to
> play chess
> +via neural network, specifically those of the LeelaChessZero
> project.")
Is Lc0 = Leela Chess Zero?  What's the connection?
> +    (home-page "https://lczero.org")
> +    (license license:gpl3+)))
Cheers
zamfofex Sept. 11, 2023, 10:22 a.m. UTC | #2
> recursive? #t is meh ._.
> Can we work around that?

Yes, presumably easily, but I don’t think it would be a good idea in this case, because it isn’t used to build bundled software, but rather just for a small project‐specific pair of source files (that are in a separate repo just because they are used by other repos of the project too).

> Can we use search-input-file or the like here?

Probably. Though would it be reasonable to package the network separately instead? Note that Lc0 is able to load various networks, and there is no canonical network, so maybe it would be useful to have it in a different package so that more can be potentially added in the future.

Then people could use them with something like ‘guix shell lc0 lc0-NETWORK_NAME’.

> Is Lc0 = Leela Chess Zero?  What's the connection?

“Lc0”, “Leela Chess Zero”, “LCZero”, and sometimes just “Leela Chess” can be used roughly interchangeably to refer to the project as a whole. Though, occasionally, people will use the term “Lc0” (sometimes capitalised as “lc0”) to refer specifically to the ‘lc0’ executable, which can use the networks from the Leela Chess Zero project, but networks created by other people too, including those of e.g. the Maia project, see <https://github.com/CSSLab/maia-chess> and <https://maiachess.com>

At some point (very early on), the code for the executable was rewritten or otherwise largely refactored, and at the same time renamed from ‘lczero’ to the current ‘lc0’, so sometimes (very rarely nowadays), people will use the term “lc0” (or “Lc0”) to refer specifically to this new executable and code base, contrasting with the former ‘lczero’ executable and its code base.

Honestly, this all feels convoluted to me, so I usually like to use the terms interchangeably, and I don’t think using them differently in the package description is a good choice.

- - - - -

Hopefully this helps clarify things well enough! If there is interest, I can submit another patch with the requested changes and the appropriate path taken regarding the packaging for the networks.
Liliana Marie Prikler Sept. 11, 2023, 6 p.m. UTC | #3
Am Montag, dem 11.09.2023 um 07:22 -0300 schrieb zamfofex:
> > recursive? #t is meh ._.
> > Can we work around that?
> 
> Yes, presumably easily, but I don’t think it would be a good idea in
> this case, because it isn’t used to build bundled software, but
> rather just for a small project‐specific pair of source files (that
> are in a separate repo just because they are used by other repos of
> the project too).
In that case, a comment explaining this in 1-2 lines would probably be
fine.

> > Can we use search-input-file or the like here?
> 
> Probably. Though would it be reasonable to package the network
> separately instead? Note that Lc0 is able to load various networks,
> and there is no canonical network, so maybe it would be useful to
> have it in a different package so that more can be potentially added
> in the future.
> 
> Then people could use them with something like ‘guix shell lc0 lc0-
> NETWORK_NAME’.
Sounds reasonable to me.  Do add a phrase or two about this to the lc0
description though if it doesn't even ship a basic network.

> 
> > Is Lc0 = Leela Chess Zero?  What's the connection?
> 
> “Lc0”, “Leela Chess Zero”, “LCZero”, and sometimes just “Leela Chess”
> can be used roughly interchangeably to refer to the project as a
> whole. Though, occasionally, people will use the term “Lc0”
> (sometimes capitalised as “lc0”) to refer specifically to the ‘lc0’
> executable, which can use the networks from the Leela Chess Zero
> project, but networks created by other people too, including those of
> e.g. the Maia project, see <https://github.com/CSSLab/maia-chess> and
> <https://maiachess.com>
> 
> At some point (very early on), the code for the executable was
> rewritten or otherwise largely refactored, and at the same time
> renamed from ‘lczero’ to the current ‘lc0’, so sometimes (very rarely
> nowadays), people will use the term “lc0” (or “Lc0”) to refer
> specifically to this new executable and code base, contrasting with
> the former ‘lczero’ executable and its code base.
> 
> Honestly, this all feels convoluted to me, so I usually like to use
> the terms interchangeably, and I don’t think using them differently
> in the package description is a good choice.
In that case, for the description we should probably go with "Leela
Chess Zero" or "@acronym{lc0, Leela Chess Zero}"

Cheers
diff mbox series

Patch

diff --git a/gnu/packages/games.scm b/gnu/packages/games.scm
index 760234b031..f82f1dcc52 100644
--- a/gnu/packages/games.scm
+++ b/gnu/packages/games.scm
@@ -118,6 +118,7 @@  (define-module (gnu packages games)
   #:use-module (gnu packages bash)
   #:use-module (gnu packages bison)
   #:use-module (gnu packages boost)
+  #:use-module (gnu packages c)
   #:use-module (gnu packages check)
   #:use-module (gnu packages cmake)
   #:use-module (gnu packages compression)
@@ -171,6 +172,7 @@  (define-module (gnu packages games)
   #:use-module (gnu packages linux)
   #:use-module (gnu packages llvm)
   #:use-module (gnu packages lua)
+  #:use-module (gnu packages machine-learning)
   #:use-module (gnu packages man)
   #:use-module (gnu packages maths)
   #:use-module (gnu packages messaging)
@@ -10409,6 +10411,63 @@  (define-public stockfish
       (home-page "https://stockfishchess.org/")
       (license license:gpl3+))))
 
+(define lc0-neural-network
+  (let ((hash
+         "f404e156ceb2882470fd8c032b8754af0fa0b71168328912eaef14671a256e34"))
+    (origin
+      (method url-fetch)
+      (uri (string-append "https://storage.lczero.org/files/networks/"
+                          hash))
+      (sha256
+       (base32
+        "03b9xl9vkiihdilz5dzcpg6g4inb6n4k5gs911i3gbd8h9sh9ixi"))
+      (file-name "lc0-neural-network"))))
+
+(define-public lc0
+  (package
+    (name "lc0")
+    (version "0.30.0")
+    (source
+     (origin
+       (method git-fetch)
+       (uri (git-reference
+             (url "https://github.com/LeelaChessZero/lc0")
+             (commit (string-append "v" version))
+             (recursive? #t)))
+       (file-name (git-file-name name version))
+       (sha256
+        (base32 "1m7k8m8iz4pxv3h9g2j1dkgryi4k9c1bcg3fx5j7ii4ysif63kj3"))))
+    (build-system meson-build-system)
+    (native-search-paths
+     (list (search-path-specification
+            (variable "XDG_DATA_DIRS")
+            (files '("share")))))
+    (inputs
+     `(("neural-network" ,lc0-neural-network)
+       ("eigen" ,eigen)
+       ("oneapi-dnnl" ,oneapi-dnnl)
+       ("zlib" ,zlib)))
+    (native-inputs
+     (list googletest ispc pkg-config python))
+    (arguments
+     '(#:phases (modify-phases %standard-phases
+                  (add-after 'install 'copy-net
+                    (lambda* (#:key outputs inputs #:allow-other-keys)
+                      (mkdir-p (string-append (assoc-ref outputs "out")
+                                              "/share/lc0"))
+                      (copy-file (assoc-ref inputs "neural-network")
+                                 (string-append (assoc-ref outputs "out")
+                                                "/share/lc0/neural-network")))))
+       #:configure-flags (list "-Ddnnl=true"
+                               (string-append
+                                "-Ddnnl_dir="
+                                (assoc-ref %build-inputs "oneapi-dnnl")))))
+    (synopsis "Chess engine using neural networks")
+    (description "Lc0 is a UCI-compliant chess engine designed to play chess
+via neural network, specifically those of the LeelaChessZero project.")
+    (home-page "https://lczero.org")
+    (license license:gpl3+)))
+
 (define-public barrage
   (package
     (name "barrage")