Skip to content

Commit

Permalink
Fixed some problems with CICYs, improved Dockerfile, and bumped to ve…
Browse files Browse the repository at this point in the history
…rsion 0.3.1
  • Loading branch information
ariostas committed Jan 31, 2022
1 parent 98c8519 commit 0e40a3a
Show file tree
Hide file tree
Showing 10 changed files with 86 additions and 53 deletions.
45 changes: 24 additions & 21 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,9 +1,14 @@
# Start from Debian Bullseye
FROM debian:bullseye

# Define build arguments
ARG USERNAME
ARG USERID
ARG ARCH
ARG AARCH
ARG VIRTUAL_ENV
ARG ALLOW_ROOT_ARG
ENV ALLOW_ROOT=$ALLOW_ROOT_ARG

# Install dependencies
RUN apt-get -yqq update
Expand All @@ -12,35 +17,34 @@ RUN apt-get -yqq install autoconf build-essential nano cmake libgmp-dev libcgal-
libmpc-dev libsuitesparse-dev libppl-dev libeigen3-dev\
libc6 libcdd0d libgmp10 libgmpxx4ldbl libstdc++6 palp\
libflint-dev libflint-arb-dev python3 python3-pip\
cython3 wget libmath-libm-perl
wget libmath-libm-perl python3-venv

# Make a soft link for python for convenience
RUN ln -s /usr/bin/python3 /usr/bin/python
# Make a soft link to the arb library so that python-flint can install
RUN echo testt ${AARCH}
# Make a soft link to the arb library and flint headers so that python-flint can install
RUN ln -s /usr/lib/${AARCH}-linux-gnu/libflint-arb.so /usr/lib/${AARCH}-linux-gnu/libarb.so

