Skip to main content

A simple lib to automatically manage the parallelled experiments

Project description

libwon

A simple lib to automatically manage the parallelled experiment details of different configs. It records the internal results, params, etc.

Install

pip install libwon

Usage

Collector

It is a global object to collect results, configs, etc.

from libwon import COLLECTOR
COLLECTOR.mute = False          # whether logging when adding values
COLLECTOR.add("info", "XXX")    # add key as info, a value of "XXX" appended to the list  
COLLECTOR.add_GPU_MEM("cuda:0") # save memory usage of cuda:0
COLLECTOR.save_all_time()       # save executing time till now
COLLECTOR.save(os.path.join(log_dir,'collector.json'))  # save the collector

ParallelGrid

It is a class to

  • generate configs from grid lists
  • execute programs in parallel with given gpu resources
  • automatically save logs, scripts, configs, results, etc., for reproducibility
  • automatically fetch logs, configs, etc., for analyses
import os
from libwon import COLLECTOR, ParallelerGrid
import pandas as pd
import json

grid_list = [   # the config grid list
    {"seed": range(3), "info":[1]},
    {"seed": [0], "info":range(3)},
]

gpus = [0, 0, 1, 2]     # the available gpu resources    

cmd = "python main.py"  # the program entry file 
readme = "test"
phone_notice = None     # phone notice if finishing the run.
gpu_arg, log_arg = "device_id", "log_dir"   # arg flags in cmd.
base_script_dir = "./"                      # the program script dir to be saved
dir, fname = os.path.abspath(__file__).split(os.sep)[-2:]
log_dir = os.path.join("../../logs/", dir, os.path.splitext(fname)[0])

class Parallel(ParallelerGrid):
    # overwrite the functions to customize
    def show(self, c):  
        exp_dir = self.exp_dir
        ana_dir = self.ana_dir
        cols = ParallelerGrid.collect_keys(grid_list)
        print("Columns", cols)
        files = os.listdir(exp_dir)
        res = {}
        for fname in files:
            folder = os.path.join(exp_dir, fname)
            info = json.load(open(os.path.join(folder, "args.json")))
            hp = tuple([info[k] for k in cols])
            try:
                COLLECTOR.load(os.path.join(exp_dir, fname, "collector.json"))
                cache = COLLECTOR.cache
                res[hp] = cache
            except Exception as e:
                print(e)

        if c == 0:
            table = []
            metrics = ['info']
            for k,v in res.items():
                table.append([*k]+[v[m][0] for m in metrics])
            df = pd.DataFrame(table, columns= cols + metrics)
            print(df)

parallel = Parallel(
    gpus = gpus,
    log_dir = log_dir,
    grid_list = grid_list,
    cmd = cmd,
    gpu_arg = gpu_arg,
    log_arg = log_arg,
    exp_script_dir = os.path.dirname(os.path.abspath(__file__)),
    base_script_dir = base_script_dir,
    readme = readme,
    phone_notice = phone_notice,
).execute()

Example

Go to the example directory.

cd examples/test1/

Check how many programs will be run, or are running, or have already finished.

python test.py -t check

Run the programs in parallel.

python test.py -t run

Show and analyze the results.

python test.py -t show -c 0

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

libwon-0.0.2.tar.gz (7.6 kB view details)

Uploaded Source

Built Distribution

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

libwon-0.0.2-py3-none-any.whl (9.4 kB view details)

Uploaded Python 3

File details

Details for the file libwon-0.0.2.tar.gz.

File metadata

  • Download URL: libwon-0.0.2.tar.gz
  • Upload date:
  • Size: 7.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.8.0 pkginfo/1.9.6 readme-renderer/34.0 requests/2.27.1 requests-toolbelt/1.0.0 urllib3/1.26.8 tqdm/4.64.1 importlib-metadata/4.8.3 keyring/23.4.1 rfc3986/1.5.0 colorama/0.4.5 CPython/3.6.13

File hashes

Hashes for libwon-0.0.2.tar.gz
Algorithm Hash digest
SHA256 0f522c69c1abe7dce76b08e1c2e264934a04ac6e207c24e6d883fc9b137c74dd
MD5 47490757d783fdd941d1d8abf13ffef5
BLAKE2b-256 3d32c6a656c5037881600ccffc7c5b9a8b21ba335fa46948056475706dfded42

See more details on using hashes here.

File details

Details for the file libwon-0.0.2-py3-none-any.whl.

File metadata

  • Download URL: libwon-0.0.2-py3-none-any.whl
  • Upload date:
  • Size: 9.4 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.8.0 pkginfo/1.9.6 readme-renderer/34.0 requests/2.27.1 requests-toolbelt/1.0.0 urllib3/1.26.8 tqdm/4.64.1 importlib-metadata/4.8.3 keyring/23.4.1 rfc3986/1.5.0 colorama/0.4.5 CPython/3.6.13

File hashes

Hashes for libwon-0.0.2-py3-none-any.whl
Algorithm Hash digest
SHA256 bd92fcf8720598e180df44d341a94e55f29a714a11fa8203fed484a6692e97d3
MD5 b77f749c72658f2156cb215ccfb52d17
BLAKE2b-256 654bdb32eef1dae50b22a6a82dd38d6bc35ae169a09787a50876e2506e749bc5

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