From afb8ef9470cf27cee699cdc9aae7593b23a70705 Mon Sep 17 00:00:00 2001 From: Cathy Yeh Date: Mon, 13 Nov 2017 13:11:31 -0800 Subject: gitignore --- .gitignore | 92 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 92 insertions(+) create mode 100644 .gitignore diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..410246f --- /dev/null +++ b/.gitignore @@ -0,0 +1,92 @@ +# Byte-compiled / optimized / DLL files +__pycache__/ +*.py[cod] +*$py.class + +# C extensions +*.so + +# Distribution / packaging +.Python +env/ +build/ +develop-eggs/ +dist/ +downloads/ +eggs/ +.eggs/ +lib/ +lib64/ +parts/ +sdist/ +var/ +*.egg-info/ +.installed.cfg +*.egg + +# 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/ + +# Translations +*.mo +*.pot + +# Django stuff: +*.log +local_settings.py + +# Flask stuff: +instance/ +.webassets-cache + +# Scrapy stuff: +.scrapy + +# Sphinx documentation +docs/_build/ + +# PyBuilder +target/ + +# IPython Notebook +.ipynb_checkpoints + +# pyenv +.python-version + +# celery beat schedule file +celerybeat-schedule + +# dotenv +.env + +# virtualenv +venv/ +ENV/ + +# Spyder project settings +.spyderproject + +# Rope project settings +.ropeproject + +# emacs autosave +*~ -- cgit v1.2.3 From ac7502a053995ae1e9217b443c73d969d5481283 Mon Sep 17 00:00:00 2001 From: Cathy Yeh Date: Mon, 13 Nov 2017 13:11:58 -0800 Subject: VERSION file --- VERSION | 1 + 1 file changed, 1 insertion(+) create mode 100644 VERSION diff --git a/VERSION b/VERSION new file mode 100644 index 0000000..8acdd82 --- /dev/null +++ b/VERSION @@ -0,0 +1 @@ +0.0.1 -- cgit v1.2.3 From 5e5dce93ad398c5df89a071179fee0f977e520cf Mon Sep 17 00:00:00 2001 From: Cathy Yeh Date: Mon, 13 Nov 2017 13:12:26 -0800 Subject: conda-build meta.yaml, .package_install_steps.py --- conda-build/.package_install_steps.py | 29 +++++++++++++++++++++++++++++ conda-build/meta.yaml | 31 +++++++++++++++++++++++++++++++ 2 files changed, 60 insertions(+) create mode 100644 conda-build/.package_install_steps.py create mode 100644 conda-build/meta.yaml diff --git a/conda-build/.package_install_steps.py b/conda-build/.package_install_steps.py new file mode 100644 index 0000000..4e22bb8 --- /dev/null +++ b/conda-build/.package_install_steps.py @@ -0,0 +1,29 @@ +import os +from setuptools import setup, find_packages +from yaml import load +import jinja2 + + +def load_meta_data(fname): + with open(fname) as input_fp: + # note that EDITABLE_FLAG is not required because we getting it from environ + template = jinja2.Template(input_fp.read(), undefined=jinja2.StrictUndefined) + return load(template.render(**os.environ)) + + +def main(): + meta_data = load_meta_data('conda-build/meta.yaml') + setup( + name=meta_data['package']['name'], + version=meta_data['package']['version'], + include_package_data=True, + zip_safe=False, + entry_points={ + 'console_scripts': meta_data['build'].get('entry_points', []) + }, + packages=find_packages() + ) + + +if __name__ == '__main__': + main() diff --git a/conda-build/meta.yaml b/conda-build/meta.yaml new file mode 100644 index 0000000..b7d065b --- /dev/null +++ b/conda-build/meta.yaml @@ -0,0 +1,31 @@ +package: + name: beliefs + version: {{ VERSION }} + +source: + git_url: .. + +build: + script: python .package_install_steps.py install + script_env: + - VERSION + +requirements: + build: + - python + - setuptools + - jinja2 + - pyyaml + + run: + - python + - jinja2 + - pyyaml + - pytest + - numpy + - networkx >=1.11 + +anaconda_upload: True + +about: + home: https://github.com/drivergroup/beliefs/ -- cgit v1.2.3 From 60c2c9ad85fd8685a69f21325c93479b2b5c59f9 Mon Sep 17 00:00:00 2001 From: Cathy Yeh Date: Mon, 13 Nov 2017 13:21:43 -0800 Subject: Makefile --- Makefile | 118 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 118 insertions(+) create mode 100644 Makefile diff --git a/Makefile b/Makefile new file mode 100644 index 0000000..805f519 --- /dev/null +++ b/Makefile @@ -0,0 +1,118 @@ +SHELL := /bin/bash + +# see git describe documentation for a descption +# the version as set in meta.yaml +RELEASE_VERSION = $(shell cat VERSION) +PROJECT_NAME = $(shell grep -Eo "name: .*" conda-build/meta.yaml | cut -f 2 -d ' ') + +GIT_URL = $(shell git config --get remote.origin.url) +GIT_REV = $(shell git rev-parse --short HEAD) +DEV_VERSION = $(RELEASE_VERSION)_dev$(GIT_REV) + +# conda-build 2.1.12 started breaking our builds. +# 2.1.10 was the last version we know works so let's lock to this and more carefully update. +CONDA_BUILD_VERSION = 2.1.10 + +CONDA_OUTPUT_FOLDER ?= /opt/releases/driver/ +# where to put the build objects. We can't use the default because +# there is a known bug by which conda can't build on encrypted drives +CONDA_BUILD_FOLDER = /tmp/$(PROJECT_NAME)_$(DEV_VERSION)_$(shell whoami) +# EXPORT_ALL_VARIABLES: will cause conflict with conda specific ENV variables. +# this is required to satisfy our dependencies +PYTHON_VERSION = 3.5 + +DRIVER_CONDA_CHANNELS = -c conda -c driver + +export GIT_LFS_SKIP_SMUDGE=1 + +.EXPORT_ALL_VARIABLES: + +#################################################################################################### +# Development commands +# + +develop: install-deps-in-current-env + VERSION=$(DEV_VERSION) DRIVER_BUILD_GIT_URL=$(GIT_URL) DRIVER_BUILD_GIT_REV=$(GIT_REV) \ + python .package_install_steps.py develop + +# builds a conda package from the meta.yaml file and places it into the local repo +build-in-current-env: verify-conda-build-installed + -mkdir -p $(CONDA_OUTPUT_FOLDER) && test -w $(CONDA_OUTPUT_FOLDER) + conda config --set anaconda_upload no + VERSION=$(DEV_VERSION) DRIVER_BUILD_GIT_URL=$(GIT_URL) DRIVER_BUILD_GIT_REV=$(GIT_REV) \ + conda-build conda-build/meta.yaml \ + $(DRIVER_CONDA_CHANNELS) \ + --croot $(CONDA_BUILD_FOLDER) \ + --output-folder $(CONDA_OUTPUT_FOLDER) \ + --python $(PYTHON_VERSION) + +# Install package into the current environment +install-in-current-env: build-in-current-env + conda install --yes $(DRIVER_CONDA_CHANNELS) -c file://$(CONDA_OUTPUT_FOLDER) $(PROJECT_NAME)=$(DEV_VERSION) + +uninstall-from-current-env: # develop uninstall # install uninstall + -conda uninstall --yes $(PROJECT_NAME) || pip uninstall --yes $(PROJECT_NAME) + +install-deps-in-current-env: install-in-current-env uninstall-from-current-env + +#################################################################################################### +# Conda environment commands +# + +# run the test scripts in a clean conda environment +setup-clean-env: + -conda create --yes --name test_env_$(PROJECT_NAME)_$(DEV_VERSION) python=$(PYTHON_VERSION) + +teardown-clean-env: + conda remove --name test_env_$(PROJECT_NAME)_$(DEV_VERSION) --all --yes + +#################################################################################################### +# Release commands +# + +git-tag: + git pull --tags + git tag -a v$(RELEASE_VERSION) -m "v$(RELEASE_VERSION)" + git push origin v$(RELEASE_VERSION) + +build-release-and-upload: verify-conda-build-installed + conda config --set anaconda_upload yes + # Create the package if it does not already exist and set the permission to + # private (to driver). + -anaconda package driver/$(PROJECT_NAME) --create --private + VERSION=$(RELEASE_VERSION) DRIVER_BUILD_GIT_URL=$(GIT_URL) DRIVER_BUILD_GIT_REV=$(GIT_REV) \ + conda-build conda-build/meta.yaml \ + $(DRIVER_CONDA_CHANNELS) \ + --croot $(CONDA_BUILD_FOLDER) \ + --python $(PYTHON_VERSION) \ + --channel driver + +release: test-in-clean-env git-tag build-release-and-upload + +#################################################################################################### +# test commands +# + +test-in-clean-env: verify-conda-build-installed + $(MAKE) setup-clean-env + source activate test_env_$(PROJECT_NAME)_$(DEV_VERSION) && \ + $(MAKE) install-in-current-env && \ + $(MAKE) test-in-current-env && \ + source deactivate test_env_$(PROJECT_NAME)_$(DEV_VERSION) + $(MAKE) teardown-clean-env + +# run tests in the current environment +test-in-current-env: + git lfs fetch + echo TEST + +#################################################################################################### +# helper commands +# + +# make sure that we don't have uncommited changes, we'll want to check for un-added files in the future +verify-changes-commited: + git diff-index --quiet HEAD -- + +verify-conda-build-installed: + -source deactivate && conda install conda-build=$(CONDA_BUILD_VERSION) --yes -- cgit v1.2.3 From eb1b4e06bbee479ff0937cc9920dd26a9f725f37 Mon Sep 17 00:00:00 2001 From: Cathy Yeh Date: Mon, 13 Nov 2017 13:23:18 -0800 Subject: beliefs package --- beliefs/__init__.py | 0 beliefs/models/DirectedGraph.py | 35 +++++++++++++++++++++++++++++++++++ beliefs/models/__init__.py | 0 3 files changed, 35 insertions(+) create mode 100644 beliefs/__init__.py create mode 100644 beliefs/models/DirectedGraph.py create mode 100644 beliefs/models/__init__.py diff --git a/beliefs/__init__.py b/beliefs/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/beliefs/models/DirectedGraph.py b/beliefs/models/DirectedGraph.py new file mode 100644 index 0000000..8dfb9bd --- /dev/null +++ b/beliefs/models/DirectedGraph.py @@ -0,0 +1,35 @@ +import networkx as nx + + +class DirectedGraph(nx.DiGraph): + """ + Base class for all directed graphical models. + """ + def __init__(self, edges, node_labels): + """ + Input: + edges: an edge list, e.g. [(parent1, child1), (parent1, child2)] + node_labels: a list of strings of node labels + """ + super().__init__() + if edges is not None: + self.add_edges_from(edges) + if node_labels is not None: + self.add_nodes_from(node_labels) + + def get_leaves(self): + """ + Returns a list of leaves of the graph. + """ + return [node for node, out_degree in self.out_degree_iter() if + out_degree == 0] + + def get_roots(self): + """ + Returns a list of roots of the graph. + """ + return [node for node, in_degree in self.in_degree().items() if + in_degree == 0] + + def get_topologically_sorted_nodes(self, reverse=False): + return nx.topological_sort(self, reverse=reverse) diff --git a/beliefs/models/__init__.py b/beliefs/models/__init__.py new file mode 100644 index 0000000..e69de29 -- cgit v1.2.3