-
Notifications
You must be signed in to change notification settings - Fork 11
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #35 from annaritz/master
Fix networkx compatibility error & add a dockerized folder
- Loading branch information
Showing
6 changed files
with
144 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
FROM ubuntu:20.04 | ||
|
||
# create conda environment in advance and activate on run | ||
|
||
# install tools | ||
RUN apt-get update \ | ||
&& apt-get install -y wget \ | ||
&& rm -rf /var/lib/apt/lists/* | ||
|
||
# install miniconda and configure bashrc | ||
ENV PATH /opt/conda/bin:$PATH | ||
RUN wget --quiet https://repo.anaconda.com/miniconda/Miniconda3-py37_4.8.3-Linux-x86_64.sh -O ~/miniconda.sh && \ | ||
/bin/bash ~/miniconda.sh -b -p /opt/conda && \ | ||
rm ~/miniconda.sh && \ | ||
/opt/conda/bin/conda clean --all && \ | ||
ln -s /opt/conda/etc/profile.d/conda.sh /etc/profile.d/conda.sh && \ | ||
echo ". /opt/conda/etc/profile.d/conda.sh" >> ~/.bashrc && \ | ||
conda init bash | ||
|
||
WORKDIR /home/graphspace-python | ||
|
||
# create graphspace-python conda environment | ||
COPY docker/minimal_env.yml ./docker/ | ||
# requests module no longer part of conda - see https://github.com/vitchyr/rlkit/issues/107 | ||
# for info about the CONDA_RESTORE_FREE_CHANNEL option. | ||
RUN CONDA_RESTORE_FREE_CHANNEL=1 conda env create -f docker/minimal_env.yml && \ | ||
echo "conda activate graphspace-python" >> ~/.bashrc | ||
|
||
# install graphspace-python | ||
COPY graphspace_python/ ./graphspace_python | ||
|
||
# add an ENV entry so graphspace_python can be accessed anywhere: | ||
# https://stackoverflow.com/questions/49631146/how-do-you-add-a-path-to-pythonpath-in-a-dockerfile/49631407 | ||
ENV PYTHONPATH "${PYTHONPATH}:/home/graphspace-python" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
# Dockerized Graphspace Python Client | ||
|
||
## Steps Illustrated Below | ||
- Build `graphspace-python` docker container | ||
- Run `graphspace-python` docker image interactively and mount example data to container | ||
- Run `graphspace-python` software on an example in this directory. | ||
|
||
## Requirements | ||
- Docker software | ||
- Mac, linux, or Windows machine | ||
|
||
## Build (Mac/Linux/Windows) | ||
|
||
To build image: start from `graphspace-python` repository __root__ directory and call: | ||
|
||
`docker build -t graphspace-python/graphspace-python -f docker/Dockerfile .` | ||
|
||
To run the image interactively (with no linked data): | ||
|
||
`docker run -it graphspace-python/graphspace-python bash` | ||
|
||
## Run (Mac/Linux) | ||
|
||
To mount the example data inside the container: | ||
|
||
`docker run -v /$(pwd)/docker/example:/home/graphspace-python/example -it graphspace-python/graphspace-python bash` | ||
|
||
then inside the container in the `/home/graphspace-python/example` directory call: | ||
|
||
`python test.py example-graph.txt user6@example.com user6` | ||
|
||
the output files will be linked to the host machine in the example subdirectory. | ||
|
||
## Run (Windows) -- AR did not test. | ||
|
||
To use the docker container with windows, use a bash terminal such as Git for Windows. | ||
|
||
To run container in Git for Windows: | ||
|
||
`winpty docker run -it graphspace-python/graphspace-python bash` | ||
|
||
To run in Git for Windows and mount the example data inside the container: | ||
|
||
`winpty docker run -v /$(pwd)/docker/example:/home/graphspace-python/example -it graphspace-python/graphspace-python bash` | ||
|
||
then inside the container in the `/home/graphspace-python/example` directory call: | ||
|
||
`python test.py example-graph.txt user6@example.com user6` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
A B | ||
A C | ||
B H | ||
B F | ||
H I | ||
C D | ||
D F | ||
F G | ||
E F | ||
C E | ||
E K | ||
K G | ||
E L | ||
J K |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
from graphspace_python.api.client import GraphSpace | ||
from graphspace_python.graphs.classes.gsgraph import GSGraph | ||
import networkx as nx | ||
import time | ||
import sys | ||
|
||
def main(graph_file,username,password): | ||
|
||
# read file as networkx graph | ||
nxG = nx.read_edgelist(graph_file) | ||
|
||
# convert networkx graph to GraphSpace object | ||
G = GSGraph() | ||
G.set_name('Docker Example %.4f' % (time.time())) | ||
for n in nxG.nodes(): | ||
G.add_node(n,label=n,popup='Node %s' % (n)) | ||
G.add_node_style(n,color='#ACCE9A',shape='rectangle',width=30,height=30) | ||
for u,v in nxG.edges(): | ||
G.add_edge(u,v,popup='Edge %s-%s' % (u,v)) | ||
G.add_edge_style(u,v,width=2,color='#281D6A') | ||
|
||
# post with unique timestamp | ||
gs = GraphSpace(username,password) | ||
try: | ||
graph = gs.update_graph(G) | ||
except: | ||
graph = gs.post_graph(G) | ||
print('posted graph') | ||
return | ||
|
||
if __name__ == '__main__': | ||
if len(sys.argv) != 4: | ||
print('USAGE: python test.py <GRAPH_FILE> <USERNAME> <PASSWORD>\n\n\twhere <USERNAME> and <PASSWORD> are GraphSpace username and password.') | ||
print('CURRENT ARGS:',sys.argv) | ||
sys.exit() | ||
|
||
main(sys.argv[1],sys.argv[2],sys.argv[3]) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
name: graphspace-python | ||
channels: | ||
dependencies: | ||
- future | ||
- networkx=1.11 | ||
- requests=2.10.0 | ||
- pytest | ||
- mock | ||
- python=3.5 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters