NNUE Parser Python Module
Overview
The NNUE Parser Python Module is a high-performance library for evaluating chess positions using an Efficiently Updatable Neural Network (NNUE). Written in Rust and exposed to Python via PyO3 and maturin, this module is optimized for speed and efficiency—allowing you to use it entirely from Python.
Features
- High Performance: Leverages SIMD optimizations for fast NNUE evaluations.
- Python-Only Interface: Use the NNUE parser directly from Python without any Rust code exposure.
- Easy to Use: Simple API for model initialization and evaluation using FEN strings.
- Lightweight: Designed for efficient memory and computational usage.
Installation
Ensure you have Rust installed along with Python (3.7 or later). Then, install maturin:
pip install maturin
Clone the repository and build the module:
git clone https://github.com/github-jimjim/NNUE-Parser
cd nnue-parser
maturin develop
This command compiles the Rust code and installs the Python module in your current environment.
Usage
Once installed, you can initialize the NNUE model and evaluate chess positions using FEN strings directly from Python:
import nnue_parser
# Initialize the NNUE model (adjust the path to your NNUE file)
nnue_parser.init_nnue_py("path/to/nnue_file")
# Example FEN string for the starting chess position
fen = "rnbqkbnr/pppppppp/8/8/8/8/PPPPPPPP/RNBQKBNR w KQkq - 0 1"
# Evaluate the position in centipawns
evaluation = nnue_parser.eval_nnue_py(fen)
print("Evaluation in centipawns:", evaluation)
Benchmarking
Measure the Nodes per Second (NPS) by running the following benchmark test for one second:
import time
import nnue_parser
def benchmark_nnue_nps():
nnue_file_path = "path/to/nnue_file"
print("Initializing NNUE model...")
nnue_parser.init_nnue_py(nnue_file_path)
fen = "rnbqkbnr/pppppppp/8/8/8/8/PPPPPPPP/RNBQKBNR w KQkq - 0 1"
# Warm-up phase
print("Warming up the model...")
for _ in range(10):
_ = nnue_parser.eval_nnue_py(fen)
print("Starting benchmark for 1 second...")
count = 0
start_time = time.perf_counter()
end_time = start_time + 1.0 # Run for 1 second
while time.perf_counter() < end_time:
_ = nnue_parser.eval_nnue_py(fen)
count += 1
total_time = time.perf_counter() - start_time
print(f"Evaluations in {total_time:.6f} seconds: {count}")
nps = count / total_time
print(f"NPS (Nodes per Second): {nps:.2f}")
if __name__ == "__main__":
benchmark_nnue_nps()
Project Structure
- src/lib.rs: Contains the NNUE parser implementation and PyO3 bindings.
- Cargo.toml: Configures Rust dependencies and the build process for PyO3 and maturin.
- README.md: This file.
Contributing
Contributions are welcome! Please open issues or submit pull requests if you have suggestions or improvements.
License
This project is licensed under the MIT License.
Metadata
Release files for nnue-parser 0.3.1
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| nnue_parser-0.3.1-cp311-cp311-win_amd64.whl | CPython 3.11 | CPython 3.11 | Windows x86-64 | Details for nnue_parser-0.3.1-cp311-cp311-win_amd64.whl |
Release files / nnue_parser-0.3.1-cp311-cp311-win_amd64.whl
| Download URL | nnue_parser-0.3.1-cp311-cp311-win_amd64.whl |
|---|---|
| Size | 129.4 kB |
| Tags | CPython 3.11 Windows x86-64 |
|
SHA-256 checksum How to use checksums |
c9a4a95b233aad25818d11cb317f9a7fc53636b1b9bb43db2468da3a9cad9cc1
|
|
BLAKE2b-256 checksum How to use checksums |
75304f362fd896e19197fd16a2c3305c84fc69dfda601a93ab1a38517c4c527b
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
maturin/1.8.1
|
Security for nnue-parser 0.3.1
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.