Permalink
Browse files

Add barvikron command line tool.

  • Loading branch information...
catch22 committed Jun 22, 2016
1 parent 6312739 commit 44cd963f0872dd96780c2c3d78520d4e687c7cbc
Showing with 74 additions and 11 deletions.
  1. +3 −1 .travis.yml
  2. +54 −0 barvikron/__main__.py
  3. +2 −2 barvikron/barvinok.py
  4. +7 −4 barvikron/kronecker.py
  5. +2 −2 barvikron/latte.py
  6. +6 −2 setup.py
@@ -13,4 +13,6 @@ install:
- pip install pytest
- pip install -e .

script: py.test --latte=$LATTE_PATH
script:
- py.test --latte=$LATTE_PATH
- barvikron [20,0] [11,9] [11,9] --latte=$LATTE_PATH
@@ -0,0 +1,54 @@
from __future__ import absolute_import, print_function
import click
import logging
from . import BarvinokEvaluator, LatteEvaluator, kronecker_weight_multiplicity, kronecker


class WeightParamType(click.ParamType):
name = 'weight'

def convert(self, value, param, ctx):
value = eval(value)
if not isinstance(value, (tuple, list)):
self.fail('%s is not a valid weight' % value, param, ctx)
return value


@click.command()
@click.argument('partitions',
metavar=u'\u03BB \u03BC \u03BD ...',
nargs=-1,
required=True,
type=WeightParamType())
@click.option(
'--barvinok',
metavar='PATH',
help='Path to barvinok_count tool (see http://barvinok.gforge.inria.fr/).')
@click.option(
'--latte',
metavar='PATH',
help='Path to LattE\'s count tool (see https://www.math.ucdavis.edu/~latte/).'
)
@click.option(
'--weight-multiplicity',
is_flag=True,
help='Compute weight multiplicity instead of Kronecker coefficient.')
@click.option('-v', '--verbose', is_flag=True)
def cli(partitions, weight_multiplicity, barvinok, latte, verbose):
# enable verbose mode?
if verbose:
logging.basicConfig(format='%(asctime)-25s %(message)s',
level=logging.INFO)

# instantiate evaluator
assert bool(barvinok) != bool(
latte), 'Specify either --barvinok or --latte.'
evaluator = BarvinokEvaluator(barvinok) if barvinok else LatteEvaluator(
latte)

# compute Kronecker coefficient
if weight_multiplicity:
g = kronecker_weight_multiplicity(partitions, evaluator)
else:
g = kronecker(partitions, evaluator)
click.echo(g)
@@ -28,9 +28,9 @@ class BarvinokEvaluator(EvaluatorBase):
Evaluate vector partition functions at given point using barvinok (http://barvinok.gforge.inria.fr/).
"""

def __init__(self, path='barvinok_count'):
def __init__(self, path):
assert os.path.isfile(
path), '%s not found (should be path to barvinok_count binary)' % path
path), '"%s" not found (should be path to barvinok_count binary)' % path
self.path = path

def eval(self, vpn, b):
@@ -63,17 +63,20 @@ def positive_roots(dims):
return roots


def kronecker(omega, evaluator):
def kronecker(partitions, evaluator):
"""
Compute Kronecker coefficient for given highest weight.
"""
# create partition function
dims = list(map(len, omega))
dims = list(map(len, partitions))
vpn = kronecker_weight_vpn(dims)

# compute highest weight and finite-difference formula
highest_weight = flatten_weight(omega)
findiff = finite_differences(positive_roots(dims))
highest_weight = flatten_weight(partitions)
proots = positive_roots(dims)
assert all(highest_weight.dot(pr) >= 0
for pr in proots), 'Highest weight should be dominant.'
findiff = finite_differences(proots)

logging.info(
'About to compute %d weight multiplicities using a partition function of size %s.',
@@ -29,9 +29,9 @@ class LatteEvaluator(EvaluatorBase):
Evaluate vector partition functions at given point using LattE's count tool (https://www.math.ucdavis.edu/~latte/).
"""

def __init__(self, path='count'):
def __init__(self, path):
assert os.path.isfile(
path), '%s not found (should be path to LattE\'s count binary)' % path
path), '"%s" not found (should be path to LattE\'s count binary)' % path
self.path = path

def eval(self, vpn, b):
@@ -36,6 +36,10 @@
'Development Status :: 4 - Beta',
'Environment :: Console',
],
install_requires=['Click'],
install_requires=['Click', 'numpy'],
packages=['barvikron'],
tests_require=['pytest'])
tests_require=['pytest'],
entry_points='''
[console_scripts]
barvikron=barvikron.__main__:cli
''')

0 comments on commit 44cd963

Please sign in to comment.