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
ae11979e
Commit
ae11979e
authored
5 years ago
by
Oscar Gustafsson
Browse files
Options
Downloads
Patches
Plain Diff
Added sfg and show_sfg methods
parent
48178a0c
No related branches found
No related tags found
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
b_asic/signal_flow_graph.py
+70
-1
70 additions, 1 deletion
b_asic/signal_flow_graph.py
test/test_sfg.py
+46
-0
46 additions, 0 deletions
test/test_sfg.py
with
116 additions
and
1 deletion
b_asic/signal_flow_graph.py
+
70
−
1
View file @
ae11979e
...
...
@@ -10,9 +10,10 @@ 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
,
DelayMap
,
MutableResultMap
,
MutableDelayMap
from
b_asic.operation
import
Operation
,
AbstractOperation
,
ResultKey
,
MutableResultMap
,
MutableDelayMap
from
b_asic.signal
import
Signal
from
b_asic.graph_component
import
GraphID
,
GraphIDNumber
,
GraphComponent
,
Name
,
TypeName
from
b_asic.special_operations
import
Input
,
Output
,
Delay
...
...
@@ -846,3 +847,71 @@ class SFG(AbstractOperation):
src
.
index
,
input_values
,
results
,
delays
,
key_base
,
bits_override
,
truncate
)
results
[
key
]
=
value
return
value
def
sfg
(
self
,
show_id
=
False
,
engine
=
None
)
->
Digraph
:
"""
Returns a Digraph of the SFG. Can be directly displayed in IPython.
Parameters
----------
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.
"""
dg
=
Digraph
()
dg
.
attr
(
rankdir
=
'
LR
'
)
if
engine
:
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
:
dg
.
edge
(
op
.
source
.
operation
.
graph_id
,
op
.
destination
.
operation
.
graph_id
,
label
=
op
.
graph_id
)
else
:
dg
.
edge
(
op
.
source
.
operation
.
graph_id
,
op
.
destination
.
operation
.
graph_id
)
else
:
if
op
.
type_name
()
==
Delay
.
type_name
():
dg
.
node
(
op
.
graph_id
,
shape
=
'
square
'
)
else
:
dg
.
node
(
op
.
graph_id
)
return
dg
def
_repr_svg_
(
self
):
return
self
.
sfg
().
_repr_svg_
()
def
show_sfg
(
self
,
format
=
None
,
show_id
=
False
,
engine
=
None
)
->
None
:
"""
Shows a visual representation of the SFG using the default system viewer.
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.
"""
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
+
46
−
0
View file @
ae11979e
...
...
@@ -1016,3 +1016,49 @@ class TestGetComponentsOfType:
assert
[
op
.
name
for
op
in
sfg_two_inputs_two_outputs
.
find_by_type_name
(
Output
.
type_name
())]
\
==
[
"
OUT1
"
,
"
OUT2
"
]
class
TestPrecedenceGraph
:
def
test_precedence_graph
(
self
,
sfg_simple_filter
):
res
=
'
digraph {
\n\t
rankdir=LR
\n\t
subgraph cluster_0
'
\
'
{
\n\t\t
label=N1
\n\t\t
"
in1.0
"
[label=in1]
\n\t\t
"
t1.0
"
[label=t1]
'
\
'
\n\t
}
\n\t
subgraph cluster_1 {
\n\t\t
label=N2
\n\t\t
"
cmul1.0
"
'
\
'
[label=cmul1]
\n\t
}
\n\t
subgraph cluster_2
'
\
'
{
\n\t\t
label=N3
\n\t\t
"
add1.0
"
[label=add1]
\n\t
}
\n\t
"
in1.0
"
'
\
'
-> add1
\n\t
add1 [label=add1 shape=square]
\n\t
in1 ->
"
in1.0
"'
\
'
\n\t
in1 [label=in1 shape=square]
\n\t
"
t1.0
"
-> cmul1
\n\t
cmul1
'
\
'
[label=cmul1 shape=square]
\n\t
"
t1.0
"
-> out1
\n\t
out1
'
\
'
[label=out1 shape=square]
\n\t
t1Out ->
"
t1.0
"
\n\t
t1Out
'
\
'
[label=t1 shape=square]
\n\t
"
cmul1.0
"
-> add1
\n\t
add1
'
\
'
[label=add1 shape=square]
\n\t
cmul1 ->
"
cmul1.0
"
\n\t
cmul1
'
\
'
[label=cmul1 shape=square]
\n\t
"
add1.0
"
-> t1In
\n\t
t1In
'
\
'
[label=t1 shape=square]
\n\t
add1 ->
"
add1.0
"
\n\t
add1
'
\
'
[label=add1 shape=square]
\n
}
'
assert
sfg_simple_filter
.
precedence_graph
().
source
==
res
class
TestSFGGraph
:
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
.
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