Metadata-Version: 2.4
Name: law
Version: 0.2.1
Summary: Build large-scale task workflows using luigi, remote job submission, remote targets, and environment sandboxing.
Project-URL: Homepage, https://github.com/riga/law
Project-URL: Documentation, https://law.readthedocs.io
Project-URL: Repository, https://github.com/riga/law.git
Project-URL: Issues, https://github.com/riga/law/issues
Author-email: Marcel Rieger <github.riga@icloud.com>
License-Expression: BSD-3-Clause
License-File: LICENSE
Keywords: apptainer,arc,cluster,docker,gfal,glite,grid,htcondor,lsf,luigi,pipeline,remote,sandboxing,singularity,slurm,submission,workflow
Classifier: Development Status :: 4 - Beta
Classifier: Intended Audience :: Developers
Classifier: Intended Audience :: Information Technology
Classifier: Intended Audience :: Science/Research
Classifier: License :: OSI Approved :: BSD License
Classifier: Operating System :: OS Independent
Classifier: Programming Language :: Python
Classifier: Programming Language :: Python :: 3
Classifier: Programming Language :: Python :: 3.9
Classifier: Programming Language :: Python :: 3.10
Classifier: Programming Language :: Python :: 3.11
Classifier: Programming Language :: Python :: 3.12
Classifier: Programming Language :: Python :: 3.13
Classifier: Programming Language :: Python :: 3.14
Requires-Python: >=3.9
Requires-Dist: luigi~=3.6
Requires-Dist: typing-extensions~=4.15
Provides-Extra: dev
Requires-Dist: build~=1.4; (python_version < '3.10') and extra == 'dev'
Requires-Dist: build~=1.5; (python_version >= '3.10') and extra == 'dev'
Requires-Dist: coverage>=7.10; extra == 'dev'
Requires-Dist: ipykernel~=6.31; extra == 'dev'
Requires-Dist: mypy~=1.19; (python_version < '3.10') and extra == 'dev'
Requires-Dist: mypy~=2.1; (python_version >= '3.10') and extra == 'dev'
Requires-Dist: pre-commit~=4.3; (python_version < '3.10') and extra == 'dev'
Requires-Dist: pre-commit~=4.6; (python_version >= '3.10') and extra == 'dev'
Requires-Dist: pytest-cov~=7.1; extra == 'dev'
Requires-Dist: pytest~=8.4; (python_version < '3.10') and extra == 'dev'
Requires-Dist: pytest~=9.1; (python_version >= '3.10') and extra == 'dev'
Requires-Dist: pyyaml~=6.0; extra == 'dev'
Requires-Dist: twine~=6.2; extra == 'dev'
Requires-Dist: types-docutils~=0.22; extra == 'dev'
Requires-Dist: types-pyyaml~=6.0; extra == 'dev'
Requires-Dist: types-requests~=2.32; extra == 'dev'
Requires-Dist: uniplot~=0.22; extra == 'dev'
Provides-Extra: docs
Requires-Dist: autodocsumm~=0.2; extra == 'docs'
Requires-Dist: myst-parser~=5.1; extra == 'docs'
Requires-Dist: sphinx-book-theme~=1.2; extra == 'docs'
Requires-Dist: sphinx-lfs-content!=1.1.11,>=1.1.10; extra == 'docs'
Requires-Dist: sphinx~=9.1; extra == 'docs'
Provides-Extra: test
Requires-Dist: awkward~=2.14; (python_version >= '3.10') and extra == 'test'
Requires-Dist: awkward~=2.8; (python_version < '3.10') and extra == 'test'
Requires-Dist: h5py~=3.14; (python_version < '3.10') and extra == 'test'
Requires-Dist: h5py~=3.16; (python_version >= '3.10') and extra == 'test'
Requires-Dist: matplotlib~=3.10; (python_version >= '3.10') and extra == 'test'
Requires-Dist: matplotlib~=3.9; (python_version < '3.10') and extra == 'test'
Requires-Dist: numpy~=2.0; (python_version < '3.10') and extra == 'test'
Requires-Dist: numpy~=2.2; (python_version >= '3.10') and extra == 'test'
Requires-Dist: pandas~=2.3; (python_version < '3.11') and extra == 'test'
Requires-Dist: pandas~=3.0; (python_version >= '3.11') and extra == 'test'
Requires-Dist: pyarrow~=21.0; (python_version < '3.10') and extra == 'test'
Requires-Dist: pyarrow~=25.0; (python_version >= '3.10') and extra == 'test'
Description-Content-Type: text/markdown

<!-- marker-before-logo -->

<p align="center">
  <a href="https://github.com/riga/law">
    <img alt="law logo" src="https://media.githubusercontent.com/media/riga/law/master/assets/logo.png" />
  </a>
</p>

<!-- marker-after-logo -->

<!-- marker-before-badges -->

<p align="center">
  <a href="https://law.readthedocs.io/en/latest">
    <img alt="Documentation status" src="https://app.readthedocs.org/projects/law/badge/?version=latest&cache-control=no-cache" />
  </a>
  <a href="https://github.com/riga/law/actions/workflows/ci.yml">
    <img alt="CI" src="https://github.com/riga/law/actions/workflows/ci.yml/badge.svg" />
  </a>
  <a href="https://github.com/riga/law/actions/workflows/deploy_images_a9.yml">
    <img alt="Docker images" src="https://github.com/riga/law/actions/workflows/deploy_images_a9.yml/badge.svg" />
  </a>
  <img alt="Python version" src="https://img.shields.io/badge/Python-%E2%89%A53.9-blue" />
  <a href="https://pypi.org/project/law">
    <img alt="Package version" src="https://img.shields.io/pypi/v/law.svg?style=flat" />
  </a>
  <a href="https://github.com/riga/law/blob/master/LICENSE">
    <img alt="License" src="https://img.shields.io/github/license/riga/law.svg" />
  </a>
  <a href="https://doi.org/10.5281/zenodo.14548877">
    <img alt="DOI" src="https://zenodo.org/badge/DOI/10.5281/zenodo.14548877.svg" />
  </a>
</p>

<!-- marker-after-badges -->

<!-- marker-before-header -->

Use law (**l**uigi **a**nalysis **w**orkflow) to build complex and large-scale task workflows.
It is built on top of [luigi](https://github.com/spotify/luigi) and adds abstractions for **run locations**, **storage locations** and **software environments**.
Law strictly disentangles these building blocks and ensures they remain interchangeable and resource-opportunistic.

Key features:

- CLI with auto-completion and interactive status and dependency inspection
- Remote targets with automatic retries and local caching
  - WebDAV, HTTP, Dropbox, SFTP, all WLCG protocols (srm, xrootd, dcap, gsiftp, webdav, ...)
- Automatic submission to batch systems from within tasks
  - HTCondor, LSF, gLite, ARC, Slurm, CMS-CRAB
- Environment sandboxing, configurable on task level
  - Docker, Singularity, Sub-Shells, Virtual envs

Version 0.1 (with Python support down to 2.7) continues to be available via the [v0.1.x](https://github.com/riga/law/tree/v0.1.x) branch and all [v0.1.*](https://github.com/riga/law/tags) tags.

<!-- marker-after-header -->

<!-- marker-before-contents -->

## Contents

- [Contents](#contents)
- [First steps](#first-steps)
  - [Installation and dependencies](#installation-and-dependencies)
  - [Usage at CERN](#usage-at-cern)
  - [Overcomplete example config](#overcomplete-example-config)
- [Projects using law](#projects-using-law)
- [Examples](#examples)
- [Further topics](#further-topics)
  - [Auto completion on the command-line](#auto-completion-on-the-command-line)
- [Development](#development)
  - [Linting, type checking \& tests](#linting-type-checking--tests)
  - [Docker images](#docker-images)
  - [Contributors](#contributors)
- [Cite law](#cite-law)

<!-- marker-after-contents -->

<!-- marker-before-body -->

## First steps

### Installation and dependencies

Install via [pip](https://pypi.org/project/law)

```shell
pip install law
```

or [conda / (micro)mamba](https://anaconda.org/conda-forge/law)

```shell
conda install -c conda-forge law
```

Remote targets use [gfal2](https://dmc-docs.web.cern.ch/dmc-docs/gfal2/gfal2.html) and its Python bindings [gfal2-python](https://pypi.org/project/gfal2-python), which must be installed separately.
The [gfal2-util](https://github.com/cern-fts/gfal2-util) command-line tools are useful as well.

```shell
conda install -c conda-forge gfal2 gfal2-python gfal2-util
```

### Usage at CERN

See the [wiki](https://github.com/riga/law/wiki/Usage-at-CERN).

### Overcomplete example config

See [law.cfg.example](https://github.com/riga/law/tree/master/law.cfg.example).

## Projects using law

- CMS Di-Higgs Inference Tools
  - Basis for statistical analysis for all Di-Higgs searches in CMS, starting at datacard-level
  - [repo](https://gitlab.cern.ch/hh/tools/inference), [docs](https://cms-hh.web.cern.ch/cms-hh/tools/inference/index.html)
- columnflow ([+ all analyses using it](https://github.com/columnflow/columnflow#projects-using-columnflow))
  - Python-based, fully automated, columnar framework, including job submission, resolution of systematics and ML pipelines, starting at NanoAOD-level with an optimized multi-threaded column reader
  - [repo](https://github.com/columnflow/columnflow), [docs](http://columnflow.readthedocs.io), [task structure](https://github.com/columnflow/columnflow/wiki#default-task-graph)
- CMS B-Tag SF Measurement
  - Automated workflow for deriving shape-calibrating b-tag scale factors, starting at MiniAOD-level
  - [repo](https://github.com/cms-btv-pog/jet-tagging-sf)
- CMS Tau POG ML Tools
  - Preprocessing pipeline for ML trainings in the TAU group
  - [repo](https://github.com/cms-tau-pog/TauMLTools)
- CMS HLT Config Parser
  - Collects information from various databases (HLT, bril, etc.) and shows menus, trigger paths, filter names for configurable MC datasets or data runs
  - [repo](https://github.com/riga/cms-hlt-parser)
- RWTH-CMS Analysis Framework
  - Basis for multiple CMS analyses ranging from Di-Higgs, to single Higgs and b-tag SF measurements, starting at NanoAOD-level and based on coffea processors
  - [repo](https://git.rwth-aachen.de/3pia/cms_analyses/common/-/tree/master/)
- CIEMAT-CMS Analysis Framework
  - Python- and RDataFrame-based framework starting from NanoAOD and targeting multiple CMS analyses
  - [repo](https://gitlab.cern.ch/cms-phys-ciemat/nanoaod_base_analysis/)
- CMS 3D Z+jet 13 TeV analysis
  - Analysis workflow management from ntuple production to final plots and fits
  - [repo](https://gitlab.etp.kit.edu/cverstege/zjet-analysis)
- NP-correction derivation tool
  - MC generation with Herwig and analysis of generated events with Rivet
  - [repo](https://github.com/HerrHorizontal/herwig-run)
- CMS SUSY Searches at DESY
  - Analysis framework for CMS SUSY searches going from custom NanoAODs -> ntuple production -> DNN-based inference -> final plots and fits
  - [repo](https://github.com/frengelk/Susy1LeptonAnalysis)
- Kingmaker (CMS ntuple production with CROWN)
  - Conversion from CMS NanoAOD to analysis ntuples using the CROWN framework. Also includes the training of an event classifier on those ntuples.
  - [repo](https://github.com/KIT-CMS/KingMaker), [CROWN](https://github.com/KIT-CMS/CROWN)

If your project uses law but is not yet listed here, feel free to open a pull request or mention your project details in a new [issue](https://github.com/riga/law/issues/new?assignees=riga&labels=docs&template=register-project.md) and it will be added.

## Examples

Most examples can be run in a dedicated Docker container via

```shell
docker run -ti riga/law:example <example_name>
```

- [tutorial](https://github.com/riga/law/tree/master/examples/tutorial): Hands-on notebook for newcomers that introduces the most important concepts step by step.
- [loremipsum](https://github.com/riga/law/tree/master/examples/loremipsum): The *hello world* example of law.
- [workflows](https://github.com/riga/law/tree/master/examples/workflows): Law workflows.
- [workflow_parameters](https://github.com/riga/law/tree/master/examples/workflow_parameters): Alternative way of parametrizing workflows with explicit branch parameters.
- [notebooks](https://github.com/riga/law/tree/master/examples/notebooks): Examples showing how to use and work with law in notebooks.
- [dropbox_targets](https://github.com/riga/law/tree/master/examples/dropbox_targets): Working with targets that are stored on Dropbox.
- [wlcg_targets](https://github.com/riga/law/tree/master/examples/wlcg_targets): Working with targets that are stored on WLCG storage elements (dCache, EOS, ...).
- [htcondor_at_vispa](https://github.com/riga/law/tree/master/examples/htcondor_at_vispa): HTCondor workflows at the [VISPA service](https://vispa.physik.rwth-aachen.de).
- [htcondor_at_cern](https://github.com/riga/law/tree/master/examples/htcondor_at_cern): HTCondor workflows at the CERN batch infrastructure.
- [CMS Crab at CERN](https://github.com/riga/law_example_CMSCrabWorkflows): CMS Crab workflows executed from lxplus at CERN.
- [sequential_htcondor_at_cern](https://github.com/riga/law/tree/master/examples/sequential_htcondor_at_cern): Continuation of the [htcondor_at_cern](https://github.com/riga/law/tree/master/examples/htcondor_at_cern) example, showing sequential jobs that eagerly start once jobs running previous requirements succeeded.
- [htcondor_at_naf](https://github.com/riga/law/tree/master/examples/htcondor_at_naf): HTCondor workflows at the German [National Analysis Facility (NAF)](https://confluence.desy.de/display/IS/NAF+-+National+Analysis+Facility).
- [slurm_at_maxwell](https://github.com/riga/law/tree/master/examples/slurm_at_maxwell): Slurm workflows at the [DESY Maxwell cluster](https://confluence.desy.de/display/MXW/Maxwell+Cluster).
- [grid_at_cern](https://github.com/riga/law_example_WLCG): Workflows that run jobs and store data on the WLCG.
- [lsf_at_cern](https://github.com/riga/law/tree/master/examples/lsf_at_cern): LSF workflows at the CERN batch infrastructure.
- [docker_sandboxes](https://github.com/riga/law/tree/master/examples/docker_sandboxes): Environment sandboxing using Docker.
- [singularity_sandboxes](https://github.com/riga/law/tree/master/examples/singularity_sandboxes): Environment sandboxing using Singularity.
- [subshell_sandboxes](https://github.com/riga/law/tree/master/examples/subshell_sandboxes): Environment sandboxing using subshells.
- [parallel_optimization](https://github.com/riga/law/tree/master/examples/parallel_optimization): Parallel optimization using [scikit optimize](https://scikit-optimize.github.io).
- [notifications](https://github.com/riga/law/tree/master/examples/notifications): Demonstration of Slack and Telegram task status notifications.
- [CMS Single Top Analysis](https://github.com/riga/law_example_CMSSingleTopAnalysis): Simple physics analysis using law.

## Further topics

### Auto completion on the command-line

#### bash

```shell
source "$( law completion )"
```

#### zsh

zsh is able to load and evaluate bash completion scripts via `bashcompinit`.
In order for `bashcompinit` to work, you should run `compinstall` to enable completion scripts:

```shell
autoload -Uz compinstall && compinstall
```

After following the instructions, these lines should be present in your `~/.zshrc`:

```shell
# The following lines were added by compinstall
zstyle :compinstall filename '~/.zshrc'

autoload -Uz +X compinit && compinit
autoload -Uz +X bashcompinit && bashcompinit
# End of lines added by compinstall
```

If this is the case, just source the law completion script (which internally enables `bashcompinit`) and you're good to go:

```shell
source "$( law completion )"
```

## Development

- Source hosted at [GitHub](https://github.com/riga/law)
- Report issues, questions, feature requests on [GitHub Issues](https://github.com/riga/law/issues)
- The current Python version for development is **3.13**.

### Linting, type checking & tests

The full testing pipeline is based on [pre-commit](https://pre-commit.com).
Run the following to install development dependencies and set it up:

```shell
# inside the cloned repository
git lfs install
pip install -e .[dev,test]
pre-commit install
```

Now, every time you make a commit, the pre-commit and pre-push hooks will automatically run linting, type checking and unit tests.
To run them manually, use

```shell
# for linting, type checking and additional checks on all files
pre-commit run --all-files

# only for staged files
pre-commit run

# or run unit tests standalone
pytest
```

### Docker images

Various `riga/law` Docker images are available on [Docker Hub](https://hub.docker.com/r/riga/law), corresponding to different OS and Python versions (based on [micromamba](https://mamba.readthedocs.io/en/latest/user_guide/micromamba.html)).

| OS          | Python | Tags                                     |
| ----------- | ------ | ---------------------------------------- |
| AlmaLinux 9 | 3.14   | a9-py314, py314                          |
| AlmaLinux 9 | 3.13   | a9-py313, a9-py3, a9, py313, py3, latest |
| AlmaLinux 9 | 3.12   | a9-py312, py312                          |
| AlmaLinux 9 | 3.11   | a9-py311, py311                          |
| AlmaLinux 9 | 3.10   | a9-py310, py310                          |
| AlmaLinux 9 | 3.9    | a9-py39, py39                            |

Start them via

```shell
docker run -ti riga/law:<the_tag>
```

### Contributors

<!-- ALL-CONTRIBUTORS-LIST:START - Do not remove or modify this section -->
<!-- prettier-ignore-start -->
<!-- markdownlint-disable -->
<table>
  <tbody>
    <tr>
      <td align="center" valign="top" width="14.28%"><a href="http://github.com/riga"><img src="https://avatars.githubusercontent.com/u/1908734?v=4?s=100" width="100px;" alt="Marcel Rieger"/><br /><sub><b>Marcel Rieger</b></sub></a><br /><a href="https://github.com/riga/law/commits?author=riga" title="Code">💻</a> <a href="https://github.com/riga/law/pulls?q=is%3Apr+reviewed-by%3Ariga" title="Reviewed Pull Requests">👀</a> <a href="#maintenance-riga" title="Maintenance">🚧</a> <a href="https://github.com/riga/law/commits?author=riga" title="Documentation">📖</a></td>
      <td align="center" valign="top" width="14.28%"><a href="https://github.com/pfackeldey"><img src="https://avatars.githubusercontent.com/u/18463582?v=4?s=100" width="100px;" alt="Peter Fackeldey"/><br /><sub><b>Peter Fackeldey</b></sub></a><br /><a href="https://github.com/riga/law/commits?author=pfackeldey" title="Code">💻</a></td>
      <td align="center" valign="top" width="14.28%"><a href="https://github.com/yrath"><img src="https://avatars.githubusercontent.com/u/20044510?v=4?s=100" width="100px;" alt="Yannik Rath"/><br /><sub><b>Yannik Rath</b></sub></a><br /><a href="https://github.com/riga/law/commits?author=yrath" title="Code">💻</a></td>
      <td align="center" valign="top" width="14.28%"><a href="https://github.com/jaimeleonh"><img src="https://avatars.githubusercontent.com/u/47629805?v=4?s=100" width="100px;" alt="Jaime Leon Holgado"/><br /><sub><b>Jaime Leon Holgado</b></sub></a><br /><a href="https://github.com/riga/law/commits?author=jaimeleonh" title="Code">💻</a></td>
      <td align="center" valign="top" width="14.28%"><a href="https://github.com/lmoureaux"><img src="https://avatars.githubusercontent.com/u/22327575?v=4?s=100" width="100px;" alt="Louis Moureaux"/><br /><sub><b>Louis Moureaux</b></sub></a><br /><a href="https://github.com/riga/law/commits?author=lmoureaux" title="Code">💻</a></td>
      <td align="center" valign="top" width="14.28%"><a href="http://www.linkedin.com/in/lgeiger"><img src="https://avatars.githubusercontent.com/u/13285808?v=4?s=100" width="100px;" alt="Lukas Geiger"/><br /><sub><b>Lukas Geiger</b></sub></a><br /><a href="https://github.com/riga/law/commits?author=lgeiger" title="Code">💻</a></td>
      <td align="center" valign="top" width="14.28%"><a href="https://too.gy"><img src="https://avatars.githubusercontent.com/u/694873?v=4?s=100" width="100px;" alt="Valentin Iovene"/><br /><sub><b>Valentin Iovene</b></sub></a><br /><a href="https://github.com/riga/law/commits?author=tgy" title="Code">💻</a></td>
    </tr>
    <tr>
      <td align="center" valign="top" width="14.28%"><a href="https://github.com/cverstege"><img src="https://avatars.githubusercontent.com/u/6241018?v=4?s=100" width="100px;" alt="Cedric Verstege"/><br /><sub><b>Cedric Verstege</b></sub></a><br /><a href="https://github.com/riga/law/commits?author=cverstege" title="Code">💻</a></td>
    </tr>
  </tbody>
</table>

<!-- markdownlint-restore -->
<!-- prettier-ignore-end -->

<!-- ALL-CONTRIBUTORS-LIST:END -->

This project follows the [all-contributors](https://github.com/all-contributors/all-contributors) specification.

## Cite law

M. Rieger, "End-to-End Analysis Automation over Distributed Resources with Luigi Analysis Workflows", *EPJ Web of Conferences* **295** (2024) 05012, [`arXiv:2402.17949`](https://arxiv.org/abs/2402.17949)

<!-- marker-after-body -->
