Skip to content

Commit 4b4258b

Browse files
committed
Update Dockerfile and its README
1 parent 9a508c0 commit 4b4258b

File tree

2 files changed

+68
-64
lines changed

2 files changed

+68
-64
lines changed

docker/README.md

Lines changed: 25 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,8 @@ OpenFermion (or any of its plugins) using the standard procedure.
1515
## What's included?
1616

1717
- Git
18-
- Python 3
18+
- Python 3.12
19+
- [Miniconda](https://www.anaconda.com/docs/getting-started/miniconda/main)
1920
- [OpenFermion](https://github.com/quantumlib/OpenFermion)
2021
- [Cirq](https://github.com/quantumlib/Cirq)
2122
- [Psi4](http://www.psicode.org)
@@ -27,6 +28,25 @@ OpenFermion (or any of its plugins) using the standard procedure.
2728

2829
## Setting up Docker for the first time
2930

31+
The Dockerfile is based on the [Ubuntu image](https://hub.docker.com/_/ubuntu) (ver. 22.04).
32+
It creates a Python (ver. 3.12) virtual environemnt (named `fermion`) using Miniconda and installs all dependencies within it. Psi4 is installed with a conda [command](https://psicode.org/installs/v191/).
33+
The default configuration uses the Miniconda installer (ver. 25.5.1-1) for Python 3.12 on Linux `aarch64` architecture.
34+
35+
### Customizing the Environment
36+
You can manually edit the Dockerfile if you need to set up a different development environment (e.g., change the Ubuntu, Python, Miniconda, or Psi4 version).
37+
38+
If your local machine builds Linux `x86_64` architecture with the Dockerfile, the `wget` command
39+
for the Miniconda installer (Line 40 in the Dockerfile)
40+
```
41+
wget https://repo.anaconda.com/miniconda/Miniconda3-py312_25.5.1-1-Linux-aarch64.sh -O ~/miniconda3/miniconda.sh && \
42+
```
43+
must be changed to
44+
```
45+
wget https://repo.anaconda.com/miniconda/Miniconda3-py312_25.5.1-1-Linux-x86_64.sh -O ~/miniconda3/miniconda.sh && \
46+
```
47+
You can check other Miniconda installers [here](https://repo.anaconda.com/miniconda/).
48+
49+
### Building Docker Image
3050
You first need to install [Docker](https://www.docker.com/).
3151
Once Docker is setup, one can navigate to the folder containing the
3252
Dockerfile for building the OpenFermion image (docker/dockerfile) and run
@@ -39,31 +59,14 @@ where "openfermion_docker" is just an arbitrary name for our docker image.
3959
Building the Dockerfile starts from a base image of Ubuntu and then installs
4060
OpenFermion, its plugins, and the necessary applications needed for running these
4161
programs. This is a fairly involved setup and will take some time
42-
(perhaps up to thiry minutes depending on the computer). Once installation has
43-
completed, run the image with
62+
(perhaps up to thirty minutes depending on the computer) and disk space (several gigabytes). Once installation has completed, run the image with
4463

4564
```
46-
docker run -it openfermion_docker
65+
docker run -it --name openfermion_container -v $(pwd):/root/workspace openfermion_docker
4766
```
48-
49-
With this command the terminal enters a new environment which emulates Ubuntu with
50-
OpenFermion and accessories installed. To transfer files from somewhere on the disk to the Docker
51-
container, first run `docker ps` in a separate terminal from the one running
52-
Docker. This returns a list of running containers, e.g.:
53-
54-
```
55-
+CONTAINER ID IMAGE COMMAND CREATED
56-
+STATUS PORTS NAMES
57-
+3cc87ed4205b 5a67a4d66d05 "/bin/bash" 2 hours ago
58-
+Up 2 hours competent_feynman
59-
```
60-
61-
In this example, the container name is "competent_feynman" (the name is
62-
random and generated automatically). Using this name, one can then copy
63-
files into the active Docker session from other terminal using:
64-
67+
where "openfermion_container" is an arbitrary choice for the name of our docker container. This command will mount your current local directory to `/root/workspace` inside the running container. You can activate the virtual environment `fermion` in the container with
6568
```
66-
docker cp [path to file on disk] [container name]:[path in container]
69+
source activate fermion
6770
```
6871

6972
An alternative way of loading files onto the Docker container is through

docker/dockerfile

Lines changed: 43 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -12,48 +12,49 @@
1212

1313
# Dockerfile for OpenFermion, Cirq, and select plugins.
1414

15-
FROM ubuntu
15+
FROM ubuntu:22.04
1616

1717
USER root
1818

19-
RUN apt-get update
20-
21-
# Install utilities
22-
RUN apt-get install -y bzip2
23-
RUN apt-get install -y cmake
24-
RUN apt-get install -y git
25-
RUN apt-get install -y wget
26-
RUN apt-get install -y libblas-dev
27-
RUN apt-get install -y liblapack-dev
28-
29-
# Install Python 3
30-
RUN apt-get install -y python3
31-
32-
# Install pip.
33-
RUN apt-get install -y python3-pip
34-
35-
# Install Psi4.
36-
RUN cd /root; wget http://vergil.chemistry.gatech.edu/psicode-download/psi4conda-1.2.1-py36-Linux-x86_64.sh
37-
RUN echo '/root/psi4conda' | bash /root/psi4conda-1.2.1-py36-Linux-x86_64.sh
38-
RUN rm /root/psi4conda-1.2.1-py36-Linux-x86_64.sh
39-
RUN export PATH=/root/psi4conda/bin:$PATH
40-
41-
# Install PySCF.
42-
RUN cd /root; git clone https://github.com/sunqm/pyscf
43-
RUN cd /root/pyscf/pyscf/lib; mkdir build; cd build; cmake ..; make
44-
45-
# Install OpenFermion, Cirq, and plugins.
46-
RUN pip3 install openfermion
47-
RUN pip3 install cirq
48-
RUN pip3 install openfermioncirq
49-
RUN pip3 install openfermionpsi4
50-
RUN pip3 install openfermionpyscf
51-
52-
# Update paths
53-
RUN export PATH=/root/psi4conda/bin:$PATH
54-
RUN export PYTHONPATH=/root/pyscf:$PYTHONPATH
55-
56-
# Make python point to python3
57-
RUN ln -s /usr/bin/python3 /usr/bin/python
58-
59-
ENTRYPOINT bash
19+
WORKDIR /root/workspace
20+
COPY . /root/workspace
21+
22+
# Set PATH for miniconda
23+
ENV PATH=/root/miniconda3/bin:$PATH
24+
# Set PATH for pyscf
25+
ENV PYTHONPATH=/root/pyscf
26+
27+
RUN apt-get update && \
28+
apt-get install -y build-essential \
29+
bzip2 \
30+
cmake \
31+
git \
32+
wget \
33+
libblas-dev \
34+
liblapack-dev \
35+
curl
36+
37+
# Install miniconda for python 3.12, Linux aarch
38+
# https://www.anaconda.com/docs/getting-started/miniconda/install#quickstart-install-instructions
39+
RUN mkdir -p ~/miniconda3 && \
40+
wget https://repo.anaconda.com/miniconda/Miniconda3-py312_25.5.1-1-Linux-aarch64.sh -O ~/miniconda3/miniconda.sh && \
41+
bash ~/miniconda3/miniconda.sh -b -u -p ~/miniconda3 && \
42+
rm ~/miniconda3/miniconda.sh && \
43+
/bin/bash -c "source ~/miniconda3/bin/activate" && \
44+
conda init --all && \
45+
# To accept a channel's Terms of Service
46+
conda tos accept --override-channels --channel https://repo.anaconda.com/pkgs/main && \
47+
conda tos accept --override-channels --channel https://repo.anaconda.com/pkgs/r && \
48+
# Create virtual env (fermion) with installing Psi4
49+
conda create -n fermion psi4 python=3.12 -c conda-forge -y && \
50+
conda install -n fermion pip -y && \
51+
# Install OpenFermion, Cirq, and plugins
52+
conda run -n fermion pip install openfermion \ cirq \ openfermioncirq \ openfermionpsi4 \ openfermionpyscf && \
53+
# Install PySCF
54+
cd /root && \
55+
git clone https://github.com/sunqm/pyscf && \
56+
cd /root/pyscf/pyscf/lib && \
57+
mkdir build && \
58+
cd build && \
59+
cmake .. && \
60+
make

0 commit comments

Comments
 (0)