Skip to main content

CASM 1.2.x development in a Docker container

Development guide

Jerry has built an image. You can pull it from Dockerhub.

docker run -it --name CONTAINER_NAME -v ${HOME}:${HOME} dengzeyu/casm_dev_env:1.2.0
  • Run command above will create a container named CONTAINER_NAME and mount your home directory to the same path in the container. The image will be pulled from dengzeyu/casm_dev_env:1.2.0 from Dockerhub. This image does not contain CASM code and you need to git clone.
  • After you create your Docker image or you pull the above image, you need to start a container with the path of your CASM code mounted inside.
  • Use -v to mount ${HOME} outside the container to ${HOME} inside the container. Then you can find everything under ${HOME} in your container as well.
  • Add -d to run this in background (detachable)
warning

Be careful. In principle, this is not safe, if you mount the whole home directory into your container, all the data outside the container could potentially be deleted from the container. It's recommended only mount the directory you are going to interact with container i.e., CASMcode.

Enter the container and compile CASM

  • You need to enter the container first
docker exec -it CONTAINER_NAME bash 
  • You can also use VSCode plugin: right click container you want to enter and click Attach Visual Studio Code Once you are in the container, run following to try your first build
git clone https://github.com/prisms-center/CASMcode.git
cd CASMcode
export CASM_DIRTY_IS_OKAY=1
export CASM_NCPU=32
git submodule init
git submodule update
bash build_install.sh
  • for version 1.x, you need to initialize and update submodules such as Eigen
  • CASM_DIRTY_IS_OKAY should be set to any numbers if you did some changes and haven't commit your changes
tip
  • You have to compile it every time when you change your code.
  • You should open CASMcode folder using File | Open Folder and make sure VSCode can detect your repository and whole source environment.
  • You should install C++ plugins.

Run CASM

  • If you're inside the container, you just run casm.
  • If you're outside, suppose you want to run casm in your current directory, and you have mount your home directory in the container:
docker exec -w $PWD CONTAINER_NAME conda run -n CASM_ENVIRONMENT_NAME_IN_CONTAINER casm

(optional) Build your own Docker image

Create Conda environment and get the environment yaml file

https://prisms-center.github.io/CASMcode_docs/pages/installation/

conda create -n casm \
--override-channels -c prisms-center -c conda-forge \
casm-cpp=1.2.0 python=3
conda activate casm
pip install casm-python

Fix libcasm error

  • You might see following errors
find_executable('ccasm'): ccasm
Found 'ccasm', but for unknown reason could not determine libcasm location.
  • To fix this, add the following to .bashrc
export PATH=CONDA_DIR/envs/casm/bin:${PATH}
export CASM=CONDA_DIR/envs/casm/
export LIBCASM=CONDA_DIR/envs/casm/lib/libcasm.so 
export LIBCCASM=CONDA_DIR/envs/casm/lib/libccasm.so

CONDA_DIR is the path of miniconda3 or anaconda3

Get a YAML file for this environment

conda activate casm # enter casm environment
conda env export > casm.yaml # export to yaml
info
  • Check casm.yaml to see if you have something like intel and remove them.
  • Add   - zlib to under dependencies
  • Remove prefix
  • The casm.yaml file below can only be used for Linux-x64 platform.
name: casm
channels:
- prisms-center
- conda-forge
- defaults
dependencies:
- _libgcc_mutex=0.1=conda_forge
- _openmp_mutex=4.5=2_gnu
- binutils_impl_linux-64=2.39=he00db2b_1
- binutils_linux-64=2.39=h5fc0e48_13
- bzip2=1.0.8=hd590300_5
- ca-certificates=2024.2.2=hbcca054_0
- casm-boost-cpp17=1.66.0=condagcc9_1
- casm-cpp=1.2.0=condagcc9_0
- gcc_impl_linux-64=9.5.0=h99780fb_19
- gcc_linux-64=9.5.0=h4258300_13
- gfortran_impl_linux-64=9.5.0=hf1096a2_19
- gfortran_linux-64=9.5.0=hdb51d14_13
- gxx_impl_linux-64=9.5.0=h99780fb_19
- gxx_linux-64=9.5.0=h43f449f_13
- kernel-headers_linux-64=2.6.32=he073ed8_17
- ld_impl_linux-64=2.39=hcc3a1bd_1
- libffi=3.4.2=h7f98852_5
- libgcc-devel_linux-64=9.5.0=h0a57e50_19
- libgcc-ng=13.2.0=h807b86a_5
- libgfortran-ng=13.2.0=h69a702a_5
- libgfortran5=13.2.0=ha4646dd_5
- libgomp=13.2.0=h807b86a_5
- libnsl=2.0.1=hd590300_0
- libsanitizer=9.5.0=h2f262e1_19
- libsqlite=3.45.2=h2797004_0
- libstdcxx-devel_linux-64=9.5.0=h0a57e50_19
- libstdcxx-ng=13.2.0=h7e041cc_5
- libuuid=2.38.1=h0b41bf4_0
- libxcrypt=4.4.36=hd590300_1
- libzlib=1.2.13=hd590300_5
- ncurses=6.4.20240210=h59595ed_0
- openssl=3.2.1=hd590300_1
- pip=24.0=pyhd8ed1ab_0
- python=3.9.19=h0755675_0_cpython
- python_abi=3.9=4_cp39
- readline=8.2=h8228510_1
- setuptools=69.2.0=pyhd8ed1ab_0
- sysroot_linux-64=2.12=he073ed8_17
- tk=8.6.13=noxft_h4845f30_101
- wheel=0.43.0=pyhd8ed1ab_1
- xz=5.2.6=h166bdaf_0
- zlib
- pip:
- casm-python==1.2.1
- deap==1.4.1
- future==1.0.0
- joblib==1.4.0
- mock==5.1.0
- numpy==1.26.4
- pandas==2.2.2
- prisms-jobs==4.0.3
- python-dateutil==2.9.0.post0
- pytz==2024.1
- scikit-learn==1.4.2
- scipy==1.13.0
- sh==2.0.6
- six==1.16.0
- threadpoolctl==3.4.0
- tzdata==2024.1

Build a docker image

docker build ./ -f casm.dockerfile -t DOCKERHUB_USER/casm_dev_env:1.2.0 --no-cache
  • I'm using following casm.dockerfile
  • Try to uncomment the last block and see if you can compile it. (You might need to change CASM_NCPU to fit your hardware configuration)
# syntax=docker/dockerfile:1
FROM continuumio/miniconda3:latest

WORKDIR /app

# Make RUN commands use `bash --login`:
SHELL ["/bin/bash", "--login", "-c"]

# Install CASM dependencies
COPY casm.yaml ./
RUN conda env create -f casm.yaml
RUN rm casm.yaml
RUN bash ~/.bashrc && conda init bash
RUN echo "conda activate casm" >> ~/.bashrc
RUN conda clean -a -y

RUN apt-get update --fix-missing && \
apt-get install -y wget bzip2 ca-certificates curl git vim build-essential autoconf m4 bash-completion libtool pkg-config zlib1g zlib1g-dev && \
apt-get clean && \
rm -rf /var/lib/apt/lists/*

# Remove CASM and keep only dependencies
RUN conda activate casm && conda remove casm-cpp --force
RUN conda activate casm && pip uninstall casm-python -y
RUN conda activate casm && python3 -m pip install gitpython

# Test: Test if you can successfully run below
# RUN git clone https://github.com/prisms-center/CASMcode.git
# WORKDIR /app/CASMcode
# ENV CASM_DIRTY_IS_OKAY=1
# ENV CASM_NCPU=32
# RUN git submodule init
# RUN git submodule update
# RUN conda activate casm && bash build_install.sh

WORKDIR /

Commit and push to your Dockerhub account

You need to run docker login before push your image

docker login --username=yourhubusername --email=youremail@company.com

Then you can push your image

docker push DOCKERHUB_USERNAME/IMAGE_NAME:VERSION