From d9c4c428b991866ad8791ddee15fad0e9f7729af Mon Sep 17 00:00:00 2001 From: Fritz Obermeyer Date: Tue, 22 Oct 2019 22:39:19 -0700 Subject: [PATCH] Bump to version 0.1.0 and prepare for release (#287) --- .gitignore | 1 + .travis.yml | 3 +++ README.md | 4 ++-- docs/requirements.txt | 1 - examples/eeg_slds.py | 6 +++--- examples/mixed_hmm/experiment.py | 13 +++++-------- examples/mixed_hmm/model.py | 3 +-- examples/mixed_hmm/seal_data.py | 2 -- funsor/adjoint.py | 14 +------------- funsor/einsum.py | 1 - funsor/interpreter.py | 2 +- funsor/memoize.py | 2 +- funsor/montecarlo.py | 3 +-- funsor/torch.py | 2 +- setup.py | 33 ++++++++++++++++++++++++++------ test/test_adjoint.py | 10 ++-------- test/test_joint.py | 2 +- test/test_memoize.py | 1 - test/test_optimizer.py | 2 +- test/test_torch.py | 2 +- 20 files changed, 52 insertions(+), 55 deletions(-) diff --git a/.gitignore b/.gitignore index de0bac825..f57e109d9 100644 --- a/.gitignore +++ b/.gitignore @@ -15,6 +15,7 @@ pyro/contrib/examples/raw pyro/_version.py processed raw +prep_seal_data.csv # Logs logs diff --git a/.travis.yml b/.travis.yml index 338fc5cfd..5aba48f61 100644 --- a/.travis.yml +++ b/.travis.yml @@ -17,6 +17,9 @@ install: # Keep track of Pyro dev branch - pip install https://github.com/pyro-ppl/pyro/archive/dev.zip + # Keep track of pyro-api master branch + - pip install https://github.com/pyro-ppl/pyro-api/archive/master.zip + - pip install .[test] - pip freeze diff --git a/README.md b/README.md index e53a62429..6e2032c4f 100644 --- a/README.md +++ b/README.md @@ -1,5 +1,5 @@ -![unstable](https://img.shields.io/badge/status-unstable-red.svg) [![Build Status](https://travis-ci.com/pyro-ppl/funsor.svg?branch=master)](https://travis-ci.com/pyro-ppl/funsor) +[![Latest Version](https://badge.fury.io/py/funsor.svg)](https://pypi.python.org/pypi/funsor) [![Documentation Status](https://readthedocs.org/projects/funsor/badge)](http://funsor.readthedocs.io) # Funsor @@ -17,7 +17,7 @@ for a system description. Funsor supports Python 3.6+. ```sh -pip install funsor@https://api.github.com/repos/pyro-ppl/funsor/tarball/master +pip install funsor ``` **Install from source:** diff --git a/docs/requirements.txt b/docs/requirements.txt index 2c24dbc82..4dc95f541 100644 --- a/docs/requirements.txt +++ b/docs/requirements.txt @@ -1,4 +1,3 @@ -contextlib2 multipledispatch numpy>=1.7 opt_einsum>=2.3.2 diff --git a/examples/eeg_slds.py b/examples/eeg_slds.py index 5e0c65a34..bb50048b9 100644 --- a/examples/eeg_slds.py +++ b/examples/eeg_slds.py @@ -8,10 +8,10 @@ [1] Anderson, B., and J. Moore. "Optimal filtering. Prentice-Hall, Englewood Cliffs." New Jersey (1979). """ import argparse -from os.path import exists -from urllib.request import urlopen import time from collections import OrderedDict +from os.path import exists +from urllib.request import urlopen import numpy as np import torch @@ -20,7 +20,7 @@ import funsor import funsor.distributions as dist import funsor.ops as ops -from funsor.pyro.convert import matrix_and_mvn_to_funsor, mvn_to_funsor, funsor_to_cat_and_mvn, funsor_to_mvn +from funsor.pyro.convert import funsor_to_cat_and_mvn, funsor_to_mvn, matrix_and_mvn_to_funsor, mvn_to_funsor # download dataset from UCI archive diff --git a/examples/mixed_hmm/experiment.py b/examples/mixed_hmm/experiment.py index 0799e5fd5..25650a36c 100644 --- a/examples/mixed_hmm/experiment.py +++ b/examples/mixed_hmm/experiment.py @@ -1,23 +1,20 @@ import argparse -import os +import functools import json +import os import uuid -import functools - -import torch import pyro import pyro.poutine as poutine +import torch import funsor.ops as ops from funsor.interpreter import interpretation from funsor.optimizer import apply_optimizer from funsor.sum_product import MarkovProduct, naive_sequential_sum_product, sum_product from funsor.terms import lazy, to_funsor - - -from model import Model, Guide -from seal_data import prepare_seal, prepare_fake +from model import Guide, Model +from seal_data import prepare_fake, prepare_seal def aic_num_parameters(model, guide=None): diff --git a/examples/mixed_hmm/model.py b/examples/mixed_hmm/model.py index b2187a020..a6f98722c 100644 --- a/examples/mixed_hmm/model.py +++ b/examples/mixed_hmm/model.py @@ -1,10 +1,9 @@ from collections import OrderedDict +import pyro import torch from torch.distributions import constraints -import pyro - import funsor.distributions as dist import funsor.ops as ops from funsor.domains import bint, reals diff --git a/examples/mixed_hmm/seal_data.py b/examples/mixed_hmm/seal_data.py index 6c5b545db..e4e9da72a 100644 --- a/examples/mixed_hmm/seal_data.py +++ b/examples/mixed_hmm/seal_data.py @@ -2,10 +2,8 @@ from urllib.request import urlopen import pandas as pd - import torch - MISSING = 1e-6 diff --git a/funsor/adjoint.py b/funsor/adjoint.py index 9c9b9a9ec..05bb24b1a 100644 --- a/funsor/adjoint.py +++ b/funsor/adjoint.py @@ -10,19 +10,7 @@ from funsor.interpreter import interpretation from funsor.ops import AssociativeOp from funsor.registry import KeyedRegistry -from funsor.terms import ( - Binary, - Cat, - Funsor, - Number, - Reduce, - Slice, - Subs, - Variable, - reflect, - substitute, - to_funsor, -) +from funsor.terms import Binary, Cat, Funsor, Number, Reduce, Slice, Subs, Variable, reflect, substitute, to_funsor from funsor.torch import Tensor, materialize diff --git a/funsor/einsum.py b/funsor/einsum.py index dd2b01b30..cce45e2f9 100644 --- a/funsor/einsum.py +++ b/funsor/einsum.py @@ -7,7 +7,6 @@ from funsor.sum_product import sum_product from funsor.terms import Funsor, lazy - BACKEND_OPS = { "torch": (ops.add, ops.mul), "pyro.ops.einsum.torch_log": (ops.logaddexp, ops.add), diff --git a/funsor/interpreter.py b/funsor/interpreter.py index 14e39f2c3..6e0cf33a7 100644 --- a/funsor/interpreter.py +++ b/funsor/interpreter.py @@ -4,11 +4,11 @@ import re import types from collections import OrderedDict +from contextlib import contextmanager from functools import singledispatch import numpy import torch -from contextlib2 import contextmanager from funsor.domains import Domain from funsor.ops import Op diff --git a/funsor/memoize.py b/funsor/memoize.py index c44ffd6fa..ad28724ec 100644 --- a/funsor/memoize.py +++ b/funsor/memoize.py @@ -1,5 +1,5 @@ from collections import Hashable -from contextlib2 import contextmanager +from contextlib import contextmanager import funsor.interpreter as interpreter diff --git a/funsor/montecarlo.py b/funsor/montecarlo.py index f507954b1..8ae20d361 100644 --- a/funsor/montecarlo.py +++ b/funsor/montecarlo.py @@ -1,6 +1,5 @@ from collections import OrderedDict - -from contextlib2 import contextmanager +from contextlib import contextmanager from funsor.integrate import Integrate from funsor.interpreter import dispatched_interpretation, interpretation diff --git a/funsor/torch.py b/funsor/torch.py index 7c87646d3..cf24824bb 100644 --- a/funsor/torch.py +++ b/funsor/torch.py @@ -2,11 +2,11 @@ import itertools import warnings from collections import OrderedDict +from contextlib import contextmanager from functools import reduce import opt_einsum import torch -from contextlib2 import contextmanager from multipledispatch import dispatch from multipledispatch.variadic import Variadic diff --git a/setup.py b/setup.py index 47774e135..90ed7be79 100644 --- a/setup.py +++ b/setup.py @@ -1,19 +1,39 @@ +import sys + from setuptools import find_packages, setup +# READ README.md for long description on PyPi. +# This requires uploading via twine, e.g.: +# $ python setup.py sdist bdist_wheel +# $ twine upload --repository-url https://test.pypi.org/legacy/ dist/* # test version +# $ twine upload dist/* +try: + long_description = open('README.md', encoding='utf-8').read() +except Exception as e: + sys.stderr.write(f'Failed to convert README.md to rst:\n {e}\n') + sys.stderr.flush() + long_description = '' + +# Remove badges since they will always be obsolete. +# This assumes the first 4 lines contain badge info. +long_description = '\n'.join(line for line in long_description.split('\n')[4:]) + setup( name='funsor', - version='0.0.0', - description='Functional analysis + tensors + symbolic algebra', + version='0.1.0', + description='A tensor-like library for functions and distributions', packages=find_packages(include=['funsor', 'funsor.*']), url='https://github.com/pyro-ppl/funsor', + project_urls={ + "Documentation": "https://funsor.pyro.ai", + }, author='Uber AI Labs', author_email='fritzo@uber.com', install_requires=[ - 'contextlib2', 'multipledispatch', 'numpy>=1.7', 'opt_einsum>=2.3.2', - 'pyro-ppl>=0.3', + 'pyro-ppl>=0.5', 'torch>=1.3.0', ], extras_require={ @@ -23,7 +43,7 @@ 'pytest>=4.1', 'pytest-xdist==1.27.0', 'torchvision==0.2.1', - 'pyro-api@https://api.github.com/repos/pyro-ppl/pyro-api/tarball/master', + 'pyro-api>=0.1', ], 'dev': [ 'flake8', @@ -36,7 +56,8 @@ 'torchvision==0.2.1', ], }, - tests_require=['flake8', 'pandas', 'pytest>=4.1'], + long_description=long_description, + long_description_content_type='text/markdown', keywords='probabilistic machine learning bayesian statistics pytorch', classifiers=[ 'Intended Audience :: Developers', diff --git a/test/test_adjoint.py b/test/test_adjoint.py index ba6ca28b6..761842c58 100644 --- a/test/test_adjoint.py +++ b/test/test_adjoint.py @@ -12,12 +12,7 @@ from funsor.einsum import BACKEND_ADJOINT_OPS, einsum, naive_einsum, naive_plated_einsum from funsor.interpreter import interpretation from funsor.optimizer import apply_optimizer -from funsor.sum_product import ( - MarkovProduct, - naive_sequential_sum_product, - sequential_sum_product, - sum_product -) +from funsor.sum_product import MarkovProduct, naive_sequential_sum_product, sequential_sum_product, sum_product from funsor.terms import Variable, reflect from funsor.testing import ( assert_close, @@ -26,10 +21,9 @@ make_plated_hmm_einsum, random_gaussian, random_tensor, - xfail_param, + xfail_param ) - EINSUM_EXAMPLES = [ "a->", "ab->", diff --git a/test/test_joint.py b/test/test_joint.py index bd0bac65f..054551d69 100644 --- a/test/test_joint.py +++ b/test/test_joint.py @@ -6,7 +6,7 @@ import funsor.ops as ops from funsor.cnf import Contraction -from funsor.delta import Delta, Delta +from funsor.delta import Delta from funsor.domains import bint, reals from funsor.gaussian import Gaussian from funsor.integrate import Integrate diff --git a/test/test_memoize.py b/test/test_memoize.py index b5cabbb57..b1954512a 100644 --- a/test/test_memoize.py +++ b/test/test_memoize.py @@ -9,7 +9,6 @@ from funsor.terms import reflect from funsor.testing import make_einsum_example, xfail_param - EINSUM_EXAMPLES = [ ("a,b->", ''), ("ab,a->", ''), diff --git a/test/test_optimizer.py b/test/test_optimizer.py index b8fda4bfd..6517a7b8e 100644 --- a/test/test_optimizer.py +++ b/test/test_optimizer.py @@ -1,8 +1,8 @@ from collections import OrderedDict -from pyro.ops.contract import einsum as pyro_einsum import pytest import torch +from pyro.ops.contract import einsum as pyro_einsum import funsor from funsor.distributions import Categorical diff --git a/test/test_torch.py b/test/test_torch.py index 90c654a22..a9269c48c 100644 --- a/test/test_torch.py +++ b/test/test_torch.py @@ -10,7 +10,7 @@ from funsor.interpreter import interpretation from funsor.terms import Cat, Lambda, Number, Slice, Stack, Variable, lazy from funsor.testing import assert_close, assert_equiv, check_funsor, random_tensor -from funsor.torch import REDUCE_OP_TO_TORCH, Einsum, Tensor, arange, align_tensors, torch_stack, torch_tensordot +from funsor.torch import REDUCE_OP_TO_TORCH, Einsum, Tensor, align_tensors, arange, torch_stack, torch_tensordot @pytest.mark.parametrize('output_shape', [(), (2,), (3, 2)], ids=str)