Skip to content
GitLab
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in
Toggle navigation
Menu
Open sidebar
Computer Engineering
B-ASIC - Better ASIC Toolbox
Commits
e004df6d
Commit
e004df6d
authored
Jun 21, 2022
by
Oscar Gustafsson
Browse files
More code quality fixes
parent
c86903f8
Pipeline
#72133
passed with stage
in 1 minute and 52 seconds
Changes
11
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
b_asic/GUI/simulate_sfg_window.py
View file @
e004df6d
...
...
@@ -109,7 +109,7 @@ class SimulateSFGWindow(QDialog):
return
_input_values
def
save_properties
(
self
):
for
sfg
,
properties
in
self
.
input_fields
.
items
():
for
sfg
,
_
properties
in
self
.
input_fields
.
items
():
input_values
=
self
.
parse_input_values
(
widget
.
text
().
split
(
","
)
if
widget
.
text
()
else
[
0
]
for
widget
in
self
.
input_fields
[
sfg
][
"input_values"
])
if
max
(
len
(
list_
)
for
list_
in
input_values
)
!=
min
(
len
(
list_
)
for
list_
in
input_values
):
self
.
_window
.
logger
.
error
(
f
"Minimum length of input lists are not equal to maximum length of input lists:
{
max
(
len
(
list_
)
for
list_
in
input_values
)
}
!=
{
min
(
len
(
list_
)
for
list_
in
input_values
)
}
."
)
...
...
b_asic/GUI/utils.py
View file @
e004df6d
...
...
@@ -5,9 +5,10 @@ def handle_error(fn):
def
wrapper
(
self
,
*
args
,
**
kwargs
):
try
:
return
fn
(
self
,
*
args
,
**
kwargs
)
except
Exception
as
e
:
except
Exception
:
self
.
_window
.
logger
.
error
(
f
"Unexpected error:
{
format_exc
()
}
"
)
QErrorMessage
(
self
.
_window
).
showMessage
(
f
"Unexpected error:
{
format_exc
()
}
"
)
QErrorMessage
(
self
.
_window
).
showMessage
(
f
"Unexpected error:
{
format_exc
()
}
"
)
return
wrapper
...
...
@@ -17,4 +18,4 @@ def decorate_class(decorator):
if
callable
(
getattr
(
cls
,
attr
)):
setattr
(
cls
,
attr
,
decorator
(
getattr
(
cls
,
attr
)))
return
cls
return
decorate
\ No newline at end of file
return
decorate
b_asic/operation.py
View file @
e004df6d
...
...
@@ -565,7 +565,7 @@ class AbstractOperation(Operation, AbstractGraphComponent):
raise
IndexError
(
f
"Output index out of range (expected 0-
{
self
.
output_count
-
1
}
, got
{
output_index
}
)"
)
# By default, assume each output depends on all inputs.
return
[
i
for
i
in
range
(
self
.
input_count
)
]
return
list
(
range
(
self
.
input_count
)
)
@
property
def
neighbors
(
self
)
->
Iterable
[
GraphComponent
]:
...
...
b_asic/signal_flow_graph.py
View file @
e004df6d
...
...
@@ -308,7 +308,7 @@ class SFG(AbstractOperation):
input_op
:
index
for
index
,
input_op
in
enumerate
(
self
.
_input_operations
)}
output_op
=
self
.
_output_operations
[
output_index
]
queue
=
deque
([
output_op
])
visited
=
set
([
output_op
])
visited
=
{
output_op
}
while
queue
:
op
=
queue
.
popleft
()
if
isinstance
(
op
,
Input
):
...
...
@@ -598,7 +598,7 @@ class SFG(AbstractOperation):
no_inputs_queue
)
>
0
,
"Illegal SFG state, dangling signals in SFG."
first_op
=
no_inputs_queue
.
popleft
()
visited
=
set
([
first_op
])
visited
=
{
first_op
}
p_queue
=
PriorityQueue
()
p_queue_entry_num
=
it
.
count
()
# Negative priority as max-heap popping is wanted
...
...
test/conftest.py
View file @
e004df6d
...
...
@@ -2,4 +2,4 @@ from test.fixtures.signal import signal, signals
from
test.fixtures.operation_tree
import
*
from
test.fixtures.port
import
*
from
test.fixtures.signal_flow_graph
import
*
import
pytest
\ No newline at end of file
import
pytest
test/fixtures/operation_tree.py
View file @
e004df6d
...
...
@@ -71,7 +71,7 @@ def butterfly_operation_tree():
v ^ v ^ v ^
butterfly butterfly butterfly
^ v ^ v ^ v
| | | | | |
| | | | | |
4 ---+ +--- (2 - 4) ---+ +--- (6 - (-2)) ---+ +--- (4 - 8) ---> out2 = -4
"""
return
Butterfly
(
*
(
Butterfly
(
*
(
Butterfly
(
Constant
(
2
),
Constant
(
4
),
name
=
"bfly3"
).
outputs
),
name
=
"bfly2"
).
outputs
),
name
=
"bfly1"
)
...
...
test/fixtures/signal_flow_graph.py
View file @
e004df6d
...
...
@@ -170,7 +170,7 @@ def sfg_custom_operation():
class
CustomOperation
(
AbstractOperation
):
def
__init__
(
self
,
src0
:
Optional
[
SignalSourceProvider
]
=
None
,
name
:
Name
=
""
):
super
().
__init__
(
input_count
=
1
,
output_count
=
2
,
name
=
name
,
input_sources
=
[
src0
])
@
classmethod
def
type_name
(
self
)
->
TypeName
:
return
"custom"
...
...
test/test_fast_simulation.py
View file @
e004df6d
...
...
@@ -91,7 +91,7 @@ class TestRunFor:
assert
simulation
.
results
[
"0"
][
4
]
==
9
assert
simulation
.
results
[
"1"
][
4
]
==
11
def
test_with_numpy_array_overflow
(
self
,
sfg_two_inputs_two_outputs
):
input0
=
np
.
array
([
5
,
9
,
25
,
-
5
,
7
])
input1
=
np
.
array
([
7
,
3
,
3
,
54
,
2
])
...
...
@@ -165,7 +165,7 @@ class TestRun:
assert
output0
[
0
]
==
11405
assert
output1
[
0
]
==
4221
def
test_accumulator
(
self
,
sfg_accumulator
):
data_in
=
np
.
array
([
5
,
-
2
,
25
,
-
6
,
7
,
0
])
reset
=
np
.
array
([
0
,
0
,
0
,
1
,
0
,
0
])
...
...
@@ -188,7 +188,7 @@ class TestRun:
simulation
=
FastSimulation
(
sfg_simple_accumulator
,
[
data_in
])
simulation
.
run
()
assert
list
(
simulation
.
results
[
"0"
])
==
[
0
,
1
,
3
,
6
,
10
,
15
,
21
,
28
,
36
,
45
]
def
test_simple_filter
(
self
,
sfg_simple_filter
):
input0
=
np
.
array
([
1
,
2
,
3
,
4
,
5
])
simulation
=
FastSimulation
(
sfg_simple_filter
,
[
input0
])
...
...
@@ -210,7 +210,7 @@ class TestLarge:
sfg
=
SFG
(
outputs
=
[
Output
(
prev_op
)])
simulation
=
FastSimulation
(
sfg
,
[])
assert
simulation
.
step
()[
0
]
==
2000
def
test_1k_subtractions
(
self
):
prev_op
=
Subtraction
(
Constant
(
0
),
Constant
(
2
))
for
_
in
range
(
999
):
...
...
@@ -218,7 +218,7 @@ class TestLarge:
sfg
=
SFG
(
outputs
=
[
Output
(
prev_op
)])
simulation
=
FastSimulation
(
sfg
,
[])
assert
simulation
.
step
()[
0
]
==
-
2000
def
test_1k_butterfly
(
self
):
prev_op_add
=
Addition
(
Constant
(
1
),
Constant
(
1
))
prev_op_sub
=
Subtraction
(
Constant
(
-
1
),
Constant
(
1
))
...
...
@@ -229,4 +229,4 @@ class TestLarge:
butterfly
=
Butterfly
(
prev_op_add
,
prev_op_sub
)
sfg
=
SFG
(
outputs
=
[
Output
(
butterfly
.
output
(
0
)),
Output
(
butterfly
.
output
(
1
))])
simulation
=
FastSimulation
(
sfg
,
[])
assert
list
(
simulation
.
step
())
==
[
0
,
2000
]
\ No newline at end of file
assert
list
(
simulation
.
step
())
==
[
0
,
2000
]
test/test_sfg.py
View file @
e004df6d
...
...
@@ -228,7 +228,7 @@ class TestComponents:
mac_sfg
=
SFG
(
inputs
=
[
inp1
,
inp2
],
outputs
=
[
out1
],
name
=
"mac_sfg"
)
assert
set
([
comp
.
name
for
comp
in
mac_sfg
.
components
])
==
{
assert
{
comp
.
name
for
comp
in
mac_sfg
.
components
}
==
{
"INP1"
,
"INP2"
,
"INP3"
,
"ADD1"
,
"ADD2"
,
"MUL1"
,
"OUT1"
,
"S1"
,
"S2"
,
"S3"
,
"S4"
,
"S5"
,
"S6"
,
"S7"
}
...
...
test/test_signal.py
View file @
e004df6d
...
...
@@ -85,4 +85,4 @@ class Bits:
def
test_bits_pos_then_none
(
self
,
signal
):
signal
.
bits
=
10
signal
.
bits
=
None
assert
signal
.
bits
is
None
\ No newline at end of file
assert
signal
.
bits
is
None
test/test_simulation.py
View file @
e004df6d
...
...
@@ -91,7 +91,7 @@ class TestRunFor:
assert
simulation
.
results
[
"0"
][
4
]
==
9
assert
simulation
.
results
[
"1"
][
4
]
==
11
def
test_with_numpy_array_overflow
(
self
,
sfg_two_inputs_two_outputs
):
input0
=
np
.
array
([
5
,
9
,
25
,
-
5
,
7
])
input1
=
np
.
array
([
7
,
3
,
3
,
54
,
2
])
...
...
@@ -165,7 +165,7 @@ class TestRun:
assert
output0
[
0
]
==
11405
assert
output1
[
0
]
==
4221
def
test_accumulator
(
self
,
sfg_accumulator
):
data_in
=
np
.
array
([
5
,
-
2
,
25
,
-
6
,
7
,
0
])
reset
=
np
.
array
([
0
,
0
,
0
,
1
,
0
,
0
])
...
...
@@ -188,7 +188,7 @@ class TestRun:
simulation
=
Simulation
(
sfg_simple_accumulator
,
[
data_in
])
simulation
.
run
()
assert
list
(
simulation
.
results
[
"0"
])
==
[
0
,
1
,
3
,
6
,
10
,
15
,
21
,
28
,
36
,
45
]
def
test_simple_filter
(
self
,
sfg_simple_filter
):
input0
=
np
.
array
([
1
,
2
,
3
,
4
,
5
])
simulation
=
Simulation
(
sfg_simple_filter
,
[
input0
])
...
...
Write
Preview
Supports
Markdown
0%
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!
Cancel
Please
register
or
sign in
to comment