# horizon12275/dredmtl-for-datalogmtl architecture

> Architecture diagram of the GitHub repository horizon12275/dredmtl-for-datalogmtl, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-04-09). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/horizon12275/dredmtl-for-datalogmtl
- Repository: https://github.com/horizon12275/dredmtl-for-datalogmtl

## Overview

1. This repository is an experiment artifact for the paper on incremental maintenance of DatalogMTL materializations. Its architecture is centered on a Python-based reasoning pipeline that takes benchmark datasets plus DatalogMTL programs, builds canonical representations, and then compares an incremental algorithm against a naive full-recompute baseline.

2. The code is split into four main scripts under `code/`, each with a distinct role in the pipeline:
   - `preparation.py` prepares benchmark data and precomputes canonical representations.
   - `DRED_mtl.py` contains the DRED<sub>MTL</sub> incremental maintenance logic.
   - `time_exp.py` runs timing experiments for deletion/insertion maintenance.
   - `count_exp.py` runs fact-count experiments after updates.
   This separation makes the architecture a two-stage system: preparation first, then experiments.

3. The main data inputs live under `data/` and are organized by representation and benchmark. `data/original_e/` contains the original benchmark facts, while `data/delta_e/` contains update sets for deletion/insertion experiments. The three benchmark families are LUBM<sub>t</sub>, iTemporal, and Weather, with separate files for fixed-size and percentage-based deltas.

4. The rule layer is stored independently under `programs/`. There is one program file per benchmark: `lubm.txt`, `iTemporal.txt`, and `weather.txt`. These DatalogMTL programs are the logical schemas that the reasoner applies over the input facts.

5. The central intermediate artifact is the canonical representation. The preparation step loads the original dataset, constructs the canonical representation, computes period information, and persists the result under `canonical_representations/` as serialized `.pkl` files. This is a key architectural boundary because later experiment runs reuse these cached objects instead of rebuilding them.

6. The incremental maintenance flow in `time_exp.py` and `count_exp.py` is:
   - load the precomputed canonical representation,
   - load the delta facts for deletion and insertion,
   - apply the DRED<sub>MTL</sub> update logic,
   - compare against a baseline that recomputes from the updated dataset from scratch.
   The baseline is therefore not a separate system, but a control path inside the experiment scripts.

7. The DRED<sub>MTL</sub> algorithm itself sits at the core of the reasoning subsystem. It operates on the canonical representation plus delta inputs, and it appears to maintain auxiliary periodic/interval metadata as part of the update process. The README’s example also indicates that cyclicity checks are part of the runtime path, so the algorithm is not just a set-difference updater; it depends on structural properties of the rule/dataset state.

8. There is an external dependency boundary around MeTeoR. The repository is built on top of the MeTeoR DatalogMTL framework, and the README shows imports from `meteor_reasoner.*`. So this repo is best understood as an application/benchmark layer plus a custom DRED<sub>MTL</sub> implementation layered on an existing reasoning engine, rather than a standalone reasoner from scratch.

9. The two experiment scripts differ only in what they measure. `time_exp.py` records execution time for incremental updates versus recomputation, while `count_exp.py` records the number of facts in the resulting canonical representation after updates. Both use the same data-loading and update pipeline, which means the architecture is shared up to the final measurement sink.

10. Output artifacts are written to experiment-specific result directories, conceptually under `results/time_exp/` and `results/count_exp/`, even though those folders are empty in the tree snapshot. This makes the repository a reproducible pipeline with cached intermediates (`canonical_representations/`) and final tabular outputs (`results/`).

11. The repository also contains compressed or partitioned benchmark data, especially for Weather, which indicates the data layer can include large multi-part archives rather than only plain text. That matters for the architecture because dataset preparation is not just parsing files; it also includes unpacking/assembling benchmark inputs before reasoning.

12. For diagramming purposes, the key data flow is: benchmark facts and rules enter preparation → canonical representation and period metadata are generated and cached → delta datasets are loaded for updates → DRED<sub>MTL</sub> or baseline recomputation produces updated materializations → timing/count outputs are saved. The main boundaries are between raw benchmark inputs, cached reasoning state, incremental update logic, and experiment reporting.

Main entry points: [`code/preparation.py`](https://github.com/horizon12275/dredmtl-for-datalogmtl/blob/main/code/preparation.py) (Preparation), [`code/time_exp.py`](https://github.com/horizon12275/dredmtl-for-datalogmtl/blob/main/code/time_exp.py) (Timing exp), [`code/count_exp.py`](https://github.com/horizon12275/dredmtl-for-datalogmtl/blob/main/code/count_exp.py) (Count exp), [`code/DRED_mtl.py`](https://github.com/horizon12275/dredmtl-for-datalogmtl/blob/main/code/DRED_mtl.py) (DRED_MTL)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_inputs["Inputs"]
  node_readme["README<br/>overview<br/>[README.md]"]
  node_program_lubm["LUBM rules<br/>program<br/>[lubm.txt]"]
  node_program_itemporal["iTemporal rules<br/>program<br/>[iTemporal.txt]"]
  node_program_weather["Weather rules<br/>program<br/>[weather.txt]"]
  node_data_original[("Original data<br/>benchmark facts")]
  node_data_delta[("Delta data<br/>update sets")]
  node_weather_archives[("Weather archives<br/>partitioned dataset")]
end

subgraph group_prep["Preparation"]
  node_prepare["Preparation<br/>pipeline stage<br/>[preparation.py]"]
end

subgraph group_reasoning["Reasoning"]
  node_dred_mtl["DRED_MTL<br/>incremental maintenance<br/>[DRED_mtl.py]"]
  node_baseline["Naive baseline<br/>full recompute<br/>[time_exp.py]"]
  node_periodic_meta["Period metadata<br/>auxiliary state"]
end

subgraph group_experiments["Experiments"]
  node_time_exp["Timing exp<br/>experiment<br/>[time_exp.py]"]
  node_count_exp["Count exp<br/>experiment<br/>[count_exp.py]"]
end

subgraph group_outputs["Outputs"]
  node_canonical_cache[("Canonical cache<br/>serialized state")]
  node_time_results["Time results<br/>experiment output"]
  node_count_results["Count results<br/>experiment output"]
end

subgraph group_external["External"]
  node_meteor{{"MeTeoR<br/>external framework"}}
end

node_readme -->|"describes"| node_prepare
node_readme -->|"describes"| node_time_exp
node_readme -->|"describes"| node_count_exp
node_program_lubm -->|"rules for"| node_prepare
node_program_itemporal -->|"rules for"| node_prepare
node_program_weather -->|"rules for"| node_prepare
node_data_original -->|"input to"| node_prepare
node_weather_archives -->|"input to"| node_prepare
node_prepare -->|"writes"| node_canonical_cache
node_canonical_cache -->|"loaded by"| node_time_exp
node_canonical_cache -->|"loaded by"| node_count_exp
node_data_delta -->|"delta input"| node_time_exp
node_data_delta -->|"delta input"| node_count_exp
node_time_exp -->|"invokes"| node_dred_mtl
node_count_exp -->|"invokes"| node_dred_mtl
node_time_exp -->|"compares"| node_baseline
node_count_exp -->|"compares"| node_baseline
node_dred_mtl -->|"maintains"| node_periodic_meta
node_periodic_meta -->|"feeds"| node_time_exp
node_meteor -.->|"framework"| node_prepare
node_meteor -.->|"framework"| node_dred_mtl
node_time_exp -->|"writes"| node_time_results
node_count_exp -->|"writes"| node_count_results

click node_readme "https://github.com/horizon12275/dredmtl-for-datalogmtl/blob/main/README.md"
click node_program_lubm "https://github.com/horizon12275/dredmtl-for-datalogmtl/blob/main/programs/lubm.txt"
click node_program_itemporal "https://github.com/horizon12275/dredmtl-for-datalogmtl/blob/main/programs/iTemporal.txt"
click node_program_weather "https://github.com/horizon12275/dredmtl-for-datalogmtl/blob/main/programs/weather.txt"
click node_data_original "https://github.com/horizon12275/dredmtl-for-datalogmtl/tree/main/data/original_e"
click node_data_delta "https://github.com/horizon12275/dredmtl-for-datalogmtl/tree/main/data/delta_e"
click node_prepare "https://github.com/horizon12275/dredmtl-for-datalogmtl/blob/main/code/preparation.py"
click node_canonical_cache "https://github.com/horizon12275/dredmtl-for-datalogmtl/tree/main/canonical_representations"
click node_dred_mtl "https://github.com/horizon12275/dredmtl-for-datalogmtl/blob/main/code/DRED_mtl.py"
click node_baseline "https://github.com/horizon12275/dredmtl-for-datalogmtl/blob/main/code/time_exp.py"
click node_time_exp "https://github.com/horizon12275/dredmtl-for-datalogmtl/blob/main/code/time_exp.py"
click node_count_exp "https://github.com/horizon12275/dredmtl-for-datalogmtl/blob/main/code/count_exp.py"
click node_weather_archives "https://github.com/horizon12275/dredmtl-for-datalogmtl/tree/main/data/original_e/weather_data"

classDef toneNeutral fill:#f8fafc,stroke:#334155,stroke-width:1.5px,color:#0f172a
classDef toneBlue fill:#dbeafe,stroke:#2563eb,stroke-width:1.5px,color:#172554
classDef toneAmber fill:#fef3c7,stroke:#d97706,stroke-width:1.5px,color:#78350f
classDef toneMint fill:#dcfce7,stroke:#16a34a,stroke-width:1.5px,color:#14532d
classDef toneRose fill:#ffe4e6,stroke:#e11d48,stroke-width:1.5px,color:#881337
classDef toneIndigo fill:#e0e7ff,stroke:#4f46e5,stroke-width:1.5px,color:#312e81
classDef toneTeal fill:#ccfbf1,stroke:#0f766e,stroke-width:1.5px,color:#134e4a
class node_readme,node_program_lubm,node_program_itemporal,node_program_weather,node_data_original,node_data_delta,node_weather_archives toneBlue
class node_prepare toneAmber
class node_dred_mtl,node_baseline,node_periodic_meta toneMint
class node_time_exp,node_count_exp toneRose
class node_canonical_cache,node_time_results,node_count_results toneIndigo
class node_meteor toneTeal
```

## Components

### Inputs

Raw benchmark facts, delta sets, and rule programs

- [README](https://github.com/horizon12275/dredmtl-for-datalogmtl/blob/main/README.md): overview · Paper-oriented usage and pipeline notes · `README.md`
- [LUBM rules](https://github.com/horizon12275/dredmtl-for-datalogmtl/blob/main/programs/lubm.txt): program · DatalogMTL program for the LUBM benchmark · `programs/lubm.txt`
- [iTemporal rules](https://github.com/horizon12275/dredmtl-for-datalogmtl/blob/main/programs/iTemporal.txt): program · DatalogMTL program for the iTemporal benchmark · `programs/iTemporal.txt`
- [Weather rules](https://github.com/horizon12275/dredmtl-for-datalogmtl/blob/main/programs/weather.txt): program · DatalogMTL program for the Weather benchmark · `programs/weather.txt`
- [Original data](https://github.com/horizon12275/dredmtl-for-datalogmtl/tree/main/data/original_e): benchmark facts · Base benchmark facts and source datasets · `data/original_e`
- [Delta data](https://github.com/horizon12275/dredmtl-for-datalogmtl/tree/main/data/delta_e): update sets · Deletion and insertion inputs for maintenance experiments · `data/delta_e`
- [Weather archives](https://github.com/horizon12275/dredmtl-for-datalogmtl/tree/main/data/original_e/weather_data): partitioned dataset · Compressed multipart weather benchmark input · `data/original_e/weather_data`

### Preparation

Builds cached canonical representations

- [Preparation](https://github.com/horizon12275/dredmtl-for-datalogmtl/blob/main/code/preparation.py): pipeline stage · Builds canonical representations and period metadata · `code/preparation.py`

### Reasoning

Incremental maintenance and baseline recomputation

- [DRED_MTL](https://github.com/horizon12275/dredmtl-for-datalogmtl/blob/main/code/DRED_mtl.py): incremental maintenance · Core incremental update logic over canonical state plus deltas · `code/DRED_mtl.py`
- [Naive baseline](https://github.com/horizon12275/dredmtl-for-datalogmtl/blob/main/code/time_exp.py): full recompute · Control path that recomputes materialization from updated data · `code/time_exp.py`
- **Period metadata**: auxiliary state · Intervals, periodicity, and cyclicity-related runtime metadata

### Experiments

Timing and fact-count measurement runs

- [Timing exp](https://github.com/horizon12275/dredmtl-for-datalogmtl/blob/main/code/time_exp.py): experiment · Measures incremental maintenance time versus recomputation · `code/time_exp.py`
- [Count exp](https://github.com/horizon12275/dredmtl-for-datalogmtl/blob/main/code/count_exp.py): experiment · Measures fact counts after updates · `code/count_exp.py`

### Outputs

Cached intermediates and reported results

- [Canonical cache](https://github.com/horizon12275/dredmtl-for-datalogmtl/tree/main/canonical_representations): serialized state · Persisted canonical representations reused by later runs · `canonical_representations`
- **Time results**: experiment output · Recorded runtime measurements
- **Count results**: experiment output · Recorded post-update fact counts

### External

Underlying reasoning framework dependency

- **MeTeoR**: external framework · Underlying DatalogMTL reasoning framework

## Connections

- README → Preparation: describes · Documents the preparation step and cached state
- README → Timing exp: describes · Documents timing experiments and baseline comparison
- README → Count exp: describes · Documents fact-count experiments
- LUBM rules → Preparation: rules for · Program used when building canonical form
- iTemporal rules → Preparation: rules for · Program used when building canonical form
- Weather rules → Preparation: rules for · Program used when building canonical form
- Original data → Preparation: input to · Base facts are normalized during preparation
- Weather archives → Preparation: input to · Multipart weather archives are assembled for preparation
- Preparation → Canonical cache: writes · Persists canonical representations for reuse
- Canonical cache → Timing exp: loaded by · Reused as the starting state for timing runs
- Canonical cache → Count exp: loaded by · Reused as the starting state for count runs
- Delta data → Timing exp: delta input · Provides update facts for timing experiments
- Delta data → Count exp: delta input · Provides update facts for count experiments
- Timing exp → DRED_MTL: invokes · Runs incremental maintenance path
- Count exp → DRED_MTL: invokes · Runs incremental maintenance path
- Timing exp → Naive baseline: compares · Measures against full recomputation control path
- Count exp → Naive baseline: compares · Uses recomputation as a reference path
- DRED_MTL → Period metadata: maintains · Updates interval and cyclicity-related metadata
- Period metadata → Timing exp: feeds · Used during update execution
- MeTeoR → Preparation: framework · Underlying reasoning engine dependency
- MeTeoR → DRED_MTL: framework · Provides core DatalogMTL runtime primitives
- Timing exp → Time results: writes · Stores runtime measurements
- Count exp → Count results: writes · Stores fact-count measurements
