Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

nodes in graph not correctly accessed #64

Closed
YoelPH opened this issue Dec 19, 2023 · 1 comment
Closed

nodes in graph not correctly accessed #64

YoelPH opened this issue Dec 19, 2023 · 1 comment
Assignees
Labels
bug Something isn't working

Comments

@YoelPH
Copy link
Contributor

YoelPH commented Dec 19, 2023

I found another small issue originating from the fact that graph.nodes is not an object anymore but a dictionary.
In graph.py two functions: to_dict and get_mermaid both try to use self.nodes as an object:

    def to_dict(self) -> dict[tuple[str, str], set[str]]:
        """Returns graph representing this instance's nodes and egdes as dictionary."""
        res = {}
        for node in self.nodes:
            node_type = "tumor" if isinstance(node, Tumor) else "lnl"
            res[(node_type, node.name)] = {o.child.name for o in node.out}
        return res


    def get_mermaid(self) -> str:
        """Prints the graph in mermaid format.

        Example:

        >>> graph_dict = {
        ...    ("tumor", "T"): ["II", "III"],
        ...    ("lnl", "II"): ["III"],
        ...    ("lnl", "III"): [],
        ... }
        >>> graph = Representation(graph_dict)
        >>> graph.edge_params["spread_T_to_II"].set_param(0.1)
        >>> graph.edge_params["spread_T_to_III"].set_param(0.2)
        >>> graph.edge_params["spread_II_to_III"].set_param(0.3)
        >>> print(graph.get_mermaid())  # doctest: +NORMALIZE_WHITESPACE
        flowchart TD
            T-->|10%| II
            T-->|20%| III
            II-->|30%| III
        <BLANKLINE>
        """
        mermaid_graph = "flowchart TD\n"

        for idx, node in enumerate(self.nodes):
            for edge in self.nodes[idx].out:
                mermaid_graph += f"\t{node.name}-->|{edge.spread_prob:.0%}| {edge.child.name}\n"

        return mermaid_graph

This does not work anmymore. For get_mermaid for example we need to fix it like this:

        for idx, node in enumerate(self.nodes):
            for edge in self.nodes[node].out:
                mermaid_graph += f"\t{node}-->|{edge.spread_prob:.0%}| {edge.child.name}\n"

        return mermaid_graph

(idx would not be needed anymore)

@rmnldwg rmnldwg self-assigned this Dec 19, 2023
@rmnldwg rmnldwg added the bug Something isn't working label Dec 19, 2023
@rmnldwg rmnldwg changed the title Issue in graph.py - nodes are wrongly used nodes in graph not correctly accessed Dec 19, 2023
@rmnldwg
Copy link
Owner

rmnldwg commented Dec 19, 2023

Thanks for the catch! The issue should be fixed on the dev branch now 👍🏻

With that issue, I noticed that the automatic test discovery does not actually run the doctests. I fixed that too, which is nice.

@rmnldwg rmnldwg closed this as completed in ddba27a Feb 6, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants