This document describes the high-level architecture of the gate_learner Python package.
The project is structured as a decoupled library with a Typer CLI wrapper. This separation ensures that the core mathematical engine remains independent of I/O, CLI parsing, and plotting logic.
+-----------------------------------------------------------------------+
| CLI Module |
| (gate_learner/cli.py, main) |
+-----------------------------------+-----------------------------------+
|
v
+-----------------------------------+-----------------------------------+
| Dataset Generator |
| (gate_learner/dataset.py) |
+-----------------------------------+-----------------------------------+
|
v
+-----------------------------------+-----------------------------------+
| Core ML Engine |
| (gate_learner/core.py) |
| +---------------------------------------------------------------+ |
| | MultilayerPerceptron | |
| | - Forward Pass (Sigmoid / ReLU Activation) | |
| | - Gradient Accumulation (BCE Loss) | |
| +-------------------------------+-------------------------------+ |
| | |
| v |
| +---------------------------------------------------------------+ |
| | AdamOptimizer | |
| | - Parameter Update (L2 Regularisation & Bias Correction) | |
| +-------------------------------+-------------------------------+ |
+-----------------------------------+-----------------------------------+
|
+-----------------------+
| |
v v
+-----------------------------------+---+ +---+--------------------+
| Storage Module | | Plot Module (Feature) |
| (gate_learner/storage.py) | | (gate_learner/plot.py) |
+---------------------------------------+ +------------------------+
Contains the mathematical representation of the neural network.
Layer: Represents a single layer containing weights, biases, and an activation function.MultilayerPerceptron: Manages a sequence of layers. It holds pre-allocated internal buffers for activations, deltas, and gradients to avoid list allocations during the training loop.AdamOptimizer: Implements the Adam optimization algorithm. It maintains its own state buffers (first and second moments) matching the network's architecture.
Generates truth tables for
Handles JSON serialisation and deserialisation of the trained model weights and training history.
Gated under optional matplotlib import. It renders a dual-axis PNG chart showing the training loss and accuracy curves over epochs.
Parses command-line arguments using typer, coordinates the training loop, manages early stopping, and handles output generation.
To achieve high performance in pure Python, list allocations are avoided inside the training loop.
- The
MultilayerPerceptronallocates its activation, delta, and gradient buffers once during initialization viaensure_buffers(). - During the forward and backward passes, these buffers are mutated in-place.
The MultilayerPerceptron and Layer classes are designed to be fully picklable (serialisable). This allows the model to be safely transferred across processes using Python's multiprocessing module for parallel hyperparameter grid search.