Skip to content

Commit 77f98ee

Browse files
committed
reconfigure .gitpod.Dockerfile; add test_quasicvx2.py
1 parent 9fcfa02 commit 77f98ee

File tree

2 files changed

+150
-36
lines changed

2 files changed

+150
-36
lines changed

Diff for: .gitpod.Dockerfile

+69-36
Original file line numberDiff line numberDiff line change
@@ -1,46 +1,79 @@
11
FROM gitpod/workspace-full
22

33
USER root
4-
54
# Install util tools.
5+
66
RUN apt-get update \
77
&& apt-get install -y \
88
apt-utils \
99
aria2 \
10-
git \
11-
less \
12-
lcov \
13-
neofetch \
14-
neovim \
10+
# utilities (not ripgrep, gh) \
1511
asciinema \
16-
tmux \
12+
bat \
13+
byobu \
14+
curl \
15+
elinks \
16+
fd-find \
17+
fish \
18+
mdp \
19+
ncdu \
20+
neofetch \
21+
patat \
22+
pkg-config \
23+
ranger \
1724
w3m \
18-
wget
19-
20-
RUN pip3 install --upgrade pip \
21-
&& pip3 install \
22-
decorator \
23-
networkx \
24-
numpy \
25-
numexpr \
26-
scipy \
27-
pre-commit \
28-
mypy \
29-
codecov \
30-
coverage \
31-
hypothesis \
32-
pytest \
33-
pytest-cov \
34-
pytest-benchmark \
35-
jupyter \
36-
jupyterlab \
37-
matplotlib
38-
39-
USER gitpod
40-
41-
# Install custom tools, runtime, etc. using apt-get
42-
# For example, the command below would install "bastet" - a command line tetris clone:
43-
#
44-
# RUN sudo apt-get -q update && # sudo apt-get install -yq bastet && # sudo rm -rf /var/lib/apt/lists/*
45-
#
46-
# More information: https://www.gitpod.io/docs/42_config_docker/
25+
# just for fun (not cmatrix) \
26+
cowsay \
27+
figlet \
28+
fortune \
29+
toilet \
30+
tty-clock
31+
32+
RUN mkdir -p /workspace/data \
33+
&& chown -R gitpod:gitpod /workspace/data
34+
35+
RUN mkdir /home/gitpod/.conda
36+
# Install conda
37+
RUN wget --quiet https://repo.anaconda.com/miniconda/Miniconda3-latest-Linux-x86_64.sh -O ~/miniconda.sh && \
38+
/bin/bash ~/miniconda.sh -b -p /opt/conda && \
39+
rm ~/miniconda.sh && \
40+
ln -s /opt/conda/etc/profile.d/conda.sh /etc/profile.d/conda.sh && \
41+
echo ". /opt/conda/etc/profile.d/conda.sh" >> ~/.bashrc && \
42+
echo "conda activate base" >> ~/.bashrc
43+
44+
RUN /opt/conda/bin/conda config --set always_yes yes --set changeps1 no \
45+
&& /opt/conda/bin/conda update -q conda \
46+
&& /opt/conda/bin/conda info -a
47+
48+
RUN /opt/conda/bin/conda install -y -c conda-forge \
49+
pandoc-crossref \
50+
pandoc
51+
52+
RUN /opt/conda/bin/pip install \
53+
codecov \
54+
coverage \
55+
coveralls \
56+
cvxpy \
57+
jupyter \
58+
jupyterlab \
59+
matplotlib \
60+
networkx \
61+
numexpr \
62+
numpy \
63+
scipy \
64+
flake8 \
65+
mypy \
66+
pre-commit \
67+
pyqt5 \
68+
pytest-benchmark \
69+
pytest-cov \
70+
pytest \
71+
yapf \
72+
lolcat
73+
74+
RUN chown -R gitpod:gitpod /opt/conda \
75+
&& chmod -R 777 /opt/conda \
76+
&& chown -R gitpod:gitpod /home/gitpod/.conda \
77+
&& chmod -R 777 /home/gitpod/.conda
78+
79+
RUN apt-get clean && rm -rf /var/cache/apt/* && rm -rf /var/lib/apt/lists/* && rm -rf /tmp/*

Diff for: tests/test_quasicvx2.py

+81
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,81 @@
1+
# -*- coding: utf-8 -*-
2+
from __future__ import print_function
3+
4+
import math
5+
6+
from pytest import approx
7+
8+
import numpy as np
9+
10+
from ellpy.cutting_plane import CUTStatus, cutting_plane_dc
11+
from ellpy.ell import ell
12+
13+
14+
def my_quasicvx_oracle(z, t: float):
15+
"""[summary]
16+
17+
Arguments:
18+
z ([type]): [description]
19+
t (float): the best-so-far optimal value
20+
21+
Returns:
22+
[type]: [description]
23+
"""
24+
x, y = z
25+
26+
# constraint 1: exp(x) <= y
27+
tmp = math.exp(x)
28+
fj = tmp - y
29+
if fj > 0:
30+
return (np.array([tmp, -1.]), fj), None
31+
32+
# constraint 2: y > 0
33+
if y <= 0.:
34+
return (np.array([0., -1.]), -y), None
35+
36+
# constraint 3: x > 0
37+
if x <= 0.:
38+
return (np.array([-1., 0.]), -x), None
39+
40+
# objective: minimize -sqrt(x) / y
41+
tmp2 = math.sqrt(x)
42+
fj = -tmp2 - t * y
43+
if fj < 0.: # feasible
44+
t = -tmp2 / y
45+
return (np.array([-0.5/tmp2, -t]), 0), t
46+
47+
return (np.array([-0.5/tmp2, -t]), fj), None
48+
49+
50+
def test_case_feasible():
51+
"""[summary]
52+
"""
53+
x0 = np.array([1., 1.]) # initial x0
54+
E = ell(10., x0)
55+
P = my_quasicvx_oracle
56+
xb, fb, ell_info = cutting_plane_dc(P, E, 0.)
57+
assert ell_info.feasible
58+
assert fb == approx(-0.4288673396685956)
59+
assert xb[0] == approx(0.501315956)
60+
assert xb[1] == approx(1.650886769)
61+
62+
63+
def test_case_infeasible1():
64+
"""[summary]
65+
"""
66+
x0 = np.array([100., 100.]) # wrong initial guess,
67+
E = ell(10., x0) # or ellipsoid is too small
68+
P = my_quasicvx_oracle
69+
_, _, ell_info = cutting_plane_dc(P, E, 0.)
70+
assert not ell_info.feasible
71+
assert ell_info.status == CUTStatus.nosoln # no sol'n
72+
73+
74+
def test_case_infeasible2():
75+
"""[summary]
76+
"""
77+
x0 = np.array([1., 1.]) # initial x0
78+
E = ell(10., x0)
79+
P = my_quasicvx_oracle
80+
_, _, ell_info = cutting_plane_dc(P, E, -100) # wrong initial best-so-far
81+
assert not ell_info.feasible

0 commit comments

Comments
 (0)