Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
B-ASIC - Better ASIC Toolbox
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Iterations
Requirements
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Test cases
Artifacts
Deploy
Releases
Package registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Code review analytics
Issue analytics
Insights
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Computer Engineering
B-ASIC - Better ASIC Toolbox
Commits
c2a7ec51
Commit
c2a7ec51
authored
4 years ago
by
Oscar Gustafsson
Browse files
Options
Downloads
Patches
Plain Diff
Better tests and methods
parent
cd5b9ee0
No related branches found
No related tags found
1 merge request
!73
Added sfg and show_sfg methods
Pipeline
#16854
passed
4 years ago
Stage: test
Changes
2
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
b_asic/signal_flow_graph.py
+28
-17
28 additions, 17 deletions
b_asic/signal_flow_graph.py
test/test_sfg.py
+18
-2
18 additions, 2 deletions
test/test_sfg.py
with
46 additions
and
19 deletions
b_asic/signal_flow_graph.py
+
28
−
17
View file @
c2a7ec51
...
...
@@ -10,6 +10,7 @@ from io import StringIO
from
queue
import
PriorityQueue
import
itertools
as
it
from
graphviz
import
Digraph
from
graphviz.backend
import
FORMATS
as
GRAPHVIZ_FORMATS
,
ENGINES
as
GRAPHVIZ_ENGINES
from
b_asic.port
import
SignalSourceProvider
,
OutputPort
from
b_asic.operation
import
Operation
,
AbstractOperation
,
ResultKey
,
MutableResultMap
,
MutableDelayMap
...
...
@@ -847,44 +848,44 @@ class SFG(AbstractOperation):
results
[
key
]
=
value
return
value
def
get_
sfg
(
self
,
format
=
None
,
show_id
=
False
)
->
Digraph
:
def
sfg
(
self
,
show_id
=
False
,
engine
=
None
)
->
Digraph
:
"""
Returns a Digraph of the SFG. Can be directly displayed in IPython.
Parameters
----------
format : string, optional
File format of the generated graph. Output formats can be found at https://www.graphviz.org/doc/info/output.html
Most common are
"
pdf
"
,
"
eps
"
,
"
png
"
, and
"
svg
"
. Default is None which leads to PDF.
show_id : Boolean, optional
If True, the graph_id:s of signals are shown. The default is False.
engine: string, optional
Graphviz layout engine to be used, see https://graphviz.org/documentation/.
Most common are
"
dot
"
and
"
neato
"
. Default is None leading to dot.
Returns
-------
Digraph
Digraph of the SFG.
"""
if
format
is
not
None
:
pg
=
Digraph
(
format
=
format
)
els
e
:
pg
=
Digraph
()
pg
.
attr
(
rankdir
=
'
LR
'
)
dg
=
Digraph
()
dg
.
attr
(
rankdir
=
'
LR
'
)
if
engin
e
:
assert
engine
in
GRAPHVIZ_ENGINES
,
"
Unknown layout engine
"
dg
.
engine
=
engine
for
op
in
self
.
_components_by_id
.
values
():
if
isinstance
(
op
,
Signal
):
if
show_id
:
p
g
.
edge
(
op
.
source
.
operation
.
graph_id
,
op
.
destination
.
operation
.
graph_id
,
label
=
op
.
graph_id
)
d
g
.
edge
(
op
.
source
.
operation
.
graph_id
,
op
.
destination
.
operation
.
graph_id
,
label
=
op
.
graph_id
)
else
:
p
g
.
edge
(
op
.
source
.
operation
.
graph_id
,
op
.
destination
.
operation
.
graph_id
)
d
g
.
edge
(
op
.
source
.
operation
.
graph_id
,
op
.
destination
.
operation
.
graph_id
)
else
:
if
op
.
type_name
()
==
Delay
.
type_name
():
p
g
.
node
(
op
.
graph_id
,
shape
=
'
square
'
)
d
g
.
node
(
op
.
graph_id
,
shape
=
'
square
'
)
else
:
p
g
.
node
(
op
.
graph_id
)
return
p
g
d
g
.
node
(
op
.
graph_id
)
return
d
g
def
show_sfg
(
self
,
format
=
None
,
show_id
=
False
)
->
None
:
def
show_sfg
(
self
,
format
=
None
,
show_id
=
False
,
engine
=
None
)
->
None
:
"""
Shows a visual representation of the SFG using the default system viewer.
...
...
@@ -898,6 +899,16 @@ class SFG(AbstractOperation):
show_id : Boolean, optional
If True, the graph_id:s of signals are shown. The default is False.
engine: string, optional
Graphviz layout engine to be used, see https://graphviz.org/documentation/.
Most common are
"
dot
"
and
"
neato
"
. Default is None leading to dot.
"""
self
.
get_sfg
(
format
=
format
,
show_id
=
show_id
).
view
()
dg
=
self
.
sfg
(
show_id
=
show_id
)
if
format
:
assert
format
in
GRAPHVIZ_FORMATS
,
"
Unknown file format
"
dg
.
format
=
format
if
engine
:
assert
engine
in
GRAPHVIZ_ENGINES
,
"
Unknown layout engine
"
dg
.
engine
=
engine
dg
.
view
()
This diff is collapsed.
Click to expand it.
test/test_sfg.py
+
18
−
2
View file @
c2a7ec51
...
...
@@ -1039,10 +1039,26 @@ class TestPrecedenceGraph:
class
TestSFGGraph
:
def
test_
get_
sfg
(
self
,
sfg_simple_filter
):
def
test_sfg
(
self
,
sfg_simple_filter
):
res
=
'
digraph {
\n\t
rankdir=LR
\n\t
in1
\n\t
in1 ->
'
\
'
add1
\n\t
out1
\n\t
t1 -> out1
\n\t
add1
\n\t
cmul1 ->
'
\
'
add1
\n\t
cmul1
\n\t
add1 -> t1
\n\t
t1 [shape=square]
\n\t
t1
'
\
'
-> cmul1
\n
}
'
assert
sfg_simple_filter
.
get_sfg
().
source
==
res
assert
sfg_simple_filter
.
sfg
().
source
==
res
def
test_sfg_show_id
(
self
,
sfg_simple_filter
):
res
=
'
digraph {
\n\t
rankdir=LR
\n\t
in1
\n\t
in1 -> add1
'
\
'
[label=s1]
\n\t
out1
\n\t
t1 -> out1 [label=s2]
\n\t
add1
'
\
'
\n\t
cmul1 -> add1 [label=s3]
\n\t
cmul1
\n\t
add1 -> t1
'
\
'
[label=s4]
\n\t
t1 [shape=square]
\n\t
t1 -> cmul1 [label=s5]
\n
}
'
assert
sfg_simple_filter
.
sfg
(
show_id
=
True
).
source
==
res
def
test_show_sfg_invalid_format
(
self
,
sfg_simple_filter
):
with
pytest
.
raises
(
AssertionError
):
sfg_simple_filter
.
show_sfg
(
format
=
"
ppddff
"
)
def
test_show_sfg_invalid_engine
(
self
,
sfg_simple_filter
):
with
pytest
.
raises
(
AssertionError
):
sfg_simple_filter
.
show_sfg
(
engine
=
"
ppddff
"
)
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