qwire, cirq, and qiskit
406
Dockerfile:
# stable Ubuntu LTS
FROM ubuntu:24.04
# force Git to fail immediately rather than trying to open an
# interactive prompt. Often bypasses the "device" error.
ENV GIT_TERMINAL_PROMPT=0
# decrease concurrency to fit on my laptop
ENV OPAMJOBS=2
# Prevent interactive prompts during package installation
ENV DEBIAN_FRONTEND=noninteractive
# Set environment variables
ENV PYTHONUNBUFFERED=1 \
PYTHONDONTWRITEBYTECODE=1
# Install system dependencies
RUN apt-get update && apt-get install -y \
build-essential \
curl \
git \
m4 \
unzip \
bubblewrap \
python3 \
python3-pip \
python3-venv \
opam \
libgmp-dev \
pkg-config \
&& rm -rf /var/lib/apt/lists/*
# Create a non-root user for OPAM and Python packages
RUN useradd -m -s /bin/bash myuseracct
USER myuseracct
WORKDIR /home/myuseracct/workspace
ENV HOME=/home/myuseracct
# Setup Python Virtual Environment and Install Quantum Frameworks
# use a venv to avoid PEP 668 restrictions in Ubuntu
ENV VIRTUAL_ENV=/home/myuseracct/venv
RUN python3 -m venv $VIRTUAL_ENV
ENV PATH="$VIRTUAL_ENV/bin:$PATH"
# Install Cirq, Qiskit, PyZX, and JupyterLab
RUN pip install --no-cache-dir --upgrade pip && \
pip install --no-cache-dir \
cirq \
jkq.ddsim \
qiskit \
pyzx \
jupyterlab
# Initialize OPAM (the OCaml Package Manager) and Rocq (formerly Coq)
# Install Coq 8.18.0 as it is the most recent version fully compatible with VyZX & SQIR.
# Install coq-bignums, a standard requirement for the inQWIRE stack; https://github.com/rocq-community/bignums
RUN opam init --disable-sandboxing -y && \
opam switch create 4.14.2 && \
eval $(opam env) && \
opam repo add rocq-released https://rocq-prover.org/opam/released && \
opam install -y dune coq.8.18.0 coq-bignums coq-interval
# initially used `coq.8.18.0` but that's incompatible with `coq-euler`
# downgrading to `coq.8.16.1` wasn't sufficient, nor was `coq.8.15.2`
# Ensure opam environment variables are loaded for subsequent RUN commands
ENV PATH="/home/myuseracct/.opam/4.14.2/bin:${PATH}"
# Build and Install Formal Verification Ecosystem (inQWIRE)
# These must be compiled in a specific order: QuantumLib -> SQIR -> QWIRE -> VyZX
# QuantumLib (Core Mathematics & Matrices) - https://github.com/inQWIRE/QuantumLib
RUN eval $(opam env) && \
git clone https://github.com/inQWIRE/QuantumLib.git /home/myuseracct/QuantumLib && \
cd /home/myuseracct/QuantumLib && \
opam install . -y
# formerly the `opam install . -y` was `make && make install` but
# evaluating Shor.v requires `coq-euler`, and `coq-euler` isn't buildable with `coq.8.18.0`
# or `coq.8.16.1` or `coq.8.15.2`. Rolling back `coq` earlier than that breaks `VyZX`
#RUN eval $(opam env) && \
# git clone https://github.com/taorunz/euler.git /home/myuseracct/euler && \
# cd /home/myuseracct/euler && \
# opam install . -y
# SQIR (Small Quantum Intermediate Representation)
RUN eval $(opam env) && \
git clone https://github.com/inQWIRE/SQIR.git /home/myuseracct/SQIR && \
cd /home/myuseracct/SQIR && \
opam install . -y
# QWIRE (Quantum Circuit Language) - https://github.com/inQWIRE/QWIRE
RUN eval $(opam env) && \
git clone https://github.com/inQWIRE/QWIRE.git /home/myuseracct/QWIRE && \
cd /home/myuseracct/QWIRE && \
opam install . -y
# VyZX (Formal Verification of PyZX) - https://github.com/inQWIRE/VyZX
RUN eval $(opam env) && \
git clone https://github.com/inQWIRE/VyZX.git /home/myuseracct/VyZX && \
cd /home/myuseracct/VyZX && \
opam install . -y
# core VOQC OCaml library - Verified Optimizer for Quantum Circuits; https://arxiv.org/abs/1912.02250
RUN eval $(opam env) && \
git clone https://github.com/inQWIRE/mlvoqc.git /home/myuseracct/mlvoqc && \
cd /home/myuseracct/mlvoqc && \
sed -i 's/zarith (>= 1.5)/(zarith (>= "1.5"))/g' dune-project && \
rm -rf .git && \
opam install . -y
# previously `sed -i 's/1.5/"1.5"/g' dune-project && \`
# see https://github.com/inQWIRE/pyvoqc#installation
RUN eval $(opam env) && \
git clone https://github.com/inQWIRE/pyvoqc /home/myuseracct/pyvoqc && \
cd /home/myuseracct/pyvoqc && \
./install.sh
# Ensure OPAM environment is automatically loaded when the user starts a bash shell
RUN echo "eval \$(opam env)" >> /home/myuseracct/.bashrc
# Expose JupyterLab port for interactive Python/Quantum computing development
EXPOSE 8888
#CMD ["/bin/bash"]
# then to use Jupyter,
# docker run -it --rm -p 8888:8888 quantum-verif-env jupyter-lab --ip=0.0.0.0 --port=8888 --no-browser
CMD ["python3", "-m", "jupyterlab", "--ip=0.0.0.0", "--port=8888", "--no-browser", "--ServerApp.token="]
and the Makefile:
# Get the machine architecture.
# On arm64 (Apple Silicon M1/M2/etc.), `uname -m` outputs "arm64".
# On amd64 (Intel), `uname -m` outputs "x86_64".
ARCH := $(shell uname -m)
ifeq ($(ARCH), arm64)
this_arch=arm64
else ifeq ($(ARCH), x86_64)
this_arch=amd64
else
@echo "Unknown architecture: $(ARCH). Cannot determine if Mac is new (arm64) or old (amd64)."
endif
IMAGE_NAME=qwire_cirq_qiskit
CONTAINER_TAG=latest-$(this_arch)
build:
docker build -t $(IMAGE_NAME):$(CONTAINER_TAG) .
run_jupyter:
docker run -it --rm -p 8888:8888 -v $(PWD):/home/myuseracct/workspace $(IMAGE_NAME):$(CONTAINER_TAG) jupyter-lab --ip=0.0.0.0 --port=8888 --no-browser
run:
docker run -it --rm -p 8888:8888 -v $(PWD):/home/myuseracct/workspace $(IMAGE_NAME):$(CONTAINER_TAG)
and to run multi-platform builds I used
docker buildx ls
docker buildx create --use --name multi-builder
docker buildx inspect --bootstrap
docker buildx build --platform linux/amd64,linux/arm64 -t benislocated/qwire_cirq_qiskit:latest --push .
Content type
Image
Digest
sha256:0c0ee77aa…
Size
1.4 GB
Last updated
5 months ago
docker pull benislocated/qwire_cirq_qiskit