Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
P
ProB 2 Jupyter Kernel
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Iterations
Requirements
Code
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Test cases
Artifacts
Deploy
Releases
Model registry
Operate
Environments
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Issue analytics
Insights
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
GitLab community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
general
stups
ProB 2 Jupyter Kernel
Commits
a654e73e
Commit
a654e73e
authored
4 years ago
by
dgelessus
Browse files
Options
Downloads
Patches
Plain Diff
Use new ProB 2 method for dot visualization without manual temp file
parent
df4aa861
Branches
Branches containing commit
Tags
Tags containing commit
No related merge requests found
Pipeline
#50786
passed
4 years ago
Stage: test
Changes
2
Pipelines
1
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
notebooks/tests/dot.ipynb
+11
-9
11 additions, 9 deletions
notebooks/tests/dot.ipynb
src/main/java/de/prob2/jupyter/commands/DotCommand.java
+5
-20
5 additions, 20 deletions
src/main/java/de/prob2/jupyter/commands/DotCommand.java
with
16 additions
and
29 deletions
notebooks/tests/dot.ipynb
+
11
−
9
View file @
a654e73e
...
...
@@ -17,6 +17,7 @@
"The following dot visualisation commands are available:\n",
"\n",
"* `machine_hierarchy` - Machine Hierarchy: Shows the machine hierarchy of a classical B model\n",
"* `operations` - Operation Call Graph: Shows the call graph of a classical B model\n",
"* `event_hierarchy` - Event Hierarchy: Shows the event hierarchy of an Event-B model\n",
"* `state_space` - State Space: Show state space\n",
"* `state_space_sfdp` - State Space (Fast): Show state space (fast)\n",
...
...
@@ -48,6 +49,7 @@
"The following dot visualisation commands are available:\n",
"\n",
"* `machine_hierarchy` - Machine Hierarchy: Shows the machine hierarchy of a classical B model\n",
"* `operations` - Operation Call Graph: Shows the call graph of a classical B model\n",
"* `event_hierarchy` - Event Hierarchy: Shows the event hierarchy of an Event-B model\n",
"* `state_space` - State Space: Show state space\n",
"* `state_space_sfdp` - State Space (Fast): Show state space (fast)\n",
...
...
@@ -108,7 +110,7 @@
"<text text-anchor=\"middle\" x=\"44.3223\" y=\"-17.9\" font-family=\"Times,serif\" font-size=\"12.00\" fill=\"#000000\">root</text>\n",
"</g>\n",
"</g>\n",
"</svg>"
"</svg>
\n
"
],
"text/plain": [
"<Dot visualization: state_space []>"
...
...
@@ -131,7 +133,7 @@
{
"data": {
"text/plain": [
"
Machine initialised using operation 0: $initialise_machine
()"
"
Executed operation: INITIALISATION
()"
]
},
"execution_count": 3,
...
...
@@ -184,7 +186,7 @@
"<text text-anchor=\"middle\" x=\"90.3223\" y=\"-101.4\" font-family=\"Times,serif\" font-size=\"12.00\" fill=\"#000000\">INITIALISATION</text>\n",
"</g>\n",
"</g>\n",
"</svg>"
"</svg>
\n
"
],
"text/plain": [
"<Dot visualization: state_space []>"
...
...
@@ -226,7 +228,7 @@
"<text text-anchor=\"middle\" x=\"27\" y=\"-7.8\" font-family=\"Times,serif\" font-size=\"14.00\" fill=\"#000000\">true</text>\n",
"</g>\n",
"</g>\n",
"</svg>"
"</svg>
\n
"
],
"text/plain": [
"<Dot visualization: invariant []>"
...
...
@@ -300,7 +302,7 @@
"<text text-anchor=\"middle\" x=\"249.5\" y=\"-101.3\" font-family=\"Times,serif\" font-size=\"14.00\" fill=\"#000000\">{(1|->2),(2|->3),(3|->1)}</text>\n",
"</g>\n",
"</g>\n",
"</svg>"
"</svg>
\n
"
],
"text/plain": [
"<Dot visualization: expr_as_graph [{(1,2),(2,3),(3,1)}]>"
...
...
@@ -449,7 +451,7 @@
"<text text-anchor=\"middle\" x=\"107.8366\" y=\"-101.3\" font-family=\"Times,serif\" font-size=\"14.00\" fill=\"#000000\">gt</text>\n",
"</g>\n",
"</g>\n",
"</svg>"
"</svg>
\n
"
],
"text/plain": [
"<Dot visualization: expr_as_graph [(\"gt\",{x,y|x:1..5 & y:1..5 & x>y})]>"
...
...
@@ -618,7 +620,7 @@
"<text text-anchor=\"middle\" x=\"21.5\" y=\"-111.9736\" font-family=\"Times,serif\" font-size=\"14.00\" fill=\"#000000\">gt</text>\n",
"</g>\n",
"</g>\n",
"</svg>"
"</svg>
\n
"
],
"text/plain": [
"<Dot visualization: expr_as_graph [(\"gt\",{x,y|x:1..5 & y:1..5 & x>y})]>"
...
...
@@ -718,7 +720,7 @@
"<polygon fill=\"#000000\" stroke=\"#000000\" points=\"154.295,-20.0001 144.295,-23.5 154.2949,-27.0001 154.295,-20.0001\"/>\n",
"</g>\n",
"</g>\n",
"</svg>"
"</svg>
\n
"
],
"text/plain": [
"<Dot visualization: formula_tree [1*2+3/4=card({1,2})]>"
...
...
@@ -828,7 +830,7 @@
"<polygon fill=\"#000000\" stroke=\"#000000\" points=\"154.295,-20.0001 144.295,-23.5 154.2949,-27.0001 154.295,-20.0001\"/>\n",
"</g>\n",
"</g>\n",
"</svg>"
"</svg>
\n
"
],
"text/plain": [
"<Dot visualization: formula_tree [thingthing=2thing=card({1,2})]>"
...
...
%% 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})]>
...
...
This diff is collapsed.
Click to expand it.
src/main/java/de/prob2/jupyter/commands/DotCommand.java
+
5
−
20
View file @
a654e73e
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
);
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment