Skip to content

Commit

Permalink
Add barvikron command line tool.
Browse files Browse the repository at this point in the history
  • Loading branch information
catch22 committed Jun 22, 2016
1 parent 6312739 commit 44cd963
Show file tree
Hide file tree
Showing 6 changed files with 74 additions and 11 deletions.
4 changes: 3 additions & 1 deletion .travis.yml
Expand Up @@ -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
54 changes: 54 additions & 0 deletions barvikron/__main__.py
@@ -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)
4 changes: 2 additions & 2 deletions barvikron/barvinok.py
Expand Up @@ -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):
Expand Down
11 changes: 7 additions & 4 deletions barvikron/kronecker.py
Expand Up @@ -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.',
Expand Down
4 changes: 2 additions & 2 deletions barvikron/latte.py
Expand Up @@ -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):
Expand Down
8 changes: 6 additions & 2 deletions setup.py
Expand Up @@ -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.