Move the plot script to R
This commit is contained in:
parent
ede25b6736
commit
1bd9cb6c0f
@ -1,65 +0,0 @@
|
||||
{
|
||||
stdenv
|
||||
, gnuplot
|
||||
, jq
|
||||
, experiments
|
||||
, garlicTools
|
||||
, getExpResult
|
||||
, writeText
|
||||
}:
|
||||
|
||||
with garlicTools;
|
||||
with stdenv.lib;
|
||||
|
||||
let
|
||||
experiment = builtins.elemAt experiments 0;
|
||||
expResult = getExpResult {
|
||||
garlicTemp = "/tmp/garlic-temp";
|
||||
inherit experiment;
|
||||
};
|
||||
#set xrange [16:1024]
|
||||
plotScript = writeText "plot.plg" ''
|
||||
set terminal png size 800,800
|
||||
set output 'out.png'
|
||||
set xrange [*:*]
|
||||
|
||||
set nokey
|
||||
set logscale x 2
|
||||
set logscale y 2
|
||||
set grid
|
||||
|
||||
set xlabel "blocksize"
|
||||
set ylabel "time (s)"
|
||||
|
||||
plot filename using 1:2 with points
|
||||
'';
|
||||
|
||||
in stdenv.mkDerivation {
|
||||
name = "plot";
|
||||
phases = [ "installPhase" ];
|
||||
buildInputs = [ jq gnuplot ];
|
||||
preferLocalBuild = true;
|
||||
dontPatchShebangs = true;
|
||||
installPhase = ''
|
||||
mkdir $out
|
||||
for unit in ${expResult}/*/*; do
|
||||
name=$(basename $unit)
|
||||
log="$unit/stdout.log"
|
||||
conf="$unit/garlic_config.json"
|
||||
bs=$(jq .blocksize $conf)
|
||||
awk "/^time /{print $bs, \$2}" $log >> $out/data.csv
|
||||
done
|
||||
gnuplot -e "filename='$out/data.csv'" ${plotScript}
|
||||
cp out.png $out/out.png
|
||||
'';
|
||||
#installPhase = ''
|
||||
# mkdir $out
|
||||
# for unit in ${expResult}/*/*; do
|
||||
# name=$(basename $unit)
|
||||
# log="$unit/stdout.log"
|
||||
# bs=$(jq .blocksize $log)
|
||||
# awk "/^time /{print $bs, \$2}" $log >> $out/data.csv
|
||||
# done
|
||||
#'';
|
||||
#gnuplot -e "filename='$out/data.csv'" ${plotScript}
|
||||
}
|
62
garlic/fig/nbody/test/default.nix
Normal file
62
garlic/fig/nbody/test/default.nix
Normal file
@ -0,0 +1,62 @@
|
||||
{
|
||||
stdenv
|
||||
, gnuplot
|
||||
, jq
|
||||
, experiments
|
||||
, garlicTools
|
||||
, getExpResult
|
||||
, writeText
|
||||
, rWrapper
|
||||
, rPackages
|
||||
}:
|
||||
|
||||
with garlicTools;
|
||||
with stdenv.lib;
|
||||
|
||||
let
|
||||
experiment = builtins.elemAt experiments 0;
|
||||
expResult = getExpResult {
|
||||
garlicTemp = "/tmp/garlic-temp";
|
||||
trebuchetStage = experiment;
|
||||
experimentStage = getExperimentStage experiment;
|
||||
};
|
||||
|
||||
customR = rWrapper.override {
|
||||
packages = with rPackages; [ tidyverse ];
|
||||
};
|
||||
|
||||
plotScript = ./plot.R;
|
||||
|
||||
in stdenv.mkDerivation {
|
||||
name = "plot";
|
||||
buildInputs = [ jq gnuplot customR ];
|
||||
preferLocalBuild = true;
|
||||
dontPatchShebangs = true;
|
||||
|
||||
inherit expResult;
|
||||
|
||||
src = ./.;
|
||||
|
||||
buildPhase = ''
|
||||
echo "using results ${expResult}"
|
||||
|
||||
substituteAllInPlace plot.R
|
||||
|
||||
for unit in ${expResult}/*/*; do
|
||||
name=$(basename $unit)
|
||||
log="$unit/stdout.log"
|
||||
conf="$unit/garlic_config.json"
|
||||
bs=$(jq .blocksize $conf)
|
||||
awk "/^time /{print $bs, \$2}" $log >> data.csv
|
||||
done
|
||||
|
||||
Rscript plot.R
|
||||
'';
|
||||
|
||||
installPhase = ''
|
||||
mkdir $out
|
||||
ln -s ${expResult} $out/result
|
||||
cp *.png $out/
|
||||
cp data.csv $out/
|
||||
'';
|
||||
}
|
74
garlic/fig/nbody/test/plot.R
Normal file
74
garlic/fig/nbody/test/plot.R
Normal file
@ -0,0 +1,74 @@
|
||||
library(ggplot2)
|
||||
library(dplyr)
|
||||
library(scales)
|
||||
|
||||
# Load the dataset
|
||||
df=read.table("data.csv", col.names=c("blocksize", "time"))
|
||||
|
||||
bs_unique = unique(df$blocksize)
|
||||
nbs=length(bs_unique)
|
||||
|
||||
# Normalize the time by the median
|
||||
D=group_by(df, blocksize) %>% mutate(tnorm = time / median(time) - 1)
|
||||
|
||||
ppi=300
|
||||
h=5
|
||||
w=5
|
||||
png("box.png", width=w*ppi, height=h*ppi, res=ppi)
|
||||
|
||||
# Create the plot with the normalized time vs blocksize
|
||||
p = ggplot(D, aes(x=blocksize, y=tnorm)) +
|
||||
|
||||
# Labels
|
||||
labs(x="Blocksize", y="Normalized time",
|
||||
title="Nbody granularity",
|
||||
subtitle="@expResult@") +
|
||||
|
||||
# Center the title
|
||||
#theme(plot.title = element_text(hjust = 0.5)) +
|
||||
|
||||
# Black and white mode (useful for printing)
|
||||
#theme_bw() +
|
||||
|
||||
# Draw boxplots
|
||||
geom_boxplot(aes(group=blocksize)) +
|
||||
|
||||
# Use log2 scale in x
|
||||
scale_x_continuous(trans=log2_trans(),
|
||||
breaks=bs_unique) +
|
||||
|
||||
scale_y_continuous(breaks = scales::pretty_breaks(n = 10)) +
|
||||
|
||||
# Add the maximum allowed error lines
|
||||
geom_hline(yintercept=c(-0.01, 0.01),
|
||||
linetype="dashed", color="red")
|
||||
|
||||
# Render the plot
|
||||
print(p)
|
||||
|
||||
# Save the png image
|
||||
dev.off()
|
||||
|
||||
D=group_by(df, blocksize) %>% mutate(tnorm = time / median(time) - 1)
|
||||
|
||||
png("scatter.png", width=w*ppi, height=h*ppi, res=ppi)
|
||||
|
||||
# Create the plot with the normalized time vs blocksize
|
||||
p = ggplot(D, aes(x=blocksize, y=time)) +
|
||||
|
||||
labs(x="Blocksize", y="Time (s)",
|
||||
title="Nbody granularity",
|
||||
subtitle="@expResult@") +
|
||||
|
||||
geom_point(
|
||||
#position=position_jitter(width=0.2, heigh=0)
|
||||
shape=21, size=1.5) +
|
||||
scale_x_continuous(trans=log2_trans(),
|
||||
breaks=bs_unique) +
|
||||
scale_y_continuous(trans=log2_trans())
|
||||
|
||||
# Render the plot
|
||||
print(p)
|
||||
|
||||
# Save the png image
|
||||
dev.off()
|
@ -295,7 +295,7 @@ let
|
||||
# Figures generated from the experiments
|
||||
fig = {
|
||||
nbody = {
|
||||
test = callPackage ./garlic/fig/nbody/test.nix {
|
||||
test = callPackage ./garlic/fig/nbody/test/default.nix {
|
||||
experiments = [
|
||||
self.bsc.garlic.exp.nbody.tampi
|
||||
];
|
||||
|
Loading…
Reference in New Issue
Block a user