Metadata-Version: 2.4
Name: foreblocks
Version: 0.1.15
Summary: Modular Time Series Forecasting Library
Author-email: Laio Seman <laioseman@gmail.com>
License: MIT License
        
        Copyright (c) 2025 Laio O. Seman
        
        Permission is hereby granted, free of charge, to any person obtaining a copy
        of this software and associated documentation files (the "Software"), to deal
        in the Software without restriction, including without limitation the rights
        to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
        copies of the Software, and to permit persons to whom the Software is
        furnished to do so, subject to the following conditions:
        
        The above copyright notice and this permission notice shall be included in all
        copies or substantial portions of the Software.
        
        THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
        IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
        FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
        AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
        LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
        OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
        SOFTWARE.
        
Project-URL: Homepage, https://github.com/lseman/foreblocks
Project-URL: Repository, https://github.com/lseman/foreblocks
Keywords: time series,forecasting,deep learning,transformer,lstm,pytorch,nas,darts
Classifier: Development Status :: 3 - Alpha
Classifier: Intended Audience :: Science/Research
Classifier: License :: OSI Approved :: MIT License
Classifier: Programming Language :: Python :: 3
Classifier: Programming Language :: Python :: 3.10
Classifier: Programming Language :: Python :: 3.11
Classifier: Programming Language :: Python :: 3.12
Classifier: Topic :: Scientific/Engineering :: Artificial Intelligence
Requires-Python: >=3.10
Description-Content-Type: text/markdown
License-File: LICENSE
Requires-Dist: torch>=2.0
Requires-Dist: numpy>=1.24
Requires-Dist: einops>=0.6
Requires-Dist: tqdm>=4.64
Provides-Extra: plotting
Requires-Dist: matplotlib>=3.6; extra == "plotting"
Provides-Extra: scientific
Requires-Dist: pandas>=1.5; extra == "scientific"
Requires-Dist: scipy>=1.10; extra == "scientific"
Requires-Dist: numba>=0.57; extra == "scientific"
Requires-Dist: scikit-learn>=1.2; extra == "scientific"
Requires-Dist: joblib>=1.3; extra == "scientific"
Requires-Dist: statsmodels>=0.14; extra == "scientific"
Requires-Dist: tabulate>=0.9; extra == "scientific"
Provides-Extra: preprocessing
Requires-Dist: foreblocks[plotting,scientific]; extra == "preprocessing"
Provides-Extra: darts
Requires-Dist: foreblocks[plotting]; extra == "darts"
Provides-Extra: darts-analysis
Requires-Dist: foreblocks[darts,scientific]; extra == "darts-analysis"
Requires-Dist: seaborn>=0.13; extra == "darts-analysis"
Provides-Extra: mltracker
Requires-Dist: requests>=2.31; extra == "mltracker"
Requires-Dist: fastapi>=0.100; extra == "mltracker"
Requires-Dist: uvicorn>=0.22; extra == "mltracker"
Requires-Dist: pydantic>=2.0; extra == "mltracker"
Requires-Dist: textual>=0.70; extra == "mltracker"
Provides-Extra: vmd
Requires-Dist: foreblocks[scientific]; extra == "vmd"
Requires-Dist: pyfftw>=0.13; extra == "vmd"
Requires-Dist: optuna>=3.0; extra == "vmd"
Provides-Extra: wavelets
Requires-Dist: scipy>=1.10; extra == "wavelets"
Requires-Dist: sympy>=1.12; extra == "wavelets"
Requires-Dist: PyWavelets>=1.4; extra == "wavelets"
Requires-Dist: pytorch_wavelets>=1.3; extra == "wavelets"
Provides-Extra: benchmark
Requires-Dist: foreblocks[plotting,scientific]; extra == "benchmark"
Requires-Dist: neuralforecast>=2.0; extra == "benchmark"
Requires-Dist: openpyxl>=3.1; extra == "benchmark"
Provides-Extra: foreminer
Requires-Dist: foreblocks[plotting,scientific]; extra == "foreminer"
Requires-Dist: ruptures>=1.1; extra == "foreminer"
Requires-Dist: networkx>=3.0; extra == "foreminer"
Requires-Dist: seaborn>=0.13; extra == "foreminer"
Provides-Extra: all
Requires-Dist: foreblocks[benchmark,darts,darts-analysis,foreminer,mltracker,preprocessing,vmd,wavelets]; extra == "all"
Provides-Extra: dev
Requires-Dist: pytest>=7.0; extra == "dev"
Requires-Dist: ipykernel>=6.0; extra == "dev"
Requires-Dist: ruff; extra == "dev"
Requires-Dist: basedpyright; extra == "dev"
Dynamic: license-file

