Python API
import griffith_logic exposes 114 symbols across 16 categories.
All of them are lazily imported (PEP 562): the underlying module is loaded on attribute access.
import griffith_logic as ml
layer = ml.LutLayer(in_dim=8, out_dim=16, n_inputs=2)All symbols
Section titled “All symbols”“Examples” counts how many tutorial pages actually import and run that API
(tallied automatically by AST analysis of examples/*.py).
| Name | Kind | Summary | Category | Examples |
|---|---|---|---|---|
LutLayer | class | N-input LUT (Look-Up Table) layer. | Core Layers | 11 |
LTTLayer | class | Linear threshold gate layer: binary input → n-input threshold function × out_dim → binary output. | Core Layers | — |
FixedLutLayer | class | A frozen LUT layer holding finalized truth tables (any number of inputs, no trainable parameters). | Core Layers | — |
Permute | class | Treats x as (…, *in_shape), reorders the axes in the order given by perm, and flattens back to (…, width). | Core Layers | — |
GroupSum | class | Layer that groups the output neurons into k classes and sums each group. | Core Layers | 10 |
get_random_connections | function | Randomly assigns N inputs to each output neuron. | Core Layers | — |
get_unique_connections | function | Connections that guarantee every input is used at least once. | Core Layers | — |
get_rot_connections | function | Regular wiring by the rot rule (2 inputs only). | Core Layers | — |
get_permutation_connections | function | Permutation (balanced surjective) wiring (2 inputs only). | Core Layers | — |
get_stretched_rot_connections | function | Stretched rot wiring (2 inputs only; the SR arm of prior internal experiments). | Core Layers | — |
get_uniform_random_connections | function | Unconstrained uniform random wiring (each slot sampled independently and uniformly; the RAND arm of prior internal experiments). | Core Layers | — |
connection_stats | function | Summarizes the coverage and usage-count distribution of a wiring table (wiring verification from prior internal experiments). | Core Layers | — |
sort_model_wiring | function | Renumbers the output neurons of every LutLayer in ascending order of their first input index. | Core Layers | — |
UnsupportedWiringError | class | Raised when sort_model_wiring does not support the model structure or wiring mode. | Core Layers | — |
get_rot_n_connections | function | n-input rot: idx[m, g] = (g · step + shifts[m]) mod in_dim (m = 0 .. n−1). | Core Layers | — |
get_butterfly_connections | function | One stage of a cyclic radix-n butterfly (bf6_stage of the BF6 / BF4 arms in prior internal | Core Layers | — |
get_local1d_connections | function | 1D local window (an n-input version of candidate B arm_local1d from prior internal experiments). | Core Layers | — |
get_local2d_connections | function | 2D local window (candidate C / L2D6 / L2D4 from prior internal experiments). | Core Layers | — |
butterfly_strides | function | Stride sequence of the butterfly stages [radix^0, radix^1, …, radix^(n_stages−1)] | Core Layers | — |
local1d_strides | function | Geometric-series strides of local1d_stride from prior internal experiments (layers 0 .. depth−1). | Core Layers | — |
ring_offsets | function | The first n entries of the sequence that lists the four ring directions of radius s, [(s,0), (0,s), (s,s), (s,−s)], | Core Layers | — |
local2d_offset_schedule | function | Offset tables of n_inputs entries for each of the n_layers hidden layers | Core Layers | — |
dedupe_connections | function | Deterministically collapses duplicates in gates that read the same input in several slots (by shifting +1). | Core Layers | — |
prop_map | function | Proportional map from gate index → input coordinate, c_g = round(g · (in_dim − 1) / (out_dim − 1)). | Core Layers | — |
ImageLayout | class | The ordering of the input bits (threshold minor). | Wiring Receptive Field & Coverage | — |
layer_stats | function | Applies core.connections.connection_stats to a per-layer index table. | Wiring Receptive Field & Coverage | — |
class_receptive_field | function | Class receptive field: the fraction of input bits a single class can read. | Wiring Receptive Field & Coverage | — |
receptive_field_upper_bound | function | Upper bound on the fraction of inputs a layer of width width can read (2W / in_dim for 2-input gates). | Wiring Receptive Field & Coverage | — |
wiring_summary | function | Wiring statistics for one network (per layer + class receptive field + structural upper bound on the receptive field). | Wiring Receptive Field & Coverage | — |
LutConv2d | class | Logic-gate tree convolution layer (CDDLGN Section 3, Eq. 2-3). | Convolution & Spatial | 2 |
ConvDLGNConfig | class | Configuration of a conv-DLGN. The defaults are the cifar10_s setting (cdlgn k=32) from prior internal experiments. | Convolution & Spatial | — |
build_conv_dlgn | function | Builds a conv-DLGN as an nn.Sequential (a serial structure that can be passed to export_ir as is). | Convolution & Spatial | — |
OrPooling2d | class | Logical OR pooling (CDDLGN Section 3.1). | Convolution & Spatial | 1 |
SpatialGroupSum | class | Layer that groups channels and sums them while preserving the spatial dimensions. | Convolution & Spatial | — |
UpSample2d | class | Nearest-neighbor upsampling (equivalent to BinaryBrain’s UpSampling). | Convolution & Spatial | — |
RDDLGN | class | Recurrent Deep Differentiable Logic Gate Network. | seq2seq (RDDLGN) | 1 |
RDDLGNConfig | class | All hyperparameters of the RDDLGN model. | seq2seq (RDDLGN) | 1 |
RDDLGNEncoder | class | RDDLGN encoder. | seq2seq (RDDLGN) | — |
RDDLGNDecoder | class | RDDLGN decoder. | seq2seq (RDDLGN) | — |
RDDLGNClassifier | class | RDDLGN encoder + classification head (text-classification distillation such as SST-2, ROADMAP-v5 Track D7). | seq2seq (RDDLGN) | — |
LogicEmbedding | class | Token embedding + sigmoid activation. | seq2seq (RDDLGN) | — |
LutStack | class | A chain of LutLayers. Used to build the N/K/L/P/M layer groups. | seq2seq (RDDLGN) | — |
LogicGPT | class | Logic-gate version of a decoder-only causal Transformer. forward(tokens[B,S]) → (logits, emb_reg). | Decoder-only Causal Transformer | 1 |
LogicGPTConfig | class | Hyperparameters for LogicGPT. | Decoder-only Causal Transformer | 1 |
truth_table_dataset | function | Builds a TensorDataset enumerating all 2^n_inputs rows of a truth table. | Logic Function Datasets | — |
LogicDatasetSpec | class | Specification of a logic function dataset (the unit looked up from the registry by, for example, the editor backend) | Logic Function Datasets | — |
LOGIC_DATASETS | constant | Logic Function Datasets | — | |
VISION_DATASETS | constant | Vision Datasets | — | |
VisionDatasetSpec | class | Metadata for a vision dataset plus a loader factory (the unit stored in the registry). | Vision Datasets | — |
load_uci_har | function | Reads the raw Inertial Signals of UCI-HAR (9 channels x 128 steps). | UCI-HAR (Activity Recognition) Dataset | 1 |
fit_thermometer_thresholds | function | Chooses per-channel thermometer thresholds from quantiles of the training data. | UCI-HAR (Activity Recognition) Dataset | 1 |
thermometer_encode | function | Converts a real-valued signal into a thermometer code (0/1 bits that stack up monotonically). | UCI-HAR (Activity Recognition) Dataset | 1 |
TrainConfig | class | Root of the training configuration (data/model/optim/run/expected_metrics). | Configuration & Shared Runner | — |
load_config | function | Builds and validates a configuration from YAML (optional) plus dot-notation overrides. | Configuration & Shared Runner | — |
dump_config | function | Converts a configuration into a YAML/JSON-safe dict | Configuration & Shared Runner | — |
save_config | function | Saves a configuration as YAML (in a form that griffith train <path> can re-run as is) | Configuration & Shared Runner | — |
run_training | function | Runs training according to the configuration and returns the final metrics. | Configuration & Shared Runner | — |
evaluate_checkpoint | function | Runs hard eval (discretized evaluation) on a checkpoint (used by griffith eval). | Configuration & Shared Runner | — |
LearningSpec | class | Per-layer / per-module learning rule specification. | Learning Algorithms | 1 |
with_learning | function | Annotates a module with a learning rule and returns it (without wrapping it). | Learning Algorithms | 1 |
get_learning_spec | function | Returns a module’s learning rule annotation (None if it is not annotated). | Learning Algorithms | — |
HybridTrainer | class | Trainer for models that mix learning rules. | Learning Algorithms | 1 |
make_train_step | function | Builds a training-step closure that applies CUDA Graphs automatically when possible. | Learning Algorithms | — |
wants_capturable | function | Decides whether capturable=True should be attempted when constructing the optimizer. | Learning Algorithms | — |
LogicLinear | class | An nn.Linear-compatible logic-gate layer. | Hybrid API | — |
LogicMLP | class | A drop-in replacement for an entire Transformer FFN (Linear → activation → Linear). | Hybrid API | — |
LogicSpec | class | Construction recipe for logic-gate layers. | Hybrid API | 1 |
ToLogic | class | Real values → [0,1] conversion. | Hybrid API | — |
FromLogic | class | [0,1] logic outputs → real values (group aggregation). | Hybrid API | — |
replace_modules | function | Replaces every submodule matching match with what factory produces. | Hybrid API | — |
convert_linear_to_logic | function | Replaces nn.Linear with LogicLinear. | Hybrid API | — |
replace_mlp_with_lut | function | Replaces whole FFN/MLP blocks with LogicMLP (the LL-ViT use case). | Hybrid API | 1 |
split_param_groups | function | Splits LUT parameters and ANN parameters into separate optimizer param groups. | Hybrid API | 1 |
EditorModelSpec | class | Specification of a Python model exposed to the editor. | Editor Integration | — |
editor_model | function | Registers a function or class as a model builder for the editor. | Editor Integration | — |
ThermometerEncoder | class | Thermometer encoding layer. | DWN / LLViT | 1 |
DWNLayer | class | The DWN LUT layer: binary input → n-input LUT × n_luts → binary output. | DWN / LLViT | 1 |
LearnableMapping | class | Layer that learns the input→LUT connections by gradient descent. | DWN / LLViT | — |
DWNClassifier | class | Classifier built from thermometer encoding + multi-layer DWN LUTs + popcount aggregation. | DWN / LLViT | 1 |
LLViTConfig | class | Configuration matching the LL-ViT CIFAR-10 target by default. | DWN / LLViT | — |
LLViT | class | Tiny ViT backbone used for baseline and LL-ViT reproduction. | DWN / LLViT | — |
LLViTChannelMixer | class | LL-ViT channel mixer: thermometer -> DWN -> DWN -> conditional sum. | DWN / LLViT | — |
ConditionalSum | class | Dense encoded-value summation after binary LUT outputs. | DWN / LLViT | — |
build_llvit_cifar10 | function | DWN / LLViT | — | |
build_deit_tiny_cifar10 | function | DWN / LLViT | — | |
spectral_norm | function | Computes the spectral norm of the LUT table matrix, specnorm(L) = ‖L·C‖₂. | DWN / LLViT | — |
Binarize | class | Binarization layer (HardTanh STE). | BinaryBrain Compatibility | — |
RealToBinary | class | Binary modulation: binarizes a real-valued input at multiple thresholds, increasing the number of frames along the batch axis. | BinaryBrain Compatibility | 1 |
BinaryToReal | class | Frame accumulation: averages the modulated frames back into real values. | BinaryBrain Compatibility | 1 |
DifferentiableLutBlock | class | A composite layer equivalent to BinaryBrain’s DifferentiableLut. | BinaryBrain Compatibility | 1 |
BinaryBrainConv2d | class | A faithful reproduction of BinaryBrain’s Convolution2d. | BinaryBrain Compatibility | — |
Concat | class | An explicit block for dim=-1 concatenation (maps to the IR concat node). | General NN Blocks | — |
Add | class | Multi-input soft logical merge (maps to the IR add node). | General NN Blocks | — |
Residual | class | Residual connection: forward(x) = merge(x, inner(x)). | General NN Blocks | — |
LogicLayerNorm | class | LayerNorm for the [0,1] logic domain. | General NN Blocks | — |
LogicBatchNorm | class | BatchNorm for the [0,1] logic domain, extracted from the BN part of DifferentiableLutBlock. | General NN Blocks | — |
LogicDropout | class | Dropout for the [0,1] logic domain. Perturbs output units with probability p during training only. | General NN Blocks | — |
LogicPositionalEncoding | class | A block that concatenates a constant positional-encoding bit string onto the input. | General NN Blocks | — |
position_codes | function | Generates a position → bit string table. | General NN Blocks | — |
LogicAttention | class | An attention block based on XNOR similarity. | General NN Blocks | — |
LogicTransformerBlock | class | Logic-gate version of a Transformer block. forward(x: (B, S, D)) → (B, S, D). | General NN Blocks | — |
blocks_to_ir | function | Converts a model assembled from blocks into an IR graph. | General NN Blocks | — |
DLGNBooleanAttention | class | Logic-gate version of the attention mechanism. | Attention | 1 |
BooleanAttentionConfig | class | Hyperparameters for DLGNBooleanAttention. | Attention | 1 |
DLGNMultiQueryAttention | class | Multi-query version of DLGN Boolean Attention. | Attention | 1 |
MultiQueryAttentionConfig | class | Hyperparameters for DLGNMultiQueryAttention. | Attention | 1 |
DLGNPositionalAttention | class | Position-based DLGN attention. | Attention | 1 |
PositionalAttentionConfig | class | Hyperparameters for DLGNPositionalAttention. | Attention | 1 |
DLGNAttentionSeq2Seq | class | A fixed-length seq2seq model built on DLGN Boolean Attention. | Attention | — |
AttentionSeq2SeqConfig | class | Hyperparameters for DLGNAttentionSeq2Seq. | Attention | — |
DLGNPointerAttention | class | A Pointer Network-style DLGN seq2seq model. | Attention | 1 |
PointerAttentionConfig | class | Hyperparameters for DLGNPointerAttention. | Attention | 1 |
DLGNAttentionTranslator | class | Bahdanau-style attention seq2seq. | Attention | — |
TranslatorConfig | class | Hyperparameters for DLGNAttentionTranslator. | Attention | — |
Categories
Section titled “Categories”| Category | Symbols | Contents |
|---|---|---|
| Core Layers | 24 | LutLayer / LTTLayer / FixedLutLayer / Permute / GroupSum / get_random_connections / get_unique_connections / get_rot_connections / get_permutation_connections / get_stretched_rot_connections / get_uniform_random_connections / connection_stats / sort_model_wiring / UnsupportedWiringError / get_rot_n_connections / get_butterfly_connections / get_local1d_connections / get_local2d_connections / butterfly_strides / local1d_strides / ring_offsets / local2d_offset_schedule / dedupe_connections / prop_map |
| Wiring Receptive Field & Coverage | 5 | ImageLayout / layer_stats / class_receptive_field / receptive_field_upper_bound / wiring_summary |
| Convolution & Spatial | 6 | LutConv2d / ConvDLGNConfig / build_conv_dlgn / OrPooling2d / SpatialGroupSum / UpSample2d |
| seq2seq (RDDLGN) | 7 | RDDLGN / RDDLGNConfig / RDDLGNEncoder / RDDLGNDecoder / RDDLGNClassifier / LogicEmbedding / LutStack |
| Decoder-only Causal Transformer | 2 | LogicGPT / LogicGPTConfig |
| Logic Function Datasets | 3 | truth_table_dataset / LogicDatasetSpec / LOGIC_DATASETS |
| Vision Datasets | 2 | VISION_DATASETS / VisionDatasetSpec |
| UCI-HAR (Activity Recognition) Dataset | 3 | load_uci_har / fit_thermometer_thresholds / thermometer_encode |
| Configuration & Shared Runner | 6 | TrainConfig / load_config / dump_config / save_config / run_training / evaluate_checkpoint |
| Learning Algorithms | 6 | LearningSpec / with_learning / get_learning_spec / HybridTrainer / make_train_step / wants_capturable |
| Hybrid API | 9 | LogicLinear / LogicMLP / LogicSpec / ToLogic / FromLogic / replace_modules / convert_linear_to_logic / replace_mlp_with_lut / split_param_groups |
| Editor Integration | 2 | EditorModelSpec / editor_model |
| DWN / LLViT | 11 | ThermometerEncoder / DWNLayer / LearnableMapping / DWNClassifier / LLViTConfig / LLViT / LLViTChannelMixer / ConditionalSum / build_llvit_cifar10 / build_deit_tiny_cifar10 / spectral_norm |
| BinaryBrain Compatibility | 5 | Binarize / RealToBinary / BinaryToReal / DifferentiableLutBlock / BinaryBrainConv2d |
| General NN Blocks | 11 | Concat / Add / Residual / LogicLayerNorm / LogicBatchNorm / LogicDropout / LogicPositionalEncoding / position_codes / LogicAttention / LogicTransformerBlock / blocks_to_ir |
| Attention | 12 | DLGNBooleanAttention / BooleanAttentionConfig / DLGNMultiQueryAttention / MultiQueryAttentionConfig / DLGNPositionalAttention / PositionalAttentionConfig / DLGNAttentionSeq2Seq / AttentionSeq2SeqConfig / DLGNPointerAttention / PointerAttentionConfig / DLGNAttentionTranslator / TranslatorConfig |
Find it by example
Section titled “Find it by example”A reverse index of the public APIs each tutorial uses.
| Tutorial | Public APIs used |
|---|---|
| Intro 3. Replace the MLP with a DLGN | GroupSum / LutLayer |
| 1. Train on MNIST | GroupSum / LutLayer |
| 2. Build a Hybrid NN | LogicSpec / LutLayer / replace_mlp_with_lut / split_param_groups |
| 3. Export to HDL | GroupSum / LutLayer |
| 4. Deploy | GroupSum / LutLayer |
| 5. Export a CNN to HDL | GroupSum / LutConv2d / LutLayer / OrPooling2d |
| 6. Switching Learning Rules (DFA / AP) | GroupSum / HybridTrainer / LearningSpec / LutLayer / with_learning |
| 7. End-to-End Walkthrough: From Training to FPGA | GroupSum / LutLayer |
| Appendix: A Minimal Look Inside, with XOR | GroupSum / LutLayer |
| Writing Shakespeare with a Logic-Gate GPT | LogicGPT / LogicGPTConfig |
| A seq2seq Model Built from RNNs Alone (RDDLGN) | RDDLGN / RDDLGNConfig |
| Gating Is a Boolean Operation (LSTM/GRU) — Logicizing the RNN | GroupSum / LutLayer |
| DWN — MNIST with Thermometer Encoding and n-Input LUTs | DWNClassifier / DWNLayer / ThermometerEncoder |
| Turning a whole diffusion model into a Boolean circuit | LutConv2d |
| A Tour of Four Logic-Gate Attention Variants | BooleanAttentionConfig / DLGNBooleanAttention / DLGNMultiQueryAttention / DLGNPointerAttention / DLGNPositionalAttention / MultiQueryAttentionConfig / PointerAttentionConfig / PositionalAttentionConfig |
| Training FPGA-Ready LUT Networks with the BinaryBrain-compatible API | BinaryToReal / DifferentiableLutBlock / RealToBinary |
| Activity Recognition (UCI-HAR, Phone Accelerometer) | GroupSum / LutLayer / fit_thermometer_thresholds / load_uci_har / thermometer_encode |