Metadata-Version: 2.4
Name: pytorchfire
Version: 1.1.0
Summary: PyTorchFire: A GPU-Accelerated Wildfire Simulator with Differentiable Cellular Automata
Project-URL: Documentation, https://pytorchfire.readthedocs.io/
Project-URL: Issues, https://github.com/xiazeyu/PyTorchFire/issues
Project-URL: Source, https://github.com/xiazeyu/PyTorchFire
Author-email: Zeyu Xia <zeyu.xia@virginia.edu>, Sibo Cheng <sibo.cheng@enpc.fr>
License: MIT License
        
        Copyright (c) 2024 Zeyu Xia
        
        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.
License-File: LICENSE
Classifier: Environment :: GPU
Classifier: Intended Audience :: Science/Research
Classifier: License :: OSI Approved :: MIT License
Classifier: Operating System :: OS Independent
Classifier: Programming Language :: Python :: 3
Classifier: Topic :: Scientific/Engineering :: Atmospheric Science
Requires-Python: >=3.12
Requires-Dist: einops
Requires-Dist: numpy
Requires-Dist: torch
Provides-Extra: examples
Requires-Dist: einops; extra == 'examples'
Requires-Dist: h5py; extra == 'examples'
Requires-Dist: mpi4py; extra == 'examples'
Requires-Dist: numpy; extra == 'examples'
Requires-Dist: tensorboard; extra == 'examples'
Requires-Dist: torch; extra == 'examples'
Requires-Dist: tqdm; extra == 'examples'
Provides-Extra: firedataforge
Requires-Dist: firedataforge; extra == 'firedataforge'
Description-Content-Type: text/markdown

# PyTorchFire: A GPU-Accelerated Wildfire Simulator with Differentiable Cellular Automata


[![Hatch project](https://img.shields.io/badge/%F0%9F%A5%9A-Hatch-4051b5.svg)](https://github.com/pypa/hatch)
[![PyPI - Version](https://img.shields.io/pypi/v/pytorchfire)](https://pypi.org/project/pytorchfire/)
[![Read the Docs](https://readthedocs.org/projects/pytorchfire/badge/)](https://pytorchfire.readthedocs.io/)

[![Paper doi](https://img.shields.io/badge/Paper%20DOI-10.1016%2Fj.envsoft.2025.106401-blue)](https://doi.org/10.1016/j.envsoft.2025.106401)
[![Paper license](http://mirrors.creativecommons.org/presskit/buttons/80x15/svg/by.svg)](http://creativecommons.org/licenses/by/4.0/)

[![Code DOI](https://img.shields.io/badge/Code_DOI-10.5281%2Fzenodo.13132218-blue)](https://doi.org/10.5281/zenodo.13132218)
[![Dataset DOI](https://img.shields.io/badge/Dataset_DOI-10.17632%2Fnx2wsksp9k.1-blue)](https://doi.org/10.17632/nx2wsksp9k.1)

## About The Project

Accurate and rapid prediction of wildfire trends is crucial for effective management and mitigation. However, the stochastic nature of fire propagation poses significant challenges in developing reliable simulators. In this paper, we introduce PyTorchFire, an open-access, PyTorch-based software that leverages GPU acceleration. With our redesigned differentiable wildfire Cellular Automata (CA) model, we achieve millisecond-level computational efficiency, significantly outperforming traditional CPU-based wildfire simulators on real-world-scale fires at high resolution. Real-time parameter calibration is made possible through gradient descent on our model, aligning simulations closely with observed wildfire behavior both temporally and spatially, thereby enhancing the realism of the simulations. Our PyTorchFire simulator, combined with real-world environmental data, demonstrates superior generalizability compared to supervised learning surrogate models. Its ability to predict and calibrate wildfire behavior in real-time ensures accuracy, stability, and efficiency. PyTorchFire has the potential to revolutionize wildfire simulation, serving as a powerful tool for wildfire prediction and management.

---

## 🚀 New Companion Tool: FireDataForge

[![Conference](https://img.shields.io/badge/Accepted-IEEE_IRI_2026-blue.svg)](#)
[![arXiv](https://img.shields.io/badge/arXiv-2606.21198-b31b1b.svg)](https://arxiv.org/abs/2606.21198)
[![Paper DOI](https://img.shields.io/badge/Paper_DOI-TBD-blue.svg)](#)
[![GitHub Repo](https://img.shields.io/badge/GitHub-FireDataForge-181717?logo=github)](https://github.com/xiazeyu/FireDataForge)
[![Code DOI](https://zenodo.org/badge/DOI/10.5281/zenodo.20743742.svg)](https://doi.org/10.5281/zenodo.20743742)

Tired of manually downloading and aligning wildfire data? We are excited to introduce **[FireDataForge](https://github.com/xiazeyu/FireDataForge)**, a unified data pipeline that perfectly complements PyTorchFire. 

FireDataForge solves the preprocessing bottleneck in wildfire research. Simply provide an **MTBS Event ID**, and it will automatically retrieve, harmonize, and align **11 distinct data sources** (including fire behavior, weather, land cover, elevation, and satellite imagery) into analysis-ready NumPy arrays with embedded metadata. 

It is the perfect upstream data provider for your PyTorchFire machine learning models and fire behavior simulations.

**📖 Read the Paper:**
> **FireDataForge: A Unified Framework for Multi-Source Wildfire Data Retrieval and Integration** > *Zeyu Xia, Lexie Chen, Ye Liu, Huilin Huang* > Accepted to the 2026 IEEE International Conference on Information Reuse and Integration for Data Science (IEEE IRI 2026). > [arXiv:2606.21198](https://arxiv.org/abs/2606.21198)
> *[The official IEEE DOI will be updated here upon release]*

👉 **[Get started with FireDataForge here!](https://github.com/xiazeyu/FireDataForge)**

---

## Getting Started
### Notebook Examples

- Wildfire Prediction: [examples/prediction.ipynb](examples/prediction.ipynb) [![Open in Colab](https://colab.research.google.com/assets/colab-badge.svg)](https://colab.research.google.com/github/xiazeyu/PyTorchFire/blob/main/examples/prediction.ipynb)
- Parameter Calibration: [examples/calibration.ipynb](examples/calibration.ipynb) [![Open in Colab](https://colab.research.google.com/assets/colab-badge.svg)](https://colab.research.google.com/github/xiazeyu/PyTorchFire/blob/main/examples/calibration.ipynb)

### Installation

Install with minimal dependencies:

```shell
pip install pytorchfire
```

Install with dependencies for examples:

```shell
pip install 'pytorchfire[examples]'
```

Install together with the [FireDataForge](https://github.com/xiazeyu/FireDataForge) data pipeline:

```shell
pip install 'pytorchfire[firedataforge]'
```

### Quick Start

To perform wildfire prediction:

```python
from pytorchfire import WildfireModel

model = WildfireModel() # Create a model with default parameters and environment data
model = model.cuda() # Move the model to GPU
# model.reset(seed=seed) # Reset the model with a seed
for _ in range(100): # Run the model for 100 steps
    model.compute() # Compute the next state
```

To perform parameter calibration:

```python
import torch
from pytorchfire import WildfireModel, BaseTrainer

model = WildfireModel()

trainer = BaseTrainer(model)

trainer.train()
trainer.evaluate()
```

### Run on Real Fires from FireDataForge

Point PyTorchFire straight at a [FireDataForge](https://github.com/xiazeyu/FireDataForge) event directory. The
harmonized terrain, fuel, wind, and observed-ignition layers are mapped onto a
`WildfireModel` for you — no manual preprocessing:

```python
import torch
from pytorchfire import load_event

# An event folder produced by FireDataForge (output/<MTBS event id>)
event = load_event('output/CA3432611848120191010')

model = event.build_model()   # WildfireModel seeded with the real fire
model = model.to('cuda' if torch.cuda.is_available() else 'cpu')
for _ in range(100):
    model.compute()

# The observed final perimeter ships with the event — use it as a calibration target
target = event.target()       # [H, W] bool tensor
```

> The reader only needs `numpy` and `torch`, so you can consume FireDataForge
> outputs without installing the (heavyweight) `firedataforge` package itself.

Runnable scripts:

- Simulate a real fire: [examples/firedataforge_simulate.py](examples/firedataforge_simulate.py)
- Calibrate parameters against the observed perimeter: [examples/firedataforge_calibration.py](examples/firedataforge_calibration.py)

```shell
python examples/firedataforge_simulate.py /path/to/output/CA3432611848120191010
python examples/firedataforge_calibration.py /path/to/output/CA3432611848120191010 --device cuda:0
```

## API Documents

See at Our [Read the Docs](https://pytorchfire.readthedocs.io/).

## Dataset

See at Our [Dataset](https://doi.org/10.17632/nx2wsksp9k.1).

## Reference

```bibtex
@article{xia2025pytorchfire,
 author = {Zeyu Xia and Sibo Cheng},
 copyright = {CC BY 4.0},
 doi = {10.1016/j.envsoft.2025.106401},
 issn = {1364-8152},
 journal = {Environmental Modelling & Software},
 keywords = {Wildfire simulation, Differentiable Cellular Automata, PyTorch-based software, Parallel computing techniques, GPU-acceleration},
 language = {English},
 month = {4},
 pages = {106401},
 title = {PyTorchFire: A GPU-accelerated wildfire simulator with Differentiable Cellular Automata},
 url = {https://www.sciencedirect.com/science/article/pii/S1364815225000854},
 volume = {188},
 year = {2025}
}
```

## License

MIT License. More information see [LICENSE](./LICENSE)

## Contact

Zeyu Xia - [zeyu.xia@virginia.edu](mailto:zeyu.xia@virginia.edu)

Sibo Cheng - [sibo.cheng@enpc.fr](mailto:sibo.cheng@enpc.fr)
