Python API
import griffith_logic が公開するシンボルは 114個、カテゴリは 16区分 です。
いずれも遅延インポート(PEP 562)で、属性アクセス時に実体モジュールが読み込まれます。
import griffith_logic as ml
layer = ml.LutLayer(in_dim=8, out_dim=16, n_inputs=2)全シンボル一覧
Section titled “全シンボル一覧”「使用例」は チュートリアル のうちそのAPIを実際に import して動かしているページ数です(examples/*.py のAST解析による自動集計)。
| 名前 | 種別 | 概要 | カテゴリ | 使用例 |
|---|---|---|---|---|
LutLayer | クラス | N入力LUT(Look-Up Table)層。 | コア層 | 11本 |
LTTLayer | クラス | 線形閾値ゲート層: 二値入力 → n 入力の閾値関数 × out_dim → 二値出力。 | コア層 | — |
FixedLutLayer | クラス | 確定済み真理値表を持つ凍結 LUT 層(任意の入力数、学習パラメータなし)。 | コア層 | — |
Permute | クラス | x を (…, *in_shape) と見なし、軸を perm の順に並べ替えて (…, width) へ戻す。 | コア層 | — |
GroupSum | クラス | 出力ニューロンをkクラスにグループ化して合計する層。 | コア層 | 10本 |
get_random_connections | 関数 | ランダムにN個の入力を各出力ニューロンに割り当てる。 | コア層 | — |
get_unique_connections | 関数 | すべての入力が少なくとも1回は使われることを保証する接続。 | コア層 | — |
get_rot_connections | 関数 | rot 規則の規則配線(2入力固定)。 | コア層 | — |
get_permutation_connections | 関数 | 置換(均衡全射)配線(2入力固定)。 | コア層 | — |
get_stretched_rot_connections | 関数 | 引き伸ばし rot 配線(2入力固定、先行実験 SR 腕)。 | コア層 | — |
get_uniform_random_connections | 関数 | 無制約の一様乱択配線(各スロットを独立に一様サンプル、先行実験 RAND 腕)。 | コア層 | — |
connection_stats | 関数 | 配線テーブルの被覆率・使用回数分布を要約する(先行実験の配線検証)。 | コア層 | — |
sort_model_wiring | 関数 | 各LutLayerの出力ニューロンを第1入力インデックス昇順にrenumberする。 | コア層 | — |
UnsupportedWiringError | クラス | sort_model_wiringが対応できないモデル構造・配線方式の場合に送出。 | コア層 | — |
get_rot_n_connections | 関数 | n 入力 rot: idx[m, g] = (g · step + shifts[m]) mod in_dim(m = 0 .. n−1)。 | コア層 | — |
get_butterfly_connections | 関数 | 循環 radix-n バタフライ 1 段(内部調査リポジトリの先行実験の BF6 / BF4 の | コア層 | — |
get_local1d_connections | 関数 | 1D 局所窓(内部調査リポジトリの先行実験の候補 B arm_local1d の n 入力版)。 | コア層 | — |
get_local2d_connections | 関数 | 2D 局所窓(内部調査リポジトリの先行実験の候補 C / L2D6 / L2D4)。 | コア層 | — |
butterfly_strides | 関数 | バタフライ段の stride 列 [radix^0, radix^1, …, radix^(n_stages−1)] | コア層 | — |
local1d_strides | 関数 | 内部調査リポジトリの先行実験の local1d_stride の幾何級数ストライド(層 0 .. depth−1)。 | コア層 | — |
ring_offsets | 関数 | 半径 s のリング 4 方向 [(s,0), (0,s), (s,s), (s,−s)] を s = 1, 2, … と並べた列の | コア層 | — |
local2d_offset_schedule | 関数 | 隠れ層 n_layers 本それぞれの n_inputs 個のオフセット表 | コア層 | — |
dedupe_connections | 関数 | 同じ入力を複数スロットで読むゲートの重複を決定的に潰す(+1 ずらし)。 | コア層 | — |
prop_map | 関数 | ゲート番号 → 入力座標の比例写像 c_g = round(g · (in_dim − 1) / (out_dim − 1))。 | コア層 | — |
ImageLayout | クラス | 入力ビットの並び(しきい値 minor)。 | 配線の受容野・被覆率 | — |
layer_stats | 関数 | 層順の添字テーブルに core.connections.connection_stats を掛ける。 | 配線の受容野・被覆率 | — |
class_receptive_field | 関数 | クラス受容野: 1 クラスが読める入力ビットの割合。 | 配線の受容野・被覆率 | — |
receptive_field_upper_bound | 関数 | 幅 width の層が読める入力の割合の上限(2 入力なら 2W / 入力次元)。 | 配線の受容野・被覆率 | — |
wiring_summary | 関数 | 1 ネット分の配線統計(層ごと + クラス受容野 + 受容野の構造上限)。 | 配線の受容野・被覆率 | — |
LutConv2d | クラス | 論理ゲートツリー畳み込み層(CDDLGN Section 3, Eq. 2-3)。 | 畳み込み・空間処理 | 2本 |
ConvDLGNConfig | クラス | conv-DLGN の構成。既定値は先行実験 cifar10_s(cdlgn k=32)。 | 畳み込み・空間処理 | — |
build_conv_dlgn | 関数 | conv-DLGN を nn.Sequential として組む(export_ir にそのまま渡せる直列構造)。 | 畳み込み・空間処理 | — |
OrPooling2d | クラス | 論理ORプーリング(CDDLGN Section 3.1)。 | 畳み込み・空間処理 | 1本 |
SpatialGroupSum | クラス | チャンネルをグループ化して合計し、空間次元を保持する層。 | 畳み込み・空間処理 | — |
UpSample2d | クラス | 最近傍補間によるアップサンプリング(BinaryBrainのUpSamplingと等価)。 | 畳み込み・空間処理 | — |
RDDLGN | クラス | Recurrent Deep Differentiable Logic Gate Network。 | seq2seq(RDDLGN) | 1本 |
RDDLGNConfig | クラス | RDDLGNモデルの全ハイパーパラメータ。 | seq2seq(RDDLGN) | 1本 |
RDDLGNEncoder | クラス | RDDLGNエンコーダ。 | seq2seq(RDDLGN) | — |
RDDLGNDecoder | クラス | RDDLGNデコーダ。 | seq2seq(RDDLGN) | — |
RDDLGNClassifier | クラス | RDDLGNエンコーダ + 分類ヘッド(SST-2等のテキスト分類蒸留、ROADMAP-v5 Track D7)。 | seq2seq(RDDLGN) | — |
LogicEmbedding | クラス | トークン埋め込み + sigmoid活性化。 | seq2seq(RDDLGN) | — |
LutStack | クラス | LutLayerの連鎖。N/K/L/P/M各レイヤーグループの構築に使う。 | seq2seq(RDDLGN) | — |
LogicGPT | クラス | decoder-only 因果Transformerの論理ゲート版。forward(tokens[B,S])→(logits, emb_reg)。 | decoder-only 因果Transformer | 1本 |
LogicGPTConfig | クラス | LogicGPTのハイパーパラメータ。 | decoder-only 因果Transformer | 1本 |
truth_table_dataset | 関数 | 真理値表から2^n_inputs全列挙のTensorDatasetを生成する。 | 論理関数データセット | — |
LogicDatasetSpec | クラス | 論理関数データセットの仕様(エディタバックエンド等からレジストリ的に引く単位) | 論理関数データセット | — |
LOGIC_DATASETS | 定数 | 論理関数データセット | — | |
VISION_DATASETS | 定数 | 視覚データセット | — | |
VisionDatasetSpec | クラス | 視覚データセットのメタ情報+ローダファクトリ(レジストリの単位)。 | 視覚データセット | — |
load_uci_har | 関数 | UCI-HAR の生 Inertial Signals(9ch × 128step)を読む。 | UCI-HAR(行動認識)データセット | 1本 |
fit_thermometer_thresholds | 関数 | 訓練データの分位点から、チャネルごとの温度計閾値を決める。 | UCI-HAR(行動認識)データセット | 1本 |
thermometer_encode | 関数 | 実数信号を温度計符号(単調に積み上がる 0/1 ビット)へ変換する。 | UCI-HAR(行動認識)データセット | 1本 |
TrainConfig | クラス | 学習設定のルート(data/model/optim/run/expected_metrics)。 | 設定管理・共通ランナー | — |
load_config | 関数 | YAML(省略可)+ドット記法オーバーライドから設定を構築・検証する。 | 設定管理・共通ランナー | — |
dump_config | 関数 | 設定をYAML/JSON安全なdictへ変換する | 設定管理・共通ランナー | — |
save_config | 関数 | 設定をYAMLで保存する(griffith train <path> でそのまま再実行できる形式) | 設定管理・共通ランナー | — |
run_training | 関数 | 設定に従って学習を実行し、最終メトリクスを返す。 | 設定管理・共通ランナー | — |
evaluate_checkpoint | 関数 | チェックポイントをhard eval(離散化評価)する(md eval用)。 | 設定管理・共通ランナー | — |
LearningSpec | クラス | レイヤ/モジュール単位の学習ルール指定。 | 学習アルゴリズム | 1本 |
with_learning | 関数 | モジュールに学習ルールを注釈して返す(ラップしない)。 | 学習アルゴリズム | 1本 |
get_learning_spec | 関数 | モジュールの学習ルール注釈を取得(未注釈ならNone)。 | 学習アルゴリズム | — |
HybridTrainer | クラス | 学習ルール混在モデルのトレーナ。 | 学習アルゴリズム | 1本 |
make_train_step | 関数 | CUDA Graphsを(可能なら)自動適用する学習stepクロージャを構築する。 | 学習アルゴリズム | — |
wants_capturable | 関数 | optimizer構築時にcapturable=Trueを試みるべきかを判定する。 | 学習アルゴリズム | — |
LogicLinear | クラス | nn.Linear互換の論理ゲート型レイヤ。 | ハイブリッドAPI | — |
LogicMLP | クラス | Transformer FFN(Linear→活性化→Linear)全体の置換体。 | ハイブリッドAPI | — |
LogicSpec | クラス | 論理ゲート型レイヤの生成レシピ。 | ハイブリッドAPI | 1本 |
ToLogic | クラス | 実数 → [0,1] 変換。 | ハイブリッドAPI | — |
FromLogic | クラス | [0,1]論理出力 → 実数変換(グループ集約)。 | ハイブリッドAPI | — |
replace_modules | 関数 | matchに一致するサブモジュールをfactoryの生成物で置換する。 | ハイブリッドAPI | — |
convert_linear_to_logic | 関数 | nn.Linear を LogicLinear に置換する。 | ハイブリッドAPI | — |
replace_mlp_with_lut | 関数 | FFN/MLPブロック全体を LogicMLP に置換する(LL-ViT用途)。 | ハイブリッドAPI | 1本 |
split_param_groups | 関数 | LUT系パラメータとANN系パラメータをoptimizer param groupに分割する。 | ハイブリッドAPI | 1本 |
EditorModelSpec | クラス | エディタへ公開するPythonモデルの仕様。 | エディタ連携 | — |
editor_model | 関数 | 関数またはクラスをエディタ用モデルbuilderとして登録する。 | エディタ連携 | — |
ThermometerEncoder | クラス | Thermometer符号化層。 | DWN / LLViT | 1本 |
DWNLayer | クラス | DWNのLUT層: 二値入力 → n入力LUT×n_luts → 二値出力。 | DWN / LLViT | 1本 |
LearnableMapping | クラス | 入力→LUTの接続を勾配で学習する層。 | DWN / LLViT | — |
DWNClassifier | クラス | Thermometer符号化 + DWN多層LUT + popcount集約の分類器。 | DWN / LLViT | 1本 |
LLViTConfig | クラス | Configuration matching the LL-ViT CIFAR-10 target by default. | DWN / LLViT | — |
LLViT | クラス | Tiny ViT backbone used for baseline and LL-ViT reproduction. | DWN / LLViT | — |
LLViTChannelMixer | クラス | LL-ViT channel mixer: thermometer -> DWN -> DWN -> conditional sum. | DWN / LLViT | — |
ConditionalSum | クラス | Dense encoded-value summation after binary LUT outputs. | DWN / LLViT | — |
build_llvit_cifar10 | 関数 | DWN / LLViT | — | |
build_deit_tiny_cifar10 | 関数 | DWN / LLViT | — | |
spectral_norm | 関数 | LUTテーブル行列のスペクトルノルム specnorm(L) = ‖L·C‖₂ を計算する。 | DWN / LLViT | — |
Binarize | クラス | 二値化層(HardTanh STE)。 | BinaryBrain互換 | — |
RealToBinary | クラス | バイナリ変調: 実数入力を複数閾値で二値化し、バッチ方向にフレーム数を増やす。 | BinaryBrain互換 | 1本 |
BinaryToReal | クラス | フレーム積算: 変調フレームを平均して実数に復元。 | BinaryBrain互換 | 1本 |
DifferentiableLutBlock | クラス | BinaryBrainのDifferentiableLutと等価なコンポジット層。 | BinaryBrain互換 | 1本 |
BinaryBrainConv2d | クラス | BinaryBrainのConvolution2d忠実再現。 | BinaryBrain互換 | — |
Concat | クラス | dim=-1連結の明示部品(IR concatノード対応)。 | 一般NN部品 | — |
Add | クラス | 多入力soft論理マージ(IR addノード対応)。 | 一般NN部品 | — |
Residual | クラス | 残差接続: forward(x) = merge(x, inner(x))。 | 一般NN部品 | — |
LogicLayerNorm | クラス | [0,1]論理域向けLayerNorm。 | 一般NN部品 | — |
LogicBatchNorm | クラス | DifferentiableLutBlockのBN部を独立化した[0,1]論理域向けBatchNorm。 | 一般NN部品 | — |
LogicDropout | クラス | [0,1]論理域向けDropout。訓練時のみ確率pで出力単位を摂動する。 | 一般NN部品 | — |
LogicPositionalEncoding | クラス | 位置エンコーディングの定数ビット列を入力へ連結する部品。 | 一般NN部品 | — |
position_codes | 関数 | 位置→ビット列テーブルを生成する。 | 一般NN部品 | — |
LogicAttention | クラス | XNOR類似度によるattention部品。 | 一般NN部品 | — |
LogicTransformerBlock | クラス | Transformerブロックの論理ゲート版。forward(x: (B, S, D)) → (B, S, D)。 | 一般NN部品 | — |
blocks_to_ir | 関数 | blocks部品で組んだモデルをIRグラフへ変換する。 | 一般NN部品 | — |
DLGNBooleanAttention | クラス | 論理ゲート版 Attention 機構。 | Attention系 | 1本 |
BooleanAttentionConfig | クラス | DLGNBooleanAttention のハイパーパラメータ。 | Attention系 | 1本 |
DLGNMultiQueryAttention | クラス | マルチクエリ版 DLGN Boolean Attention。 | Attention系 | 1本 |
MultiQueryAttentionConfig | クラス | DLGNMultiQueryAttention のハイパーパラメータ。 | Attention系 | 1本 |
DLGNPositionalAttention | クラス | 位置ベース DLGN Attention。 | Attention系 | 1本 |
PositionalAttentionConfig | クラス | DLGNPositionalAttention のハイパーパラメータ。 | Attention系 | 1本 |
DLGNAttentionSeq2Seq | クラス | DLGN Boolean Attention を使った固定長 seq2seq モデル。 | Attention系 | — |
AttentionSeq2SeqConfig | クラス | DLGNAttentionSeq2Seq のハイパーパラメータ。 | Attention系 | — |
DLGNPointerAttention | クラス | Pointer Network 風の DLGN seq2seq モデル。 | Attention系 | 1本 |
PointerAttentionConfig | クラス | DLGNPointerAttention のハイパーパラメータ。 | Attention系 | 1本 |
DLGNAttentionTranslator | クラス | Bahdanau-style Attention seq2seq。 | Attention系 | — |
TranslatorConfig | クラス | DLGNAttentionTranslator のハイパーパラメータ。 | Attention系 | — |
| カテゴリ | シンボル数 | 収録シンボル |
|---|---|---|
| コア層 | 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 |
| 配線の受容野・被覆率 | 5 | ImageLayout / layer_stats / class_receptive_field / receptive_field_upper_bound / wiring_summary |
| 畳み込み・空間処理 | 6 | LutConv2d / ConvDLGNConfig / build_conv_dlgn / OrPooling2d / SpatialGroupSum / UpSample2d |
| seq2seq(RDDLGN) | 7 | RDDLGN / RDDLGNConfig / RDDLGNEncoder / RDDLGNDecoder / RDDLGNClassifier / LogicEmbedding / LutStack |
| decoder-only 因果Transformer | 2 | LogicGPT / LogicGPTConfig |
| 論理関数データセット | 3 | truth_table_dataset / LogicDatasetSpec / LOGIC_DATASETS |
| 視覚データセット | 2 | VISION_DATASETS / VisionDatasetSpec |
| UCI-HAR(行動認識)データセット | 3 | load_uci_har / fit_thermometer_thresholds / thermometer_encode |
| 設定管理・共通ランナー | 6 | TrainConfig / load_config / dump_config / save_config / run_training / evaluate_checkpoint |
| 学習アルゴリズム | 6 | LearningSpec / with_learning / get_learning_spec / HybridTrainer / make_train_step / wants_capturable |
| ハイブリッドAPI | 9 | LogicLinear / LogicMLP / LogicSpec / ToLogic / FromLogic / replace_modules / convert_linear_to_logic / replace_mlp_with_lut / split_param_groups |
| エディタ連携 | 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互換 | 5 | Binarize / RealToBinary / BinaryToReal / DifferentiableLutBlock / BinaryBrainConv2d |
| 一般NN部品 | 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 |
各チュートリアルが使っている公開APIの一覧(逆引き)。
| チュートリアル | 使っている公開API |
|---|---|
| 入門3. MLPをDLGNへ置き換える | GroupSum / LutLayer |
| 1. MNISTを学習する | GroupSum / LutLayer |
| 2. ハイブリッドNNを作る | LogicSpec / LutLayer / replace_mlp_with_lut / split_param_groups |
| 3. HDLへエクスポート | GroupSum / LutLayer |
| 4. デプロイする | GroupSum / LutLayer |
| 5. CNNをHDLへエクスポート | GroupSum / LutConv2d / LutLayer / OrPooling2d |
| 6. 学習則を切り替える(DFA / AP法) | GroupSum / HybridTrainer / LearningSpec / LutLayer / with_learning |
| 7. 通しチュートリアル: 学習からFPGAまで | GroupSum / LutLayer |
| 付録: XORで仕組みを最小で覗く | GroupSum / LutLayer |
| 論理ゲートGPTでシェイクスピアを書く | LogicGPT / LogicGPTConfig |
| RNNだけで作るseq2seq(RDDLGN) | RDDLGN / RDDLGNConfig |
| ゲーティングはブール演算である(LSTM/GRU)— RNNの論理化 | GroupSum / LutLayer |
| DWN — 温度計符号化とn入力LUTで解くMNIST | DWNClassifier / DWNLayer / ThermometerEncoder |
| 拡散モデルを丸ごとブール回路にする | LutConv2d |
| 論理ゲートAttentionの4変種ツアー | BooleanAttentionConfig / DLGNBooleanAttention / DLGNMultiQueryAttention / DLGNPointerAttention / DLGNPositionalAttention / MultiQueryAttentionConfig / PointerAttentionConfig / PositionalAttentionConfig |
| BinaryBrain互換APIでFPGA向けLUT網を学習する | BinaryToReal / DifferentiableLutBlock / RealToBinary |
| 行動認識(UCI-HAR、スマホ加速度) | GroupSum / LutLayer / fit_thermometer_thresholds / load_uci_har / thermometer_encode |