{"id":13738441,"url":"https://github.com/koaning/memo","last_synced_at":"2025-03-31T11:01:27.562Z","repository":{"id":37703136,"uuid":"316819881","full_name":"koaning/memo","owner":"koaning","description":"Decorators that logs stats.","archived":false,"fork":false,"pushed_at":"2025-03-07T15:01:18.000Z","size":532,"stargazers_count":109,"open_issues_count":5,"forks_count":9,"subscribers_count":3,"default_branch":"main","last_synced_at":"2025-03-24T09:43:46.550Z","etag":null,"topics":["grid","json-blobs","simulation"],"latest_commit_sha":null,"homepage":"https://koaning.github.io/memo/getting-started.html","language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/koaning.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null}},"created_at":"2020-11-28T20:52:35.000Z","updated_at":"2025-03-07T15:01:22.000Z","dependencies_parsed_at":"2024-04-16T22:03:43.966Z","dependency_job_id":"766af088-75ae-4082-8e3e-546c75790bfd","html_url":"https://github.com/koaning/memo","commit_stats":{"total_commits":94,"total_committers":5,"mean_commits":18.8,"dds":"0.19148936170212771","last_synced_commit":"b2a289d7ddcd5013576370489a2ddadb8477b960"},"previous_names":[],"tags_count":1,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/koaning%2Fmemo","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/koaning%2Fmemo/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/koaning%2Fmemo/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/koaning%2Fmemo/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/koaning","download_url":"https://codeload.github.com/koaning/memo/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":246457967,"owners_count":20780676,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["grid","json-blobs","simulation"],"created_at":"2024-08-03T03:02:22.555Z","updated_at":"2025-03-31T11:01:27.536Z","avatar_url":"https://github.com/koaning.png","language":"Python","funding_links":[],"categories":["Python"],"sub_categories":[],"readme":"![](https://github.com/koaning/memo/raw/main/docs/header.png)\n\n\u003e Looking for the programming language? You want [memo-lang](https://github.com/kach/memo) instead. \n\n## Installation\n\n```\npip install memo\n```\n\n## Documentation\n\nThe documentation can be found [here](https://koaning.github.io/memo/).\n\nThe quickstart guide is found [here](https://koaning.github.io/memo/getting-started.html).\n\n## Usage\n\nHere's an example of utility functions provided by our library.\n\n```python\nimport numpy as np\nfrom memo import memlist, memfile, grid, time_taken\n\ndata = []\n\n@memfile(filepath=\"results.jsonl\")\n@memlist(data=data)\n@time_taken()\ndef birthday_experiment(class_size, n_sim):\n    \"\"\"Simulates the birthday paradox. Vectorized = Fast!\"\"\"\n    sims = np.random.randint(1, 365 + 1, (n_sim, class_size))\n    sort_sims = np.sort(sims, axis=1)\n    n_uniq = (sort_sims[:, 1:] != sort_sims[:, :-1]).sum(axis = 1) + 1\n    proba = np.mean(n_uniq != class_size)\n    return {\"est_proba\": proba}\n\nfor settings in grid(class_size=[5, 10, 20, 30], n_sim=[1000, 1_000_000]):\n    birthday_experiment(**settings)\n```\n\nThe decorators `memlist` and `memfile` are making sure that the keyword arugments and\ndictionary output of the `birthday_experiment` are logged. The contents of the `results.jsonl`-file\nand the `data` variable looks like this;\n\n```\n{\"class_size\": 5, \"n_sim\": 1000, \"est_proba\": 0.024, \"time_taken\": 0.0004899501800537109}\n{\"class_size\": 5, \"n_sim\": 1000000, \"est_proba\": 0.027178, \"time_taken\": 0.19407916069030762}\n{\"class_size\": 10, \"n_sim\": 1000, \"est_proba\": 0.104, \"time_taken\": 0.000598907470703125}\n{\"class_size\": 10, \"n_sim\": 1000000, \"est_proba\": 0.117062, \"time_taken\": 0.3751380443572998}\n{\"class_size\": 20, \"n_sim\": 1000, \"est_proba\": 0.415, \"time_taken\": 0.0009679794311523438}\n{\"class_size\": 20, \"n_sim\": 1000000, \"est_proba\": 0.411571, \"time_taken\": 0.7928380966186523}\n{\"class_size\": 30, \"n_sim\": 1000, \"est_proba\": 0.703, \"time_taken\": 0.0018239021301269531}\n{\"class_size\": 30, \"n_sim\": 1000000, \"est_proba\": 0.706033, \"time_taken\": 1.1375510692596436}\n```\n\nThe nice thing about being able to log results to a file or to the web is that\nyou can also more easily parallize your jobs! For example now you can use the `Runner`\nclass to parrallelize the function call with [joblib].\n\n[joblib]: https://joblib.readthedocs.io/en/latest/\n\n```python\nimport numpy as np\nfrom memo import memlist, memfile, grid, time_taken, Runner\n\ndata = []\n\n@memfile(filepath=\"results.jsonl\")\n@memlist(data=data)\n@time_taken()\ndef birthday_experiment(class_size, n_sim):\n    \"\"\"Simulates the birthday paradox. Vectorized = Fast!\"\"\"\n    sims = np.random.randint(1, 365 + 1, (n_sim, class_size))\n    sort_sims = np.sort(sims, axis=1)\n    n_uniq = (sort_sims[:, 1:] != sort_sims[:, :-1]).sum(axis = 1) + 1\n    proba = np.mean(n_uniq != class_size)\n    return {\"est_proba\": proba}\n\n# declare all the settings to loop over\nsettings = grid(class_size=range(20, 30), n_sim=[100, 10_000, 1_000_000])\n\n# use a runner to run over all the settings\nrunner = Runner(backend=\"threading\", n_jobs=-1)\nrunner.run(func=birthday_experiment, settings=settings, progbar=True)\n```\n\n## Features\n\nThis library also offers decorators to pipe to other sources.\n\n- `memlist` sends the json blobs to a list\n- `memfile` sends the json blobs to a file\n- `memweb` sends the json blobs to a server via http-post requests\n- `memfunc` sends the data to a callable that you supply, like `print`\n- `grid` generates a convenient grid for your experiments\n- `random_grid` generates a randomized grid for your experiments\n- `time_taken` also logs the time the function takes to run\n\nWe also offer an option to parallelize function calls using joblib. This\nis facilitated with a `Runner` class which supports multiple backends.\n\n- `Runner(backend=\"loky\")`\n- `Runner(backend=\"threading\")`\n- `Runner(backend=\"multiprocessing\")`\n\nCheck the API docs [here](https://koaning.github.io/memo/util.html) for more information on\nhow these work.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fkoaning%2Fmemo","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fkoaning%2Fmemo","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fkoaning%2Fmemo/lists"}