Skip to main content

No project description provided

Project description

Looking for the programming language? You want memo-lang instead.

Installation

pip install memo

Documentation

The documentation can be found here.

The quickstart guide is found here.

Usage

Here's an example of utility functions provided by our library.

import numpy as np
from memo import memlist, memfile, grid, time_taken

data = []

@memfile(filepath="results.jsonl")
@memlist(data=data)
@time_taken()
def birthday_experiment(class_size, n_sim):
    """Simulates the birthday paradox. Vectorized = Fast!"""
    sims = np.random.randint(1, 365 + 1, (n_sim, class_size))
    sort_sims = np.sort(sims, axis=1)
    n_uniq = (sort_sims[:, 1:] != sort_sims[:, :-1]).sum(axis = 1) + 1
    proba = np.mean(n_uniq != class_size)
    return {"est_proba": proba}

for settings in grid(class_size=[5, 10, 20, 30], n_sim=[1000, 1_000_000]):
    birthday_experiment(**settings)

The decorators memlist and memfile are making sure that the keyword arugments and dictionary output of the birthday_experiment are logged. The contents of the results.jsonl-file and the data variable looks like this;

{"class_size": 5, "n_sim": 1000, "est_proba": 0.024, "time_taken": 0.0004899501800537109}
{"class_size": 5, "n_sim": 1000000, "est_proba": 0.027178, "time_taken": 0.19407916069030762}
{"class_size": 10, "n_sim": 1000, "est_proba": 0.104, "time_taken": 0.000598907470703125}
{"class_size": 10, "n_sim": 1000000, "est_proba": 0.117062, "time_taken": 0.3751380443572998}
{"class_size": 20, "n_sim": 1000, "est_proba": 0.415, "time_taken": 0.0009679794311523438}
{"class_size": 20, "n_sim": 1000000, "est_proba": 0.411571, "time_taken": 0.7928380966186523}
{"class_size": 30, "n_sim": 1000, "est_proba": 0.703, "time_taken": 0.0018239021301269531}
{"class_size": 30, "n_sim": 1000000, "est_proba": 0.706033, "time_taken": 1.1375510692596436}

The nice thing about being able to log results to a file or to the web is that you can also more easily parallize your jobs! For example now you can use the Runner class to parrallelize the function call with joblib.

import numpy as np
from memo import memlist, memfile, grid, time_taken, Runner

data = []

@memfile(filepath="results.jsonl")
@memlist(data=data)
@time_taken()
def birthday_experiment(class_size, n_sim):
    """Simulates the birthday paradox. Vectorized = Fast!"""
    sims = np.random.randint(1, 365 + 1, (n_sim, class_size))
    sort_sims = np.sort(sims, axis=1)
    n_uniq = (sort_sims[:, 1:] != sort_sims[:, :-1]).sum(axis = 1) + 1
    proba = np.mean(n_uniq != class_size)
    return {"est_proba": proba}

# declare all the settings to loop over
settings = grid(class_size=range(20, 30), n_sim=[100, 10_000, 1_000_000])

# use a runner to run over all the settings
runner = Runner(backend="threading", n_jobs=-1)
runner.run(func=birthday_experiment, settings=settings, progbar=True)

Features

This library also offers decorators to pipe to other sources.

  • memlist sends the json blobs to a list
  • memfile sends the json blobs to a file
  • memweb sends the json blobs to a server via http-post requests
  • memfunc sends the data to a callable that you supply, like print
  • grid generates a convenient grid for your experiments
  • random_grid generates a randomized grid for your experiments
  • time_taken also logs the time the function takes to run

We also offer an option to parallelize function calls using joblib. This is facilitated with a Runner class which supports multiple backends.

  • Runner(backend="loky")
  • Runner(backend="threading")
  • Runner(backend="multiprocessing")

Check the API docs here for more information on how these work.

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

memo-0.2.4.tar.gz (11.3 kB view details)

Uploaded Source

Built Distribution

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

memo-0.2.4-py2.py3-none-any.whl (13.2 kB view details)

Uploaded Python 2Python 3

File details

Details for the file memo-0.2.4.tar.gz.

File metadata

  • Download URL: memo-0.2.4.tar.gz
  • Upload date:
  • Size: 11.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.12.0

File hashes

Hashes for memo-0.2.4.tar.gz
Algorithm Hash digest
SHA256 c42e4a0046aae85df4bcd2b72df72858df8f15ea75392bb34a53f68f26679f04
MD5 aee0bb9f99a936126d327911f3e9054d
BLAKE2b-256 fb26c0e02465e864b10fca4b1403a5338b4374f315eab9ce02f536b36b97c056

See more details on using hashes here.

File details

Details for the file memo-0.2.4-py2.py3-none-any.whl.

File metadata

  • Download URL: memo-0.2.4-py2.py3-none-any.whl
  • Upload date:
  • Size: 13.2 kB
  • Tags: Python 2, Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.12.0

File hashes

Hashes for memo-0.2.4-py2.py3-none-any.whl
Algorithm Hash digest
SHA256 bdafa9cd66b5b88244aa91fa1977f169e5fd729c102f3824e32160e5da5306ed
MD5 82bb621f36eac66f7896ce1a6bcf45e5
BLAKE2b-256 1190622132f3f76f98b61375bf9eeff7bc74b33757c2b9738496209f7912d9ef

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