# Fix flint headers
RUN cp -r /usr/include/flint/* /usr/include/
RUN ln -s /usr/include/flint/* /usr/include/

# Set up non-root user
ARG USERID
RUN groupadd -r -g $USERID cytools && useradd -r -s /bin/bash -u $USERID -g cytools -m cytools
USER cytools
RUN groupadd -r -g $USERID $USERNAME && useradd -r -s /bin/bash -u $USERID -g $USERNAME -m $USERNAME\
|| echo "Skipping user creation"
USER $USERNAME

# Create python virtual environment for non-root user
RUN python3 -m venv $VIRTUAL_ENV
ENV PATH="$VIRTUAL_ENV/bin:$PATH"

# Install pip packages
ENV CVXOPT_SUITESPARSE_INC_DIR=/usr/include/suitesparse
RUN pip3 install --upgrade pip
RUN pip3 install --no-warn-script-location numpy scipy jupyterlab cvxopt gekko pymongo ortools tqdm
RUN pip3 install --no-warn-script-location python-flint matplotlib
RUN pip3 install --no-warn-script-location --user scikit-sparse cysignals gmpy2==2.1.0a4
RUN pip3 install --no-warn-script-location pplpy
RUN pip3 install --no-warn-script-location -f https://download.mosek.com/stable/wheel/index.html Mosek
RUN pip3 install numpy scipy jupyterlab cvxopt gekko pymongo ortools tqdm cython
RUN pip3 install python-flint matplotlib
RUN pip3 install scikit-sparse cysignals gmpy2==2.1.0a4
RUN pip3 install pplpy
RUN pip3 install -f https://download.mosek.com/stable/wheel/index.html Mosek
ENV MOSEKLM_LICENSE_FILE=/opt/cytools/external/mosek/mosek.lic

# Fix cvxopt bug
USER root
RUN sed -i -e 's/mosek.solsta.near_optimal/ /g' /home/cytools/.local/lib/python3.9/site-packages/cvxopt/coneprog.py
RUN sed -i -e 's/mosek.solsta.near_optimal/ /g' $VIRTUAL_ENV/lib/python3.9/site-packages/cvxopt/coneprog.py

# Install TOPCOM
WORKDIR /opt/cytools/external/topcom-mod
Expand Down Expand Up @@ -78,9 +82,8 @@ ENV OMP_NUM_THREADS=1
ENV OPENBLAS_NUM_THREADS=1

# Set entry path
WORKDIR /home/cytools/mounted_volume
WORKDIR /home/$USERNAME/mounted_volume

# Start jupyter lab by default
USER cytools
ENV PATH="/home/cytools/.local/bin:$PATH"
CMD jupyter lab --ip 0.0.0.0 --port 2875 --no-browser
USER $USERNAME
CMD jupyter lab --ip 0.0.0.0 --port 2875 --no-browser $ALLOW_ROOT
24 changes: 21 additions & 3 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ endif
USERID=$(shell id -u)
USERIDN=$(shell id -u -n)

.PHONY: all build rebuild install uninstall run pull update test
.PHONY: all build rebuild install uninstall run pull update test build-with-root-user

all:
@echo "Please specify an instruction (e.g make build)"
Expand All @@ -32,15 +32,19 @@ build:
false; \
fi
@ echo "Building CYTools image for user $(USERIDN)..."
sudo docker build -t cytools:uid-$(USERID) --build-arg USERID=$(USERID) --build-arg ARCH=$(arch) --build-arg AARCH=$(aarch) .
sudo docker build -t cytools:uid-$(USERID) --build-arg USERNAME=cytools\
--build-arg USERID=$(USERID) --build-arg ARCH=$(arch) --build-arg AARCH=$(aarch)\
--build-arg VIRTUAL_ENV=/home/cytools/cytools-venv/ --build-arg ALLOW_ROOT_ARG=" " .
@ echo "Successfully built CYTools image for user $(USERIDN)"

rebuild:
@if [ "$(USERID)" = "0" ]; then \
echo "Please run make as a non-root user and without sudo!"; \
false; \
fi
sudo docker build --no-cache -t cytools:uid-$(USERID) --build-arg USERID=$(USERID) --build-arg ARCH=$(arch) --build-arg AARCH=$(aarch) .
sudo docker build --no-cache -t cytools:uid-$(USERID) --build-arg USERNAME=cytools\
--build-arg USERID=$(USERID) --build-arg ARCH=$(arch) --build-arg AARCH=$(aarch)\
--build-arg VIRTUAL_ENV=/home/cytools/cytools-venv/ --build-arg ALLOW_ROOT_ARG=" " .

install: build
@if [ "$(USERID)" = "0" ]; then \
Expand Down Expand Up @@ -113,3 +117,17 @@ test: unittests
false; \
fi
sudo docker run --rm -it -v ${PWD}/unittests:/home/cytools/mounted_volume/ cytools bash -c "bash run_tests.sh"

build-with-root-user:
@ echo " "
@ echo "********************************************************************"
@ echo "Warning: You are building an image with a root user. Any user with "
@ echo "access to this image will be able to have root access to the host "
@ echo "computer as well. Please proceed with care.";
@ echo "********************************************************************"
@ echo " "
@ read -p "Press enter to continue or ctrl+c to cancel"
sudo docker build -t cytools:root --build-arg USERNAME=root\
--build-arg USERID=0 --build-arg ARCH=$(arch) --build-arg AARCH=$(aarch)\
--build-arg VIRTUAL_ENV=/opt/cytools/cytools-venv/ --build-arg ALLOW_ROOT_ARG="--allow-root" .
@ echo "Successfully built CYTools image with root user."
2 changes: 1 addition & 1 deletion cytools/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
from cytools.utils import read_polytopes, fetch_polytopes

# Latest version
version = "0.3.0"
version = "0.3.1"
versions_with_serious_bugs = []

# Check for more recent versions of CYTools
Expand Down
51 changes: 35 additions & 16 deletions cytools/calabiyau.py
Original file line number Diff line number Diff line change
Expand Up @@ -917,7 +917,7 @@ def glsm_charge_matrix(self, include_origin=True):
if self._glsm_charge_matrix is not None:
return np.array(self._glsm_charge_matrix)[:,(0 if include_origin else 1):]
toric_divs = [0]+list(self.prime_toric_divisors())
pts = self.ambient_variety().polytope().points_to_indices(self.ambient_variety().triangulation().points()[toric_divs])
pts = self.polytope().points_to_indices(self.polytope().points()[toric_divs])
self._glsm_charge_matrix = self.polytope().glsm_charge_matrix(
include_origin=True,
points=pts)
Expand Down Expand Up @@ -955,7 +955,7 @@ def glsm_linear_relations(self, include_origin=True):
if self._glsm_linrels is not None:
return np.array(self._glsm_linrels)[(0 if include_origin else 1):,(0 if include_origin else 1):]
toric_divs = [0]+list(self.prime_toric_divisors())
pts = self.ambient_variety().polytope().points_to_indices(self.ambient_variety().triangulation().points()[toric_divs])
pts = self.polytope().points_to_indices(self.polytope().points()[toric_divs])
self._glsm_linrels = self.polytope().glsm_linear_relations(
include_origin=True,
points=pts)
Expand Down Expand Up @@ -1003,9 +1003,10 @@ def divisor_basis(self, include_origin=True, as_matrix=False):
"""
if self._divisor_basis is None:
self.set_divisor_basis(self.polytope().glsm_basis(
integral=True,
include_origin=True,
points=self.polytope().points_to_indices(self.triangulation().points()))
integral=True,
include_origin=True,
points=self.polytope().points_to_indices(
self.polytope().points()[[0]+list(self.prime_toric_divisors())]))
)
if len(self._divisor_basis.shape) == 1:
if 0 in self._divisor_basis and not include_origin:
Expand Down Expand Up @@ -1275,6 +1276,24 @@ def intersection_numbers(self, in_basis=False, zero_as_anticanonical=False,
intnums_cy[ii] = int(round(intnums_cy[ii]))
else:
self._is_smooth = False
# Now we find the prime toric divisors and reindex accordingly
intnum_ind = set.union(*[set(ii) for ii in intnums_cy])
triang_inds = sorted(intnum_ind)
self._prime_divs = tuple(self.triangulation().triangulation_to_polytope_indices([i for i in triang_inds if i]))
divs_dict = {ii:i for i,ii in enumerate(self._prime_divs,1)}
divs_dict[0] = 0
intnums_cy = {tuple(divs_dict[i] for i in ii):intnums_cy[ii] for ii in intnums_cy}
# If there are some non-intersecting divisors we construct a better
# toric variety in the background
if len(self._prime_divs) == self.ambient_variety().triangulation().points().shape[0]-1:
self._optimal_ambient_var = self._ambient_var
else:
heights = self.triangulation().cpl_cone().tip_of_stretched_cone(1)[triang_inds]
try:
self._optimal_ambient_var = self.polytope().triangulate(heights=heights, points=self.polytope().points_to_indices(
self.polytope().points()[[0]+list(self._prime_divs)])).get_toric_variety()
except:
raise Exception("This type of complete intersection is not supported.")
self._intersection_numbers[4*exact_arithmetic] = intnums_cy
# Now intersection numbers have been computed
if zero_as_anticanonical and not in_basis:
Expand All @@ -1300,14 +1319,17 @@ def prime_toric_divisors(self):
**Description:**
Returns the list of inherited prime toric divisors. Due to the sorting
of points in the polytope class, this list is trivial for
hypersurfaces, but may be non-trivial for CICYs.
hypersurfaces, but may be non-trivial for CICYs. The indices in the
returned tuple correspond to indices of the corresponding points of the
polytope (i.e. if $n$ is in the tuple, then the $n$th point in
```p.points()``` is a prime toric divisor that intersects the CY).
**Arguments:**
None
**Returns:**
*(tuple)* A list of indices indicating the prime toric divisors of the
ambient variety that intersect the CY.
*(tuple)* A list of indices indicating the points in the polytope whose
corresponding prime toric divisor intersects the CY.
**Example:**
We construct a Calabi-Yau hypersurface and find the list of prime toric
Expand All @@ -1322,16 +1344,13 @@ def prime_toric_divisors(self):
"""
if self._prime_divs is not None:
return self._prime_divs
intnum_ind = set.union(*[set(ii) for ii in self.intersection_numbers()])
self._prime_divs = tuple(i for i in intnum_ind if i)
# If there are some non-intersecting divisors we construct a better
# toric variety in the background
if len(self._prime_divs) == self.ambient_variety().triangulation().points().shape[0]-1:
if self._is_hypersurface:
self._prime_divs = tuple(range(1,self.polytope().points_not_interior_to_facets().shape[0]))
self._optimal_ambient_var = self._ambient_var
else:
heights = self._ambient_var.mori_cone().dual().tip_of_stretched_cone(1)[[0]+list(self._prime_divs)]
self._optimal_ambient_var = self.polytope().triangulate(heights=heights, points=self.polytope().points_to_indices(
self.ambient_variety().triangulation().points()[[0]+list(self._prime_divs)])).get_toric_variety()
# For CICYs we have to compute intersection numbers and the
# variables are set during the computation
self.intersection_numbers()
return self._prime_divs

def second_chern_class(self, in_basis=False):
Expand Down
2 changes: 1 addition & 1 deletion scripts/linux/cytools
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ cat << EOF
░░█████████ █████ █████ ░░██████ ░░██████ █████ ██████
░░░░░░░░░ ░░░░░ ░░░░░ ░░░░░░ ░░░░░░ ░░░░░ ░░░░░░
Developed by Liam McAllister's Group | Version 0.3.0
Developed by Liam McAllister's Group | Version 0.3.1
https://cytools.liammcallistergroup.com
EOF
Expand Down
2 changes: 1 addition & 1 deletion scripts/macos/cytools
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ cat << EOF
░░█████████ █████ █████ ░░██████ ░░██████ █████ ██████
░░░░░░░░░ ░░░░░ ░░░░░ ░░░░░░ ░░░░░░ ░░░░░ ░░░░░░
Developed by Liam McAllister's Group | Version 0.3.0
Developed by Liam McAllister's Group | Version 0.3.1
https://cytools.liammcallistergroup.com
EOF
Expand Down
5 changes: 0 additions & 5 deletions scripts/windows/fixdockerfile.ps1

This file was deleted.

4 changes: 1 addition & 3 deletions scripts/windows/install.bat
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,9 @@

set PWS=powershell.exe -ExecutionPolicy Bypass -NoLogo -NoProfile

%PWS% -File "%~p0%fixdockerfile.ps1"

docker info || echo. && echo "Please make sure that Docker is installed and running" && timeout /t 10 && exit

docker build -t cytools --build-arg USERID=1000 --build-arg ARCH=amd64 --build-arg AARCH=x86_64 ../../ || echo. && echo "There was an error while building the image. Please let the developers know, and try using a stable version of the package." && timeout /t 10 && exit
docker build -t cytools --build-arg USERNAME=root --build-arg USERID=0 --build-arg ARCH=amd64 --build-arg AARCH=x86_64 --build-arg VIRTUAL_ENV=/opt/cytools/cytools-venv/ --build-arg ALLOW_ROOT_ARG="--allow-root" ../../ || echo. && echo "There was an error while building the image. Please let the developers know, and try using a stable version of the package." && timeout /t 10 && exit

set TARGET="%appdata%\CYTools\cytools.bat"
set TARGETU="%appdata%\CYTools\uninstall.bat"
Expand Down
2 changes: 1 addition & 1 deletion scripts/windows/launcher.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ $banner=@"
░░█████████ █████ █████ ░░██████ ░░██████ █████ ██████
░░░░░░░░░ ░░░░░ ░░░░░ ░░░░░░ ░░░░░░ ░░░░░ ░░░░░░
Developed by Liam McAllister's Group | Version 0.3.0
Developed by Liam McAllister's Group | Version 0.3.1
https://cytools.liammcallistergroup.com
"@
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

setuptools.setup(
name="cytools",
version="0.3.0",
version="0.3.1",
author="Liam McAllister Group",
author_email="",
description="A software package for analyzing Calabi-Yau hypersurfaces in toric varieties.",
Expand Down

0 comments on commit 0e40a3a

Please sign in to comment.