#!/usr/bin/env python3
"""Debug isomorphism behavior."""

import networkx as nx
from networkx.algorithms import isomorphism

# Target graph with self-loop
target = nx.DiGraph()
target.add_node('n1')
target.add_edge('n1', 'n1')  # self-loop

# Motif 1: Two different nodes (like ()-->())
motif1 = nx.DiGraph()
motif1.add_node('a')
motif1.add_node('b')
motif1.add_edge('a', 'b')

# Motif 2: Self-loop (like (n)-->(n))
motif2 = nx.DiGraph()
motif2.add_node('n')
motif2.add_edge('n', 'n')

print("=== Target graph (has self-loop) ===")
print(f"Nodes: {list(target.nodes())}")
print(f"Edges: {list(target.edges())}")
print()

print("=== Motif 1: Two different nodes (a)->(b) ===")
print(f"Nodes: {list(motif1.nodes())}")
print(f"Edges: {list(motif1.edges())}")
matcher1 = isomorphism.DiGraphMatcher(target, motif1)
matches1 = list(matcher1.subgraph_isomorphisms_iter())
print(f"Matches: {matches1}")
print(f"Expected: [] (injective mapping prevents a->n1, b->n1)")
print()

print("=== Motif 2: Self-loop (n)->(n) ===")
print(f"Nodes: {list(motif2.nodes())}")
print(f"Edges: {list(motif2.edges())}")
matcher2 = isomorphism.DiGraphMatcher(target, motif2)
matches2 = list(matcher2.subgraph_isomorphisms_iter())
print(f"Matches: {matches2}")
print(f"Expected: [{'n': 'n1'}] or similar")
