Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

mpi4py Jupyter tutorial and frontend tutorial outline #69

Merged
merged 7 commits into from
Nov 10, 2023
Merged
Show file tree
Hide file tree
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
45 changes: 41 additions & 4 deletions .devcontainer/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ RUN mkdir /opt/spack-environment \
&& echo ' - [email protected]+coinhsl~mumps+metis' \
&& echo ' - [email protected]+blas' \
&& echo ' - py-jupyterlab' \
&& echo ' - py-ipyparallel' \
&& echo ' concretizer:' \
&& echo ' unify: true' \
&& echo ' reuse: true' \
Expand All @@ -28,15 +29,32 @@ RUN mkdir /opt/spack-environment \
&& echo ' - openmpi' \
&& echo ' zlib-api:' \
&& echo ' - zlib' \
&& echo ' zlib-ng:' \
&& echo ' buildable: false' \
&& echo ' config:' \
&& echo ' install_tree: /opt/software' \
&& echo ' view: /opt/views/view') > /opt/spack-environment/spack.yaml

# This is manual, and required to build Ipopt
COPY coinhsl-archive-2019.05.21.tar.gz /opt/spack-environment/coinhsl-archive-2019.05.21.tar.gz

# Find external packages
RUN cd /opt/spack-environment && spack env activate . && spack external find --all --exclude python

# Do this separate of install to cache keys...
RUN spack mirror add develop https://binaries.spack.io/develop && spack buildcache keys --install --trust
RUN cd /opt/spack-environment && spack env activate . && spack mirror add develop https://binaries.spack.io/develop && spack buildcache keys --install --trust && spack concretize -f && spack mirror create -a

# Install Ipopt w/ CoinHSL (and other deps) in stages to cache builds
RUN cd /opt/spack-environment && spack env activate . && spack install --fail-fast ipopt

# Install PETSc
RUN cd /opt/spack-environment && spack env activate . && spack install --fail-fast petsc

# Install py-jupyterlab
RUN cd /opt/spack-environment && spack env activate . && spack install --fail-fast py-jupyterlab

# Install py-ipyparallel
RUN cd /opt/spack-environment && spack env activate . && spack install --fail-fast py-ipyparallel

# Install the software, remove unnecessary deps
RUN cd /opt/spack-environment && spack env activate . && spack install --fail-fast && spack gc -y
Expand Down Expand Up @@ -72,7 +90,7 @@ RUN { \


RUN apt-get -yqq update && apt-get -yqq upgrade \
&& apt-get -yqq install gfortran \
&& apt-get -yqq install gfortran npm postgresql \
&& rm -rf /var/lib/apt/lists/*
ENTRYPOINT [ "/entrypoint.sh" ]
CMD [ "/bin/bash" ]
Expand All @@ -83,6 +101,25 @@ RUN echo "source /entrypoint.sh" >> /home/vscode/.bashrc
# Install the Jupyter kernel
RUN . /entrypoint.sh && \
python3 -m ipykernel install \
--name py311-exago\
--display-name ExaGO \
--name py311-exago \
--display-name "ExaGO" \
--prefix=

# Install the mpi4py Jupyter kernel
RUN . /entrypoint.sh && \
python3 -m ipykernel install \
--name py311-mpi4py-exago \
--display-name "ExaGO w/ MPI" \
--prefix=

# Make modifications that are necessary to run mpi4py in kernelspec
RUN sed -i 's/\"\/opt\/views\/view\/bin\/python3\"/\"mpiexec\", \"-n\", \"1\", \"\/opt\/views\/view\/bin\/python3\"/g' /usr/local/share/jupyter/kernels/py311-mpi4py-exago/kernel.json
jaelynlitz marked this conversation as resolved.
Show resolved Hide resolved

# Configure user for container
USER vscode

# Install nvm
RUN mkdir -p /home/vscode/nvm && cd /home/vscode/nvm && curl -O https://raw.githubusercontent.com/nvm-sh/nvm/v0.39.1/install.sh
RUN chown vscode /home/vscode/nvm/install.sh && chmod +x /home/vscode/nvm/install.sh

# Install NodeJS version 16.13.0 with nvm
137 changes: 137 additions & 0 deletions .devcontainer/create_dockerfile_devcontainer.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,137 @@
#!/bin/bash
cameronrutherford marked this conversation as resolved.
Show resolved Hide resolved
# Generates Dockerfile for use as Devcontainer...

# Only necessary for HTTPS operations on PNNL VPN
# export HTTPS_PROXY=http://proxy01.pnl.gov:3128 &&
# export https_proxy=http://proxy01.pnl.gov:3128 &&

# Get CoinHSL tarball if not present
if [ ! -f "./coinhsl-archive-2019.05.21.tar.gz" ]; then
echo "No coinhsl-archive-2019.05.21.tar.gz found - make sure to get your own license and copy it to this directory"
echo "Note that the tarball must be named coinhsl-archive-2019.05.21.tar.gz"
exit 1
fi

# Add read/execute permissions to CoinHSL tarball
chmod +rx ./coinhsl-archive-2019.05.21.tar.gz &&

# If "-f" flag passed, force rebuild
if [ "$1" == "-f" ]; then
echo "Forcing rebuild" &&
rm -rf ~/.spack &&
rm -rf ./spack &&
rm -rf ./spack-env
fi

# or no ./spack dir, force a rebuild
if [ ! -d "./tpl/spack/share" ]; then
echo "No spack submodule directory found, downloading spack"
git submodule update --init --recursive
fi

export SPACK_PYTHON=$(which python3) &&
# Setup spack
source ./tpl/spack/share/spack/setup-env.sh &&

# Create heredoc for spack.yaml with environment
cat > $(pwd)/spack.yaml <<EOF
spack:
specs:
- [email protected]+ipopt+python+mpi
- petsc~fortran~hdf5~hypre+metis
- [email protected]+coinhsl~mumps+metis
- [email protected]+blas
- py-jupyterlab
- py-ipyparallel
concretizer:
unify: true
reuse: true
mirrors:
spack: https://binaries.spack.io/develop
container:
format: docker
images:
build: spack/ubuntu-jammy
final: mcr.microsoft.com/devcontainers/python:3.11-bookworm
os_packages:
command: apt
build:
- autoconf
final:
- gfortran
- npm
- postgresql
packages:
all:
providers:
mpi:
- openmpi
zlib-api:
- zlib
zlib-ng:
buildable: false
EOF

# Containerize into a Dockerfile
# Eventually put this straight into ExaGO repo...
spack containerize > ./.devcontainer/Dockerfile

# THIS ONLY WORKS ON MAC!!! - maybe get gsed wit brew working...
# Add Docker command before "# Install" that copies CoinHSL into image
sed -i "" "s|# Install the software|# This is manual, and required to build Ipopt\nCOPY coinhsl-archive-2019.05.21.tar.gz /opt/spack-environment/coinhsl-archive-2019.05.21.tar.gz\n\n# Install the software|" ./.devcontainer/Dockerfile

# Find external packages
sed -i "" "s|# Install the software|# Find external packages\nRUN cd /opt/spack-environment \&\& spack env activate . \&\& spack external find --all --exclude python\n\n# Install the software|" ./.devcontainer/Dockerfile

# Also trusts the build cache and create source mirror
sed -i "" "s|# Install the software|# Do this separate of install to cache keys...\nRUN cd /opt/spack-environment \&\& spack env activate . \&\& spack mirror add develop https://binaries.spack.io/develop \&\& spack buildcache keys --install --trust \&\& spack concretize -f \&\& spack mirror create -a\n\n# Install the software|" ./.devcontainer/Dockerfile

# Install Ipopt and packages in separate stages to cache builds
sed -i "" "s|# Install the software|# Install Ipopt w/ CoinHSL (and other deps) in stages to cache builds\nRUN cd /opt/spack-environment \&\& spack env activate . \&\& spack install --fail-fast ipopt\n\n# Install the software|" ./.devcontainer/Dockerfile
sed -i "" "s|# Install the software|# Install PETSc \nRUN cd /opt/spack-environment \&\& spack env activate . \&\& spack install --fail-fast petsc\n\n# Install the software|" ./.devcontainer/Dockerfile
sed -i "" "s|# Install the software|# Install py-jupyterlab\nRUN cd /opt/spack-environment \&\& spack env activate . \&\& spack install --fail-fast py-jupyterlab\n\n# Install the software|" ./.devcontainer/Dockerfile
sed -i "" "s|# Install the software|# Install py-ipyparallel\nRUN cd /opt/spack-environment \&\& spack env activate . \&\& spack install --fail-fast py-ipyparallel\n\n# Install the software|" ./.devcontainer/Dockerfile

# Configure environment for VSCode User in devcontainer
echo "# Make sure devcontainer user gets spack packages" >> ./.devcontainer/Dockerfile
echo "RUN echo \"source /entrypoint.sh\" >> /home/vscode/.bashrc" >> ./.devcontainer/Dockerfile

# Finally install the Jupyter kernel
echo "" >> ./.devcontainer/Dockerfile
echo "# Install the Jupyter kernel" >> ./.devcontainer/Dockerfile
echo "RUN . /entrypoint.sh && \\" >> ./.devcontainer/Dockerfile
echo " python3 -m ipykernel install \\" >> ./.devcontainer/Dockerfile
echo " --name py311-exago \\" >> ./.devcontainer/Dockerfile
echo " --display-name \"ExaGO\" \\" >> ./.devcontainer/Dockerfile
echo " --prefix=$(which jupyter)" >> ./.devcontainer/Dockerfile

# Install the mpi4py Jupyter kernel
echo "" >> ./.devcontainer/Dockerfile
echo "# Install the mpi4py Jupyter kernel" >> ./.devcontainer/Dockerfile
echo "RUN . /entrypoint.sh && \\" >> ./.devcontainer/Dockerfile
echo " python3 -m ipykernel install \\" >> ./.devcontainer/Dockerfile
echo " --name py311-mpi4py-exago \\" >> ./.devcontainer/Dockerfile
echo " --display-name \"ExaGO w/ MPI\" \\" >> ./.devcontainer/Dockerfile
echo " --prefix=$(which jupyter)" >> ./.devcontainer/Dockerfile

# Modify mpi4py kernel to actually launch process with mpiexec
echo "" >> ./.devcontainer/Dockerfile
echo "# Make modifications that are necessary to run mpi4py in kernelspec" >> ./.devcontainer/Dockerfile
echo "RUN sed -i 's/\\\"\/opt\/views\/view\/bin\/python3\\\"/\\\"mpiexec\\\", \\\"-n\\\", \\\"1\\\", \\\"\/opt\/views\/view\/bin\/python3\\\"/g' /usr/local/share/jupyter/kernels/py311-mpi4py-exago/kernel.json" >> ./.devcontainer/Dockerfile

# Make sure vscode user is correct
echo "" >> ./.devcontainer/Dockerfile
echo "# Configure user for container" >> ./.devcontainer/Dockerfile
echo "USER vscode" >> ./.devcontainer/Dockerfile

# Install nvm for VSCode user
echo "" >> ./.devcontainer/Dockerfile
echo "# Install nvm" >> ./.devcontainer/Dockerfile
echo "RUN mkdir -p /home/vscode/nvm && cd /home/vscode/nvm && curl -O https://raw.githubusercontent.com/nvm-sh/nvm/v0.39.1/install.sh" >> ./.devcontainer/Dockerfile
echo "RUN chown vscode /home/vscode/nvm/install.sh && chmod +x /home/vscode/nvm/install.sh" >> ./.devcontainer/Dockerfile

# Install NodeJS version 16.13.0 with nvm
echo "" >> ./.devcontainer/Dockerfile
echo "# Install NodeJS version 16.13.0 with nvm" >> ./.devcontainer/Dockerfile
#echo "RUN . /opt/nvm/nvm.sh && \\" >> ./.devcontainer/Dockerfile
#echo " nvm install v16.13.0" >> ./.devcontainer/Dockerfile
3 changes: 2 additions & 1 deletion .devcontainer/devcontainer.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@
"ms-azuretools.vscode-docker",
"github.vscode-github-actions",
"ms-toolsai.jupyter",
"GitHub.copilot"
"GitHub.copilot",
"ms-vsliveshare.vsliveshare"
]
}
},
Expand Down
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ install/*
.ubuild.json
*__pycache__*
*nvblas.conf
spack-*
spack*
.vscode/
coinhsl-*
node_modules
Expand All @@ -14,3 +14,4 @@ package-lock.json
config.py
spack_*
hiop/
solution
4 changes: 4 additions & 0 deletions docs/devcontainer/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,10 @@
1. open your local clone of exago in VSCode
1. copy the CoinHSL 2019 tarball to the top level of your exago directory

## Generate the container

Spack is used to generate the base image, with some sed/echo commands used to fine-tune Dockerfile for use case within a Dev Container. Run `.devcontainer/create_dockerfile.sh` in order to re-generate the Dockerfile. This should be done semi-frequently whenever a spack version or exago version needs updating.
jaelynlitz marked this conversation as resolved.
Show resolved Hide resolved

## Build Container

The build info for this container is in `.devcontainer/`. There is a Dockerfile and json file associated with the configuration.
Expand Down
Loading
Loading