Skip to content
GitLab
Menu
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
Pierre Donat-Bouillud
audio-adaptive-scheduling
Commits
8404646e
Commit
8404646e
authored
Feb 25, 2019
by
Pierre Donat-Bouillud
Browse files
Displaying measured and theoretical model side to side.
parent
355ddb1a
Pipeline
#707
passed with stage
in 1 minute and 57 seconds
Changes
3
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
pipeline.py
View file @
8404646e
...
...
@@ -7,7 +7,7 @@ Execute all the stuff:
- comparing graphs
Dependencies:
pip3 install tqdm numpy matlpotlib adjusttext
pip3 install tqdm numpy matlpotlib adjusttext
"""
import
argparse
...
...
@@ -22,6 +22,8 @@ import csv
import
matplotlib.pyplot
as
plt
import
numpy
as
np
from
adjustText
import
adjust_text
from
operator
import
itemgetter
from
matplotlib.ticker
import
MultipleLocator
parser
=
argparse
.
ArgumentParser
(
description
=
"Generate graphs, execute them, and then evaluate their quality"
,
\
...
...
@@ -55,7 +57,7 @@ def get_costs(csvname):
"""Get csv file with execution times and compute average execution time
for a cycle as well as total execution time"""
with
open
(
csvname
,
"r"
)
as
csvfile
:
csvfile
.
readline
()
# To remove first line where there are number of n
d
oes and edges
csvfile
.
readline
()
# To remove first line where there are number of no
d
es and edges
csvreader
=
csv
.
DictReader
(
csvfile
,
delimiter
=
'
\t
'
)
total
=
0.
nb_rows
=
0
...
...
@@ -64,8 +66,6 @@ def get_costs(csvname):
nb_rows
+=
1
return
total
/
float
(
nb_rows
),
total
def
process_graph
(
graph
):
tqdm
.
write
(
"Processing "
+
graph
,
end
=
" "
)
basename
,
ext
=
os
.
path
.
splitext
(
graph
)
...
...
@@ -83,7 +83,7 @@ def process_graph(graph):
tqdm
.
write
(
"Executing graphs"
)
for
graph
in
tqdm
(
glob
.
iglob
(
"*.ag"
)):
tqdm
.
write
(
graph
)
subprocess
.
run
([
graph_exec
,
"-m"
,
"-b"
,
graph
],
check
=
True
)
subprocess
.
run
([
graph_exec
,
"-m"
,
"-b"
,
"-c"
,
"60000"
,
graph
],
check
=
True
)
# Get execution times for reports (-m option)
basename
,
_
=
os
.
path
.
splitext
(
os
.
path
.
basename
(
graph
))
reports
=
glob
.
glob
(
"*"
+
basename
+
"*.csv"
)
...
...
@@ -130,29 +130,79 @@ def results_to_csv(graphname, qualities, costs):
result
[
"Total"
]
=
total
writer
.
writerow
(
result
)
def
plot
(
qualities
,
costs
):
def
load_theo
(
filename
):
"""Load quality and cost from the theoretical model"""
with
open
(
filename
,
"r"
,
newline
=
''
)
as
csvfile
:
csvreader
=
csv
.
DictReader
(
csvfile
,
delimiter
=
'
\t
'
)
qualities
=
[]
costs
=
[]
for
row
in
csvreader
:
qualities
.
append
(
row
[
"Quality"
])
costs
.
append
(
row
[
"Cost"
])
return
qualities
,
costs
def
sort_by_quality
(
qualities
,
costs
):
return
[[
*
x
]
for
x
in
zip
(
*
sorted
(
zip
(
qualities
,
costs
),
key
=
itemgetter
(
0
)))]
def
plot
(
qualities
,
costs
,
qualities_th
,
costs_th
):
q
=
[]
c_cycle
=
[]
c_total
=
[]
texts
=
[]
fig
,
axes
=
plt
.
subplots
(
2
,
1
)
ax1
=
axes
[
0
]
ax2
=
axes
[
1
]
for
k
in
sorted
(
qualities
.
keys
()):
q
.
append
(
qualities
[
k
])
cycle
,
total
=
costs
[
k
]
c_cycle
.
append
(
cycle
)
c_total
.
append
(
total
)
texts
.
append
(
plt
.
text
(
qualities
[
k
],
cycle
,
k
,
ha
=
'center'
,
va
=
'center'
))
name
=
k
.
split
(
"-"
)[
-
1
]
texts
.
append
(
ax1
.
text
(
qualities
[
k
],
cycle
,
name
,
ha
=
'center'
,
va
=
'center'
))
q
.
append
(
1.
)
name
=
list
(
sorted
(
costs
.
keys
()))[
0
]
cost
,
total
=
costs
[
name
]
c_cycle
.
append
(
cost
)
c_total
.
append
(
total
)
texts
.
append
(
plt
.
text
(
1.0
,
cost
,
name
,
ha
=
'center'
,
va
=
'center'
))
plt
.
plot
(
q
,
c_cycle
,
'ro'
)
#plt.plot(q, c_total)
plt
.
ylabel
(
"cost per cycle (ms)"
)
plt
.
xlabel
(
"quality"
)
adjust_text
(
texts
)
texts
.
append
(
ax1
.
text
(
1.0
,
cost
,
"0"
,
ha
=
'center'
,
va
=
'center'
))
q
,
c_cycle
=
sort_by_quality
(
q
,
c_cycle
)
#print("Measured: ", q, c_cycle)
color
=
'tab:red'
ax1
.
set_ylabel
(
"cost per cycle (ms)"
)
ax1
.
set_xlabel
(
"quality"
)
ax1
.
scatter
(
q
,
c_cycle
,
label
=
"Measured"
,
color
=
color
)
#ax1.tick_params(axis='y', labelcolor=color)
texts_th
=
[]
for
(
i
,
(
quality
,
cost
))
in
enumerate
(
zip
(
qualities_th
,
costs_th
)):
texts_th
.
append
(
ax2
.
text
(
quality
,
cost
,
str
(
i
),
ha
=
'center'
,
va
=
'center'
))
color
=
'tab:blue'
ax2
.
set_ylabel
(
"cost"
)
ax2
.
set_xlabel
(
"quality"
)
qualities_th
,
costs_th
=
sort_by_quality
(
qualities_th
,
costs_th
)
ax2
.
scatter
(
qualities_th
,
costs_th
,
label
=
"Model"
,
color
=
color
)
#ax2.tick_params(axis='y', color=color)
adjust_text
(
texts
,
ax
=
ax1
)
adjust_text
(
texts_th
,
ax
=
ax2
)
fig
.
tight_layout
()
fig
.
legend
()
plt
.
show
()
#print("limits are: x1=[", ax1.get_xlim(), "], x2=[", ax2.get_xlim(), "]")
if
args
.
graph
:
for
graph
in
tqdm
(
args
.
graph
):
...
...
@@ -162,8 +212,9 @@ if args.graph:
tqdm
.
write
(
"Costs are "
+
str
(
costs
))
basename
,
_
=
os
.
path
.
splitext
(
os
.
path
.
basename
(
graph
))
# We stay in the directory created in process_graph
results_to_csv
(
basename
+
"-exec-report"
,
qualities
,
costs
)
q_th
,
c_th
=
load_theo
(
basename
+
"-theo.csv"
)
# Display in a graph
plot
(
qualities
,
costs
)
plot
(
qualities
,
costs
,
q_th
,
c_th
)
os
.
chdir
(
".."
)
elif
args
.
nodes
:
print
(
"Processing all graphs "
,
end
=
""
)
...
...
src/audiograph.rs
View file @
8404646e
...
...
@@ -351,7 +351,7 @@ impl AudioGraph {
else
{
//We are not after a resampler so we propagate the min buffer size of the previous edges.
(
buf_size
,
samplerate
)
};
println!
(
"Buffer size={}; samplerate={}"
,
new_buf_size
,
new_samplerate
);
//
println!("Buffer size={}; samplerate={}", new_buf_size, new_samplerate);
//Modify all outcoming buffer sizes
let
mut
output_edges
=
self
.outputs_mut
(
node
);
while
let
Some
(
edge
)
=
output_edges
.next_edge
(
&
self
.graph
)
{
...
...
src/audiograph_exec.rs
View file @
8404646e
...
...
@@ -29,7 +29,7 @@ use audio_adaptive::sndfile;
const
CHANNELS
:
i32
=
1
;
const
SAMPLE_RATE
:
u32
=
44_100
;
const
NB_CYCLES
:
u32
=
6
000
;
const
NB_CYCLES
:
u32
=
12
000
;
const
FRAMES_PER_BUFFER
:
usize
=
64
;
#[derive(Clone,
Copy,
Debug)]
...
...
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Attach a 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