diff --git a/docker/README.md b/docker/README.md index aa87a5ddb..dbe99e830 100644 --- a/docker/README.md +++ b/docker/README.md @@ -1,10 +1,7 @@ # Docker setup for OpenFermion and select plugins This Docker image contains [OpenFermion](https://github.com/quantumlib/OpenFermion) -and its available plugins for -[Cirq](https://github.com/quantumlib/Cirq), -[Psi4](https://github.com/quantumlib/OpenFermion-Psi4), and -[PySCF](https://github.com/quantumlib/OpenFermion-PySCF). +and its several available plugins. Check out Docker's [website](https://www.docker.com/what-container) for a description of what a container image is and why it can be so useful. The Docker-based installation is extremely robust and runs on any operating @@ -15,57 +12,60 @@ OpenFermion (or any of its plugins) using the standard procedure. ## What's included? - Git -- Python 3 +- Python 3.12 +- [Miniforge](https://github.com/conda-forge/miniforge) - [OpenFermion](https://github.com/quantumlib/OpenFermion) -- [Cirq](https://github.com/quantumlib/Cirq) - [Psi4](http://www.psicode.org) -- [PySCF](https://github.com/sunqm/pyscf) -- [OpenFermion-Cirq](https://github.com/quantumlib/OpenFermion-Cirq) - [OpenFermion-Psi4](https://github.com/quantumlib/OpenFermion-Psi4) - [OpenFermion-PySCF](https://github.com/quantumlib/OpenFermion-PySCF) ## Setting up Docker for the first time +The Dockerfile is based on the [Ubuntu image](https://hub.docker.com/_/ubuntu) (ver. 22.04). +Detecting your host's architecture is handled automatically through the following docker image building process, so you don't have to check it manually. +It creates a Python (ver. 3.12) virtual environment (named `fermion`) using Miniforge and installs all dependencies within it. Psi4 is installed with a [conda command](https://psicode.org/installs/v191/). +You can manually edit the Dockerfile if you need to set up a different development environment (e.g., changing the versions of Ubuntu, Python, Miniforge, Psi4, etc.). + +### Building Docker Image You first need to install [Docker](https://www.docker.com/). Once Docker is setup, one can navigate to the folder containing the -Dockerfile for building the OpenFermion image (docker/dockerfile) and run +Dockerfile for building the OpenFermion image (/docker/dockerfile) and run ``` docker build -t openfermion_docker . ``` - where "openfermion_docker" is just an arbitrary name for our docker image. Building the Dockerfile starts from a base image of Ubuntu and then installs OpenFermion, its plugins, and the necessary applications needed for running these -programs. This is a fairly involved setup and will take some time -(perhaps up to thiry minutes depending on the computer). Once installation has -completed, run the image with +programs. This will take few minutes (depending on the computer) and disk space (several gigabytes). +Line 18 in the Dockerfile ``` -docker run -it openfermion_docker +COPY . /root/workspace ``` +copy the files in the current local directory (where the Dockerfile is located) when the image is built. +If you don't want to copy the files, delete the line first and then build the image. -With this command the terminal enters a new environment which emulates Ubuntu with -OpenFermion and accessories installed. To transfer files from somewhere on the disk to the Docker -container, first run `docker ps` in a separate terminal from the one running -Docker. This returns a list of running containers, e.g.: - +### Running the Container +Once the image has been built, run the image with ``` -+CONTAINER ID IMAGE COMMAND CREATED -+STATUS PORTS NAMES -+3cc87ed4205b 5a67a4d66d05 "/bin/bash" 2 hours ago -+Up 2 hours competent_feynman +docker run -it --name openfermion_container -v $(pwd):/root/workspace openfermion_docker ``` +where "openfermion_container" is an arbitrary choice for the name of our docker container. This command will mount your current local directory, where the Dockerfile is located, to `/root/workspace` inside the running container. +By default, the virtual environment `fermion` is automatically activated in the running container. -In this example, the container name is "competent_feynman" (the name is -random and generated automatically). Using this name, one can then copy -files into the active Docker session from other terminal using: +If you don't want to mount the current directory, run the following command instead: +``` +docker run -it --name openfermion_container openfermion_docker +``` +### Copy Local Files into the Container +Line 18 in the Dockerfile (`COPY . /root/workspace`) copies the current files only once when the image is built. +Local files in any directories can be copied using: ``` docker cp [path to file on disk] [container name]:[path in container] ``` - An alternative way of loading files onto the Docker container is through remote repos such as GitHub. Git is installed in the Docker image. After `docker run`, one could run "git clone ..." etc to pull files diff --git a/docker/dockerfile b/docker/dockerfile index 81c2ca3f2..72e1bc000 100644 --- a/docker/dockerfile +++ b/docker/dockerfile @@ -12,48 +12,35 @@ # Dockerfile for OpenFermion, Cirq, and select plugins. -FROM ubuntu - -USER root - -RUN apt-get update - -# Install utilities -RUN apt-get install -y bzip2 -RUN apt-get install -y cmake -RUN apt-get install -y git -RUN apt-get install -y wget -RUN apt-get install -y libblas-dev -RUN apt-get install -y liblapack-dev - -# Install Python 3 -RUN apt-get install -y python3 - -# Install pip. -RUN apt-get install -y python3-pip - -# Install Psi4. -RUN cd /root; wget http://vergil.chemistry.gatech.edu/psicode-download/psi4conda-1.2.1-py36-Linux-x86_64.sh -RUN echo '/root/psi4conda' | bash /root/psi4conda-1.2.1-py36-Linux-x86_64.sh -RUN rm /root/psi4conda-1.2.1-py36-Linux-x86_64.sh -RUN export PATH=/root/psi4conda/bin:$PATH - -# Install PySCF. -RUN cd /root; git clone https://github.com/sunqm/pyscf -RUN cd /root/pyscf/pyscf/lib; mkdir build; cd build; cmake ..; make - -# Install OpenFermion, Cirq, and plugins. -RUN pip3 install openfermion -RUN pip3 install cirq -RUN pip3 install openfermioncirq -RUN pip3 install openfermionpsi4 -RUN pip3 install openfermionpyscf - -# Update paths -RUN export PATH=/root/psi4conda/bin:$PATH -RUN export PYTHONPATH=/root/pyscf:$PYTHONPATH - -# Make python point to python3 -RUN ln -s /usr/bin/python3 /usr/bin/python - -ENTRYPOINT bash +FROM ubuntu:22.04 + +WORKDIR /root/workspace +COPY . /root/workspace + +# Set PATH for miniforge +ENV PATH="/root/conda/bin:${PATH}" + +RUN apt-get update && \ + apt-get install -y --no-install-recommends git=1:2.34.1-1ubuntu1.15 \ + wget=1.21.2-2ubuntu1.1 \ + libblas-dev=3.10.0-2ubuntu1 \ + liblapack-dev=3.10.0-2ubuntu1 \ + # in order to verify github's certificate + ca-certificates=20240203~22.04.1 \ + build-essential=12.9ubuntu3 && \ + # delete the apt-get lists after the installation + apt-get clean && \ + rm -rf /var/lib/apt/lists/* + +# Install miniforge https://github.com/conda-forge/miniforge?tab=readme-ov-file#as-part-of-a-ci-pipeline +RUN wget -O Miniforge3.sh "https://github.com/conda-forge/miniforge/releases/download/25.3.1-0/Miniforge3-25.3.1-0-$(uname)-$(uname -m).sh" && \ + bash Miniforge3.sh -b -p "${HOME}/conda" && \ + rm Miniforge3.sh && \ + conda init bash && \ + # Create virtual env (fermion) with installing Psi4 + conda create -n fermion psi4==1.10 python=3.12 -c conda-forge -y && \ + # Install OpenFermion and plugins + conda install -n fermion -c conda-forge openfermion==1.7.1 openfermionpsi4==0.5 openfermionpyscf==0.5 -y + +# Activate venv (fermion) +RUN echo "conda activate fermion" >> ~/.bashrc