semvec/pypi-packages huggingface dataset:
recoverable-async-task 0.2.4
`recoverable-async-task` is a Python library that streamlines the handling of asynchronous tasks through its `RecoverableAsyncTask` class, with the added benefit of **supporting task checkpointing and resumption**. This feature ensures that tasks can pick up from where they left off in the event of unexpected failures.
Requires Python: >=3.10

# recoverable-async-task

[English](README.md) | [中文文档](README_ZH.md)

`recoverable-async-task` is a lightweight Python library that focuses on providing JSONL-based checkpoint recovery functionality for async tasks. It automatically records task execution states, allowing tasks to resume from where they left off after interruption, making it ideal for handling large-scale, time-consuming asynchronous tasks.

## Installation

```bash
pip install recoverable-async-task
```

## Quick Start

Here's a simple example demonstrating how to use the `make_recoverable` decorator to handle async tasks:

```python
import asyncio
import random
from recoverable_async_task import make_recoverable


async def main():
    @make_recoverable(
        storage_path_name=".checkpoint/example-task",  # Checkpoint file storage path
        show_progress=True,                           # Show progress bar
        force_rerun=False,                            # Don't force rerun completed tasks
    )
    async def task(id: int) -> dict | None:
        await asyncio.sleep(0.1)
        try:
            if random.randint(1, 2) == 1:
                raise Exception(f"Task {id=} failed!")
            return {"id": id, "data": f"Task {id=} finished!"}
        except Exception as e:
            print(f"Error: {e}")
            return None

    # Execute tasks and collect results
    task_ids = list(range(10))  # Create 10 test tasks
    async for result in task.as_completed(task_ids):
        print(result)


if __name__ == "__main__":
    asyncio.run(main())
```

## Configuration Parameters

The `make_recoverable` decorator supports the following parameters:

- `storage_path_name`: str, optional
  - Storage path for checkpoint files
  - Defaults to the decorated function's name
- `show_progress`: bool, defaults to True
  - Whether to display a progress bar
  - Shows completed/total tasks count
- `force_rerun`: bool, defaults to False
  - Whether to force rerun completed tasks
  - Useful for scenarios requiring recalculation

## Checkpoint Recovery Mechanism

When task execution fails:
1. Successfully completed task states are saved in the checkpoint file
2. When rerunning the program, completed tasks are automatically skipped
3. Only previously failed or unexecuted tasks will be processed
4. This process can be repeated until all tasks are completed

## Concurrency Control

This library focuses on providing checkpoint recovery functionality. For more powerful concurrency control features, we recommend using the [adaptio](https://github.com/Haskely/adaptio) library.

## Development Guide

This project uses [uv](https://docs.astral.sh/uv/#getting-started) for environment management:

```bash
# Install dependencies
uv sync

# Run tests
pytest

# Format code
pre-commit run --all-files
```
moving-targets 0.4.2
Moving Targets: a framework for constrained machine learning
Requires Python: >=3.8

# Moving Targets

Moving Targets is novel hybrid technique which can be used to inject external constraints and domain knowledge into any
machine learning model. The algorithm is based on an iterative schemes that alternates between two steps: a learner
step, which is in charge of training the machine learning model, and a master step, which refines the model predictions
by projecting them into the feasible space, so that the model can be learnt again on these adjusted targets. Since the
model is general-purpose, it can address any type of learner and constraints, given that these constraints lead to a
solvable constrained optimization problem (see the original [paper](https://arxiv.org/abs/2002.10766) for details).

## How To Use

You can install the Moving Targets' library via ```pip``` by pasting this command in your terminal:

```
pip install moving-targets
```

The library contains various classes and utility functions, but the core of the algorithm can be found in the ```MACS```
class, which needs both a ```Learner``` and a ```Master``` instance in order to be instantiated — additional parameters
such as the initial step or a list of ```Metric``` objects may be optionally passed as well. Once the ```MACS``` object
has been built, it can be used as a classical machine learning model along with its methods ```fit()```,
```predict()```, and ```evaluate()```.

A predefined set of learners, metrics, and callbacks can be found in the respective modules. Instead, as regards the
master, you will need to extend one of the template ones in order to formulate your constrained optimization problem,
even though the master formulation is facilitated by a set of predefined loss functions and backend objects that wrap
some of the most famous constraint optimization solvers — e.g., Cplex, Gurobi, CvxPy, etc.

More specific tutorials to learn how to use Moving Targets can be found in the ```examples``` module.

## How To Cite

If you use Moving Targets in your works, please cite the following article:

```
@article{Detassis2020,
  title={Teaching the Old Dog New Tricks: Supervised Learning with Constraints},
  author={Detassis, Fabrizio and Lombardi, Michele and Milano, Michela},
  journal={arXiv preprint arXiv:2002.10766},
  year={2020}
}
```

## Contacts

* Maintainer: [luca.giuliani13@unibo.it](mailto:luca.giuliani13@unibo.it)