A project to build a neural network out of logic gates.
This repository contains a pure C implementation of a Multi-Layer Perceptron (MLP) trained using differentiable logic gates, featuring export via the AIGER format.
This work is directly inspired by the groundbreaking research of Felix Petersen et al. on hardware-efficient neural networks.
This project implements a sparse MLP in which each neuron has fewer than 16 inputs.
Each neuron is converted into a logic circuit using the Quine–McCluskey algorithm, producing an AND network.
Finally, all generated circuits are assembled together to build a large AIGER file.
The goal of this project is to train neural networks that can be exported and executed as digital logic circuits.
- Sparse MLP training on datasets using primitives defined in `problem.h`
- Example implementation using MNIST
- AIGER export
- Interactive training
- Sparse architecture with fewer than 16 inputs per neuron
- Logic synthesis of neurons into AND networks using Quine–McCluskey
- Compatible with ABC for balancing and optimization
On MNIST, the project achieves:
- 87% accuracy
- 54 layers
- Around 84k AND gates
You need:
make- AIGER software installed
- ABC installed
makeTraining is performed using the primitives defined in problem.h.
An example configuration using MNIST is already provided.
After training, the network can be exported to an AIGER file. (press G key in GUI)
For better results, balance and optimize the generated circuit using ABC.
Example:
abc
read out.aig
balance
rewrite
balance
write optimized.aigThis project implements and expands upon the concepts introduced in the following landmark paper:
Felix Petersen, Christian Borgelt, Hilde Kuehne, and Oliver Deussen. "Deep Differentiable Logic Gate Networks." Published at NeurIPS 2022. arXiv:2210.08277
This project is licensed under the Creative Commons Attribution-NonCommercial-ShareAlike 4.0 International License.
https://creativecommons.org/licenses/by-nc-sa/4.0/
The pipeline is simple:
- Train a sparse MLP
- Convert each neuron into boolean logic using the Quine–McCluskey algorithm
- Generate an AND network
- Merge all neuron circuits together
- Export the final network as an AIGER file
- Optimize the circuit using ABC