REProducible Experimental environment.
Project description
# fret
[](https://travis-ci.org/yxonic/fret)
[](https://coveralls.io/github/yxonic/fret?branch=master)
[](https://www.codacy.com/app/yxonic/fret?utm_source=github.com&utm_medium=referral&utm_content=yxonic/fret&utm_campaign=Badge_Grade)
[](https://pypi.python.org/pypi/fret)
[](https://pypi.python.org/pypi/fret)
Framework for Reproducible ExperimenTs. Read on for a quick guide. Full documentation [here](https://yxonic.github.io/fret/index.html).
## Installation
From pip:
```sh
pip install fret
```
From source: clone the repository and then run: `python setup.py install`.
## Tutorial
### Basic Usage
Create a file named `app.py` with content:
```python
import fret
@fret.command
def run(ws):
model = ws.build()
print(model)
@fret.configurable
class Model:
def __init__(self, x=3, y=4):
...
```
Then under the same directory, you can run:
```sh
$ fret config Model
[ws/_default] configured "main" as "Model" with: x=3, y=4
$ fret run
Model(x=3, y=4)
$ fret config Model -x 5 -y 10
[ws/_default] configured "main" as "Model" with: x=5, y=10
$ fret run
Model(x=5, y=10)
```
### Using Workspace
You can specify different configuration in different workspace:
```sh
$ fret -w ws/model1 config Model
[ws/model1] configured "main" as "Model" with: x=3, y=4
$ fret -w ws/model2 config Model -x 5 -y 10
[ws/model2] configured "main" as "Model" with: x=5, y=10
$ fret -w ws/model1 run
Model(x=3, y=4)
$ fret -w ws/model2 run
Model(x=5, y=10)
```
### Save/Load
```python
import fret
@fret.command
def train(ws):
model = ws.build()
model.train()
ws.save(model, 'trained')
@fret.command
def test(ws):
model = ws.load('ws/best/snapshot/main.trained.pt')
print(model.weight)
@fret.configurable
@fret.stateful('weight')
class Model:
def __init__(self):
self.weight = 0
def train(self):
self.weight = 23
```
```sh
$ fret -w ws/best config Model
[ws/_default] configured "main" as "Model"
$ fret -w ws/best train
$ fret test
23
```
### An Advanced Workflow
In `app.py`:
```python
import time
import fret
@fret.configurable
@fret.stateful('value')
class Model:
def __init__(self):
self.value = 0
@fret.command
def resumable(ws):
model = ws.build()
with ws.run('exp-1') as run:
run.register(model)
cnt = run.acc()
for e in fret.nonbreak(run.range(5)):
# with `nonbreak`, the program always finish this loop before exit
model.value += e
time.sleep(0.2)
cnt += 1
print('current epoch: %d, sum: %d, cnt: %d' %
(e, model.value, cnt))
```
Then you can stop and restart this program anytime, with consistent results:
```sh
$ fret resumable
current epoch: 0, sum: 0, cnt: 1
current epoch: 1, sum: 1, cnt: 2
^CW SIGINT received. Delaying KeyboardInterrupt.
current epoch: 2, sum: 3, cnt: 3
Traceback (most recent call last):
...
KeyboardInterrupt
W cancelled by user
$ fret resumable
current epoch: 3, sum: 6, cnt: 4
current epoch: 4, sum: 10, cnt: 5
```
### Submodule
```python
@fret.configurable
class A:
def __init__(self, foo):
...
@fret.configurable(submodules=['sub'])
class B:
def __init__(self, sub, bar=3):
self.sub = sub(foo='bar') # call sub to build submodule
```
```sh
$ fret config sub A
[ws/_default] configured "sub" as "A"
$ fret config B
[ws/_default] configured "main" as "B" with: sub='sub', bar=3
$ fret run
B(sub=A(), bar=3)
```
### Inheritance
```python
@fret.configurable
class A:
def __init__(self, foo='bar', sth=3):
...
@fret.configurable
class B(A):
def __init__(self, bar=3, **others):
super().__init__(**others)
...
```
```sh
$ fret config B -foo baz -bar 0
[ws/_default] configured "main" as "B" with: bar=0, foo='baz', sth=3
$ fret run
B(bar=0, foo='baz', sth=3)
```
### Internals
```python
>>> config = fret.Configuration({'foo': 'bar'})
>>> config
foo='bar'
```
[](https://travis-ci.org/yxonic/fret)
[](https://coveralls.io/github/yxonic/fret?branch=master)
[](https://www.codacy.com/app/yxonic/fret?utm_source=github.com&utm_medium=referral&utm_content=yxonic/fret&utm_campaign=Badge_Grade)
[](https://pypi.python.org/pypi/fret)
[](https://pypi.python.org/pypi/fret)
Framework for Reproducible ExperimenTs. Read on for a quick guide. Full documentation [here](https://yxonic.github.io/fret/index.html).
## Installation
From pip:
```sh
pip install fret
```
From source: clone the repository and then run: `python setup.py install`.
## Tutorial
### Basic Usage
Create a file named `app.py` with content:
```python
import fret
@fret.command
def run(ws):
model = ws.build()
print(model)
@fret.configurable
class Model:
def __init__(self, x=3, y=4):
...
```
Then under the same directory, you can run:
```sh
$ fret config Model
[ws/_default] configured "main" as "Model" with: x=3, y=4
$ fret run
Model(x=3, y=4)
$ fret config Model -x 5 -y 10
[ws/_default] configured "main" as "Model" with: x=5, y=10
$ fret run
Model(x=5, y=10)
```
### Using Workspace
You can specify different configuration in different workspace:
```sh
$ fret -w ws/model1 config Model
[ws/model1] configured "main" as "Model" with: x=3, y=4
$ fret -w ws/model2 config Model -x 5 -y 10
[ws/model2] configured "main" as "Model" with: x=5, y=10
$ fret -w ws/model1 run
Model(x=3, y=4)
$ fret -w ws/model2 run
Model(x=5, y=10)
```
### Save/Load
```python
import fret
@fret.command
def train(ws):
model = ws.build()
model.train()
ws.save(model, 'trained')
@fret.command
def test(ws):
model = ws.load('ws/best/snapshot/main.trained.pt')
print(model.weight)
@fret.configurable
@fret.stateful('weight')
class Model:
def __init__(self):
self.weight = 0
def train(self):
self.weight = 23
```
```sh
$ fret -w ws/best config Model
[ws/_default] configured "main" as "Model"
$ fret -w ws/best train
$ fret test
23
```
### An Advanced Workflow
In `app.py`:
```python
import time
import fret
@fret.configurable
@fret.stateful('value')
class Model:
def __init__(self):
self.value = 0
@fret.command
def resumable(ws):
model = ws.build()
with ws.run('exp-1') as run:
run.register(model)
cnt = run.acc()
for e in fret.nonbreak(run.range(5)):
# with `nonbreak`, the program always finish this loop before exit
model.value += e
time.sleep(0.2)
cnt += 1
print('current epoch: %d, sum: %d, cnt: %d' %
(e, model.value, cnt))
```
Then you can stop and restart this program anytime, with consistent results:
```sh
$ fret resumable
current epoch: 0, sum: 0, cnt: 1
current epoch: 1, sum: 1, cnt: 2
^CW SIGINT received. Delaying KeyboardInterrupt.
current epoch: 2, sum: 3, cnt: 3
Traceback (most recent call last):
...
KeyboardInterrupt
W cancelled by user
$ fret resumable
current epoch: 3, sum: 6, cnt: 4
current epoch: 4, sum: 10, cnt: 5
```
### Submodule
```python
@fret.configurable
class A:
def __init__(self, foo):
...
@fret.configurable(submodules=['sub'])
class B:
def __init__(self, sub, bar=3):
self.sub = sub(foo='bar') # call sub to build submodule
```
```sh
$ fret config sub A
[ws/_default] configured "sub" as "A"
$ fret config B
[ws/_default] configured "main" as "B" with: sub='sub', bar=3
$ fret run
B(sub=A(), bar=3)
```
### Inheritance
```python
@fret.configurable
class A:
def __init__(self, foo='bar', sth=3):
...
@fret.configurable
class B(A):
def __init__(self, bar=3, **others):
super().__init__(**others)
...
```
```sh
$ fret config B -foo baz -bar 0
[ws/_default] configured "main" as "B" with: bar=0, foo='baz', sth=3
$ fret run
B(bar=0, foo='baz', sth=3)
```
### Internals
```python
>>> config = fret.Configuration({'foo': 'bar'})
>>> config
foo='bar'
```
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
fret-0.2.2.tar.gz
(14.5 kB
view details)
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
fret-0.2.2-py3-none-any.whl
(16.4 kB
view details)
File details
Details for the file fret-0.2.2.tar.gz.
File metadata
- Download URL: fret-0.2.2.tar.gz
- Upload date:
- Size: 14.5 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/1.12.1 pkginfo/1.4.2 requests/2.19.1 setuptools/40.8.0 requests-toolbelt/0.8.0 tqdm/4.28.1 CPython/3.6.5
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
8e5fe55734ba1caefe8b753d76174f9bcbd2789e449c1967ce5bb1261fcb6ae5
|
|
| MD5 |
b195f44c530077f8c6a65df6039477c4
|
|
| BLAKE2b-256 |
4f7d5e7597cdcdbd453994d2fd26b9d8cf4792bcade06718bae7579fe7e4233d
|
File details
Details for the file fret-0.2.2-py3-none-any.whl.
File metadata
- Download URL: fret-0.2.2-py3-none-any.whl
- Upload date:
- Size: 16.4 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/1.12.1 pkginfo/1.4.2 requests/2.19.1 setuptools/40.8.0 requests-toolbelt/0.8.0 tqdm/4.28.1 CPython/3.6.5
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
b69ca4b5153e3ebb462a5a4f088a59b3a91a1c8da4d4c456443bc44bd404434b
|
|
| MD5 |
b956edf3f8c2defe6d803b0f2ab79c64
|
|
| BLAKE2b-256 |
16a08b20c39e617376164461f43c6a84e61f478615843b6afefb09f1c46218c6
|