Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 6 additions & 2 deletions src/tnfr/operators.py
Original file line number Diff line number Diff line change
Expand Up @@ -256,7 +256,11 @@ def _epi_items():

def aplicar_remesh_si_estabilizacion_global(G, pasos_estables_consecutivos: Optional[int] = None) -> None:
# Ventanas y umbrales
w_estab = int(G.graph.get("REMESH_STABILITY_WINDOW", DEFAULTS["REMESH_STABILITY_WINDOW"]))
w_estab = (
pasos_estables_consecutivos
if pasos_estables_consecutivos is not None
else int(G.graph.get("REMESH_STABILITY_WINDOW", DEFAULTS["REMESH_STABILITY_WINDOW"]))
)
frac_req = float(G.graph.get("FRACTION_STABLE_REMESH", DEFAULTS["FRACTION_STABLE_REMESH"]))
req_extra = bool(G.graph.get("REMESH_REQUIRE_STABILITY", DEFAULTS["REMESH_REQUIRE_STABILITY"]))
min_sync = float(G.graph.get("REMESH_MIN_PHASE_SYNC", DEFAULTS["REMESH_MIN_PHASE_SYNC"]))
Expand Down Expand Up @@ -293,4 +297,4 @@ def aplicar_remesh_si_estabilizacion_global(G, pasos_estables_consecutivos: Opti
return
# 4) Aplicar y registrar
aplicar_remesh_red(G)
G.graph["_last_remesh_step"] = step_idx
G.graph["_last_remesh_step"] = step_idx
34 changes: 34 additions & 0 deletions tests/test_remesh.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
import sys
from pathlib import Path

import networkx as nx

# Asegurar que src esté en el path para importar tnfr
ROOT = Path(__file__).resolve().parents[1]
sys.path.insert(0, str(ROOT / "src"))

from tnfr.constants import attach_defaults
from tnfr.operators import aplicar_remesh_si_estabilizacion_global


def test_aplicar_remesh_usa_parametro_personalizado():
G = nx.Graph()
G.add_node(0)
attach_defaults(G)

# Historial suficiente para el parámetro personalizado
hist = G.graph.setdefault("history", {})
hist["stable_frac"] = [1.0, 1.0, 1.0]

# Historial de EPI necesario para aplicar_remesh_red
tau = G.graph["REMESH_TAU"]
G.graph["_epi_hist"] = [{0: 0.0} for _ in range(tau + 1)]

# Sin parámetro personalizado no se debería activar
aplicar_remesh_si_estabilizacion_global(G)
assert "_last_remesh_step" not in G.graph

# Con parámetro personalizado se activa con 3 pasos estables
aplicar_remesh_si_estabilizacion_global(G, pasos_estables_consecutivos=3)
assert G.graph["_last_remesh_step"] == len(hist["stable_frac"])