forked from IDSIA/sacred
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmodular.py
executable file
·66 lines (47 loc) · 1.47 KB
/
modular.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
#!/usr/bin/env python
# coding=utf-8
"""
This is a very basic example of how to use Sacred.
"""
from __future__ import division, print_function, unicode_literals
from sacred import Experiment, Ingredient
# ============== Ingredient 0: settings =================
s = Ingredient("settings")
@s.config
def cfg1():
verbose = True
# ============== Ingredient 1: dataset.paths =================
data_paths = Ingredient("dataset.paths", ingredients=[s])
@data_paths.config
def cfg2(settings):
v = not settings['verbose']
base = '/home/sacred/'
# ============== Ingredient 2: dataset =======================
data = Ingredient("dataset", ingredients=[data_paths, s])
@data.config
def cfg3(paths):
basepath = paths['base'] + 'datasets/'
filename = "foo.hdf5"
@data.capture
def foo(basepath, filename, paths, settings):
print(paths)
print(settings)
return basepath + filename
# ============== Experiment ==============================
ex = Experiment('modular_example', ingredients=[data, data_paths])
@ex.config
def cfg(dataset):
a = 10
b = 17
c = a + b
out_base = dataset['paths']['base'] + 'outputs/'
out_filename = dataset['filename'].replace('.hdf5', '.out')
@ex.automain
def main(a, b, c, out_base, out_filename, dataset):
print('a =', a)
print('b =', b)
print('c =', c)
print('out_base =', out_base, out_filename)
# print("dataset", dataset)
# print("dataset.paths", dataset['paths'])
print("foo()", foo())