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

Bug fix and tests for to_graphviz with Diagram objects #850

Merged
merged 4 commits into from
Oct 3, 2023

Conversation

slwu89
Copy link
Member

@slwu89 slwu89 commented Sep 16, 2023

The method to_graphviz_property_graph(d::Diagram; kw...) would previous fail if given a diagram with anonymous ob/homs in the indexing category. It now checks if the graph associated to the indexing category is a NamedGraph, if so it will use the names in vname, and otherwise empty names are used. This PR also adds tests for both the named and anonymous case, as it seems to_graphviz for diagrams was not previously being tested.

@slwu89 slwu89 marked this pull request as draft October 1, 2023 22:11
@slwu89
Copy link
Member Author

slwu89 commented Oct 1, 2023

@epatters I've rebased this after #858. Before I request a review, I have a question. As part of this, I am trying to extend the graph method defined in FinCats to accept a Presentation and make a NamedGraph. This will help simplify the graphviz code, and its also nice for other non graphics related programming.

However, I cannot figure out why when I uncomment this line to import the method https://github.com/slwu89/Catlab.jl/blob/graphviz-diagram/src/graphs/NamedGraphs.jl#L14, Julia complains with the error ERROR: LoadError: UndefVarError: `CategoricalAlgebra` not defined. Do you have any idea how I can extend that method in the named graphs module?

@epatters
Copy link
Member

epatters commented Oct 2, 2023

The reason is that CategoricalAlgebra is loaded in Catlab after Graphs, i.e., CategoricalAlgebra depends on Graphs, not the other around. So any interoperability layer between the two should go in CategoricalAlgebra.

In fact, I think the function you are looking for is already available on main: https://github.com/slwu89/Catlab.jl/blob/54b8e25ef13a7e125f36e687f02c58b9f1646cd1/src/categorical_algebra/FinCats.jl#L113

@slwu89
Copy link
Member Author

slwu89 commented Oct 2, 2023

Ah, thanks @epatters for clearing that up!

Yes I did see that graph method, but I think it only works for a FinCator a FinCat presented by an actual graph object. I was interested in implementing something that would work for a Presentation, like:

julia> graph(SchWeightedGraph)
ERROR: MethodError: no method matching graph(::Presentation{ThSchema, Symbol})

But I think that should wait for another PR and this one should just get those tests for visualizing a diagram in.

@epatters
Copy link
Member

epatters commented Oct 2, 2023

IIRC, you can just wrap the Presentation in a FinCat, i.e., call graph(FinCat(my_presentation)).

@slwu89 slwu89 changed the title to_graphviz for diagrams with anonymous objects Fmplement tests for to_graphviz with Diagram objects Oct 2, 2023
@slwu89 slwu89 changed the title Fmplement tests for to_graphviz with Diagram objects Implement tests for to_graphviz with Diagram objects Oct 2, 2023
@slwu89 slwu89 marked this pull request as ready for review October 2, 2023 23:51
@AlgebraicJulia AlgebraicJulia deleted a comment from github-actions bot Oct 3, 2023
@epatters epatters changed the title Implement tests for to_graphviz with Diagram objects Bug fix and tests for to_graphviz with Diagram objects Oct 3, 2023
Copy link
Member

@epatters epatters left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, thanks Sean!

@@ -93,7 +93,7 @@ function to_graphviz_property_graph(d::Diagram; kw...)
pg = to_graphviz_property_graph(g; kw...)
for v in vertices(g)
tᵥ = ob_map(d, v)
labels = has_vertex_names(g) ? [tᵥ] : [vertex_name(g,v), tᵥ]
labels = has_vertex_names(g) ? [vertex_name(g,v), tᵥ] : [tᵥ]
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Haha, this is why it's good to have tests. Thanks!

@epatters epatters merged commit 8563949 into AlgebraicJulia:main Oct 3, 2023
13 checks passed
@slwu89 slwu89 deleted the graphviz-diagram branch October 3, 2023 00:58
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants