Skip to content

Commit

Permalink
Cleaned up and environment update
Browse files Browse the repository at this point in the history
  • Loading branch information
Anantha Ravi Kiran Lanka Subrahmanya committed Aug 7, 2019
1 parent d1532e6 commit fa70688
Show file tree
Hide file tree
Showing 84 changed files with 80 additions and 31,970 deletions.
23 changes: 18 additions & 5 deletions INSTALL.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,12 @@ Step 1: Follow the instructions in the graphnn github
- Follow the instructions to install Graphnn and mvc_lib : https://github.com/Hanjun-Dai/graphnn

Step 2: Install scip-4.0.1-affected (in dep/ subfolder):
- [Optional] (If using open source solver:) https://projects.coin-or.org/Clp
- [Optional] Use SoPlex; so much faster than Clp
- Install gurobi-7.4 / CLP / SoPLEX
- Update the LDFLAGS to the relevant LP solvers include and library paths in make/make.project
- Use gurobi-7.4 version
- Make command: make OPT=opt ZIMPL=false LPS=grb (or) make OPT=opt ZIMPL=false LPS=clp [for clp solver]
- Make command:
-- For Gurobi: make OPT=opt ZIMPL=false LPS=grb
-- For CLP: make OPT=opt ZIMPL=false LPS=clp
-- For SoPLEX: make OPT=opt ZIMPL=false LPS=spx

Step 3: Install Lapack
- Install https://github.com/Reference-LAPACK/lapack
Expand All @@ -18,7 +19,19 @@ Step 4: Install scip-dagger
- Install co-training/scip-dagger
- make OPT=opt ZIMPL=false LPS=grb (or) clp [Use the same command as in step 2].

Step 5: Define macros in your ~/.bashrc (and remember to restart your terminal) :
Step 5: Install python dependencies - run the following instructions; remember to activate the environment before any run
1) Setup or update conda environment
```
conda env create -f envs/copier.yml
or
conda env update -f envs/copier.yml
```
2) Switch to coper environment
```
source activate copier
```

Step 6: Define macros in your ~/.bashrc (and remember to restart your terminal) :
- export COTRAIN_HOME=\<path to local copier folder\>
- export COTRAIN_DATA=\<path to data\>
- export COTRAIN_SCATCH=\<path to scratch folder\>
Expand Down
1 change: 1 addition & 0 deletions envs/copier.yml
Original file line number Diff line number Diff line change
Expand Up @@ -59,4 +59,5 @@ dependencies:
- wheel=0.33.4
- xz=5.2.4
- zlib=1.2.11
- tqdm

2 changes: 1 addition & 1 deletion joint-pyscripts/cmp_sols.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ def readSols(src):
def main(src1, src2, dst, threshold):
objSrc1 = readSols(src1)
objSrc2 = readSols(src2)
allF = np.unique(objSrc1.keys() + objSrc2.keys())
allF = np.unique(list(objSrc1.keys()) + list(objSrc2.keys()))
os.system('mkdir -p %s'%dst)

for cF in allF:
Expand Down
84 changes: 41 additions & 43 deletions joint-pyscripts/cotrain-withRL.sh
Original file line number Diff line number Diff line change
Expand Up @@ -434,55 +434,53 @@ if [ "$train" = true ]; then
softlink $data "gpickle" $gexp $i

# ## Run branch and bound for linear programming formuulation
#time learn_bnb $data "lpfiles" ".lp" $lpexp $i $LPCOUNT
time learn_bnb $data "lpfiles" ".lp" $lpexp $i $LPCOUNT

#### Run Sparial policy
time learn_spatial $data "gpickle" ".gpickle" $gexp $i $cost $decay $SPATIAL_ITER

for (( j=$init; j<$i+1; j=$j+1)); do
# Current iteration data
iterlpexp="$lpexp"_"$j"
itergexp="$gexp"_"$j"

## Quadratic solution to lp solution
gpickleFolder=$data/"gpickle/unlabeled"$j/
lpFolder=$data/"lpfiles/unlabeled"$j/

if [ "$self_imit" -gt "0" ]; then
# Co-training

# BnB to spatial
`rm -R -f $COTRAIN_SCRATCH/$gpickleFolder/$iterlpexp/`
mkdir -p $COTRAIN_SCRATCH/$gpickleFolder/$iterlpexp/
cp -al $COTRAIN_SCRATCH/$lpFolder/$iterlpexp/ $COTRAIN_SCRATCH/$gpickleFolder/

## Spatial to BnB
`rm -R -f $COTRAIN_SCRATCH/$lpFolder/$itergexp/`
mkdir -p $COTRAIN_SCRATCH/$lpFolder/$itergexp/
cp -al $COTRAIN_SCRATCH/$gpickleFolder/$itergexp/ $COTRAIN_SCRATCH/$lpFolder/

elif [ "$self_imit" -lt "0" ]; then

# BnB to spatial
`rm -R -f $COTRAIN_SCRATCH/$gpickleFolder/$iterlpexp/`
mkdir -p $COTRAIN_SCRATCH/$gpickleFolder/$iterlpexp/
cp -al $COTRAIN_SCRATCH/$lpFolder/$iterlpexp/ $COTRAIN_SCRATCH/$gpickleFolder/
fi

exit

#for (( j=$init; j<$i+1; j=$j+1)); do
# # Current iteration data
# iterlpexp="$lpexp"_"$j"
# itergexp="$gexp"_"$j"

# ## Quadratic solution to lp solution
# gpickleFolder=$data/"gpickle/unlabeled"$j/
# lpFolder=$data/"lpfiles/unlabeled"$j/

# if [ "$self_imit" -gt "0" ]; then
# # Co-training

# # BnB to spatial
# `rm -R -f $COTRAIN_SCRATCH/$gpickleFolder/$iterlpexp/`
# mkdir -p $COTRAIN_SCRATCH/$gpickleFolder/$iterlpexp/
# cp -al $COTRAIN_SCRATCH/$lpFolder/$iterlpexp/ $COTRAIN_SCRATCH/$gpickleFolder/

# ## Spatial to BnB
# `rm -R -f $COTRAIN_SCRATCH/$lpFolder/$itergexp/`
# mkdir -p $COTRAIN_SCRATCH/$lpFolder/$itergexp/
# cp -al $COTRAIN_SCRATCH/$gpickleFolder/$itergexp/ $COTRAIN_SCRATCH/$lpFolder/

# elif [ "$self_imit" -lt "0" ]; then

# # BnB to spatial
# `rm -R -f $COTRAIN_SCRATCH/$gpickleFolder/$iterlpexp/`
# mkdir -p $COTRAIN_SCRATCH/$gpickleFolder/$iterlpexp/
# cp -al $COTRAIN_SCRATCH/$lpFolder/$iterlpexp/ $COTRAIN_SCRATCH/$gpickleFolder/
# fi

# # compare and destination
# lpOut=$COTRAIN_SCRATCH/$data"/sol/train/"$lpexp/
# gOut=$COTRAIN_SCRATCH/$data"/sol/train/"$gexp/
# compare and destination
lpOut=$COTRAIN_SCRATCH/$data"/sol/train/"$lpexp/
gOut=$COTRAIN_SCRATCH/$data"/sol/train/"$gexp/

# python joint-pyscripts/cmp_sols.py --s1 $COTRAIN_SCRATCH/$lpFolder/$iterlpexp/ \
# --s2 $COTRAIN_SCRATCH/$lpFolder/$itergexp/ \
# --d $lpOut --t 0
# python joint-pyscripts/cmp_sols.py --s1 $COTRAIN_SCRATCH/$gpickleFolder/$itergexp/ \
# --s2 $COTRAIN_SCRATCH/$gpickleFolder/$iterlpexp/ \
# --d $gOut --t 0
python joint-pyscripts/cmp_sols.py --s1 $COTRAIN_SCRATCH/$lpFolder/$iterlpexp/ \
--s2 $COTRAIN_SCRATCH/$lpFolder/$itergexp/ \
--d $lpOut --t 0
python joint-pyscripts/cmp_sols.py --s1 $COTRAIN_SCRATCH/$gpickleFolder/$itergexp/ \
--s2 $COTRAIN_SCRATCH/$gpickleFolder/$iterlpexp/ \
--d $gOut --t 0

#done
done
done

# Now save them for the future
Expand Down
2 changes: 1 addition & 1 deletion scip-dagger/pyscripts/kerasify.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ def write_floats(file, floats):
assert written == len(floats)

def export_model(model, filename):
with open(filename, 'w') as f:
with open(filename, 'wb') as f:

def write_activation(activation):
if activation == 'linear':
Expand Down
2 changes: 1 addition & 1 deletion scip-dagger/pyscripts/normdata.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ def readCSV(normInpF):
norm_min = []
norm_max = []
print('Reading %s'%normInpF)
with open(normInpF, "rb") as csv_file:
with open(normInpF, "r") as csv_file:
reader = csv.reader(csv_file, delimiter=',')
for line in reader:
norm_min.append(float(line[0]))
Expand Down
4 changes: 2 additions & 2 deletions spatial-policy/graph_comb_opt/code/s2v_mvc/evaluate.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import numpy as np
import networkx as nx
import cPickle as cp
#import _pickle as cp
#import cPickle as cp
import _pickle as cp
import pickle
import random
import ctypes
Expand Down
4 changes: 2 additions & 2 deletions spatial-policy/graph_comb_opt/code/s2v_mvc/main.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
from __future__ import division
import numpy as np
import networkx as nx
import cPickle as cp
#import _pickle as cp
#import cPickle as cp
import _pickle as cp
import random
import ctypes
import os
Expand Down
5 changes: 2 additions & 3 deletions spatial-policy/graph_comb_opt/code/s2v_mvc/mvc_lib/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,7 @@ gnn_lib = $(lib_dir)/libgnn.a
include_dirs = $(CUDA_HOME)/include/ include/ $(GNN_HOME)/include/

CXXFLAGS += $(addprefix -I,$(include_dirs)) -Wno-unused-local-typedef
#CXXFLAGS += -fPIC -DUSE_GPU
CXXFLAGS += -fPIC
CXXFLAGS += -fPIC -DUSE_GPU
CXXFLAGS += -DGPU_MODE
cpp_files = $(shell $(FIND) src/lib -name "*.cpp" -printf "%P\n")
cxx_obj_files = $(subst .cpp,.o,$(cpp_files))
Expand All @@ -26,7 +25,7 @@ all: $(target)

build/dll/libmvc.so : src/mvc_lib.cpp $(gnn_lib) $(objs)
$(dir_guard)
$(CXX) -shared $(CXXFLAGS) -MMD -o $@ $(filter %.cpp %.o, $^) -lcblas -lm -L$(TBB_LIBRARY_RELEASE) -L$(lib_dir) -lgnn $(LDFLAGS)
$(CXX) -shared $(CXXFLAGS) -MMD -o $@ $(filter %.cpp %.o, $^) -L$(TBB_LIBRARY_RELEASE) -L$(lib_dir) -lgnn $(LDFLAGS)

DEPS += $(target_dep)

Expand Down

This file was deleted.

7 changes: 5 additions & 2 deletions spatial-policy/graph_comb_opt/code/s2v_mvc/mvc_lib/mvc_lib.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ def __init__(self, inp):
self.lib.Test.restype = ctypes.c_double
self.lib.GetSol.restype = ctypes.c_double
arr = (ctypes.c_char_p * len(inp))()
#arr[:] = args
for j, val in enumerate(inp):
arr[j] = val.encode('utf-8')
self.lib.Init(len(inp), arr)
Expand Down Expand Up @@ -67,11 +68,13 @@ def InsertGraph(self, g, is_test, opt=None, prob=0.5):


def LoadModel(self, path_to_model):
p = ctypes.cast(path_to_model, ctypes.c_char_p)
p = ctypes.cast(path_to_model.encode('utf-8'), ctypes.c_char_p)
#p = ctypes.cast(path_to_model, ctypes.c_char_p)
self.lib.LoadModel(p)

def SaveModel(self, path_to_model):
p = ctypes.cast(path_to_model, ctypes.c_char_p)
p = ctypes.cast(path_to_model.encode('utf-8'), ctypes.c_char_p)
#p = ctypes.cast(path_to_model, ctypes.c_char_p)
self.lib.SaveModel(p)

def GetSol(self, gid, maxn):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
#include <signal.h>

using namespace gnn;
using namespace std;

void intHandler(int dummy) {
exit(0);
Expand All @@ -36,10 +37,9 @@ MvcEnv* test_env;
int Init(const int argc, const char** argv)
{
signal(SIGINT, intHandler);

cfg::LoadParams(argc, argv);
GpuHandle::Init(cfg::dev_id, 1);

net = new QNet();
net->BuildNet();

Expand Down
Binary file not shown.
Loading

0 comments on commit fa70688

Please sign in to comment.