def METHOD_NAME(filename):
    modules: dict[str, int] = {}
    def _register_module(name):
        if modules.get(name) is not None:
            return
        modules[name] = len(modules)
    with open(filename, "w") as f:
        f.write("digraph {\n")
        for from_name, to_name in observations:
            _register_module(from_name)
            _register_module(to_name)
        for module_name, id in sorted(modules.items(), key=lambda x: x[1]):
            f.write(f'  {id} [label="{module_name}" color="red"]\n')
        for pair in observations:
            f.write(f'  {modules[pair[0]]} -> {modules[pair[1]]} [color="gray"]\n')
        f.write("}\n")