-
Notifications
You must be signed in to change notification settings - Fork 21
Expand file tree
/
Copy path01_session.py
More file actions
executable file
·62 lines (49 loc) · 1.77 KB
/
Copy path01_session.py
File metadata and controls
executable file
·62 lines (49 loc) · 1.77 KB
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
#!/usr/bin/env python3
"""Example: @stx.session -- Reproducible Experiment Tracking
Run:
python 01_session.py input.csv
python 01_session.py input.csv --n-samples 200 --learning-rate 0.01
python 01_session.py --help
Output:
01_session_out/FINISHED_SUCCESS/<timestamp>/
├── sine.png, sine.csv
├── CONFIGS/CONFIG.yaml
└── logs/{stdout,stderr}.log
"""
import numpy as np
import scitex as stx
@stx.session
def main(
data_path: str = "./data.csv", # python 01_session.py --data-path data.csv
n_samples: int = 100, # --n-samples 200
learning_rate: float = 0.001, # --learning-rate 0.01
CONFIG=stx.session.INJECTED, # ./config/*.yaml aggregated
COLORS=stx.session.INJECTED, # Color palette
plt=stx.session.INJECTED, # Pre-configured matplotlib
rngg=stx.session.INJECTED, # Random number generator (global)
logger=stx.session.INJECTED, # Session logger
):
"""Demonstrate @stx.session with auto-CLI and config injection."""
# Log session info
logger.info(f"Session ID: {CONFIG.ID}")
logger.info(f"Output dir: {CONFIG.SDIR_RUN}")
logger.info(f"Data path: {data_path}")
logger.info(f"n_samples={n_samples}, lr={learning_rate}")
# Generate demo data
x = np.linspace(0, 2 * np.pi, n_samples)
y = np.sin(x) + np.random.randn(n_samples) * 0.1
# Plot with figrecipe (injected plt)
fig, ax = stx.plt.subplots()
ax.plot(x, y)
ax.set_xyt("Time", "Amplitude", f"Sine Wave (n={n_samples})")
# Save figure (auto-exports sine.png + sine.csv)
stx.io.save(fig, "sine.png")
# Save parameters
stx.io.save(
{"n_samples": n_samples, "learning_rate": learning_rate},
"params.yaml",
)
logger.info("Done")
return 0
if __name__ == "__main__":
main()