Skip to content

Commit 2c249ed

Browse files
authored
Merge pull request #325 from openworm/dev_0.9.2
Restructure to make versioning easier
2 parents 1c1e08f + 769b191 commit 2c249ed

15 files changed

+158
-29
lines changed
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
name: Docker Image Test - quick
2+
3+
on:
4+
push:
5+
branches: [ master, dev* ]
6+
pull_request:
7+
branches: [ master, dev* ]
8+
9+
jobs:
10+
11+
build:
12+
13+
runs-on: [ ubuntu-18.04, ubuntu-20.04, ubuntu-22.04 ]
14+
steps:
15+
- uses: actions/checkout@v2
16+
- name: Build the Docker image
17+
run: |
18+
chmod a+w output/
19+
ls -alt
20+
./build.sh
21+
- name: Info on Docker images
22+
run: |
23+
docker -v
24+
docker images
25+
- name: Run the Docker image
26+
run: |
27+
./run-quick.sh
28+
- name: Info on generated files
29+
run: |
30+
ls -alt
31+
ls -alt output
32+
ls -alt output/S*
33+
cat output/S*/report.json

.github/workflows/docker-image.yml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,12 +16,18 @@ jobs:
1616
- uses: actions/checkout@v2
1717
- name: Build the Docker image
1818
run: |
19+
chmod a+w output/
20+
ls -alt
1921
./build.sh
22+
- name: Info on Docker images
23+
run: |
24+
docker images
2025
- name: Run the Docker image
2126
run: |
2227
./run.sh
2328
- name: Info on generated files
2429
run: |
30+
ls -alt
2531
ls -alt output
2632
ls -alt output/C2*
2733
cat output/C2_*/report.json

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,3 +3,4 @@ output/C2*
33
/rebuild2.sh
44
/output/siminfo.py
55
/output/wor*
6+
/output/Sibernetic_*

LICENSE

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
Copyright (c) 2012-2022 Individual Authors of code
1+
Copyright (c) 2012-2022 Individual Authors of code
22

33
Permission is hereby granted, free of charge, to any person obtaining a copy
44
of this software and associated documentation files (the "Software"), to deal

VERSION

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
0.9.2

build.sh

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
11
#!/bin/bash
22

3-
docker build "$@" -t "openworm/openworm:0.9.2" .
3+
version=$(<VERSION) # Read version of Dockerfile from file VERSION
4+
docker build "$@" -t "openworm/openworm:$version" .

build2.sh

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,4 +4,5 @@
44
# Note: Python 2 is no longer officially supported and this Docker image will
55
# probably stop working eventually...
66

7-
docker build "$@" -t "openworm/openworm:0.9.2_py2" -f Dockerfile2 .
7+
version=$(<VERSION) # Read version of Dockerfile from file VERSION
8+
docker build "$@" -t "openworm/openworm:${version}_py2" -f Dockerfile2 .

master_openworm.py

Lines changed: 48 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
import matplotlib
33
matplotlib.use('Agg')
44
import shutil
5-
from subprocess import Popen, PIPE, check_output
5+
from subprocess import Popen, PIPE, check_output, STDOUT
66
import os
77
import pwd
88
import shlex
@@ -12,7 +12,7 @@
1212
import math
1313

1414
print("*****************************")
15-
print("OpenWorm Master Script v0.9.2")
15+
print("OpenWorm Master Script v0.9.3")
1616
print("*****************************")
1717
print("")
1818
print("This script attempts to run a full pass through the OpenWorm scientific libraries.")
@@ -76,16 +76,32 @@
7676
def execute_with_realtime_output(command, directory, env=None):
7777
p = None
7878
try:
79-
p = Popen(shlex.split(command), stdout=PIPE, bufsize=1, cwd=directory, env=env)
79+
80+
print('>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>')
81+
print('>> Executing command: %s'%command)
82+
print('>> --------------------------------------------------------------')
83+
p = Popen(shlex.split(command),
84+
stdout=PIPE,
85+
stderr=STDOUT,
86+
cwd=directory,
87+
env=env)
8088
with p.stdout:
8189
for line in iter(p.stdout.readline, b''):
82-
print(line.decode('utf-8'), end='')
90+
print('>> %s'%line.decode('utf-8'), end='')
8391
p.wait() # wait for the subprocess to exit
8492
except KeyboardInterrupt as e:
8593
print("Caught CTRL+C")
8694
if p:
8795
p.kill()
8896
raise e
97+
print('>> --------------------------------------------------------------')
98+
print('>> Command exited with %i: %s'%(p.returncode,command))
99+
print('>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>\n')
100+
101+
if p.returncode!=0:
102+
print('Exiting as the last command failed')
103+
exit(p.returncode)
104+
89105

