Reproduce Machine Learning experiments easily
Project description
Overview
Mitosis is an experiment runner. It handles administrative tasks to decrease the mental overhead of collaboration:
- Creating a CLI for your experiment
- Recording commit information
- Tracking parameterization, as well as parameter names (e.g. "low-noise")
- Storing logs
- Generating HTML visuals
- Pickling result data
The virtuous consequence of these checks and organization is a faster workflow, a more rigorous scientific method, and reduced mental overhead of collaboration.
This article describes some of the design goals of mitosis.
Trivial Example
Hypothesis: the maximum value of a sine wave is equal to its amplitude.
sine_experiment/__init__.py
import numpy as np
import matplotlib.pyplot as plt
name = "sine-exp"
lookup_dict = {"frequency": {"fast": 10, "slow": 1}}
def run(amplitude, frequency):
"""Deterimne if the maximum value of the sine function equals ``amplitude``"""
x = np.arange(0, 10, .05)
y = amplitude * np.sin(frequency * x)
err = np.abs(max(y) - amplitude)
plt.title("What's the maximum value of a sine wave?")
plt.plot(x, y, label="trial data")
plt.plot(x, amplitude * np.ones_like(x), label="expected")
plt.legend()
return {"main": err, "data": y}
pyproject.toml
[tool.mitosis.steps]
my_exp = ["sine_experiment:run", "sine_experiment:lookup_dict"]
Commit these changes to a repository. After installing sine_experiment as a python package, in CLI, run:
mitosis my_exp --param my_exp.frequency=slow --eval-param my_exp.amplitude=4
Mitosis will run sin_experiment.run(), saving
all output as an html file in a subdirectory. It will also
track the parameters and results.
If you later change the variant named "slow" to set frequency=2, mitosis will
raise a RuntimeError, preventing you from running a trial. If you want to run
sine_experiment with a different parameter value, you need to name that variant
something new. Eval parameters, like "amplitude" in the example, behave differently.
Rather than being specified by lookup_dict, they are evaluated directly.
Use
Philosophically, an experiment is any time we run code with an aim to convince someone of something. As code, mitosis takes the approach that an experiment is a callable (or a sequence of callables).
Using mitosis involves registering experiments in pyproject.toml, naming interesting parameters, running experiments on the command line, and browsing results.
Registration
mitosis uses the tool.mitosis.steps table of pyproject.toml to learn
what python callables are experiment steps
and where to lookup named parameter values.
It uses a syntax evocative of entry points:
[tool.mitosis.steps]
my_exp = ["sine_experiment:run", "sine_experiment:lookup_dict"]
Experiment steps must be callables with a dictionary return type. The returned dictionary is required to have a key "main". All but the final step in an experiment must also have a key "data" that gets passed to the first argument of the subsequent step. If the key "metrics" is present, it will display prominently in the HTML output
Developer note: Building an experiment step static type at mitosis._typing.ExpRun
CLI
The basic invocation lists the steps along with the values of any parameters for each step.
mitosis [OPTION...] step [steps...] [[-p step.lookup_param=key...]
[-e step.eval_param=val...]]...
Some nuance:
--debugcan be used to waive a lot of the reproducibility checks mitosis does. This arg allows you to run experiments in a dirty git repository (or no repository) and will neither save results in the experimental database, nor increment the trials counter, nor verify/lock in the definitions of any variants. It will, however, create the output notebook. It also changes the experiment log level from INFO to DEBUG.- lookup parameters can be nearly any python object that is pickleable. Tracking
parameter values can be turned off for parameters either for something that isn't
pickleable (e.g. a lambda function) or isn't important to track
(e.g. which GPU to run on). This can be done with eval or lookup parameters
by adding a
+to the parameter, e.g.-e +jax_playground.gpu_id=1. - Eval parameters which are strings will need quotation marks that escape the shell
(e.g.
-e smoothing.kernel=\"rbf\") -eand-pare short form for--eval-paramand--param(lookup param).
Results
Trials are saved in trials/ (or whatever is passed after -F). Each trial has a
pseudorandom bytes key, postpended to a metadata folder and an html output filename.
There are two obviously useful things to do after an experiment:
- view the html file.
python -m http.serveris helpful to browse results - load the data with
mitosis.load_trial_data()
Beyond this, the metadata mitosis keeps to disk is useful for troubleshooting or reproducing experiments, but no facility yet exists to browse or compare experiments.
API
Mitosis is primarily intended as a command line program, so mitosis --help has the syntax documentation.
There is only one intentionally public part of the api: mitosis.load_trial_data().
Project details
Release history Release notifications | RSS feed
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
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file mitosis-0.6.2.tar.gz.
File metadata
- Download URL: mitosis-0.6.2.tar.gz
- Upload date:
- Size: 28.1 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
c38f083c86d9f74bdd1d07d90205e1d60c2f87826c194a083e2a3319f4ac4d81
|
|
| MD5 |
ec4c96a2a4269d39ba02f29eb3f89395
|
|
| BLAKE2b-256 |
57f561d5978122f5e25f167dbf6c1d5228f31ce17c8ad2d103b8ba3ffe276601
|
Provenance
The following attestation bundles were made for mitosis-0.6.2.tar.gz:
Publisher:
release.yaml on Jacob-Stevens-Haas/mitosis
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
mitosis-0.6.2.tar.gz -
Subject digest:
c38f083c86d9f74bdd1d07d90205e1d60c2f87826c194a083e2a3319f4ac4d81 - Sigstore transparency entry: 1095536007
- Sigstore integration time:
-
Permalink:
Jacob-Stevens-Haas/mitosis@c2116c94146a99938480c825f207a47296f503d2 -
Branch / Tag:
refs/tags/0.6.2 - Owner: https://github.com/Jacob-Stevens-Haas
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
release.yaml@c2116c94146a99938480c825f207a47296f503d2 -
Trigger Event:
push
-
Statement type:
File details
Details for the file mitosis-0.6.2-py3-none-any.whl.
File metadata
- Download URL: mitosis-0.6.2-py3-none-any.whl
- Upload date:
- Size: 25.7 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
23f43e829d22db06910a52ee21d913e4d6184ad19dd59038dc5a166597af453a
|
|
| MD5 |
d2759d22ced3f6e2a158a763de655ffd
|
|
| BLAKE2b-256 |
5f814158e939ccd277b4c8796a8c76af1f7753df4051e178035ecaa9918eaeed
|
Provenance
The following attestation bundles were made for mitosis-0.6.2-py3-none-any.whl:
Publisher:
release.yaml on Jacob-Stevens-Haas/mitosis
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
mitosis-0.6.2-py3-none-any.whl -
Subject digest:
23f43e829d22db06910a52ee21d913e4d6184ad19dd59038dc5a166597af453a - Sigstore transparency entry: 1095536013
- Sigstore integration time:
-
Permalink:
Jacob-Stevens-Haas/mitosis@c2116c94146a99938480c825f207a47296f503d2 -
Branch / Tag:
refs/tags/0.6.2 - Owner: https://github.com/Jacob-Stevens-Haas
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
release.yaml@c2116c94146a99938480c825f207a47296f503d2 -
Trigger Event:
push
-
Statement type: