Skip to content
Snippets Groups Projects
Commit a654e73e authored by dgelessus's avatar dgelessus
Browse files

Use new ProB 2 method for dot visualization without manual temp file

parent df4aa861
Branches
Tags
No related merge requests found
Pipeline #50786 passed
%% Cell type:code id: tags:
``` prob
:help :dot
```
%% Output
```
:dot COMMAND [FORMULA]
```
Execute and show a dot visualisation.
The following dot visualisation commands are available:
* `machine_hierarchy` - Machine Hierarchy: Shows the machine hierarchy of a classical B model
* `operations` - Operation Call Graph: Shows the call graph of a classical B model
* `event_hierarchy` - Event Hierarchy: Shows the event hierarchy of an Event-B model
* `state_space` - State Space: Show state space
* `state_space_sfdp` - State Space (Fast): Show state space (fast)
* `current_state` - Current State in State Space: Show current state and successors in state space
* `history` - Path to Current State: Show a path leading to current state
* `signature_merge` - Signature Merge: Show signature-merged reduced state space
* `dfa_merge` - DFA Merge: Show state space as deterministic automaton (DFA)
* `transition_diagram` - State Space Expression Projection...: Project state space onto expression values and show transition diagram
* `enable_graph` - Enable Graph: Show enabling graph of events
* `state_as_graph` - Current State as Graph: Show values in current state as a graph
* `custom_graph` - Customized Current State as Graph: Show values in current state as a graph using CUSTOM_GRAPH_EDGES
* `expr_as_graph` - (Relational) Expression as Graph...: Show (relational) expression value as a graph
* `formula_tree` - Custom Predicate/Expression Formula Tree...: Show predicate/expressions and sub-formulas as a tree
* `invariant` - Invariant Formula Tree: Show invariant as a formula tree
* `properties` - Properties Formula Tree: Show properties as a formula tree
* `assertions` - Assertions Formula Tree: Show assertions as a formula tree
* `deadlock` - Deadlock Formula Tree: Show deadlocking status as a formula tree
* `goal` - Goal Formula Tree: Show GOAL as a formula tree
* `dependence_graph` - Dependence Graph: Show dependence graph of events
* `variable_modification_graph` - Variable Read/Write Graph: Show variable modification by operations and reading in guards
* `definitions` - Definitions Graph: Show dependence graph of DEFINITIONS
* `predicate_dependency` - Predicate Dependency Graph...: Show dependence graph of conjuncts of a predicate
* `last_error` - Last Error Formula Tree: Show last error source as a formula tree
:dot COMMAND [FORMULA]
Execute and show a dot visualisation.
The following dot visualisation commands are available:
* `machine_hierarchy` - Machine Hierarchy: Shows the machine hierarchy of a classical B model
* `operations` - Operation Call Graph: Shows the call graph of a classical B model
* `event_hierarchy` - Event Hierarchy: Shows the event hierarchy of an Event-B model
* `state_space` - State Space: Show state space
* `state_space_sfdp` - State Space (Fast): Show state space (fast)
* `current_state` - Current State in State Space: Show current state and successors in state space
* `history` - Path to Current State: Show a path leading to current state
* `signature_merge` - Signature Merge: Show signature-merged reduced state space
* `dfa_merge` - DFA Merge: Show state space as deterministic automaton (DFA)
* `transition_diagram` - State Space Expression Projection...: Project state space onto expression values and show transition diagram
* `enable_graph` - Enable Graph: Show enabling graph of events
* `state_as_graph` - Current State as Graph: Show values in current state as a graph
* `custom_graph` - Customized Current State as Graph: Show values in current state as a graph using CUSTOM_GRAPH_EDGES
* `expr_as_graph` - (Relational) Expression as Graph...: Show (relational) expression value as a graph
* `formula_tree` - Custom Predicate/Expression Formula Tree...: Show predicate/expressions and sub-formulas as a tree
* `invariant` - Invariant Formula Tree: Show invariant as a formula tree
* `properties` - Properties Formula Tree: Show properties as a formula tree
* `assertions` - Assertions Formula Tree: Show assertions as a formula tree
* `deadlock` - Deadlock Formula Tree: Show deadlocking status as a formula tree
* `goal` - Goal Formula Tree: Show GOAL as a formula tree
* `dependence_graph` - Dependence Graph: Show dependence graph of events
* `variable_modification_graph` - Variable Read/Write Graph: Show variable modification by operations and reading in guards
* `definitions` - Definitions Graph: Show dependence graph of DEFINITIONS
* `predicate_dependency` - Predicate Dependency Graph...: Show dependence graph of conjuncts of a predicate
* `last_error` - Last Error Formula Tree: Show last error source as a formula tree
%% Cell type:code id: tags:
``` prob
:dot state_space
```
%% Output
<Dot visualization: state_space []>
%% Cell type:code id: tags:
``` prob
:init
```
%% Output
Machine initialised using operation 0: $initialise_machine()
Executed operation: INITIALISATION()
%% Cell type:code id: tags:
``` prob
:dot state_space
```
%% Output
<Dot visualization: state_space []>
%% Cell type:code id: tags:
``` prob
:dot invariant
```
%% Output
<Dot visualization: invariant []>
%% Cell type:code id: tags:
``` prob
:dot expr_as_graph {1|->2, 2|->3, 3|->1}
```
%% Output
<Dot visualization: expr_as_graph [{(1,2),(2,3),(3,1)}]>
%% Cell type:code id: tags:
``` prob
:dot expr_as_graph ("gt",{x,y|x:1..5 & y:1..5 & x>y},"half",{y,x|x:1..5 & y:1..5 & x+x=y})
```
%% Output
<Dot visualization: expr_as_graph [("gt",{x,y|x:1..5 & y:1..5 & x>y})]>
%% Cell type:code id: tags:
``` prob
:pref DOT_ENGINE=circo
```
%% Output
Preference changed: DOT_ENGINE = circo
%% Cell type:code id: tags:
``` prob
:dot expr_as_graph ("gt",{x,y|x:1..5 & y:1..5 & x>y},"half",{y,x|x:1..5 & y:1..5 & x+x=y})
```
%% Output
<Dot visualization: expr_as_graph [("gt",{x,y|x:1..5 & y:1..5 & x>y})]>
%% Cell type:code id: tags:
``` prob
:pref DOT_ENGINE=dot
```
%% Output
Preference changed: DOT_ENGINE = dot
%% Cell type:code id: tags:
``` prob
:dot formula_tree 1*2 + 3/4 = card({1, 2})
```
%% Output
<Dot visualization: formula_tree [1*2+3/4=card({1,2})]>
%% Cell type:markdown id: tags:
Local variables can be used in dot visualisation parameters.
%% Cell type:code id: tags:
``` prob
:let thing 1*2 + 3/4
```
%% Output
$2$
2
%% Cell type:code id: tags:
``` prob
:dot formula_tree thing = card({1, 2})
```
%% Output
<Dot visualization: formula_tree [thingthing=2thing=card({1,2})]>
......
package de.prob2.jupyter.commands;
import java.io.IOException;
import java.io.UncheckedIOException;
import java.nio.file.Files;
import java.nio.file.Path;
import java.util.Arrays;
import java.util.Collections;
import java.util.List;
import java.util.function.Supplier;
import java.util.stream.Collectors;
import java.util.stream.Stream;
import com.google.common.collect.ImmutableMap;
import com.google.inject.Inject;
......@@ -111,24 +107,13 @@ public final class DotCommand implements Command {
.findAny()
.orElseThrow(() -> new UserErrorException("No such dot command: " + command));
final Path outPath;
try {
outPath = Files.createTempFile(null, "svg");
} catch (final IOException e) {
throw new UncheckedIOException("Failed to create temp file", e);
}
// Provide source code (if any) to error highlighter
final Runnable execute = () -> dotCommand.visualizeAsSvgToFile(outPath, dotCommandArgs);
final Supplier<String> execute = () -> dotCommand.visualizeAsSvgToString(dotCommandArgs);
final String svg;
if (code != null) {
CommandUtils.withSourceCode(code, execute);
svg = CommandUtils.withSourceCode(code, execute);
} else {
execute.run();
}
final String svg;
try (final Stream<String> lines = Files.lines(outPath)) {
svg = lines.collect(Collectors.joining("\n"));
} catch (final IOException e) {
throw new UncheckedIOException("Failed to read dot output", e);
svg = execute.get();
}
final DisplayData result = new DisplayData(String.format("<Dot visualization: %s %s>", command, dotCommandArgs));
result.putSVG(svg);
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment