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

Hypergraph JSON de/serialisation #259

Open
toumix opened this issue Jan 12, 2024 · 4 comments
Open

Hypergraph JSON de/serialisation #259

toumix opened this issue Jan 12, 2024 · 4 comments

Comments

@toumix
Copy link
Collaborator

toumix commented Jan 12, 2024

DisCoPy already has JSON de/serialisation for the Diagram class, see dumps and loads.

We need the same feature for the Hypergraph class.

@colltoaction
Copy link
Contributor

For example, AlgebraicJulia has several schemas that @epatters worked on here:

https://github.com/AlgebraicJulia/Catlab.jl/blob/main/src/wiring_diagrams/JSON.jl

Given the maturity of the Julia ecosystem I think this can be a great implementation advantage.

@toumix
Copy link
Collaborator Author

toumix commented Jan 12, 2024

Yes it would be nice to use the same convention as in Catlab!

One caveat though is that the schema you refer to only deals with monogamous hypergraphs (see issue #25), i.e. every wire has exactly two ports as endpoints whereas the hypergraphs in DisCoPy have spiders which can connect to an arbitrary number of ports.

@colltoaction
Copy link
Contributor

What is the goal of this issue? Is it interoperability? Because just to get a JSON file an option is to take the DiGraph and export using NetworkX:

discopy/discopy/hypergraph.py

Lines 1094 to 1098 in ec3c570

def to_graph(self) -> Graph:
"""
Translate a hypergraph into a labeled graph with nodes for inputs,
outputs, boxes, domain, codomain and spiders.
"""

@toumix toumix changed the title Hypergraph JSON Hypergraph JSON de/serialisation Jan 15, 2024
@toumix
Copy link
Collaborator Author

toumix commented Jan 16, 2024

The goal of this issue is de/serialisation so that a Hypergraph can e.g. be stored on the disk, sent over the network and loaded somewhere else by another DisCoPy script. Interoperability would come as a second step, but for now there is no established format to serialise hypergraph representations of string diagrams.

This could be done by composing the existing methods to_ and from_graph with the existing NetworkX serialisation as you suggest, but AFAIK the label of the boxes would be lost in the process.

The easiest way would be to simply extend the to_ and from_tree methods to translate hypergraphs into JSON and back, directly translating the attributes dom, cod, boxes, wires, spider_types.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants