Skip to content
/ arggo Public

The no-brainer Python library for experiment management

License

Notifications You must be signed in to change notification settings

mikimn/arggo

Repository files navigation

🚢 Arggo

Coverage Build Status PyPI version

The no-brainer Python package for experiment management

⚠️ This library is still in early development. We welcome contributors and early feedback 🚧


🚢 Arggo is a Python library for managing experiment runs in a clean and elegant manner.

Core features:

  • 📊 Dataclass-powered automatic argument parsing
  • 🏈 No more passing args around. arggo.consume makes it easy for every function to consume argument objects!
  • 🔄 Reproducibility - re-run previously saved 🚢 Arggo runs with a single command.
  • 🔒 Isolation - 🚢 Arggo creates a new running directory for each run by default.

Upcoming:

  • 🏄 Versatility – Arggo is plugin-based, and all behaviors can be controlled for, configured, or disabled.

🚢 Arggo is largely inspired by Hydra and the HfArgumentParser utility from 🤗 Transformers.

Table of Contents

Installation

To install Arggo, run

pip install arggo

Getting Started

The simplest use case of Arggo is to setup arguments for a script. Start by defining arguments in a data class:

from dataclasses import dataclass
from arggo.dataclass_utils import parser_field

@dataclass
class Arguments:
    name: str = parser_field(help="The user's name.")
    should_greet: bool = parser_field(help="Whether or not I should greet the user")

Then, annotate your main function to magically receive an arguments class :

import arggo


@arggo.consume
def main(args: Arguments):
    if args.should_greet:
        print(f"Greetings, {args.name}!")

Test by running

python main.py --name John --should_greet

Outputs

Greetings, John!

That's it!

Usage

Configuration

You can configure Arggo by using arggo.configure() instead, like so:

import arggo


@arggo.configure(
    parser_argument_index=1,
    logging_dir="my_logs"
)
def greet_user(count: int, args: Arguments):
    numeral = {1: "st", 2: "nd", 3: "rd"}
    numeral = numeral[count] if count in numeral else 'th'
    if args.should_greet:
        print(f"Greetings for the {count}{numeral} time, {args.name}!")


def main():
    for i in range(4):
        greet_user(i)


main()

Running

python main.py --name John

Outputs

Greetings for the 0th time, John!
Greetings for the 1st time, John!
Greetings for the 2nd time, John!
Greetings for the 3rd time, John!

The consume and configure() decorators work for any function, and guarantee that the same objects are provided each time.

Note: Arggo relies on the first configure() it uses to load everything, initialize the work directory and configure parametes. Future versions will make consume automatically find the appropriate type parameter to inject the arguments object into, and consequently configure() will throw an error when used more than once.

Contributing

We welcome early adopters and contributors to this project! See the Contributing section for details.

License

This project is open-sourced under the MIT license. See LICENSE for details.

Attributions

Icons made by Freepik from www.flaticon.com

About

The no-brainer Python library for experiment management

Resources

License

Code of conduct

Stars

Watchers

Forks

Packages

No packages published

Languages