No project description provided
Project description
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.
memlists
sends the json blobs to a listmemfile
sends the json blobs to a filememweb
sends the json blobs to a server via http-post requestsmemfunc
sends the data to a callable that you supply, likeprint
grid
generates a convenient grid for your experimentsrandom_grid
generates a randomized grid for your experimentstime_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
Built Distribution
File details
Details for the file memo-0.2.3.tar.gz
.
File metadata
- Download URL: memo-0.2.3.tar.gz
- Upload date:
- Size: 10.1 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.8.0 pkginfo/1.8.2 readme-renderer/32.0 requests/2.27.1 requests-toolbelt/0.9.1 urllib3/1.26.8 tqdm/4.62.3 importlib-metadata/4.11.1 keyring/23.5.0 rfc3986/2.0.0 colorama/0.4.4 CPython/3.8.6
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | a167c7ffe7688521c13306dad4954f9e7dfe3a4ad9388ebea17b1286fe9e57c8 |
|
MD5 | f3ec80466e8776f290e930f534d63628 |
|
BLAKE2b-256 | 17ed98a257deaff4cf1c70484522bde8caffa4578285252a52d5fc58c08380af |
File details
Details for the file memo-0.2.3-py2.py3-none-any.whl
.
File metadata
- Download URL: memo-0.2.3-py2.py3-none-any.whl
- Upload date:
- Size: 13.1 kB
- Tags: Python 2, Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.8.0 pkginfo/1.8.2 readme-renderer/32.0 requests/2.27.1 requests-toolbelt/0.9.1 urllib3/1.26.8 tqdm/4.62.3 importlib-metadata/4.11.1 keyring/23.5.0 rfc3986/2.0.0 colorama/0.4.4 CPython/3.8.6
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 24cf2c8461dfafc0f18febce6f032ef8167317539fd812e43edf22bfdd1278b7 |
|
MD5 | cd50447d18bd1e535f3ffb0050e7d307 |
|
BLAKE2b-256 | bd31cd73cc347fa691967c02e87a863e8a9dab9dfb3dcd4020e680c8592bf4b1 |