Skip to content

Commit f93ee7e

Browse files
ValerianReyclaude
andauthored
test: Move results folders inside tests/ subdirectories (#696)
* `static_plotter` now saves to `tests/plots/results/` instead of `images/` at the repo root * Profiler now saves to `tests/profiling/results/` instead of `traces/` at the repo root * Renamed `TRACES_DIR` → `PROFILING_RESULTS_DIR` and added `TESTS_DIR` in `tests/paths.py` * Updated `.gitignore` to match the new locations Co-authored-by: Claude Sonnet 4.6 <noreply@anthropic.com>
1 parent ad000c2 commit f93ee7e

10 files changed

Lines changed: 33 additions & 27 deletions

File tree

‎.gitignore‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ CLAUDE.md
33
.claude/
44

55
# Profiling results
6-
traces/
6+
tests/profiling/results/
77

88
# Trajectories results
99
tests/trajectories/results/
@@ -18,7 +18,7 @@ uv.lock
1818
.idea/
1919

2020
# Generated images
21-
images/
21+
tests/plots/results/
2222

2323
# Byte-compiled / optimized / DLL files
2424
__pycache__/

‎tests/paths.py‎

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,7 @@
11
from pathlib import Path
22

33
TORCHJD_DIR = Path(__file__).parent.parent
4-
TRACES_DIR = TORCHJD_DIR / "traces"
4+
TESTS_DIR = Path(__file__).parent
5+
PLOTS_RESULTS_DIR = TESTS_DIR / "plots" / "results"
6+
PROFILING_RESULTS_DIR = TESTS_DIR / "profiling" / "results"
7+
TRAJECTORIES_RESULTS_DIR = TESTS_DIR / "trajectories" / "results"

‎tests/plots/static_plotter.py‎

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
1-
import os
2-
31
import torch
2+
from paths import PLOTS_RESULTS_DIR
43
from plotly import graph_objects as go
54

65
from plots._utils import (
@@ -268,14 +267,14 @@ def main(
268267
)
269268
fig.update_yaxes(range=[-0.1, 2.1], showgrid=False, zeroline=False, visible=False)
270269

271-
os.makedirs("images/", exist_ok=True)
272-
fig.write_image(f"images/{filename}.pdf")
270+
PLOTS_RESULTS_DIR.mkdir(exist_ok=True)
271+
fig.write_image(PLOTS_RESULTS_DIR / f"{filename}.pdf")
273272
# Alternative: use .svg here and then convert to pdf using rsvg-convert. Install
274273
# [rsvg-convert](https://manpages.ubuntu.com/manpages/bionic/man1/rsvg-convert.1.html) and run:
275274
# `rsvg-convert -f pdf -o filename.pdf filename.svg`
276275
# To do that on all files at ones, run:
277276
# ```
278-
# for file in images/*.svg; do rsvg-convert -f pdf -o "${file%.svg}.pdf" "$file"; done
277+
# for file in tests/plots/results/*.svg; do rsvg-convert -f pdf -o "${file%.svg}.pdf" "$file"; done
279278
# ```
280279

281280

‎tests/profiling/plot_memory_timeline.py‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
matplotlib.use("Agg") # Use non-GUI backend to avoid tkinter dependency
1414
import matplotlib.pyplot as plt
1515
import numpy as np
16-
from paths import TRACES_DIR
16+
from paths import PROFILING_RESULTS_DIR
1717

1818

1919
@dataclass
@@ -63,7 +63,7 @@ def plot_memory_timelines(experiment: str, folders: list[str]) -> None:
6363
cpu_timelines = []
6464
cuda_timelines = []
6565
for folder in folders:
66-
path = TRACES_DIR / folder / f"{experiment}.json"
66+
path = PROFILING_RESULTS_DIR / folder / f"{experiment}.json"
6767
cpu_timeline, cuda_timeline = extract_memory_timelines(path)
6868
cpu_timelines.append(cpu_timeline)
6969
cuda_timelines.append(cuda_timeline)
@@ -104,7 +104,7 @@ def plot_memory_timelines(experiment: str, folders: list[str]) -> None:
104104

105105
fig.tight_layout()
106106

107-
output_dir = Path(TRACES_DIR / "memory_timelines")
107+
output_dir = Path(PROFILING_RESULTS_DIR / "memory_timelines")
108108
output_dir.mkdir(parents=True, exist_ok=True)
109109
output_path = output_dir / f"{experiment}.png"
110110
print(f"\nSaving plot to: {output_path}")

‎tests/profiling/run_profiler.py‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323
)
2424
from utils.tensors import make_inputs_and_targets
2525

26-
from tests.paths import TRACES_DIR
26+
from tests.paths import PROFILING_RESULTS_DIR
2727
from torchjd.aggregation import UPGrad, UPGradWeighting
2828
from torchjd.autogram import Engine
2929

@@ -98,7 +98,7 @@ def _save_and_print_trace(
9898
batch_size: int,
9999
) -> None:
100100
filename = f"{factory}-bs{batch_size}-{DEVICE.type}.json"
101-
output_dir = TRACES_DIR / method_name
101+
output_dir = PROFILING_RESULTS_DIR / method_name
102102
output_dir.mkdir(parents=True, exist_ok=True)
103103
trace_path = output_dir / filename
104104

‎tests/trajectories/_paths.py‎

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,23 @@
11
from pathlib import Path
22

3-
RESULTS_DIR = Path(__file__).parent / "results"
3+
from tests.paths import TRAJECTORIES_RESULTS_DIR
44

55

66
def get_params_dir(objective_key: str) -> Path:
7-
return RESULTS_DIR / objective_key / "X"
7+
return TRAJECTORIES_RESULTS_DIR / objective_key / "X"
88

99

1010
def get_values_dir(objective_key: str) -> Path:
11-
return RESULTS_DIR / objective_key / "Y"
11+
return TRAJECTORIES_RESULTS_DIR / objective_key / "Y"
1212

1313

1414
def get_param_plots_dir(objective_key: str) -> Path:
15-
return RESULTS_DIR / objective_key / "param_plots"
15+
return TRAJECTORIES_RESULTS_DIR / objective_key / "param_plots"
1616

1717

1818
def get_value_plots_dir(objective_key: str) -> Path:
19-
return RESULTS_DIR / objective_key / "value_plots"
19+
return TRAJECTORIES_RESULTS_DIR / objective_key / "value_plots"
2020

2121

2222
def get_distance_to_pf_plots_dir(objective_key: str) -> Path:
23-
return RESULTS_DIR / objective_key / "distance_to_pf"
23+
return TRAJECTORIES_RESULTS_DIR / objective_key / "distance_to_pf"

‎tests/trajectories/optimize.py‎

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
import numpy as np
1919
import torch
2020

21+
from tests.paths import TRAJECTORIES_RESULTS_DIR
2122
from torchjd.aggregation import Stateful
2223
from trajectories._constants import (
2324
AGGREGATORS,
@@ -29,7 +30,7 @@
2930
OBJECTIVES,
3031
)
3132
from trajectories._optimization import optimize
32-
from trajectories._paths import RESULTS_DIR, get_params_dir, get_values_dir
33+
from trajectories._paths import get_params_dir, get_values_dir
3334

3435
warnings.filterwarnings("ignore")
3536

@@ -88,7 +89,7 @@ def main() -> None:
8889
"learning_rates": learning_rates,
8990
"initial_points": initial_points,
9091
}
91-
with open(RESULTS_DIR / objective_key / "metadata.json", "w") as f:
92+
with open(TRAJECTORIES_RESULTS_DIR / objective_key / "metadata.json", "w") as f:
9293
json.dump(metadata, f)
9394

