Skip to content

Commit c326397

Browse files
committed
Merge branch 'master' into development
2 parents f9f0707 + 499344a commit c326397

16 files changed

+183
-73
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-latest
14+
15+
steps:
16+
- uses: actions/checkout@v2
17+
- name: Build the Docker image
18+
run: |
19+
chmod a+w output/
20+
ls -alt
21+
./build.sh
22+
- name: Info on Docker images
23+
run: |
24+
docker -v
25+
docker images
26+
- name: Run the Docker image
27+
run: |
28+
./run-quick.sh
29+
- name: Info on generated files
30+
run: |
31+
ls -alt
32+
ls -alt output
33+
ls -alt output/*

.github/workflows/docker-image.yml

Lines changed: 8 additions & 2 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 -v
25+
docker images
2026
- name: Run the Docker image
2127
run: |
2228
./run.sh
2329
- name: Info on generated files
2430
run: |
31+
ls -alt
2532
ls -alt output
26-
ls -alt output/C2*
27-
cat output/C2_*/report.json
33+
ls -alt output/*

.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_*

Dockerfile

Lines changed: 17 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
FROM ubuntu:18.04
1+
FROM ubuntu:22.04
22

33
LABEL maintainer="David Lung ([email protected]); Padraig Gleeson ([email protected])"
44

@@ -36,7 +36,7 @@ RUN apt-get update && apt-get install -y --no-install-recommends apt-utils \
3636
wget nano htop build-essential make git automake autoconf \
3737
g++ rpm libtool libncurses5-dev zlib1g-dev bison flex lsb-core \
3838
sudo xorg openbox x11-xserver-utils \
39-
libxext-dev libncurses-dev python-dev mercurial \
39+
libxext-dev libncurses-dev python3-dev mercurial \
4040
freeglut3-dev libglu1-mesa-dev libglew-dev python3-dev python3-pip python3-lxml python3-scipy python3-tk \
4141
kmod dkms linux-source linux-headers-generic \
4242
maven openjdk-8-jdk \
@@ -50,7 +50,7 @@ RUN apt-get update && apt-get install -y --no-install-recommends apt-utils \
5050

5151
RUN sudo usermod -a -G video $USER
5252

53-
USER $USER
53+
#USER $USER
5454
ENV HOME /home/$USER
5555
WORKDIR $HOME
5656

@@ -62,29 +62,20 @@ RUN sudo update-alternatives --install /usr/bin/pip pip /usr/bin/pip3 10
6262
################################################################################
6363
######## Install NEURON simulator
6464

65-
RUN sudo pip install neuron==7.8.1
65+
RUN pip3 install neuron==8.0.1
6666

6767

6868
################################################################################
6969
######## Install c302 for building neuronal network models
7070

71-
72-
# TODO remove this line after we have better dependency management. The
73-
# current version of gitpython requires python >= 3.7, which is newer than the
74-
# python included in the base image. Therefore, we manually install an older
75-
# gitpython to be used with OpenWormData.
76-
# See https://github.com/openworm/OpenWorm/pull/316
77-
RUN sudo pip install 'gitpython==2.1.15' markupsafe
78-
79-
RUN sudo pip install 'NeuroMLlite<0.5.0' # for python 3.6...
80-
8171
RUN git clone https://github.com/openworm/c302.git && \
8272
cd c302 && \
83-
git checkout ow-0.9.2 && \
73+
git checkout ow-0.9.3 && \
8474
sudo pip install .
8575

86-
# Note: owmeta, owmeta-core and pyNeuroML installed with the above library
76+
# Note: pyNeuroML installed with the above library
8777

78+
RUN pip3 install owmeta-core==0.13.5
8879
RUN owm bundle remote --user add ow 'https://raw.githubusercontent.com/openworm/owmeta-bundles/master/index.json'
8980

9081

@@ -93,9 +84,7 @@ RUN owm bundle remote --user add ow 'https://raw.githubusercontent.com/openworm/
9384

9485
RUN git clone https://github.com/openworm/sibernetic.git && \
9586
cd sibernetic && \
96-
git checkout ow-0.9.1 # fixed to a specific branch
97-
98-
RUN cp c302/pyopenworm.conf sibernetic/ # Temp step until PyOpenWorm can be run from any dir...
87+
git checkout ow-0.9.3 # fixed to a specific branch
9988

10089

10190
################################################################################
@@ -105,10 +94,6 @@ ENV C302_HOME=$HOME/c302/c302
10594
ENV SIBERNETIC_HOME=$HOME/sibernetic
10695
ENV PYTHONPATH=$PYTHONPATH:$HOME/c302:$SIBERNETIC_HOME
10796

108-
# Not working with --chown=$USER:$USER
109-
COPY ./master_openworm.py $HOME/master_openworm.py
110-
RUN sudo chown $USER:$USER $HOME/master_openworm.py
111-
11297

11398
################################################################################
11499
######## Install Intel OpenCL libraries needed for Sibernetic
@@ -135,25 +120,16 @@ sudo apt install -y ocl-icd-opencl-dev vim
135120
######## Build Sibernetic
136121

137122
RUN cd sibernetic && \
138-
sed -i -e "s/lpython2.7/lpython3.6m/g" makefile && \
139-
sed -i -e "s/n2.7/n3.6/g" makefile && \
140-
make clean && make all # Use python 3 libs
141-
142-
# intel i5, hd 5500, linux 4.15.0-39-generic
143-
# ./Release/Sibernetic -f worm -no_g device=CPU 190ms
144-
# ./Release/Sibernetic -f worm -no_g device=GPU 150ms (initialization takes some time)
145-
146-
# Intel(R) Xeon(R) CPU E5-1650 v4 @ 3.60GHz, linux 4.4.0-139-generic
147-
# ./Release/Sibernetic -f worm -no_g device=CPU 60ms
148-
#
149-
# after installing the nvidia driver used in host:
150-
## wget http://us.download.nvidia.com/tesla/390.30/nvidia-diag-driver-local-repo-ubuntu1604-390.30_1.0-1_amd64.deb
151-
## sudo dpkg -i nvidia-diag-driver-local-repo-ubuntu1604-390.30_1.0-1_amd64.deb
152-
## sudo apt-key add /var/nvidia-diag-driver-local-repo-390.30/7fa2af80.pub
153-
## sudo apt-get update
154-
## sudo apt-get install -y cuda-drivers
155-
# ./Release/Sibernetic -f worm -no_g device=GPU 37ms
123+
sed -i -e "s/n2.7/n3.10/g" makefile && \
124+
make clean && make all && ldd ./Release/Sibernetic # Use python 3 libs
125+
126+
127+
################################################################################
128+
######## Copy master python script
156129

130+
# Not working with --chown=$USER:$USER
131+
COPY ./master_openworm.py $HOME/master_openworm.py
132+
RUN sudo chown $USER:$USER $HOME/master_openworm.py
157133

158134
RUN echo '\n\nalias cd..="cd .."\nalias h=history\nalias ll="ls -alt"' >> ~/.bashrc
159135

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ We have put together a [Docker container](https://hub.docker.com/r/openworm/open
2727

2828
<img src="https://raw.githubusercontent.com/openworm/OpenWorm/master/img/muscle-activity.png" width="250"><img src="https://raw.githubusercontent.com/openworm/OpenWorm/master/img/neuron-activity.png" width="350">
2929

30-
**NOTE**: Running the simulation for the full amount of time would produce content like the above. However, in order to run in a reasonable amount of time, the default run time for the simulation is limited. As such, you will see only a partial output, equivalent to about 5% of run time, compared to the examples above. To extend the run time, use the `-d` argument as described below.
30+
**NOTE**: Running the simulation for the full amount of time would produce content like the above. However, in order to run in a reasonable amount of time, **the default run time for the simulation is limited**. As such, you will see only a partial output, equivalent to about 5% of run time, compared to the examples above. To extend the run time, use the `-d` argument as described below.
3131

3232
**Installation**
3333

VERSION

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

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.3" .
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.3_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: 54 additions & 14 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
@@ -76,22 +76,38 @@
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'])
92108

93109
try:
94-
os.system('xhost +')
110+
os.system('echo Granting permissions for xhost && xhost +')
95111
except:
96112
print("Unexpected error: %s" % sys.exc_info()[0])
97113

@@ -110,23 +126,30 @@ 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,
116136
'logstep': 100,
117137
'reference': 'FW',
118138
'c302params': 'C2',
119139
'verbose': False,
120-
'device': 'GPU',
140+
'device': 'CPU',
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()
127-
my_env["DISPLAY"] = ":44"
147+
DISPLAY = ':44'
148+
my_env["DISPLAY"] = DISPLAY
128149

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

131154
try:
132155
command = """python sibernetic_c302.py
@@ -151,6 +174,9 @@ def execute_with_realtime_output(command, directory, env=None):
151174
DEFAULTS['datareader'],
152175
'simulations')
153176
#DEFAULTS['outDir'])
177+
178+
if noc302: command += ' -noc302'
179+
154180
execute_with_realtime_output(command, os.environ['SIBERNETIC_HOME'], env=my_env)
155181
except KeyboardInterrupt as e:
156182
pass
@@ -162,9 +188,13 @@ def execute_with_realtime_output(command, directory, env=None):
162188
for directory in dirnames:
163189
if directory.startswith('%s_%s' % (DEFAULTS['c302params'], DEFAULTS['reference'])):
164190
all_subdirs.append(os.path.join(dirpath, directory))
191+
if directory.startswith('Sibernetic'):
192+
all_subdirs.append(os.path.join(dirpath, directory))
165193

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

169199
try:
170200
os.mkdir('%s/output' % OW_OUT_DIR)
@@ -198,20 +228,30 @@ def execute_with_realtime_output(command, directory, env=None):
198228
print("Moving %s to %s"%(wcon, new_sim_out))
199229
shutil.move(wcon, new_sim_out)
200230

231+
time.sleep(2)
201232

202233
# Rerun and record simulation
203-
os.system('export DISPLAY=:44')
234+
execute_with_realtime_output('ls -alt /tmp/.X11-unix', os.environ['SIBERNETIC_HOME'], env=my_env)
235+
os.system('export DISPLAY=%s'%DISPLAY)
236+
execute_with_realtime_output('ls -alt /tmp/.X11-unix', os.environ['SIBERNETIC_HOME'], env=my_env)
204237
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))
238+
command = 'tmux new-session -d -P -s SiberneticRecording "DISPLAY=%s ffmpeg -r 30 -f x11grab -draw_mouse 0 -s 1920x1080 -i %s -filter:v "crop=1200:800:100:100" -cpu-used 0 -b:v 384k -qmin 10 -qmax 42 -maxrate 384k -bufsize 1000k -an %s/%s"' % (DISPLAY, DISPLAY, new_sim_out, sibernetic_movie_name)
239+
execute_with_realtime_output(command, os.environ['SIBERNETIC_HOME'], env=my_env)
240+
241+
time.sleep(3)
242+
243+
execute_with_realtime_output('tmux list-sessions', os.environ['SIBERNETIC_HOME'], env=my_env)
206244

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

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

213251
time.sleep(3)
214252

253+
execute_with_realtime_output('ls -alt %s'%latest_subdir, os.environ['SIBERNETIC_HOME'], env=my_env)
254+
215255
# Remove black frames at the beginning of the recorded video
216256
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)
217257
outstr = str(check_output(command, shell=True).decode('utf-8'))
@@ -247,7 +287,7 @@ def execute_with_realtime_output(command, directory, env=None):
247287
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'))
248288
os.system('ffmpeg -r 100 -i %s -r 100 -vb 60M %s/speeded_%s' % ('tmp/out%06d.jpg', new_sim_out, sibernetic_movie_name))
249289

250-
os.system('sudo rm -r tmp/*')
290+
os.system('rm -r tmp/*')
251291

252292

253293

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

0 commit comments

Comments
 (0)