TimeGym
Controlled verification and diagnosis for forecasting pipelines.
A forecast can have the same numerical error and still be on the wrong dates, the wrong targets, or the wrong scale. TimeGym catches that. It generates synthetic forecasting cases whose true conditional distribution is known, runs your model on them, checks the output against an explicit contract, scores it against the known reference, and writes down why anything failed.
Documentation · Quick start · Tutorials · API · Changelog
Install
Python 3.11–3.15 (>=3.11,<3.16), following pandas support.
pip install timegym # core: NumPy, pandas, SciPy
pip install "timegym[plots]" # plus Matplotlib for the figures
pip install "timegym[sklearn]" # plus the scikit-learn adapter
From a clone, pip install -e '.[dev]' installs everything needed to run the
tests and notebooks.
Sixty seconds
from timegym import NaiveForecaster, Pipeline, Scenario
pipeline = Pipeline(NaiveForecaster(strategy="last"))
report = pipeline.test(
scenarios=[Scenario("random_walk", context_length=120, horizon=12)],
seeds=[0, 1, 2],
)
print(report.summary)
report.assert_passed() # raises on FAIL or ERROR, never on unsupported capabilities
report.to_json("report.json")
Every case in the report carries the scenario, the seed, the model's parameters, each diagnostic with its status and evidence, and the versions of everything involved, so a failure can be reproduced later from the file alone.
To look at the forecasts instead of the numbers, keep the run:
run = pipeline.run(seeds=[0, 1, 2])
run.plot_forecasts()
run.plot_errors(metric="mean_reference_mse")
What it checks
Contracts. A Forecast is a point array (H, D), optional quantiles
(H, D, Q) and optional joint samples (S, H, D). TimeGym checks the index
against the requested future, the target names and order, shapes, finiteness
and quantile ordering before any score is computed. A misaligned index is a
FAIL with the offending labels in the evidence, not a slightly worse MSE.
References. Each synthetic scenario knows its conditional mean, variance, cross-horizon covariance, quantiles and samples given the observed context. Scores against the reference (mean-reference MSE, CRPS, energy and variogram scores) measure distance to the truth, not to one noisy realisation.
Diagnostics with evidence. Optional Monte Carlo covariance checks compare an
ensemble to the known law at a stated significance level; equivariance checks
verify what a model claims; eight output-fault fixtures with paired repairs
show what each check catches. Accuracy stays INCONCLUSIVE until you supply
an acceptance rule: TimeGym never invents a threshold.
Scenarios. White noise, trend, seasonality, AR(1) and random walks with or without drift; multiple correlated targets; composed trend, seasonality and noise with scheduled changes, Merton jumps, GARCH volatility and hidden regimes; joint shocks, jumps and regimes across targets, each with explicit reference capabilities. The scenario guide explains what every family can and cannot certify.
Bring your own model
Any object with fit(context) and predict(future_index) returning a
Forecast is a model. The custom model tutorial
writes a nearest-analogues forecaster from scratch, tests it on synthetic
suites, then on real data with and without a known truth.
scikit-learn regressors plug in through a recursive, direct or multioutput reduction that fits its transforms on the training window only:
from sklearn.linear_model import Ridge
from sklearn.preprocessing import StandardScaler
from timegym import Pipeline
pipeline = Pipeline(window_length=12).add(StandardScaler()).add(Ridge(alpha=1.0))
report = pipeline.test(seeds=[0])
Native models pass as an unfitted factory, Pipeline(model_factory=lambda: MyModel(...)),
or as an instance with clone_unfitted(); TimeGym refits from scratch for every
case and never assumes a deep copy clears fitted state.
Tutorials
| Group | Notebook | What it shows |
|---|---|---|
| Start | Quick start | A pipeline, a matrix of cases, error distributions |
| Find what breaks | Faults, repairs and replay | Invalid outputs, inverse scaling, replaying a saved report |
| Write and test a custom model | A forecaster from scratch, synthetic suites, real data | |
| Shape the forecast | Target transforms | Log, Box-Cox and difference transforms, inverted on the forecast |
| Reductions | Recursive, direct and multioutput sklearn forecasts compared | |
| Multivariate forecasting | Several targets, lag features, per-target scores | |
| Real-data forecasts | Ordered origins on the AirPassengers series | |
| Measure uncertainty | Univariate uncertainty | Marginal intervals, coverage, CRPS |
| Multivariate uncertainty | Joint paths, dependence, covariance checks | |
| Stress-test | Capability sweeps | Five families, context and noise sweeps |
| Composed and financial stresses | Jumps, GARCH, hidden regimes, one mechanism at a time | |
| Joint financial uncertainty | Shared shocks and regimes, CCC-GARCH, broken dependence |
The notebooks run on CPU with local data. pip install -e '.[notebooks]' and
python -m jupyterlab notebooks opens them; the
notebook guide describes the folder.
The paper
The method and two controlled studies are described in the manuscript kept in
this repository: paper/main.tex, built into a
single-file version with every figure and table
generated from the recorded study results. The studies, their frozen records
and the exact reproduction recipe are in experiments/
and paper/README.md. The original 2021 prototype is on
arXiv as 2105.01404.
Development
The package is written in notebooks. The source notebooks under notebooks/
generate every module in timegym/; edit the notebook, export, test:
python tools/export_notebooks.py
python tools/export_notebooks.py --check
python -m pytest
Contributing describes the cycle, the versioning rule and the compatibility policy; releasing describes how a tag becomes a PyPI release with an archived DOI.
Scope
TimeGym does not locate the root cause of a bug, repair models, detect general leakage, infer conditional references for arbitrary generators, or handle panels, hierarchies, missing or irregular observations. Unsupported checks are reported as unsupported, never silently skipped or fabricated.
Cite
Cite the software by version; GitHub's "Cite this repository" reads the same metadata from CITATION.cff. When a release is archived on Zenodo, cite that release's DOI.
@software{seca2026timegym,
author = {Seca, Diogo},
title = {{TimeGym: verification and diagnosis for forecasting pipelines}},
year = {2026},
version = {1.1.0},
url = {https://github.com/diogoseca/timegym},
}
Seca, D. (2026). TimeGym: verification and diagnosis for forecasting pipelines (Version 1.1.0) [Computer software]. https://github.com/diogoseca/timegym
The earlier manuscript:
@article{seca2021timegym,
author = {Seca, Diogo},
title = {{TimeGym: Debugging for Time Series Modeling in Python}},
year = {2021},
doi = {10.48550/arXiv.2105.01404},
url = {https://arxiv.org/abs/2105.01404v1},
}
MIT license. Datasets and cited works keep their own attribution; see data provenance.
Metadata
Release files for timegym 1.1.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| timegym-1.1.0.tar.gz | 8.0 MB | With provenance | Details for timegym-1.1.0.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| timegym-1.1.0-py3-none-any.whl | Python 3 | none | any | Details for timegym-1.1.0-py3-none-any.whl |
Total release size: 8.1 MB
Release files / timegym-1.1.0.tar.gz
| Download URL | timegym-1.1.0.tar.gz |
|---|---|
| Size | 8.0 MB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
29f28a92b03f1e224086982e0fbdafe55043de6dc55e1c46ef6012eda6df2da9
|
|
BLAKE2b-256 checksum How to use checksums |
df9ae56a7db6f55d6463e0a83e4d2b2899897ec089f02b035ec862138920d40f
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.16
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Nov 5, 2026.
Transparency logRelease files / timegym-1.1.0-py3-none-any.whl
| Download URL | timegym-1.1.0-py3-none-any.whl |
|---|---|
| Size | 82.3 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
34d9fbd49e80b52d8c55e038409fc7f3396ca2923652dd05aeb1bf2b2062644e
|
|
BLAKE2b-256 checksum How to use checksums |
966eb2fd3cb917703541f54d3e5da84742a8fa4bb4b84d837061d039bc69f201
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.16
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Nov 5, 2026.
Transparency logSecurity for timegym 1.1.0
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
Full provenance
Both files in this release have been uploaded with provenance metadata.
Attestation for timegym-1.1.0.tar.gz
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Nov 5, 2026.
Transparency logA note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.