Skip to content

Commit

Permalink
[geometric decomposition] support normaliz version 3.4.0
Browse files Browse the repository at this point in the history
  • Loading branch information
Stephan Jahn committed Sep 17, 2017
1 parent 58464e8 commit 94b9d56
Show file tree
Hide file tree
Showing 5 changed files with 55 additions and 22 deletions.
11 changes: 10 additions & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ matrix:
- graphviz
env:
- MATRIX_EVAL="export CC=gcc-6 && export CXX=g++-6"
- NORMALIZ_VERSION=3.3.0
before_install:
- eval ${MATRIX_EVAL}
python: 2.7
Expand All @@ -27,6 +28,7 @@ matrix:
- graphviz
env:
- MATRIX_EVAL="export CC=gcc-7 && export CXX=g++-7"
- NORMALIZ_VERSION=3.4.0
before_install:
- eval ${MATRIX_EVAL}
python: 2.7
Expand All @@ -43,6 +45,7 @@ matrix:
- graphviz
env:
- MATRIX_EVAL="export CC=gcc-6 && export CXX=g++-6"
- NORMALIZ_VERSION=3.4.0
before_install:
- eval ${MATRIX_EVAL}
python: 3.5
Expand All @@ -59,6 +62,7 @@ matrix:
- graphviz
env:
- MATRIX_EVAL="export CC=gcc-7 && export CXX=g++-7"
- NORMALIZ_VERSION=3.3.0
before_install:
- eval ${MATRIX_EVAL}
python: 3.5
Expand All @@ -75,6 +79,7 @@ matrix:
- graphviz
env:
- MATRIX_EVAL="export CC=gcc-6 && export CXX=g++-6"
- NORMALIZ_VERSION=3.3.0
python: 3.6
before_install:
- eval ${MATRIX_EVAL}
Expand All @@ -91,6 +96,7 @@ matrix:
- graphviz
env:
- MATRIX_EVAL="export CC=gcc-7 && export CXX=g++-7"
- NORMALIZ_VERSION=3.4.0
python: 3.6
before_install:
- eval ${MATRIX_EVAL}
Expand All @@ -100,6 +106,8 @@ matrix:
osx_image: xcode8
language: c++
compiler: clang
env:
- NORMALIZ_VERSION=3.3.0
before_install:
- brew install graphviz
- pip install nose
Expand All @@ -108,14 +116,15 @@ matrix:
osx_image: xcode9
language: c++
compiler: clang
env:
- NORMALIZ_VERSION=3.4.0
before_install:
- brew install graphviz
- sudo mkdir /usr/local/man
- sudo chmod 777 /usr/local/man # `nose` installs there
- pip install nose

install:
- export NORMALIZ_VERSION=3.3.0
- export PATH=${TRAVIS_BUILD_DIR}/dist_install/bin:$PATH
- export SECDEC_CONTRIB=${TRAVIS_BUILD_DIR}/dist_install/
- export PYTHONPATH=${TRAVIS_BUILD_DIR}/dist_install/pySecDec_install:$PYTHONPATH
Expand Down
4 changes: 2 additions & 2 deletions README.MD
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,8 @@ you need the `normaliz` executable,
which can be downloaded from https://www.normaliz.uni-osnabrueck.de
[W. Bruns and B. Ichim and T. Römer and R. Sieg and C. Söger].
The geometric decomposition module is
designed for normaliz version 3 - currently versions 3.0.0, 3.1.0, 3.1.1 and
3.3.0 are known to work. We recommend to set your $PATH such that the `normaliz`
designed for normaliz version 3 - currently versions 3.0.0, 3.1.0, 3.1.1,
3.3.0, and 3.4.0 are known to work. We recommend to set your $PATH such that the `normaliz`
executable is found. Alternatively, you can pass the path to the `normaliz` executable
directly to the functions that need it.

Expand Down
6 changes: 3 additions & 3 deletions doc/source/installation.rst
Original file line number Diff line number Diff line change
Expand Up @@ -61,9 +61,9 @@ If you want to use the :mod:`geometric decomposition <pySecDec.decomposition.geo
module, you need the `normaliz` [BIR]_ command line executable.
The :mod:`geometric decomposition <pySecDec.decomposition.geometric>` module is
designed for `normaliz` version 3 - currently versions ``3.0.0``, ``3.1.0``, ``3.1.1``,
and ``3.3.0`` are known to work. We recommend to set your ``$PATH`` such that the `normaliz`
executable is found. Alternatively, you can pass the path to the `normaliz` executable
directly to the functions that need it.
``3.3.0``, and ``3.4.0`` are known to work. We recommend to set your ``$PATH`` such that the
`normaliz` executable is found. Alternatively, you can pass the path to the `normaliz`
executable directly to the functions that need it.

.. _installation_neato:

Expand Down
54 changes: 38 additions & 16 deletions pySecDec/decomposition/geometric.py
Original file line number Diff line number Diff line change
Expand Up @@ -272,23 +272,34 @@ def _make_run_card_facets2vertices(self):

def _read_cst_file(self, filepath):
with open(filepath, 'r') as f:
# the first two lines contain the array dimensions
shape = int(f.readline()), int(f.readline())
# the first two lines may contain the array dimensions
try:
shape = int(f.readline()), int(f.readline())
except ValueError:
# more than a single number in first two lines
# --> file does not contain dimensions
f.seek(0)

# the reduced input comes next (space and newline separated) and is terminated by a line containing letters
array_as_str = ''
array_lines = []
current_str = f.readline()
while re.match(r'^[\-0-9 ]+$', current_str) is not None:
array_as_str += current_str
array_lines.append(current_str)
current_str = f.readline()
array_as_str = ''.join(array_lines)

return np.fromstring(array_as_str, sep=' ', dtype=int).reshape(shape)
return np.fromstring(array_as_str, sep=' ', dtype=int).reshape(len(array_lines),-1)

def _read_ext_file(self, filepath):
with open(filepath, 'r') as f:
# the first two lines contain the array dimensions
shape = int(f.readline()), int(f.readline())
return np.fromfile(f, sep=' ', dtype=int).reshape(shape)
# the first two lines may contain the array dimensions
try:
shape = int(f.readline()), int(f.readline())
except ValueError:
# more than a single number in first two lines
# --> file does not contain dimensions
f.seek(0)
return np.loadtxt(f, dtype=int)

def triangulate(cone, normaliz='normaliz', workdir='normaliz_tmp', keep_workdir=False, switch_representation=False):
'''
Expand Down Expand Up @@ -384,25 +395,36 @@ def triangulate(cone, normaliz='normaliz', workdir='normaliz_tmp', keep_workdir=
# read normaliz output
# normaliz reorders the rays and defines its ordering in "normaliz.tgn"
with open(os.path.join(workdir, 'normaliz.tgn'),'r') as f:
# the first two lines contain the array dimensions
shape = int(f.readline()), int(f.readline())
original_cone = np.fromfile(f, sep=' ', dtype=int).reshape(shape)
# the first two lines may contain the array dimensions
try:
shape = int(f.readline()), int(f.readline())
except ValueError:
# more than a single number in first two lines
# --> file does not contain dimensions
f.seek(0)
original_cone = np.loadtxt(f, dtype=int)

# the triangulation is given as indices of `original_cone`
with open(os.path.join(workdir, 'normaliz.tri'),'r') as f:
# the first two lines contain the array dimensions
shape = int(f.readline()), int(f.readline())
# the first two lines may contain the array dimensions
try:
shape = int(f.readline()), int(f.readline())
except ValueError:
# more than a single number in first two lines
# --> file does not contain dimensions
f.seek(0)

# it is terminated by a line containing letters
array_as_str = ''
array_lines = []
current_str = f.readline()
while re.match(r'^[\-0-9 ]+$', current_str) is not None:
array_as_str += current_str
array_lines.append(current_str)
current_str = f.readline()
array_as_str = ''.join(array_lines)

# `[:,:-1]` to delete the last column (last column are the determiants)
# `-1` normaliz starts counting at `1` while python starts at `0`
simplicial_cones_indices = np.fromstring(array_as_str, sep=' ', dtype=int).reshape(shape)[:,:-1] - 1
simplicial_cones_indices = np.fromstring(array_as_str, sep=' ', dtype=int).reshape(len(array_lines),-1)[:,:-1] - 1

return original_cone[simplicial_cones_indices]

Expand Down
2 changes: 2 additions & 0 deletions pySecDec/decomposition/test_geometric_decomposition.py
Original file line number Diff line number Diff line change
Expand Up @@ -305,6 +305,7 @@ def test_3D_geometric_decomposition_selected_indices(self):
indices = [0,2,3]
subsectors = list( geometric_decomposition(sector, indices, workdir='tmpdir_test_3D_geometric_decomposition_selected_indices_python' + python_major_version) )

#@attr('active')
class TestPolytope(unittest.TestCase):
def setUp(self):
self.vertices = [[2,1],
Expand Down Expand Up @@ -574,6 +575,7 @@ def test_vertex_incidence_lists(self):
# The ordering is not important but must be fixed to compare the arrays
np.testing.assert_array_equal(sort_2D_array(polytope.facets[value]), sort_2D_array(target_incidence_lists[key]))

#@attr('active')
def test_vertex2facet(self):
polytope1 = Polytope(vertices=self.vertices)
polytope2 = Polytope(vertices=self.vertices_with_inside)
Expand Down

0 comments on commit 94b9d56

Please sign in to comment.