-
Notifications
You must be signed in to change notification settings - Fork 1
/
experiments.py
executable file
·41 lines (34 loc) · 1.21 KB
/
experiments.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
#!/usr/bin/env python3
import os
import sys
import subprocess
import errno
original_dir = os.curdir
try:
os.mkdir('temp')
except FileExistsError:
print("WARNING: 'temp/' already exists, its contents may be overwritten.", file=sys.stdout)
finally:
os.chdir('temp/')
network = '../src/parameters/network.mat'
experiments = '../src/parameters/experiments/'
for config in os.listdir(experiments):
print("\nRunning experiment configuration", config, "...")
sim = ['octave', '../src/run_experiment.m', network, experiments + config, '../src']
proc = subprocess.run(sim, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
print(proc.stdout.decode())
print(proc.stderr.decode(), file=sys.stderr)
figures = '../doc/img/'
try:
os.mkdir(figures)
except FileExistsError:
if input("\nWARNING: 'doc/img/' already exists, continue? [y/n]: " ) != 'y':
exit(errno.EEXIST)
print("Cropping figures (requires pdfcrop) ...")
for fig in os.listdir():
crop = ['pdfcrop', fig, figures + fig]
proc = subprocess.run(crop, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
print(proc.stdout.decode())
print(proc.stderr.decode(), file=sys.stderr)
if proc.returncode == 0:
os.remove(fig)