Skip to content

Commit

Permalink
Initial commit of tool
Browse files Browse the repository at this point in the history
  • Loading branch information
Kasekopf committed Jul 15, 2019
1 parent 37ad231 commit d75c1ff
Show file tree
Hide file tree
Showing 1,005 changed files with 313,238 additions and 23 deletions.
2 changes: 2 additions & 0 deletions .gitattributes
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
solvers/* linguist-vendored
src/tensorcsp/* linguist-vendored
130 changes: 130 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,130 @@
# Byte-compiled / optimized / DLL files
__pycache__/
*.py[cod]
*$py.class

# C extensions
*.so

# Distribution / packaging
.Python
build/
develop-eggs/
dist/
downloads/
eggs/
.eggs/
lib/
lib64/
parts/
sdist/
var/
wheels/
*.egg-info/
.installed.cfg
*.egg
MANIFEST

# PyInstaller
# Usually these files are written by a python script from a template
# before PyInstaller builds the exe, so as to inject date/other infos into it.
*.manifest
*.spec

# Installer logs
pip-log.txt
pip-delete-this-directory.txt

# Unit test / coverage reports
htmlcov/
.tox/
.coverage
.coverage.*
.cache
nosetests.xml
coverage.xml
*.cover
.hypothesis/
.pytest_cache/

# Translations
*.mo
*.pot

# Django stuff:
*.log
local_settings.py
db.sqlite3

# Flask stuff:
instance/
.webassets-cache

# Scrapy stuff:
.scrapy

# Sphinx documentation
docs/_build/

# PyBuilder
target/

# Jupyter Notebook
.ipynb_checkpoints

# pyenv
.python-version

# celery beat schedule file
celerybeat-schedule

# SageMath parsed files
*.sage.py

# Environments
.env
.venv
env/
venv/
ENV/
env.bak/
venv.bak/

# Spyder project settings
.spyderproject
.spyproject

# Rope project settings
.ropeproject

# mkdocs documentation
/site

# mypy
.mypy_cache/

# CUSTOM Exclusions
# IPython notebooks
*.ipynb
/.idea/*

# Compressed Benchmarks
*.zip

# Local experiment data
/experiments/*
# Local figure data
/figures/*

# C++ object files
/cpp/*.o
/cpp/*/*.o
/cpp/*/*/*.o
/cpp/*/*/*/*.o

# VSCode files
/cpp/.vscode/*
/cpp/*.code-workspace

# Singularity container
tensororder
42 changes: 21 additions & 21 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -1,21 +1,21 @@
MIT License

Copyright (c) 2019 Vardi's Group

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
MIT License
Copyright (c) 2019 Vardi's Group
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
7 changes: 7 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
export TENSORORDER_DIR=$(dir $(abspath $(lastword $(MAKEFILE_LIST))))

tensororder: Singularity
singularity build tensororder Singularity

clean:
rm tensororder
39 changes: 37 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,2 +1,37 @@
# TensorOrder
A tool for weighted model counting through tensor network contraction
# TensorOrder
A Python 3 tool for automatically contracting tensor networks for weighted model counting.

## Running with Singularity
Because of the variety of dependencies used in the various tree decomposition tools, it is recommended to use the [Singularity](https://www.sylabs.io/) container to run TensorOrder.

### Building the container
The container can be built with the following commands (make requires root to build the Singularity container):
```
git clone https://github.com/vardigroup/TensorOrder.git
cd TensorOrder
sudo make
```

### Usage
Once built, example usage is:
```
./tensororder --method="line-Flow" < "benchmarks/cubic_vertex_cover/cubic_vc_50_0.cnf"
```


## Running without Singularity
TensorOrder can also be used directly as a Python 3 tool. The primary script is located in `src/tensororder.py`. Example usage is
```python src/tensororder.py --method="line-Flow" < "benchmarks/cubic_vertex_cover/cubic_vc_50_0.cnf" ```

TensorOrder requires the following python packages (see [requirements.txt](requirements.txt) for a working set of exact version information if needed):
1. `click`
2. `numpy`
3. `python-igraph`
4. `networkx`
5. `cached_property`

Moreover, the various tensor methods each require additional setup.
* For KCMR-metis and KCMR-gn, METIS must be installed using the instructions [here](src/tensorcsp).
* For line-Tamaki and factor-Tamaki, the tree-decomposition solver Tamaki must be compiled using the `heuristic` instructions [here](solvers/TCS-Meiji).
* For line-Flow and factor-Flow, the tree-decomposition solver FlowCutter must be compiled using the instructions [here](solvers/flow-cutter-pace17).
* For line-htd and factor-htd, the tree-decomposition solver htd must be compiled using the instructions [here](solvers/htd-master).
57 changes: 57 additions & 0 deletions Singularity
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
Bootstrap: docker
From: python:3.7-slim

%setup
cp -R ${TENSORORDER_DIR-$PWD}/solvers ${SINGULARITY_ROOTFS}/solvers
cp -R ${TENSORORDER_DIR-$PWD}/src ${SINGULARITY_ROOTFS}/src
wget http://glaros.dtc.umn.edu/gkhome/fetch/sw/metis/metis-5.1.0.tar.gz -P ${SINGULARITY_ROOTFS}/solvers/

%post
apt-get update

# TensorOrder
apt-get -y install g++ make libxml2-dev zlib1g-dev
pip install click numpy python-igraph networkx cached_property

# METIS
apt-get -y install g++ make cmake
cd /solvers/
tar -xvf metis-5.1.0.tar.gz
rm metis-5.1.0.tar.gz
cd /solvers/metis-5.1.0
make config shared=1
make
make install
pip install metis

# TCS-Meiji
# deal with slim variants not having man page directories (which causes "update-alternatives" to fail)
mkdir -p /usr/share/man/man1
apt-get install -y make openjdk-11-jdk
cd /solvers/TCS-Meiji
make heuristic

# FlowCutter
apt-get -y install g++
cd /solvers/flow-cutter-pace17
chmod +x ./build.sh
./build.sh

# Htd
apt-get -y install g++ cmake
cd /solvers/htd-master
cmake .
make

%environment
export METIS_DLL=/solvers/metis-5.1.0/build/Linux-x86_64/libmetis/libmetis.so

%help
This is a Singularity container for the TensorOrder tool.
See "$SINGULARITY_NAME --help" for usage.

%runscript
export TENSORORDER_CALLER="$SINGULARITY_NAME"
exec python /src/tensororder.py "$@"


76 changes: 76 additions & 0 deletions benchmarks/cubic_vertex_cover/cubic_vc_50_0.cnf
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
p cnf 50 75
1 26 0
1 2 0
1 11 0
2 4 0
2 48 0
3 32 0
3 19 0
3 23 0
4 13 0
4 41 0
5 13 0
5 34 0
5 17 0
6 32 0
6 7 0
6 42 0
7 46 0
7 10 0
8 38 0
8 37 0
8 30 0
9 21 0
9 38 0
9 10 0
10 27 0
11 21 0
11 20 0
12 23 0
12 15 0
12 36 0
13 44 0
14 45 0
14 24 0
14 40 0
15 35 0
15 20 0
16 36 0
16 48 0
16 27 0
17 45 0
17 39 0
18 26 0
18 39 0
18 50 0
19 50 0
19 22 0
20 22 0
21 36 0
22 47 0
23 46 0
24 43 0
24 31 0
25 28 0
25 43 0
25 30 0
26 42 0
27 29 0
28 31 0
28 47 0
29 49 0
29 48 0
30 34 0
31 47 0
32 35 0
33 35 0
33 49 0
33 37 0
34 44 0
37 50 0
38 46 0
39 43 0
40 44 0
40 41 0
41 42 0
45 49 0
12 changes: 12 additions & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
cached-property==1.5.1
certifi==2018.4.16
Click==7.0
decorator==4.3.0
llvmlite==0.26.0
metis==0.2a4
networkx==2.1
numba==0.41.0
numpy==1.15.0
python-igraph==0.7.1.post6
scipy==1.1.0
sparse==0.5.0+16.ge80efc7.dirty
21 changes: 21 additions & 0 deletions solvers/TCS-Meiji/LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
MIT License

Copyright (c) 2017 Hisao Tamaki, Hiromu Ohtsuka, Takuto Sato, Keitaro Makii

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
Loading

0 comments on commit d75c1ff

Please sign in to comment.