talosdb 0.1.0__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- talosdb-0.1.0/LICENSE +21 -0
- talosdb-0.1.0/PKG-INFO +159 -0
- talosdb-0.1.0/README.md +131 -0
- talosdb-0.1.0/pyproject.toml +45 -0
- talosdb-0.1.0/setup.cfg +4 -0
- talosdb-0.1.0/src/talosdb.egg-info/PKG-INFO +159 -0
- talosdb-0.1.0/src/talosdb.egg-info/SOURCES.txt +9 -0
- talosdb-0.1.0/src/talosdb.egg-info/dependency_links.txt +1 -0
- talosdb-0.1.0/src/talosdb.egg-info/requires.txt +5 -0
- talosdb-0.1.0/src/talosdb.egg-info/top_level.txt +1 -0
- talosdb-0.1.0/tests/test_talosdb.py +299 -0
talosdb-0.1.0/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 GrindelfP
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
talosdb-0.1.0/PKG-INFO
ADDED
|
@@ -0,0 +1,159 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: talosdb
|
|
3
|
+
Version: 0.1.0
|
|
4
|
+
Summary: Lightweight experiment storage library for scientific simulations.
|
|
5
|
+
Author-email: GrindelfP <grindelf.perlomutrovij@gmail.com>
|
|
6
|
+
License: MIT
|
|
7
|
+
Project-URL: Homepage, https://github.com/GrindelfP/talosdb
|
|
8
|
+
Project-URL: Repository, https://github.com/GrindelfP/talosdb
|
|
9
|
+
Project-URL: Bug Tracker, https://github.com/GrindelfP/talosdb/issues
|
|
10
|
+
Keywords: experiment,simulation,storage,science,numpy
|
|
11
|
+
Classifier: Development Status :: 3 - Alpha
|
|
12
|
+
Classifier: Intended Audience :: Science/Research
|
|
13
|
+
Classifier: License :: OSI Approved :: MIT License
|
|
14
|
+
Classifier: Programming Language :: Python :: 3
|
|
15
|
+
Classifier: Programming Language :: Python :: 3.10
|
|
16
|
+
Classifier: Programming Language :: Python :: 3.11
|
|
17
|
+
Classifier: Programming Language :: Python :: 3.12
|
|
18
|
+
Classifier: Topic :: Scientific/Engineering
|
|
19
|
+
Classifier: Topic :: Software Development :: Libraries :: Python Modules
|
|
20
|
+
Requires-Python: >=3.10
|
|
21
|
+
Description-Content-Type: text/markdown
|
|
22
|
+
License-File: LICENSE
|
|
23
|
+
Requires-Dist: numpy>=1.24
|
|
24
|
+
Provides-Extra: dev
|
|
25
|
+
Requires-Dist: pytest>=7.0; extra == "dev"
|
|
26
|
+
Requires-Dist: pytest-cov; extra == "dev"
|
|
27
|
+
Dynamic: license-file
|
|
28
|
+
|
|
29
|
+
# talosdb
|
|
30
|
+
|
|
31
|
+
Lightweight experiment storage library for scientific simulations.
|
|
32
|
+
Named after Talos I station.
|
|
33
|
+
|
|
34
|
+
## Installation
|
|
35
|
+
|
|
36
|
+
```bash
|
|
37
|
+
pip install src
|
|
38
|
+
```
|
|
39
|
+
|
|
40
|
+
## Quickstart
|
|
41
|
+
|
|
42
|
+
```python
|
|
43
|
+
from src import TalosDB
|
|
44
|
+
from itertools import product
|
|
45
|
+
|
|
46
|
+
db = TalosDB("~/science/results")
|
|
47
|
+
exp = db.experiment("vc_sweep_2025")
|
|
48
|
+
|
|
49
|
+
A_grid = [0.5, 1.0, 1.5]
|
|
50
|
+
beta_grid = [1.0, 2.0]
|
|
51
|
+
|
|
52
|
+
for A, beta in product(A_grid, beta_grid):
|
|
53
|
+
result = simulate(A, beta) # numpy array
|
|
54
|
+
with exp.run({"A": A, "beta": beta}) as run:
|
|
55
|
+
run.save(result)
|
|
56
|
+
run.save_params({"gamma": 0.1, "T": 300}) # extra constants
|
|
57
|
+
run.save_plot(my_plot_fn, result)
|
|
58
|
+
```
|
|
59
|
+
|
|
60
|
+
## File layout
|
|
61
|
+
|
|
62
|
+
```
|
|
63
|
+
db_root/
|
|
64
|
+
└── vc_sweep_2025/
|
|
65
|
+
├── experiment.json # metadata: name, creation date
|
|
66
|
+
├── A=0.5_beta=1.0/
|
|
67
|
+
│ ├── data.dat # human-readable TSV (numpy array)
|
|
68
|
+
│ ├── params.json # all parameters (name + extra)
|
|
69
|
+
│ └── plot.png # if save_plot() was called
|
|
70
|
+
└── A=1.0_beta=2.0/
|
|
71
|
+
├── data.dat
|
|
72
|
+
└── params.json
|
|
73
|
+
```
|
|
74
|
+
|
|
75
|
+
## API reference
|
|
76
|
+
|
|
77
|
+
### TalosDB
|
|
78
|
+
|
|
79
|
+
```python
|
|
80
|
+
db = TalosDB("path/to/db") # creates root folder if absent
|
|
81
|
+
db.experiment("name") # create / open experiment
|
|
82
|
+
db.experiment() # name = datetime stamp
|
|
83
|
+
db.list_experiments() # → list[str]
|
|
84
|
+
db.delete_experiment("name", confirm=True)
|
|
85
|
+
```
|
|
86
|
+
|
|
87
|
+
### Experiment
|
|
88
|
+
|
|
89
|
+
```python
|
|
90
|
+
exp = db.experiment("my_exp")
|
|
91
|
+
|
|
92
|
+
# Create / open a run
|
|
93
|
+
run = exp.run({"A": 0.5, "beta": 1.0})
|
|
94
|
+
# or as context manager (marks failed.json on exception):
|
|
95
|
+
with exp.run({"A": 0.5, "beta": 1.0}) as run:
|
|
96
|
+
...
|
|
97
|
+
|
|
98
|
+
# Load
|
|
99
|
+
run = exp.load({"A": 0.5, "beta": 1.0}) # exact match
|
|
100
|
+
runs = exp.query({"beta": 1.0}) # subset match → list[Run]
|
|
101
|
+
runs = exp.all_runs() # every run
|
|
102
|
+
```
|
|
103
|
+
|
|
104
|
+
### Run
|
|
105
|
+
|
|
106
|
+
```python
|
|
107
|
+
run.save(result) # numpy array → data.dat
|
|
108
|
+
run.save_params({"gamma": 0.1, "T": 300}) # extra params → params.json
|
|
109
|
+
run.save_plot(plot_fn, result) # calls plot_fn(result, path)
|
|
110
|
+
|
|
111
|
+
result = run.load_data() # → np.ndarray
|
|
112
|
+
params = run.load_params() # → dict
|
|
113
|
+
run.is_failed() # → bool
|
|
114
|
+
run.load_failure() # → dict with error info
|
|
115
|
+
```
|
|
116
|
+
|
|
117
|
+
### plot_fn contract
|
|
118
|
+
|
|
119
|
+
```python
|
|
120
|
+
def my_plot_fn(result, save_path):
|
|
121
|
+
fig, ax = plt.subplots()
|
|
122
|
+
ax.plot(result[:, 0], result[:, 1])
|
|
123
|
+
fig.savefig(save_path)
|
|
124
|
+
plt.close(fig)
|
|
125
|
+
```
|
|
126
|
+
|
|
127
|
+
talosdb does not import matplotlib — rendering is entirely the caller's responsibility.
|
|
128
|
+
|
|
129
|
+
## .dat format
|
|
130
|
+
|
|
131
|
+
Arrays are stored as human-readable TSV with a small header:
|
|
132
|
+
|
|
133
|
+
```
|
|
134
|
+
# shape: 100 2
|
|
135
|
+
# dtype: float64
|
|
136
|
+
0.0 0.001
|
|
137
|
+
0.1 0.043
|
|
138
|
+
...
|
|
139
|
+
```
|
|
140
|
+
|
|
141
|
+
3D+ arrays are split into labelled 2D slices:
|
|
142
|
+
|
|
143
|
+
```
|
|
144
|
+
# shape: 2 3 4
|
|
145
|
+
# dtype: float64
|
|
146
|
+
# slice [0]
|
|
147
|
+
1.0 2.0 3.0 4.0
|
|
148
|
+
5.0 6.0 7.0 8.0
|
|
149
|
+
9.0 10.0 11.0 12.0
|
|
150
|
+
|
|
151
|
+
# slice [1]
|
|
152
|
+
...
|
|
153
|
+
```
|
|
154
|
+
|
|
155
|
+
The shape header ensures exact reconstruction on load regardless of dimensionality.
|
|
156
|
+
|
|
157
|
+
## License
|
|
158
|
+
|
|
159
|
+
MIT
|
talosdb-0.1.0/README.md
ADDED
|
@@ -0,0 +1,131 @@
|
|
|
1
|
+
# talosdb
|
|
2
|
+
|
|
3
|
+
Lightweight experiment storage library for scientific simulations.
|
|
4
|
+
Named after Talos I station.
|
|
5
|
+
|
|
6
|
+
## Installation
|
|
7
|
+
|
|
8
|
+
```bash
|
|
9
|
+
pip install src
|
|
10
|
+
```
|
|
11
|
+
|
|
12
|
+
## Quickstart
|
|
13
|
+
|
|
14
|
+
```python
|
|
15
|
+
from src import TalosDB
|
|
16
|
+
from itertools import product
|
|
17
|
+
|
|
18
|
+
db = TalosDB("~/science/results")
|
|
19
|
+
exp = db.experiment("vc_sweep_2025")
|
|
20
|
+
|
|
21
|
+
A_grid = [0.5, 1.0, 1.5]
|
|
22
|
+
beta_grid = [1.0, 2.0]
|
|
23
|
+
|
|
24
|
+
for A, beta in product(A_grid, beta_grid):
|
|
25
|
+
result = simulate(A, beta) # numpy array
|
|
26
|
+
with exp.run({"A": A, "beta": beta}) as run:
|
|
27
|
+
run.save(result)
|
|
28
|
+
run.save_params({"gamma": 0.1, "T": 300}) # extra constants
|
|
29
|
+
run.save_plot(my_plot_fn, result)
|
|
30
|
+
```
|
|
31
|
+
|
|
32
|
+
## File layout
|
|
33
|
+
|
|
34
|
+
```
|
|
35
|
+
db_root/
|
|
36
|
+
└── vc_sweep_2025/
|
|
37
|
+
├── experiment.json # metadata: name, creation date
|
|
38
|
+
├── A=0.5_beta=1.0/
|
|
39
|
+
│ ├── data.dat # human-readable TSV (numpy array)
|
|
40
|
+
│ ├── params.json # all parameters (name + extra)
|
|
41
|
+
│ └── plot.png # if save_plot() was called
|
|
42
|
+
└── A=1.0_beta=2.0/
|
|
43
|
+
├── data.dat
|
|
44
|
+
└── params.json
|
|
45
|
+
```
|
|
46
|
+
|
|
47
|
+
## API reference
|
|
48
|
+
|
|
49
|
+
### TalosDB
|
|
50
|
+
|
|
51
|
+
```python
|
|
52
|
+
db = TalosDB("path/to/db") # creates root folder if absent
|
|
53
|
+
db.experiment("name") # create / open experiment
|
|
54
|
+
db.experiment() # name = datetime stamp
|
|
55
|
+
db.list_experiments() # → list[str]
|
|
56
|
+
db.delete_experiment("name", confirm=True)
|
|
57
|
+
```
|
|
58
|
+
|
|
59
|
+
### Experiment
|
|
60
|
+
|
|
61
|
+
```python
|
|
62
|
+
exp = db.experiment("my_exp")
|
|
63
|
+
|
|
64
|
+
# Create / open a run
|
|
65
|
+
run = exp.run({"A": 0.5, "beta": 1.0})
|
|
66
|
+
# or as context manager (marks failed.json on exception):
|
|
67
|
+
with exp.run({"A": 0.5, "beta": 1.0}) as run:
|
|
68
|
+
...
|
|
69
|
+
|
|
70
|
+
# Load
|
|
71
|
+
run = exp.load({"A": 0.5, "beta": 1.0}) # exact match
|
|
72
|
+
runs = exp.query({"beta": 1.0}) # subset match → list[Run]
|
|
73
|
+
runs = exp.all_runs() # every run
|
|
74
|
+
```
|
|
75
|
+
|
|
76
|
+
### Run
|
|
77
|
+
|
|
78
|
+
```python
|
|
79
|
+
run.save(result) # numpy array → data.dat
|
|
80
|
+
run.save_params({"gamma": 0.1, "T": 300}) # extra params → params.json
|
|
81
|
+
run.save_plot(plot_fn, result) # calls plot_fn(result, path)
|
|
82
|
+
|
|
83
|
+
result = run.load_data() # → np.ndarray
|
|
84
|
+
params = run.load_params() # → dict
|
|
85
|
+
run.is_failed() # → bool
|
|
86
|
+
run.load_failure() # → dict with error info
|
|
87
|
+
```
|
|
88
|
+
|
|
89
|
+
### plot_fn contract
|
|
90
|
+
|
|
91
|
+
```python
|
|
92
|
+
def my_plot_fn(result, save_path):
|
|
93
|
+
fig, ax = plt.subplots()
|
|
94
|
+
ax.plot(result[:, 0], result[:, 1])
|
|
95
|
+
fig.savefig(save_path)
|
|
96
|
+
plt.close(fig)
|
|
97
|
+
```
|
|
98
|
+
|
|
99
|
+
talosdb does not import matplotlib — rendering is entirely the caller's responsibility.
|
|
100
|
+
|
|
101
|
+
## .dat format
|
|
102
|
+
|
|
103
|
+
Arrays are stored as human-readable TSV with a small header:
|
|
104
|
+
|
|
105
|
+
```
|
|
106
|
+
# shape: 100 2
|
|
107
|
+
# dtype: float64
|
|
108
|
+
0.0 0.001
|
|
109
|
+
0.1 0.043
|
|
110
|
+
...
|
|
111
|
+
```
|
|
112
|
+
|
|
113
|
+
3D+ arrays are split into labelled 2D slices:
|
|
114
|
+
|
|
115
|
+
```
|
|
116
|
+
# shape: 2 3 4
|
|
117
|
+
# dtype: float64
|
|
118
|
+
# slice [0]
|
|
119
|
+
1.0 2.0 3.0 4.0
|
|
120
|
+
5.0 6.0 7.0 8.0
|
|
121
|
+
9.0 10.0 11.0 12.0
|
|
122
|
+
|
|
123
|
+
# slice [1]
|
|
124
|
+
...
|
|
125
|
+
```
|
|
126
|
+
|
|
127
|
+
The shape header ensures exact reconstruction on load regardless of dimensionality.
|
|
128
|
+
|
|
129
|
+
## License
|
|
130
|
+
|
|
131
|
+
MIT
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
[build-system]
|
|
2
|
+
requires = ["setuptools>=68", "wheel"]
|
|
3
|
+
|
|
4
|
+
[project]
|
|
5
|
+
name = "talosdb"
|
|
6
|
+
version = "0.1.0"
|
|
7
|
+
description = "Lightweight experiment storage library for scientific simulations."
|
|
8
|
+
readme = "README.md"
|
|
9
|
+
license = { text = "MIT" }
|
|
10
|
+
requires-python = ">=3.10"
|
|
11
|
+
authors = [
|
|
12
|
+
{ name = "GrindelfP", email = "grindelf.perlomutrovij@gmail.com" },
|
|
13
|
+
]
|
|
14
|
+
keywords = ["experiment", "simulation", "storage", "science", "numpy"]
|
|
15
|
+
classifiers = [
|
|
16
|
+
"Development Status :: 3 - Alpha",
|
|
17
|
+
"Intended Audience :: Science/Research",
|
|
18
|
+
"License :: OSI Approved :: MIT License",
|
|
19
|
+
"Programming Language :: Python :: 3",
|
|
20
|
+
"Programming Language :: Python :: 3.10",
|
|
21
|
+
"Programming Language :: Python :: 3.11",
|
|
22
|
+
"Programming Language :: Python :: 3.12",
|
|
23
|
+
"Topic :: Scientific/Engineering",
|
|
24
|
+
"Topic :: Software Development :: Libraries :: Python Modules",
|
|
25
|
+
]
|
|
26
|
+
dependencies = [
|
|
27
|
+
"numpy>=1.24",
|
|
28
|
+
]
|
|
29
|
+
|
|
30
|
+
[project.optional-dependencies]
|
|
31
|
+
dev = [
|
|
32
|
+
"pytest>=7.0",
|
|
33
|
+
"pytest-cov",
|
|
34
|
+
]
|
|
35
|
+
|
|
36
|
+
[project.urls]
|
|
37
|
+
Homepage = "https://github.com/GrindelfP/talosdb"
|
|
38
|
+
Repository = "https://github.com/GrindelfP/talosdb"
|
|
39
|
+
"Bug Tracker" = "https://github.com/GrindelfP/talosdb/issues"
|
|
40
|
+
|
|
41
|
+
[tool.setuptools.packages.find]
|
|
42
|
+
where = ["src"]
|
|
43
|
+
|
|
44
|
+
[tool.pytest.ini_options]
|
|
45
|
+
testpaths = ["tests"]
|
talosdb-0.1.0/setup.cfg
ADDED
|
@@ -0,0 +1,159 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: talosdb
|
|
3
|
+
Version: 0.1.0
|
|
4
|
+
Summary: Lightweight experiment storage library for scientific simulations.
|
|
5
|
+
Author-email: GrindelfP <grindelf.perlomutrovij@gmail.com>
|
|
6
|
+
License: MIT
|
|
7
|
+
Project-URL: Homepage, https://github.com/GrindelfP/talosdb
|
|
8
|
+
Project-URL: Repository, https://github.com/GrindelfP/talosdb
|
|
9
|
+
Project-URL: Bug Tracker, https://github.com/GrindelfP/talosdb/issues
|
|
10
|
+
Keywords: experiment,simulation,storage,science,numpy
|
|
11
|
+
Classifier: Development Status :: 3 - Alpha
|
|
12
|
+
Classifier: Intended Audience :: Science/Research
|
|
13
|
+
Classifier: License :: OSI Approved :: MIT License
|
|
14
|
+
Classifier: Programming Language :: Python :: 3
|
|
15
|
+
Classifier: Programming Language :: Python :: 3.10
|
|
16
|
+
Classifier: Programming Language :: Python :: 3.11
|
|
17
|
+
Classifier: Programming Language :: Python :: 3.12
|
|
18
|
+
Classifier: Topic :: Scientific/Engineering
|
|
19
|
+
Classifier: Topic :: Software Development :: Libraries :: Python Modules
|
|
20
|
+
Requires-Python: >=3.10
|
|
21
|
+
Description-Content-Type: text/markdown
|
|
22
|
+
License-File: LICENSE
|
|
23
|
+
Requires-Dist: numpy>=1.24
|
|
24
|
+
Provides-Extra: dev
|
|
25
|
+
Requires-Dist: pytest>=7.0; extra == "dev"
|
|
26
|
+
Requires-Dist: pytest-cov; extra == "dev"
|
|
27
|
+
Dynamic: license-file
|
|
28
|
+
|
|
29
|
+
# talosdb
|
|
30
|
+
|
|
31
|
+
Lightweight experiment storage library for scientific simulations.
|
|
32
|
+
Named after Talos I station.
|
|
33
|
+
|
|
34
|
+
## Installation
|
|
35
|
+
|
|
36
|
+
```bash
|
|
37
|
+
pip install src
|
|
38
|
+
```
|
|
39
|
+
|
|
40
|
+
## Quickstart
|
|
41
|
+
|
|
42
|
+
```python
|
|
43
|
+
from src import TalosDB
|
|
44
|
+
from itertools import product
|
|
45
|
+
|
|
46
|
+
db = TalosDB("~/science/results")
|
|
47
|
+
exp = db.experiment("vc_sweep_2025")
|
|
48
|
+
|
|
49
|
+
A_grid = [0.5, 1.0, 1.5]
|
|
50
|
+
beta_grid = [1.0, 2.0]
|
|
51
|
+
|
|
52
|
+
for A, beta in product(A_grid, beta_grid):
|
|
53
|
+
result = simulate(A, beta) # numpy array
|
|
54
|
+
with exp.run({"A": A, "beta": beta}) as run:
|
|
55
|
+
run.save(result)
|
|
56
|
+
run.save_params({"gamma": 0.1, "T": 300}) # extra constants
|
|
57
|
+
run.save_plot(my_plot_fn, result)
|
|
58
|
+
```
|
|
59
|
+
|
|
60
|
+
## File layout
|
|
61
|
+
|
|
62
|
+
```
|
|
63
|
+
db_root/
|
|
64
|
+
└── vc_sweep_2025/
|
|
65
|
+
├── experiment.json # metadata: name, creation date
|
|
66
|
+
├── A=0.5_beta=1.0/
|
|
67
|
+
│ ├── data.dat # human-readable TSV (numpy array)
|
|
68
|
+
│ ├── params.json # all parameters (name + extra)
|
|
69
|
+
│ └── plot.png # if save_plot() was called
|
|
70
|
+
└── A=1.0_beta=2.0/
|
|
71
|
+
├── data.dat
|
|
72
|
+
└── params.json
|
|
73
|
+
```
|
|
74
|
+
|
|
75
|
+
## API reference
|
|
76
|
+
|
|
77
|
+
### TalosDB
|
|
78
|
+
|
|
79
|
+
```python
|
|
80
|
+
db = TalosDB("path/to/db") # creates root folder if absent
|
|
81
|
+
db.experiment("name") # create / open experiment
|
|
82
|
+
db.experiment() # name = datetime stamp
|
|
83
|
+
db.list_experiments() # → list[str]
|
|
84
|
+
db.delete_experiment("name", confirm=True)
|
|
85
|
+
```
|
|
86
|
+
|
|
87
|
+
### Experiment
|
|
88
|
+
|
|
89
|
+
```python
|
|
90
|
+
exp = db.experiment("my_exp")
|
|
91
|
+
|
|
92
|
+
# Create / open a run
|
|
93
|
+
run = exp.run({"A": 0.5, "beta": 1.0})
|
|
94
|
+
# or as context manager (marks failed.json on exception):
|
|
95
|
+
with exp.run({"A": 0.5, "beta": 1.0}) as run:
|
|
96
|
+
...
|
|
97
|
+
|
|
98
|
+
# Load
|
|
99
|
+
run = exp.load({"A": 0.5, "beta": 1.0}) # exact match
|
|
100
|
+
runs = exp.query({"beta": 1.0}) # subset match → list[Run]
|
|
101
|
+
runs = exp.all_runs() # every run
|
|
102
|
+
```
|
|
103
|
+
|
|
104
|
+
### Run
|
|
105
|
+
|
|
106
|
+
```python
|
|
107
|
+
run.save(result) # numpy array → data.dat
|
|
108
|
+
run.save_params({"gamma": 0.1, "T": 300}) # extra params → params.json
|
|
109
|
+
run.save_plot(plot_fn, result) # calls plot_fn(result, path)
|
|
110
|
+
|
|
111
|
+
result = run.load_data() # → np.ndarray
|
|
112
|
+
params = run.load_params() # → dict
|
|
113
|
+
run.is_failed() # → bool
|
|
114
|
+
run.load_failure() # → dict with error info
|
|
115
|
+
```
|
|
116
|
+
|
|
117
|
+
### plot_fn contract
|
|
118
|
+
|
|
119
|
+
```python
|
|
120
|
+
def my_plot_fn(result, save_path):
|
|
121
|
+
fig, ax = plt.subplots()
|
|
122
|
+
ax.plot(result[:, 0], result[:, 1])
|
|
123
|
+
fig.savefig(save_path)
|
|
124
|
+
plt.close(fig)
|
|
125
|
+
```
|
|
126
|
+
|
|
127
|
+
talosdb does not import matplotlib — rendering is entirely the caller's responsibility.
|
|
128
|
+
|
|
129
|
+
## .dat format
|
|
130
|
+
|
|
131
|
+
Arrays are stored as human-readable TSV with a small header:
|
|
132
|
+
|
|
133
|
+
```
|
|
134
|
+
# shape: 100 2
|
|
135
|
+
# dtype: float64
|
|
136
|
+
0.0 0.001
|
|
137
|
+
0.1 0.043
|
|
138
|
+
...
|
|
139
|
+
```
|
|
140
|
+
|
|
141
|
+
3D+ arrays are split into labelled 2D slices:
|
|
142
|
+
|
|
143
|
+
```
|
|
144
|
+
# shape: 2 3 4
|
|
145
|
+
# dtype: float64
|
|
146
|
+
# slice [0]
|
|
147
|
+
1.0 2.0 3.0 4.0
|
|
148
|
+
5.0 6.0 7.0 8.0
|
|
149
|
+
9.0 10.0 11.0 12.0
|
|
150
|
+
|
|
151
|
+
# slice [1]
|
|
152
|
+
...
|
|
153
|
+
```
|
|
154
|
+
|
|
155
|
+
The shape header ensures exact reconstruction on load regardless of dimensionality.
|
|
156
|
+
|
|
157
|
+
## License
|
|
158
|
+
|
|
159
|
+
MIT
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
|
|
@@ -0,0 +1,299 @@
|
|
|
1
|
+
"""
|
|
2
|
+
Tests for src.
|
|
3
|
+
"""
|
|
4
|
+
import json
|
|
5
|
+
import math
|
|
6
|
+
import warnings
|
|
7
|
+
from pathlib import Path
|
|
8
|
+
|
|
9
|
+
import numpy as np
|
|
10
|
+
import pytest
|
|
11
|
+
|
|
12
|
+
from src import TalosDB, Experiment, Run
|
|
13
|
+
|
|
14
|
+
|
|
15
|
+
# ---------------------------------------------------------------------------
|
|
16
|
+
# Fixtures
|
|
17
|
+
# ---------------------------------------------------------------------------
|
|
18
|
+
|
|
19
|
+
@pytest.fixture
|
|
20
|
+
def db(tmp_path):
|
|
21
|
+
return TalosDB(tmp_path / "testdb")
|
|
22
|
+
|
|
23
|
+
|
|
24
|
+
@pytest.fixture
|
|
25
|
+
def exp(db):
|
|
26
|
+
return db.experiment("test_exp")
|
|
27
|
+
|
|
28
|
+
|
|
29
|
+
# ---------------------------------------------------------------------------
|
|
30
|
+
# _params_to_dirname / _dirname_to_params round-trip
|
|
31
|
+
# ---------------------------------------------------------------------------
|
|
32
|
+
|
|
33
|
+
class TestDirnameParsing:
|
|
34
|
+
def test_basic_roundtrip(self):
|
|
35
|
+
from src import _params_to_dirname, _dirname_to_params
|
|
36
|
+
params = {"A": 0.5, "beta": 1.0}
|
|
37
|
+
assert _dirname_to_params(_params_to_dirname(params)) == params
|
|
38
|
+
|
|
39
|
+
def test_int_value(self):
|
|
40
|
+
from src import _params_to_dirname, _dirname_to_params
|
|
41
|
+
params = {"N": 100, "mode": 2}
|
|
42
|
+
result = _dirname_to_params(_params_to_dirname(params))
|
|
43
|
+
assert result == params
|
|
44
|
+
|
|
45
|
+
def test_string_value(self):
|
|
46
|
+
from src import _params_to_dirname, _dirname_to_params
|
|
47
|
+
params = {"solver": "euler", "A": 1.0}
|
|
48
|
+
result = _dirname_to_params(_params_to_dirname(params))
|
|
49
|
+
assert result == params
|
|
50
|
+
|
|
51
|
+
def test_underscore_in_value(self):
|
|
52
|
+
"""Values containing underscores must not confuse the parser."""
|
|
53
|
+
from src import _params_to_dirname, _dirname_to_params
|
|
54
|
+
params = {"method": "runge_kutta", "A": 0.5}
|
|
55
|
+
dirname = _params_to_dirname(params)
|
|
56
|
+
parsed = _dirname_to_params(dirname)
|
|
57
|
+
assert parsed["method"] == "runge_kutta"
|
|
58
|
+
assert math.isclose(parsed["A"], 0.5)
|
|
59
|
+
|
|
60
|
+
def test_sorted_keys(self):
|
|
61
|
+
from src import _params_to_dirname
|
|
62
|
+
d1 = _params_to_dirname({"beta": 1.0, "A": 0.5})
|
|
63
|
+
d2 = _params_to_dirname({"A": 0.5, "beta": 1.0})
|
|
64
|
+
assert d1 == d2
|
|
65
|
+
|
|
66
|
+
|
|
67
|
+
# ---------------------------------------------------------------------------
|
|
68
|
+
# .dat round-trip
|
|
69
|
+
# ---------------------------------------------------------------------------
|
|
70
|
+
|
|
71
|
+
class TestDatFormat:
|
|
72
|
+
def _roundtrip(self, arr, tmp_path):
|
|
73
|
+
from src import _save_dat, _load_dat
|
|
74
|
+
p = tmp_path / "test.dat"
|
|
75
|
+
_save_dat(p, arr)
|
|
76
|
+
return _load_dat(p)
|
|
77
|
+
|
|
78
|
+
def test_1d(self, tmp_path):
|
|
79
|
+
arr = np.linspace(0, 1, 50)
|
|
80
|
+
result = self._roundtrip(arr, tmp_path)
|
|
81
|
+
assert result.shape == arr.shape
|
|
82
|
+
np.testing.assert_array_almost_equal(result, arr)
|
|
83
|
+
|
|
84
|
+
def test_2d(self, tmp_path):
|
|
85
|
+
arr = np.random.rand(20, 3)
|
|
86
|
+
result = self._roundtrip(arr, tmp_path)
|
|
87
|
+
assert result.shape == arr.shape
|
|
88
|
+
np.testing.assert_array_almost_equal(result, arr)
|
|
89
|
+
|
|
90
|
+
def test_3d(self, tmp_path):
|
|
91
|
+
arr = np.random.rand(4, 5, 6)
|
|
92
|
+
result = self._roundtrip(arr, tmp_path)
|
|
93
|
+
assert result.shape == arr.shape
|
|
94
|
+
np.testing.assert_array_almost_equal(result, arr)
|
|
95
|
+
|
|
96
|
+
def test_4d(self, tmp_path):
|
|
97
|
+
arr = np.arange(2 * 3 * 4 * 5, dtype=float).reshape(2, 3, 4, 5)
|
|
98
|
+
result = self._roundtrip(arr, tmp_path)
|
|
99
|
+
assert result.shape == arr.shape
|
|
100
|
+
np.testing.assert_array_equal(result, arr)
|
|
101
|
+
|
|
102
|
+
def test_human_readable(self, tmp_path):
|
|
103
|
+
"""The .dat file must be readable as plain text."""
|
|
104
|
+
from src import _save_dat
|
|
105
|
+
arr = np.array([[1.0, 2.0], [3.0, 4.0]])
|
|
106
|
+
p = tmp_path / "test.dat"
|
|
107
|
+
_save_dat(p, arr)
|
|
108
|
+
text = p.read_text()
|
|
109
|
+
assert "# shape:" in text
|
|
110
|
+
assert "# dtype:" in text
|
|
111
|
+
assert "1.0\t2.0" in text
|
|
112
|
+
|
|
113
|
+
def test_integer_dtype(self, tmp_path):
|
|
114
|
+
arr = np.array([1, 2, 3, 4, 5], dtype=np.int32)
|
|
115
|
+
result = self._roundtrip(arr, tmp_path)
|
|
116
|
+
assert result.dtype == arr.dtype
|
|
117
|
+
np.testing.assert_array_equal(result, arr)
|
|
118
|
+
|
|
119
|
+
|
|
120
|
+
# ---------------------------------------------------------------------------
|
|
121
|
+
# Run
|
|
122
|
+
# ---------------------------------------------------------------------------
|
|
123
|
+
|
|
124
|
+
class TestRun:
|
|
125
|
+
def test_save_and_load_data(self, exp):
|
|
126
|
+
run = exp.run({"A": 0.5, "beta": 1.0})
|
|
127
|
+
data = np.random.rand(10, 2)
|
|
128
|
+
run.save(data)
|
|
129
|
+
loaded = run.load_data()
|
|
130
|
+
np.testing.assert_array_almost_equal(loaded, data)
|
|
131
|
+
|
|
132
|
+
def test_save_params_merges(self, exp):
|
|
133
|
+
run = exp.run({"A": 0.5, "beta": 1.0})
|
|
134
|
+
run.save_params({"gamma": 0.1, "T": 300})
|
|
135
|
+
params = run.load_params()
|
|
136
|
+
assert params["A"] == 0.5
|
|
137
|
+
assert params["beta"] == 1.0
|
|
138
|
+
assert params["gamma"] == 0.1
|
|
139
|
+
assert params["T"] == 300
|
|
140
|
+
|
|
141
|
+
def test_save_params_no_extra(self, exp):
|
|
142
|
+
run = exp.run({"A": 1.0})
|
|
143
|
+
run.save_params()
|
|
144
|
+
params = run.load_params()
|
|
145
|
+
assert params == {"A": 1.0}
|
|
146
|
+
|
|
147
|
+
def test_save_plot(self, exp, tmp_path):
|
|
148
|
+
run = exp.run({"A": 0.5})
|
|
149
|
+
data = np.eye(3)
|
|
150
|
+
saved_paths = []
|
|
151
|
+
|
|
152
|
+
def fake_plot(result, save_path):
|
|
153
|
+
save_path = Path(save_path)
|
|
154
|
+
save_path.write_text("fake_image")
|
|
155
|
+
saved_paths.append(save_path)
|
|
156
|
+
|
|
157
|
+
run.save_plot(fake_plot, data)
|
|
158
|
+
assert len(saved_paths) == 1
|
|
159
|
+
assert saved_paths[0].exists()
|
|
160
|
+
|
|
161
|
+
def test_load_data_missing_raises(self, exp):
|
|
162
|
+
run = exp.run({"A": 99.0})
|
|
163
|
+
with pytest.raises(FileNotFoundError):
|
|
164
|
+
run.load_data()
|
|
165
|
+
|
|
166
|
+
def test_load_params_missing_raises(self, exp):
|
|
167
|
+
run = exp.run({"A": 99.0})
|
|
168
|
+
with pytest.raises(FileNotFoundError):
|
|
169
|
+
run.load_params()
|
|
170
|
+
|
|
171
|
+
def test_context_manager_success(self, exp):
|
|
172
|
+
data = np.arange(5, dtype=float)
|
|
173
|
+
with exp.run({"A": 1.0}) as run:
|
|
174
|
+
run.save(data)
|
|
175
|
+
assert not run.is_failed()
|
|
176
|
+
|
|
177
|
+
def test_context_manager_failure(self, exp):
|
|
178
|
+
with pytest.raises(RuntimeError):
|
|
179
|
+
with exp.run({"A": 2.0}) as run:
|
|
180
|
+
raise RuntimeError("simulation exploded")
|
|
181
|
+
assert run.is_failed()
|
|
182
|
+
info = run.load_failure()
|
|
183
|
+
assert info["error"] == "RuntimeError"
|
|
184
|
+
assert "simulation exploded" in info["message"]
|
|
185
|
+
|
|
186
|
+
def test_is_failed_false_by_default(self, exp):
|
|
187
|
+
run = exp.run({"A": 3.0})
|
|
188
|
+
assert not run.is_failed()
|
|
189
|
+
|
|
190
|
+
def test_overwrite_warning(self, exp):
|
|
191
|
+
exp.run({"A": 0.5, "beta": 1.0})
|
|
192
|
+
with warnings.catch_warnings(record=True) as w:
|
|
193
|
+
warnings.simplefilter("always")
|
|
194
|
+
exp.run({"A": 0.5, "beta": 1.0})
|
|
195
|
+
assert len(w) == 1
|
|
196
|
+
assert "already exists" in str(w[0].message)
|
|
197
|
+
|
|
198
|
+
def test_overwrite_no_warning(self, exp):
|
|
199
|
+
exp.run({"A": 0.5, "beta": 1.0})
|
|
200
|
+
with warnings.catch_warnings(record=True) as w:
|
|
201
|
+
warnings.simplefilter("always")
|
|
202
|
+
exp.run({"A": 0.5, "beta": 1.0}, overwrite=True)
|
|
203
|
+
assert len(w) == 0
|
|
204
|
+
|
|
205
|
+
|
|
206
|
+
# ---------------------------------------------------------------------------
|
|
207
|
+
# Experiment
|
|
208
|
+
# ---------------------------------------------------------------------------
|
|
209
|
+
|
|
210
|
+
class TestExperiment:
|
|
211
|
+
def test_name(self, exp):
|
|
212
|
+
assert exp.name == "test_exp"
|
|
213
|
+
|
|
214
|
+
def test_meta_file_created(self, exp):
|
|
215
|
+
assert (exp.path / "experiment.json").exists()
|
|
216
|
+
|
|
217
|
+
def test_load_exact(self, exp):
|
|
218
|
+
params = {"A": 0.5, "beta": 1.0}
|
|
219
|
+
run = exp.run(params)
|
|
220
|
+
run.save_params()
|
|
221
|
+
loaded = exp.load(params)
|
|
222
|
+
assert loaded.path == run.path
|
|
223
|
+
|
|
224
|
+
def test_load_missing_raises(self, exp):
|
|
225
|
+
with pytest.raises(FileNotFoundError):
|
|
226
|
+
exp.load({"A": 999.0})
|
|
227
|
+
|
|
228
|
+
def test_query_subset(self, exp):
|
|
229
|
+
for beta in [1.0, 2.0]:
|
|
230
|
+
for A in [0.5, 1.0]:
|
|
231
|
+
r = exp.run({"A": A, "beta": beta})
|
|
232
|
+
r.save_params()
|
|
233
|
+
results = exp.query({"beta": 1.0})
|
|
234
|
+
assert len(results) == 2
|
|
235
|
+
assert all(r.load_params()["beta"] == 1.0 for r in results)
|
|
236
|
+
|
|
237
|
+
def test_query_no_match(self, exp):
|
|
238
|
+
exp.run({"A": 0.5}).save_params()
|
|
239
|
+
assert exp.query({"A": 999.0}) == []
|
|
240
|
+
|
|
241
|
+
def test_all_runs(self, exp):
|
|
242
|
+
for i in range(3):
|
|
243
|
+
exp.run({"i": i}).save_params()
|
|
244
|
+
runs = exp.all_runs()
|
|
245
|
+
assert len(runs) == 3
|
|
246
|
+
|
|
247
|
+
def test_repr(self, exp):
|
|
248
|
+
assert "test_exp" in repr(exp)
|
|
249
|
+
|
|
250
|
+
|
|
251
|
+
# ---------------------------------------------------------------------------
|
|
252
|
+
# TalosDB
|
|
253
|
+
# ---------------------------------------------------------------------------
|
|
254
|
+
|
|
255
|
+
class TestTalosDB:
|
|
256
|
+
def test_creates_directory(self, tmp_path):
|
|
257
|
+
path = tmp_path / "newdb"
|
|
258
|
+
db = TalosDB(path)
|
|
259
|
+
assert db.path.exists()
|
|
260
|
+
|
|
261
|
+
def test_experiment_creates_subdir(self, db):
|
|
262
|
+
exp = db.experiment("alpha")
|
|
263
|
+
assert (db.path / "alpha").is_dir()
|
|
264
|
+
|
|
265
|
+
def test_experiment_auto_name(self, db):
|
|
266
|
+
exp = db.experiment()
|
|
267
|
+
assert exp.path.exists()
|
|
268
|
+
|
|
269
|
+
def test_list_experiments(self, db):
|
|
270
|
+
db.experiment("a")
|
|
271
|
+
db.experiment("b")
|
|
272
|
+
db.experiment("c")
|
|
273
|
+
names = db.list_experiments()
|
|
274
|
+
assert "a" in names
|
|
275
|
+
assert "b" in names
|
|
276
|
+
assert "c" in names
|
|
277
|
+
|
|
278
|
+
def test_delete_experiment_requires_confirm(self, db):
|
|
279
|
+
db.experiment("to_delete")
|
|
280
|
+
with pytest.raises(ValueError, match="confirm=True"):
|
|
281
|
+
db.delete_experiment("to_delete")
|
|
282
|
+
|
|
283
|
+
def test_delete_experiment(self, db):
|
|
284
|
+
db.experiment("to_delete")
|
|
285
|
+
db.delete_experiment("to_delete", confirm=True)
|
|
286
|
+
assert "to_delete" not in db.list_experiments()
|
|
287
|
+
|
|
288
|
+
def test_delete_experiment_missing_raises(self, db):
|
|
289
|
+
with pytest.raises(FileNotFoundError):
|
|
290
|
+
db.delete_experiment("ghost", confirm=True)
|
|
291
|
+
|
|
292
|
+
def test_tilde_expansion(self, monkeypatch, tmp_path):
|
|
293
|
+
monkeypatch.setenv("HOME", str(tmp_path))
|
|
294
|
+
db = TalosDB("~/mydb")
|
|
295
|
+
assert db.path.exists()
|
|
296
|
+
assert str(tmp_path) in str(db.path)
|
|
297
|
+
|
|
298
|
+
def test_repr(self, db):
|
|
299
|
+
assert "TalosDB" in repr(db)
|