from ergodic import identify_effect
from ergodic.graph import cpdag, dag, mixed

# 1. Four single graphs in which X may cause Y.
worlds = {
    "measured confounder": dag(["Z -> X", "Z -> Y", "X -> Y"]),
    "hidden confounder, mediator": dag(["U -> X", "U -> Y", "X -> M", "M -> Y"], latent=["U"]),
    "hidden confounder, instrument": dag(["Z -> X", "U -> X", "U -> Y", "X -> Y"], latent=["U"]),
    "hidden confounder only": dag(["U -> X", "U -> Y", "X -> Y"], latent=["U"]),
}
for name, graph in worlds.items():
    result = identify_effect(graph, "X", "Y")
    print(f"{name}: {result}")

# 2. The hedge explains why the last one fails.
print(result.hedge)

# 3. Two equivalence classes, as discovery returns them.
for graph in [cpdag(["Z --- X", "X --> Y", "W --> Y"]), cpdag(["Z --- X", "X --- Y"])]:
    result = identify_effect(graph, "X", "Y")
    print(bool(result), result.strategy, sorted(result.adjustment_set or []))

# 4. A graph without a verified face is refused, with advice.
try:
    identify_effect(mixed(["Z -> X", "Z -> Y", "X -> Y"]), "X", "Y")
except ValueError as error:
    print(error)