9495
for aggregator_key in aggregator_keys:

‎tests/trajectories/plot_distance_to_pf.py‎

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,10 @@
1515
import numpy as np
1616
import torch
1717

18+
from tests.paths import TRAJECTORIES_RESULTS_DIR
1819
from trajectories._constants import AGGREGATOR_ORDER, AGGREGATORS, LATEX_NAMES, OBJECTIVES
1920
from trajectories._pareto_utils import make_2d_pf_distance_fn
20-
from trajectories._paths import RESULTS_DIR, get_distance_to_pf_plots_dir, get_values_dir
21+
from trajectories._paths import get_distance_to_pf_plots_dir, get_values_dir
2122
from trajectories._plotters import (
2223
MultiEvolutionPlotter,
2324
SquareBoxAspectSetter,
@@ -51,7 +52,7 @@ def main() -> None:
5152
args = parser.parse_args()
5253
objective_key = args.objective
5354

54-
with open(RESULTS_DIR / objective_key / "metadata.json") as f:
55+
with open(TRAJECTORIES_RESULTS_DIR / objective_key / "metadata.json") as f:
5556
metadata = json.load(f)
5657

5758
values_dir = get_values_dir(objective_key)

‎tests/trajectories/plot_params.py‎

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
import matplotlib.pyplot as plt
1515
import numpy as np
1616

17+
from tests.paths import TRAJECTORIES_RESULTS_DIR
1718
from trajectories._constants import (
1819
AGGREGATOR_ORDER,
1920
AGGREGATORS,
@@ -24,7 +25,7 @@
2425
from trajectories._objectives import ElementWiseQuadratic, WithSPSMappingMixin
2526
from trajectories._optimization import compute_gradient_cosine_similarities
2627
from trajectories._pareto_utils import sample_2d_spss
27-
from trajectories._paths import RESULTS_DIR, get_param_plots_dir, get_params_dir
28+
from trajectories._paths import get_param_plots_dir, get_params_dir
2829
from trajectories._plotters import (
2930
AxesPlotter,
3031
ContentLimAdjuster,
@@ -61,7 +62,7 @@ def main() -> None:
6162
args = parser.parse_args()
6263
objective_key = args.objective
6364

64-
with open(RESULTS_DIR / objective_key / "metadata.json") as f:
65+
with open(TRAJECTORIES_RESULTS_DIR / objective_key / "metadata.json") as f:
6566
metadata = json.load(f)
6667

6768
params_dir = get_params_dir(objective_key)

‎tests/trajectories/plot_values.py‎

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
import matplotlib.pyplot as plt
1515
import numpy as np
1616

17+
from tests.paths import TRAJECTORIES_RESULTS_DIR
1718
from trajectories._constants import (
1819
AGGREGATOR_ORDER,
1920
AGGREGATORS,
@@ -23,7 +24,7 @@
2324
)
2425
from trajectories._objectives import WithSPSMappingMixin
2526
from trajectories._pareto_utils import compute_normalized_2d_pf_distances, sample_2d_pf
26-
from trajectories._paths import RESULTS_DIR, get_value_plots_dir, get_values_dir
27+
from trajectories._paths import get_value_plots_dir, get_values_dir
2728
from trajectories._plotters import (
2829
ContentLimAdjuster,
2930
HeatmapPlotter,
@@ -58,7 +59,7 @@ def main() -> None:
5859
args = parser.parse_args()
5960
objective_key = args.objective
6061

61-
with open(RESULTS_DIR / objective_key / "metadata.json") as f:
62+
with open(TRAJECTORIES_RESULTS_DIR / objective_key / "metadata.json") as f:
6263
metadata = json.load(f)
6364

6465
values_dir = get_values_dir(objective_key)

0 commit comments

Comments
 (0)