# ml-kuleuven/deepproblog architecture

> Architecture diagram of the GitHub repository ml-kuleuven/deepproblog, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2025-01-16). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/ml-kuleuven/deepproblog
- Repository: https://github.com/ml-kuleuven/deepproblog

## Overview

##### Main Components
The system architecture should highlight these key components:

a) Core Engine Layer:
- Exact Engine
- Approximate Engine
- Prolog Engine
- Neural Predicates System

b) Integration Layer:
- ProbLog Integration
- PyTorch Integration
- SWI-Prolog Integration

c) Inference System:
- Arithmetic Circuit
- Graph Semiring
- Query Processing

##### Component Relationships

**┌─────────────────────────────────────────────────────────────┐**
- DeepProbLog System                      │
- ┬─────────────────────┬───────────────────┤
- Core Engine   │  Neural Processing  │    Integration    │
- Layer        │
- ┌─────────────┐ │   ┌─────────────┐  │  ┌────────────┐  │
- Exact Engine │ │   │   Neural    │  │  │  ProbLog   │  │
- ┘ │   │ Predicates  │  │  │  Bridge    │  │
- ┌─────────────┐ │   └─────────────┘  │  └────────────┘  │
- Approximate  │ │   ┌─────────────┐  │  ┌────────────┐  │
- Engine     │ │   │  PyTorch    │  │  │ SWI-Prolog │  │
- ┘ │   │  Networks   │  │  │  Bridge    │  │
- ┌─────────────┐ │   └─────────────┘  │  └────────────┘  │
- Prolog Engine│ │                     │                  │
- ┘ │                     │                  │
- ┴─────────────────────┴──────────────────┘

##### Implementation Details

a) Engine Layer:
- Connection between exact and approximate inference
- Prolog engine's interaction with SWI-Prolog
- Neural predicate integration points

b) Neural Integration:
- PyTorch network integration
- Tensor processing flow
- Probability calculation points

c) Data Flow:
- Query processing path
- Result propagation
- Optimization feedback loops

##### Additional Elements

Supporting components:
- Dataset handlers
- Optimization system
- Testing framework
- Example implementations

##### Architectural Patterns

Patterns:
- Modular engine design
- Plugin-based neural network integration
- Layered inference system

##### External Dependencies

Connections to:
- ProbLog
- PyTorch
- SWI-Prolog
- PySDD

Remember to emphasize the unique aspects of DeepProbLog, particularly the neural predicate system and its integration with probabilistic logic programming.

## Diagram (Mermaid)

```mermaid
flowchart TB
    subgraph DPL["DeepProbLog System"]
        subgraph Core["Core Engine Layer"]
            EE["Exact Engine"]
            AE["Approximate Engine"]
            PE["Prolog Engine"]
            NP["Neural Predicates"]
        end

        subgraph Neural["Neural Processing Layer"]
            NN["Neural Networks"]
            PT["PyTorch Integration"]
            NPS["Neural Predicates System"]
        end

        subgraph Int["Integration Layer"]
            PB["ProbLog Bridge"]
            SWI["SWI-Prolog Bridge"]
        end

        subgraph Inf["Inference System"]
            AC["Arithmetic Circuit"]
            GS["Graph Semiring"]
            QP["Query Processing"]
        end

        subgraph Sup["Supporting Systems"]
            DH["Dataset Handler"]
            MC["Model Core"]
            OP["Optimizer"]
            TS["Training System"]
        end
    end

    %% Core Engine Relationships
    EE --> AC
    AE --> AC
    PE --> SWI
    NP --> PT

    %% Neural Processing Relationships
    NN --> NPS
    PT --> NPS
    NPS --> MC

    %% Inference System Relationships
    AC --> GS
    GS --> QP
    QP --> MC

    %% Integration Layer Relationships
    PB --> PE
    SWI --> PE

    %% Supporting Systems Relationships
    DH --> MC
    MC --> OP
    OP --> TS
    TS --> MC

    %% Styling
    classDef core fill:#a8d1f0
    classDef neural fill:#90EE90
    classDef integration fill:#FFB366
    classDef inference fill:#DDA0DD
    classDef support fill:#F0E68C

    class EE,AE,PE,NP core
    class NN,PT,NPS neural
    class PB,SWI integration
    class AC,GS,QP inference
    class DH,MC,OP,TS support

    %% Click Events
    click EE "https://github.com/ML-KULeuven/deepproblog/blob/master/src/deepproblog/engines/exact_engine.py"
    click AE "https://github.com/ML-KULeuven/deepproblog/blob/master/src/deepproblog/engines/approximate_engine.py"
    click PE "https://github.com/ML-KULeuven/deepproblog/blob/master/src/deepproblog/engines/prolog_engine/engine.py"
    click NP "https://github.com/ML-KULeuven/deepproblog/blob/master/src/deepproblog/network.py"
    click PT "https://github.com/ML-KULeuven/deepproblog/blob/master/src/deepproblog/network.py"
    click SWI "https://github.com/ML-KULeuven/deepproblog/blob/master/src/deepproblog/engines/prolog_engine/swip.py"
    click AC "https://github.com/ML-KULeuven/deepproblog/blob/master/src/deepproblog/arithmetic_circuit.py"
    click GS "https://github.com/ML-KULeuven/deepproblog/blob/master/src/deepproblog/semiring/graph_semiring.py"
    click QP "https://github.com/ML-KULeuven/deepproblog/blob/master/src/deepproblog/query.py"
    click DH "https://github.com/ML-KULeuven/deepproblog/blob/master/src/deepproblog/dataset.py"
    click MC "https://github.com/ML-KULeuven/deepproblog/blob/master/src/deepproblog/model.py"
    click OP "https://github.com/ML-KULeuven/deepproblog/blob/master/src/deepproblog/optimizer.py"
    click TS "https://github.com/ML-KULeuven/deepproblog/blob/master/src/deepproblog/train.py"
```
