Skip to content

Core Concepts

This page is a map of the concepts. It gives you the names and how they relate to each other, and leaves the mathematics and the step-by-step procedures to the pages they belong to.

In one sentence, here is what the library does:

Train the logic circuit itself by gradient descent, then take it out as a pure Boolean circuit the moment training ends.

During training everything is real-valued (orange); once extracted it is bits (green). This site consistently distinguishes the two worlds by color: orange = real-valued, green = logic.

graph LR
subgraph real["Real-valued world (training, orange)"]
x["input [0,1]"] --> l1["LutLayer<br/>soft mixture of gates"]
l1 --> l2["LutLayer"]
l2 --> gs["GroupSum<br/>exit to class scores"]
gs --> loss["cross_entropy<br/>+ Adam"]
loss -.gradient.-> l1
end
gs ==>|"model.eval() = argmax discretization"| ir
subgraph logic["Logic world (inference, green)"]
ir[("IR (JSON)<br/>truth tables + wiring<br/>= source of truth")]
ir --> sim["simulate<br/>(numpy golden)"]
ir --> hdl["Verilog / VHDL"]
hdl --> fpga["FPGA / ASIC"]
end
style real fill:#f9731626,stroke:#f97316
style logic fill:#10b98126,stroke:#10b981

There is exactly one bridge from orange to green: discretization via eval(), and the IR. Because that boundary is a single point, you can swap out the training side and leave the circuit side untouched.

ConceptIn one lineWhere it mattersMore
soft / hard dualityTraining uses a weighted average over all gates (differentiable); inference picks one with argmaxmodel.train() / model.eval()What is DLGN?
LutLayerOne output neuron = one N-input LUT (truth table). What is learned is not weights but which gateModel definitionLutLayer internals
GroupSumSplits the final gate outputs evenly across k classes, sums them and divides by tau. The exit from logic to class scoresEnd of the modelParameterization
IRJSON containing nothing but truth tables and wiring. The source of truth for everything downstreamAfter trainingWorking with IR
HDLSynthesizable Verilog / VHDL generated from the IRDeploymentHDL export

“Pick a gate” is a discrete operation, so gradients cannot flow through it as-is. During training we therefore mix all candidate gates with a probability distribution (softmax), and at inference argmax settles on exactly one.

model.train()
acc_soft = (model(x).argmax(-1) == y).float().mean() # accuracy of the relaxation itself
model.eval() # ← here it collapses into a circuit
acc_hard = (model(x).argmax(-1) == y).float().mean() # accuracy of the circuit you would burn

Always look at hard. The gap between soft and hard is called the discretization gap, and keeping it small is quality itself (→ Reading training curves).

2. LutLayer — learning the kind of gate, not weights

Section titled “2. LutLayer — learning the kind of gate, not weights”

Each output neuron of LutLayer(in_dim, out_dim, n_inputs=N) is one N-input LUT. Every gate picks up only N of the input lines, sparsely (the wiring is fixed at initialization); what is learned is the contents of the truth table over those N inputs.

NNumber of candidatesWhere it sits
2the 16 two-input Boolean functionsdifflogic-compatible. Exact, fast gradients
42^16The balanced choice
62^64Maps one-to-one onto an FPGA LUT6 cell

3. GroupSum — the exit from logic to scores

Section titled “3. GroupSum — the exit from logic to scores”

Classification needs a score per class, but logic gates only ever produce bits. GroupSum(k, tau) splits the final layer’s outputs into k equal groups, sums each group and divides by tau to get logits. It costs a single adder, so it is cheap on the circuit side too.

model = nn.Sequential(
LutLayer(400, 2000, n_inputs=2),
LutLayer(2000, 2000, n_inputs=2),
GroupSum(k=10, tau=10.0), # 2000 gates → 10 classes (200 gates per class)
)

4. IR — the source of truth for everything downstream

Section titled “4. IR — the source of truth for everything downstream”

export_ir() walks the trained model and emits JSON normalized into a collection of truth tables, no matter which parameterization was used for training. Verilog, VHDL, the simulator and the visual editor are all derived from that IR.

ir = export_ir(model, input_width=400, name='mnist')
validate(ir, target='hdl') # check bit widths and topological order up front

The generated Verilog / VHDL is synthesizable RTL you can hand straight to vendor tools. That it behaves identically to the original model is guaranteed mechanically by three-way equivalence:

PyTorch hard eval ⇔ ir/simulate (numpy golden) ⇔ HDL simulation

Only when all three agree on every vector can you say it is ready to burn.