90106

91107
sys.path.append(os.environ['C302_HOME'])
@@ -110,6 +126,10 @@ def execute_with_realtime_output(command, directory, env=None):
110126
if 'DURATION' in os.environ:
111127
sim_duration = float(os.environ['DURATION'])
112128

129+
noc302 = False
130+
if 'NOC302' in os.environ:
131+
noc302 = bool(os.environ['NOC302'])
132+
113133
DEFAULTS = {'duration': sim_duration,
114134
'dt': 0.005,
115135
'dtNrn': 0.05,
@@ -119,13 +139,15 @@ def execute_with_realtime_output(command, directory, env=None):
119139
'verbose': False,
120140
'device': 'GPU',
121141
'configuration': 'worm_crawl_half_resolution',
122-
'noc302': False,
142+
'noc302': noc302,
123143
'datareader': 'UpdatedSpreadsheetDataReader2',
124144
'outDir': OW_OUT_DIR}
125145

126146
my_env = os.environ.copy()
127147
my_env["DISPLAY"] = ":44"
128148

149+
# Xvfb or X virtual framebuffer is a display server implementing the X11 display server protocol.
150+
# In contrast to other display servers, Xvfb performs all graphical operations in virtual memory without showing any screen output.
129151
os.system('Xvfb :44 -listen tcp -ac -screen 0 1920x1080x24+32 &') # TODO: terminate xvfb after recording
130152

131153
try:
@@ -151,6 +173,9 @@ def execute_with_realtime_output(command, directory, env=None):
151173
DEFAULTS['datareader'],
152174
'simulations')
153175
#DEFAULTS['outDir'])
176+
177+
if noc302: command += ' -noc302'
178+
154179
execute_with_realtime_output(command, os.environ['SIBERNETIC_HOME'], env=my_env)
155180
except KeyboardInterrupt as e:
156181
pass
@@ -162,9 +187,13 @@ def execute_with_realtime_output(command, directory, env=None):
162187
for directory in dirnames:
163188
if directory.startswith('%s_%s' % (DEFAULTS['c302params'], DEFAULTS['reference'])):
164189
all_subdirs.append(os.path.join(dirpath, directory))
190+
if directory.startswith('Sibernetic'):
191+
all_subdirs.append(os.path.join(dirpath, directory))
165192

166193
latest_subdir = max(all_subdirs, key=os.path.getmtime)
167-
194+
print('\n========================================================================\n')
195+
print('Finished main simulation, data saved in: %s'%latest_subdir)
196+
execute_with_realtime_output('ls -alt %s'%latest_subdir, os.environ['SIBERNETIC_HOME'], env=my_env)
168197

169198
try:
170199
os.mkdir('%s/output' % OW_OUT_DIR)
@@ -198,19 +227,27 @@ def execute_with_realtime_output(command, directory, env=None):
198227
print("Moving %s to %s"%(wcon, new_sim_out))
199228
shutil.move(wcon, new_sim_out)
200229

230+
time.sleep(2)
201231

202232
# Rerun and record simulation
203233
os.system('export DISPLAY=:44')
204234
sibernetic_movie_name = '%s.mp4' % os.path.split(latest_subdir)[-1]
205-
os.system('tmux new-session -d -s SiberneticRecording "DISPLAY=:44 ffmpeg -r 30 -f x11grab -draw_mouse 0 -s 1920x1080 -i :44 -filter:v "crop=1200:800:100:100" -cpu-used 0 -b:v 384k -qmin 10 -qmax 42 -maxrate 384k -bufsize 1000k -an %s/%s"' % (new_sim_out, sibernetic_movie_name))
235+
command = 'tmux new-session -d -s SiberneticRecording "DISPLAY=:44 ffmpeg -r 30 -f x11grab -draw_mouse 0 -s 1920x1080 -i :44 -filter:v "crop=1200:800:100:100" -cpu-used 0 -b:v 384k -qmin 10 -qmax 42 -maxrate 384k -bufsize 1000k -an %s/%s"' % (new_sim_out, sibernetic_movie_name)
236+
execute_with_realtime_output(command, os.environ['SIBERNETIC_HOME'], env=my_env)
237+
238+
time.sleep(3)
239+
240+
execute_with_realtime_output('tmux list-sessions', os.environ['SIBERNETIC_HOME'], env=my_env)
206241

207242
command = './Release/Sibernetic -f %s -l_from lpath=%s' % (DEFAULTS['configuration'], latest_subdir)
208243
execute_with_realtime_output(command, os.environ['SIBERNETIC_HOME'], env=my_env)
209244

210-
os.system('tmux send-keys -t SiberneticRecording q')
211-
os.system('tmux send-keys -t SiberneticRecording "exit" C-m')
245+
execute_with_realtime_output('tmux send-keys -t SiberneticRecording q', os.environ['SIBERNETIC_HOME'], env=my_env)
246+
execute_with_realtime_output('tmux send-keys -t SiberneticRecording "exit" C-m', os.environ['SIBERNETIC_HOME'], env=my_env)
212247

213-
time.sleep(3)
248+
time.sleep(5)
249+
250+
execute_with_realtime_output('ls -alt %s'%latest_subdir, os.environ['SIBERNETIC_HOME'], env=my_env)
214251

215252
# Remove black frames at the beginning of the recorded video
216253
command = "ffmpeg -i %s/%s -vf blackdetect=d=0:pic_th=0.70:pix_th=0.10 -an -f null - 2>&1 | grep blackdetect" % (new_sim_out, sibernetic_movie_name)
@@ -247,7 +284,7 @@ def execute_with_realtime_output(command, directory, env=None):
247284
os.system('ffmpeg -ss 1 -i %s/cut_%s -vf "select=gt(scene\,0.1)" -vsync vfr -vf fps=fps=1/1 %s' % (new_sim_out, sibernetic_movie_name, 'tmp/out%06d.jpg'))
248285
os.system('ffmpeg -r 100 -i %s -r 100 -vb 60M %s/speeded_%s' % ('tmp/out%06d.jpg', new_sim_out, sibernetic_movie_name))
249286

250-
os.system('sudo rm -r tmp/*')
287+
os.system('rm -r tmp/*')
251288

252289

253290

rebuild.sh

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
11
#!/bin/bash
22

3-
docker build "$@" -t "openworm/openworm:0.9.2" --no-cache .
3+
version=$(<VERSION) # Read version of Dockerfile from file VERSION
4+
docker build "$@" -t "openworm/openworm:$version" --no-cache .

run-quick.sh

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
#!/bin/bash
2+
3+
#from: https://unix.stackexchange.com/a/129401
4+
while getopts ":d:p:" opt; do
5+
case $opt in
6+
d) duration="$OPTARG"
7+
;;
8+
p) p_out="$OPTARG"
9+
;;
10+
\?) echo "Invalid option -$OPTARG" >&2
11+
;;
12+
esac
13+
done
14+
15+
OW_OUT_DIR=/home/ow/shared
16+
HOST_OUT_DIR=$PWD
17+
version=$(<VERSION) # Read version of Dockerfile from file VERSION
18+
19+
xhost +
20+
21+
22+
NOC302_PART="-e NOC302=1"
23+
DURATION_PART="-e DURATION=3"
24+
25+
docker run -d \
26+
--name openworm_$version \
27+
--device=/dev/dri:/dev/dri \
28+
-e DISPLAY=$DISPLAY \
29+
$NOC302_PART \
30+
$DURATION_PART \
31+
-e OW_OUT_DIR=$OW_OUT_DIR \
32+
-v /tmp/.X11-unix:/tmp/.X11-unix:rw \
33+
--privileged \
34+
-v $HOST_OUT_DIR:$OW_OUT_DIR:rw \
35+
openworm/openworm:$version \
36+
bash -c "DISPLAY=:44 python master_openworm.py"
37+
38+
docker logs -f openworm_$version

0 commit comments

Comments
 (0)