TorchLogix Package

The main TorchLogix package provides the core functionality for differentiable logic gate neural networks.

Main Classes

CompiledLogicNet

Unified compiled logic network that handles convolutional, pooling, and linear layers.

Package Contents

The main package for torchlogix.

class torchlogix.CompiledLogicNet(model, input_shape, device='cpu', num_bits=64, cpu_compiler='gcc', verbose=False, use_bitpacking=True)[source]

Bases: Module

Unified compiled logic network that handles convolutional, pooling, and linear layers.

__init__(model, input_shape, device='cpu', num_bits=64, cpu_compiler='gcc', verbose=False, use_bitpacking=True)[source]

Initialize internal Module state, shared by both nn.Module and ScriptModule.

compile(opt_level=1, save_lib_path=None, verbose=False)[source]

Compile the network to a shared library.

forward(x, verbose=False)[source]

Forward pass through the compiled network.

Return type:

IntTensor

get_c_code()[source]

Generate the complete C code for the network.

Return type:

str

get_gate_code(var1, var2, gate_op)[source]

Generate C code for a logic gate operation.

Return type:

str

static load(save_lib_path, input_shape, num_classes=None, num_bits=64)[source]

Load a compiled network from a shared library.

Note: input_shape is required here since we’re loading a pre-compiled library without access to the original model structure for inference.

training: bool
class torchlogix.PackBitsTensor(t, bit_count=32, device='cuda')[source]

Bases: object

__init__(t, bit_count=32, device='cuda')[source]
flatten(start_dim=0, end_dim=-1, **kwargs)[source]

Returns the PackBitsTensor object itself. Arguments are ignored.

group_sum(k)[source]

Submodules