From 39945e8821a464fa41ba35fc42237299c65e5997 Mon Sep 17 00:00:00 2001 From: Cedric Date: Tue, 28 Apr 2026 07:27:08 +0000 Subject: [PATCH] feat: helper to visualize adjacency in a file --- tests/test_adjacency.py | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/tests/test_adjacency.py b/tests/test_adjacency.py index 5c33038..5e8a129 100644 --- a/tests/test_adjacency.py +++ b/tests/test_adjacency.py @@ -1,5 +1,6 @@ import jax.numpy as jnp import pytest +import numpy as np from brittle_star_project.trainers.PPOTrainer import build_adjacency, MorphMode @@ -71,6 +72,20 @@ def test_segment_structure(): assert adj[arm, first_seg] == 1 assert adj[first_seg, arm] == 1 + save_adj(adj) + + +def save_adj(adj, name="adjacency_debug.txt"): + a = np.array(adj) + + with open(name, "w") as f: + f.write("\nAdjacency matrix:\n") + f.write(" " + " ".join([f"{i:2d}" for i in range(a.shape[0])]) + "\n") + + for i, row in enumerate(a): + line = f"{i:2d} " + " ".join(["█" if x > 0 else "." for x in row]) + f.write(line + "\n") + def test_no_isolated_nodes(): adj = build_adjacency([4, 4, 4, 4, 4], MorphMode.SEGMENT)