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

Simplified json file format for graphs #281

Merged
merged 7 commits into from
Jan 22, 2025

Conversation

jvdwetering
Copy link
Collaborator

This fixes #243, #193 and means #123 can be closed as now all core features for multigraphs should just work.

The original json format was inherited from Quantomatic, which is no longer in development or used, so using this format has no added use. In this pull request I build a method to convert Graphs to dicts and back in a simple way. The format is as follows:

{version: int, #to be future proof in case we add new features, so we know how to load the format.
backend: str, #which backend the graph should be loaded
variable_types: dict[names,0|1],
name: str,
scalar: str representation of Scalar,
inputs: list[int],
outputs: list[int],
auto_simplify: bool, # to make multigraphs load the correct value for here and prevent parallel edges from being removed.
vertices: list[VertData],
edges: [source,target,edgetype]
}

The VertData is as follows:

VertData = {
id: int, # Specifies what the index is of the vertex so that we preserve all the indices when we save and load, implements #193 
t: VertexType,
pos: [float,float],
phase: str,
data: dict[str,Any], # Contains all the g.vdata(v,..)
is_ground: bool # Whether there is a 'ground' generator attached to this vertex. Only used in mixed quantum/classical vertices
}

Because the version is now remembered in the json, I interpret a lack of a version in the dict as meaning it was saved in the old format. The legacy code is still there and hence can still be loaded.

@jvdwetering jvdwetering merged commit 9697249 into master Jan 22, 2025
3 checks passed
@jvdwetering jvdwetering deleted the feature/new-graph-file-format branch January 22, 2025 15:24
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

Successfully merging this pull request may close these issues.

Saving/loading is broken for multigraphs
1 participant