# foreBlocks

[![PyPI Version](https://img.shields.io/pypi/v/foreblocks.svg)](https://pypi.org/project/foreblocks/)
[![Python Versions](https://img.shields.io/pypi/pyversions/foreblocks.svg)](https://pypi.org/project/foreblocks/)
[![License](https://img.shields.io/github/license/lseman/foreblocks)](LICENSE)

![ForeBlocks Logo](web/logo.svg#gh-light-mode-only)
![ForeBlocks Logo](web/logo_dark.svg#gh-dark-mode-only)

**foreBlocks** is a modular PyTorch library for time-series forecasting. The repository combines:

- `foreblocks`: forecasting models, training, evaluation, preprocessing, and DARTS search
- `foretools`: companion utilities, synthetic data generation, decomposition, and analysis notebooks

The project is best approached as a research toolkit rather than a single monolithic framework. The most stable public entry points are the top-level imports exported from `foreblocks`.

## Install

```bash
pip install foreblocks
```

Install optional extras when you need specific subsystems:

| Extra | Adds |
| --- | --- |
| `mltracker` | experiment tracking API and UI dependencies |
| `vmd` | VMD decomposition and Optuna-based search support |
| `wavelets` | optional wavelet backends |
| `benchmark` | external forecasting baselines and spreadsheet readers |
| `foreminer` | changepoint-detection support |
| `all` | all runtime extras above |

Examples:

```bash
pip install "foreblocks[mltracker]"
pip install "foreblocks[vmd,wavelets]"
pip install "foreblocks[all]"
```

Local development install:

```bash
git clone https://github.com/lseman/foreblocks.git
cd foreblocks
pip install -e ".[dev]"
```

## Validated Quickstart

The example below is intentionally small and uses the most reliable path through the current API: a direct forecaster with a custom head, trained through `Trainer`.

```python
import numpy as np
import torch
import torch.nn as nn

from foreblocks import (
    ForecastingModel,
    ModelEvaluator,
    Trainer,
    TrainingConfig,
    create_dataloaders,
)

seq_len = 24
horizon = 6
n_features = 4

rng = np.random.default_rng(0)
X_train = rng.normal(size=(64, seq_len, n_features)).astype("float32")
y_train = rng.normal(size=(64, horizon)).astype("float32")
X_val = rng.normal(size=(16, seq_len, n_features)).astype("float32")
y_val = rng.normal(size=(16, horizon)).astype("float32")

train_loader, val_loader = create_dataloaders(
    X_train,
    y_train,
    X_val,
    y_val,
    batch_size=16,
)

head = nn.Sequential(
    nn.Flatten(),
    nn.Linear(seq_len * n_features, 64),
    nn.GELU(),
    nn.Linear(64, horizon),
)

model = ForecastingModel(
    head=head,
    forecasting_strategy="direct",
    model_type="head_only",
    target_len=horizon,
)

trainer = Trainer(
    model,
    config=TrainingConfig(
        num_epochs=5,
        batch_size=16,
        patience=3,
        use_amp=False,
    ),
    auto_track=False,
)

history = trainer.train(train_loader, val_loader)
evaluator = ModelEvaluator(trainer)
metrics = evaluator.compute_metrics(torch.tensor(X_val), torch.tensor(y_val))

print(history.train_losses[-1], metrics)
```

This path was smoke-tested in the repository. Once that is working, move on to encoder/decoder models, preprocessing, and DARTS.

## Public API

These are the top-level imports currently exposed by `foreblocks`:

| Import | Purpose |
| --- | --- |
| `ForecastingModel` | Core forecasting wrapper for direct, autoregressive, and seq2seq-style models |
| `Trainer` | Training loop with NAS hooks, MLTracker integration, and optional conformal support |
| `ModelEvaluator` | Prediction helpers, metrics, cross-validation, and training-curve plots |
| `TimeSeriesHandler` | Time-series handling pipeline for windowing, scaling, filtering, imputation, and time features |
| `TimeSeriesDataset` | Dataset wrapper used by the dataloader helper |
| `create_dataloaders` | Build train/validation PyTorch dataloaders from NumPy arrays |
| `ModelConfig`, `TrainingConfig` | Lightweight configuration dataclasses |
| `LSTMEncoder`, `LSTMDecoder`, `GRUEncoder`, `GRUDecoder` | Recurrent encoder/decoder blocks |
| `TransformerEncoder`, `TransformerDecoder` | Transformer backbones and related advanced features |
| `AttentionLayer` | Attention module entry point |

## Repository Map

| Path | What it contains |
| --- | --- |
| `foreblocks/core` | `ForecastingModel`, heads, conformal utilities, sampling |
| `foreblocks/training` | `Trainer`, training loop, quantization utilities |
| `foreblocks/evaluation` | `ModelEvaluator`, benchmarking helpers |
| `foreblocks/ts_handler` | `TimeSeriesHandler`, imputation, filtering, outlier handling |
| `foreblocks/tf` | transformer stack, attention variants, MoE, norms, embeddings |
| `foreblocks/darts` | neural architecture search pipeline and evaluation |
| `foretools/tsgen` | synthetic time-series generator and notebooks |
| `examples/` | notebooks and runnable usage examples |
| `web/` | static landing page assets for the published site root |
| `docs/` | MkDocs source for the versioned documentation site published under `/docs/` |

## Documentation Map

Start here if you are new to the repository:

- [Documentation Overview](docs/overview.md)
- [Getting Started](docs/getting-started.md)
- [Docs Home](docs/index.md)

Topic guides:

- [Preprocessor Guide](docs/preprocessor.md)
- [Custom Blocks Guide](docs/custom_blocks.md)
- [Transformer Guide](docs/transformer.md)
- [MoE Guide](docs/moe.md)
- [DARTS Guide](docs/darts.md)
- [Troubleshooting](docs/troubleshooting.md)

Companion tooling:

- [Foretools Overview](docs/foretools/index.md)
- [Time Series Generator](docs/foretools/tsgen.md)
- [BOHB Search](docs/foretools/bohb.md)
- [VMD Decomposition](docs/foretools/vmd.md)

Useful notebooks and examples:

- [Synthetic Series Notebook](foretools/tsgen/ts_gen_complete_series.ipynb)
- [TS Generator Documentation Notebook](foretools/tsgen/ts_gen_doc.ipynb)
- [Example notebooks](examples/)

There is also a repository-local docs navigation file at [`mkdocs.yml`](mkdocs.yml). The current publishing model is:

- site root `/`: custom landing page from `web/index.html`
- site docs `/docs/`: MkDocs site built from `docs/`

## Current Project Status

- The repository is broad and still evolving. Some subsystems are more mature than others.
- The top-level imports listed above are the safest place to start.
- `Trainer` supports MLTracker and conformal prediction, but you can disable tracking during local smoke tests with `auto_track=False`.
- `MultiAttention` now includes an experimental attention-matching KV compaction mode for dense paged causal decode. Enable it with `use_attention_matching_compaction=True` and `use_mla=False`.
- For decoder-based seq2seq and transformer workflows, use the topic guides before wiring custom modules, because dimension contracts are stricter than the direct head path.
- `TrainingConfig` now lives in a single canonical location and includes trainer, NAS, MLTracker, and conformal settings.

## Contributing

Documentation improvements are especially valuable here because the repository spans forecasting models, search, preprocessing, and auxiliary tooling. If you add or change a public API, update:

1. this `README.md`
2. the relevant guide under `docs/`
3. at least one runnable example or notebook
