8000 Ability to export TLC state graph · Issue #639 · tlaplus/tlaplus · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

Ability to export TLC state graph #639

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

Open
will62794 opened this issue Jun 26, 2021 · 7 comments
Open

Ability to export TLC state graph #639

will62794 opened this issue Jun 26, 2021 · 7 comments
Labels
enhancement Lets change things for the better help wanted We need your help TLA+ Foundation Funding Tools The command line tools - TLC, SANY, ...

Comments

@will62794
Copy link
Contributor
will62794 commented Jun 26, 2021

In some cases it would be helpful to have the ability to export the state graph generated by TLC in an easily parseable format (e.g. JSON) for use by other tools, scripts, applications, etc. This could presumably be built as a straightforward implementation of the StateWriter interface. I have implemented a minimal prototype of this, using the previously developed functionality from the Json community module.

@lemmy lemmy added enhancement Lets change things for the better Tools The command line tools - TLC, SANY, ... help wanted We need your help labels Jun 26, 2021
@lemmy
Copy link
Member
lemmy commented Jun 26, 2021

On the command line, this could be made available as another sub-parameter of -dump, i.e., -dump json or -dump json,dot if the GraphViz output is requested as well.

Who is going to finish and create a PR?

@pfeodrippe
Copy link
Contributor

Great, @will62794! Are you working on this? I have created a state writer to output a Transit file (EDN on Json) at https://github.com/pfeodrippe/recife/blob/dfs/src/recife/core.clj#L788, it would indeed help a lot with scripts and tooling (I'm driving implementation code from it, it's awesome!), I'm just skeptical about outputting JSON as it does not retain some types (like sets).

Do you have some preferred idea about the structure of the generated file? Want to see if it matches mine and if I'm missing something.

@jonesmartins
Copy link
Contributor
jonesmartins commented Dec 30, 2021

@pfeodrippe
I suggest JSON dump files not to be too far from DOT files:

nodes: {
 0: "/\ a = 1 /\ b = 1",
 1: "/\ a = 2 /\ b = 1",
 2: "/\ a = 1 /\ b = 2",
 3: "/\ a = 2 /\ b = 2"
},
edges: {
  "IncreaseOne": [ (0, 1), (0, 2) ],
  "IncreaseBoth": [ (0, 3) ]
}```

@lemmy
Copy link
Member
lemmy commented Dec 30, 2021

What is missing from https://graphviz.org/docs/outputs/json/ that converting TLC's dot output to json is not feasible?

@jonesmartins
Copy link
Contributor
jonesmartins commented Dec 30, 2021

My argument would be for simplicity.

The closest generated JSON format I had in mind when converting from dot was dot_json. I still believe we'd be simplifying the output by using a separate tool instead of dot. Compare what TLC needs with all of DOT's options. State graphs always have nodes with the same rank, are always digraphs, etc.

I tested dot -Tdot_json after running Leader.tla from "Real Time is Really Simple". It was the first "moderately-sized" state space I found. It's only useful for calculating file size.

Leader.tla has 3 actions and it generated 2393 states and 8340 edges with my configuration file. The generated dot_json JSON file had 43 subgraphs (I don't know why) and was 79 thousand lines long.

Including line breaks, my suggestion would bring this value down to:
node_str_overhead (always 2 lines) + nodes + edges_str_overhead (always 2 lines) + action_str_overhead (2 lines per action) + actions =
= 2 + 2393 + 2 + 2 * 8340 + 8340 = 27417.
This is almost 3 times less...

In my previous example: 4 nodes, 3 actions gave a 2 + 4 + 2 + 4 + 3 = 15 line file.

nodes: {
 0: "/\ a = 1 /\ b = 1",
 1: "/\ a = 2 /\ b = 1",
 2: "/\ a = 1 /\ b = 2",
 3: "/\ a = 2 /\ b = 2"
},
edges: {
  "IncreaseOne": [ 
    (0, 1), 
    (0, 2)
  ],
  "IncreaseBoth": [ 
    (0, 3)
  ]
}

Pros:

  • Smaller file;
  • Simpler format, easily parsed compared to dot_json alternative;

Cons:

  • Implementing a new feature;
  • Doesn't include colors or legends;
  • Very specific to state graphs;

Maybe other people have better suggestions?

@lemmy
Copy link
Member
lemmy commented Dec 30, 2021

When I added dot support, I didn't bother to remove redundant nodes and edges assuming the overhead doesn't matter for small graphs that can reasonably be rendered. If the file size is an issue, I'd suggest first improving the current implementation.
Ranking could also be made configurable similar to actionnames and the legend.

Anyway, it shouldn't be difficult to also add a json printer given that a json lib is already part of TLC, and state graphing amounts to implementing one or two interfaces.

@smheidrich
Copy link

In case anyone else comes across this issue and prefers a quick workaround over recompiling with the patch linked above, here is a small Python script to transform the output of dot -Tjson (as suggested in #639 (comment)) applied to a state graph dot file into a JSON format that's easier to work with: tlaplus-dot-json-to-reasonable-json.py (README)

@lemmy lemmy changed the title Ability to export TLC state graph in JSON format Ability to export TLC state graph Nov 12, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement Lets change things for the better help wanted We need your help TLA+ Foundation Funding Tools The command line tools - TLC, SANY, ...
Development

No branches or pull requests

5 participants
0