Skip to main content

The no-brainer package for setting up python experiments.

Project description

:ship: Arggo

Coverage Build Status PyPI version

The no-brainer Python package for experiment management

:warning: This library is still in early development. We welcome contributors and early feedback :construction:


:ship: Arggo is a Python toolkit for managing reproducible runs in a clean and elegant manner.

Core features:

  • :bar_chart: Automatic dataclass-powered argument parsing and injection.
  • :computer: Powerful CLI for run management and bootstrapping
  • :arrows_counterclockwise: Reproducibility - re-run previously saved :ship: Arggo runs with a single command.
  • :lock: Isolation - :ship: Arggo creates a new running directory for each run by default.

Upcoming:

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

:ship: 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 consume/configure()-decorated call in a process to load everything and initialize the work directory; calling that same decorated function again (e.g. in a loop, as above) reuses it. Calling a different consume/configure()-decorated entry point in the same process instead raises ArggoAlreadyConfiguredError, since only one entry point's configuration can be in effect per process.

Parameter Styles

Arguments can be passed either argparse-style (--name value, or --name=value) or Hydra-style (name=value), and the two can be freely mixed on the same command line:

python main.py --name John should_greet=true

A bare key=value token is only treated as Hydra-style if it doesn't already start with -, so --name=John keeps its usual argparse meaning. Hyphens in a Hydra-style key are normalized to underscores (some-field=value sets some_field), since dataclass field names are Python identifiers and can't contain hyphens.

Meta-arguments

Arggo attaches meta-arguments to each script, allowing for some extra functionality. To view all possible meta-arguments, run your script with the --arggo_help flag

python main.py --arggo_help

These names are reserved by Arggo and cannot be used as dataclass field names:

  • arggo_help
  • arggo_interactive
  • arggo_reproduce

Installed plugins may reserve additional names of their own (see each plugin's own documentation, e.g. Weights & Biases below). If a field collides with any reserved name, Arggo raises ArggoReservedError. Rename the field, or opt out with @arggo.configure(override_reserved_arguments=True) if you're sure the collision is intentional.

Interactive Runs

You can provide arguments to a program interactively by supplying the --arggo_interactive flag:

python main.py --arggo_help

Command Line Interface

Arggo powers a CLI for many useful actions. To view more information, run

arggo-cli --help

Creating a New Experiment

arggo-cli experiment create <experiment_name>

This command automatically creates a starter file <experiment_name>.py

Reproducing an Existing Experiment

To reproduce results of a previous experiment run, type

arggo-cli experiment reproduce <experiment_name>

This looks for any experiments in the logs/ folder, and allows you to interactively choose which one to reproduce.

Plugins

Weights & Biases

If wandb is installed, Arggo automatically logs each run's parameters to it as a config dict, and records the run's id/name/url in the saved parameters.json. Pass --wandb_disable to opt out for a single run, even with wandb installed.

Development

Running tests

To run all tests:

python -m pytest --cov=arggo

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

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

arggo-0.3.1.tar.gz (27.1 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

arggo-0.3.1-py3-none-any.whl (24.3 kB view details)

Uploaded Python 3

File details

Details for the file arggo-0.3.1.tar.gz.

File metadata

  • Download URL: arggo-0.3.1.tar.gz
  • Upload date:
  • Size: 27.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.10.20

File hashes

Hashes for arggo-0.3.1.tar.gz
Algorithm Hash digest
SHA256 283603ac06457d6585f7090e2a7612ca3f4e2255239072446ec50c00682d268a
MD5 c89692cf5c7dd9e565f52803edeba421
BLAKE2b-256 1855e8f4fa6d6320fcc163406e06d41c894b82bb326699effd9574f927b49b05

See more details on using hashes here.

File details

Details for the file arggo-0.3.1-py3-none-any.whl.

File metadata

  • Download URL: arggo-0.3.1-py3-none-any.whl
  • Upload date:
  • Size: 24.3 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.10.20

File hashes

Hashes for arggo-0.3.1-py3-none-any.whl
Algorithm Hash digest
SHA256 b3c4e90abc60c28b9e2ee0944dd187b80b3738655ec70a52f6883b3dcb40473d
MD5 f4fe6be3b532bcb4c5b776a437da3fd5
BLAKE2b-256 dd06a6beaeb1ff9a4c5687b55f9f9d013ea61ff82ef689097c2f17783eb137c7

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page