Skip to content

Python Hierarchy Implementation #16

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 130 commits into from
Jul 7, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
130 commits
Select commit Hold shift + click to select a range
ae3022d
changed bayesmix submodule to forked
taguhiM Apr 9, 2022
d544420
test commit to check submodules - done
taguhiM Apr 9, 2022
c1ece8c
check submodule behaviour
taguhiM Apr 15, 2022
e6381e2
adding lib/math submodule
taguhiM Apr 15, 2022
09b080e
Python hierarchy in external main
EnricoPaglia Apr 21, 2022
09dd210
update .gitignore
taguhiM Apr 25, 2022
13296ec
migrate compute_posterior_hypers : running super slow
taguhiM Apr 25, 2022
2220011
migrate summary_statistics methods
taguhiM Apr 26, 2022
b4dd38d
change append to subscript (faster)
taguhiM Apr 30, 2022
9404c84
fixed numerical mistakes in compute_posterior_hypers, from append to …
taguhiM May 2, 2022
4b32c0a
declare as global vars all fun.attr methods
taguhiM May 2, 2022
b015840
submodule update
taguhiM May 3, 2022
8107d0c
added namespace for python global variables (attr)
taguhiM May 3, 2022
d674670
modified to use pybind11 built-in type conversions (stl, eigen)
taguhiM May 3, 2022
7b673b3
modify summary statistics to be stored in a vector
taguhiM May 9, 2022
59d2b6c
initial trials to run from python
taguhiM May 9, 2022
d7c91e5
update bayesmix - modified tbb in cmake
taguhiM May 12, 2022
e6ba3d3
Merge branch 'bayesmix-dev:master' into master
taguhiM May 13, 2022
8e7d10a
build with cmake instead of setup
taguhiM May 18, 2022
c377845
update submodules
taguhiM May 18, 2022
846a99b
Merge branch 'master' into build_cmake
taguhiM May 18, 2022
b2cd9ca
Merge branch 'py_hier' into build_cmake
taguhiM May 18, 2022
b73cc75
first working run from python, yay!
taguhiM May 18, 2022
0acfa82
add cmake in the bash script
taguhiM May 19, 2022
9b8247f
Implementing pythonhierarchy int Python
EnricoPaglia May 23, 2022
9e5aea5
Compiles, no core dumped, python hierarchy not found
EnricoPaglia May 24, 2022
ac43c0b
update submodule pybind11
taguhiM May 24, 2022
689b446
update structure
taguhiM May 24, 2022
e77819d
add empty readme
taguhiM May 24, 2022
54706a3
renamed bayesmix_ to bayesmix
taguhiM May 24, 2022
493db9d
update submodule PATH
taguhiM May 24, 2022
2da95e6
add py_hier directory
taguhiM May 24, 2022
43c74cc
updates to new structure | partially working
taguhiM May 24, 2022
2d10546
critical | forgot to add in the last commit
taguhiM May 24, 2022
0cb3a6d
py_hier works, algorithm runs, can see plots but core_dumped in the e…
taguhiM May 24, 2022
839eca2
modified bounds for python
taguhiM May 24, 2022
25eec2c
add executable permission
taguhiM May 28, 2022
a7a0450
added draft implementations of non-conjugate python hierarchy
taguhiM May 28, 2022
94e326f
added more draft implementations
taguhiM May 28, 2022
907e9de
modified inheritance to base
taguhiM May 28, 2022
a96d42e
fixes in hypers
taguhiM May 28, 2022
f13e0e6
removed broken submodules, added new ones
taguhiM May 31, 2022
5369421
fixed broken submodules
taguhiM May 31, 2022
94fabef
removed old incorrect gitmodule
taguhiM May 31, 2022
6c774d8
merging fixes
taguhiM May 31, 2022
47ce8fa
Commented plot_mcmc and run_mcmc out of target_sources
gbpollam May 31, 2022
d2a3d40
modified gitignore
taguhiM Jun 1, 2022
c7fffaa
Merge non conjugate and mixing draft
EnricoPaglia Jun 2, 2022
10f4190
Submodules update
EnricoPaglia Jun 2, 2022
5b521d2
Submodules update
EnricoPaglia Jun 2, 2022
d9bc6b3
restore convert_proto.sh
EnricoPaglia Jun 2, 2022
7969bca
NonConjugate Hierarchy modifications - bugfixing needed
gbpollam Jun 4, 2022
a065fd6
mixing implementation to be tested, non_conjugate_hier commented
EnricoPaglia Jun 5, 2022
7142e76
Mixing draft, first working implementation
EnricoPaglia Jun 6, 2022
4c93598
Same as previous commit
EnricoPaglia Jun 6, 2022
da12ff5
Implementation of LapNIG in python
EnricoPaglia Jun 8, 2022
a27fbe2
added missing implementations for py mixing, commented unnecessary me…
taguhiM Jun 9, 2022
1a4da88
Renaming fun, deleting commented code
EnricoPaglia Jun 9, 2022
fc01b61
Mixing changer implementation
EnricoPaglia Jun 9, 2022
ddd1ea0
removed some comments, updated submodules
taguhiM Jun 10, 2022
f1b219d
preserved only py hier implementation for the pr
taguhiM Jun 11, 2022
dc91b7c
removed lib/math submodule
taguhiM Jun 11, 2022
16b47a9
PythonHierarchy inheriting from AbstractHierarchy instead of BaseHier…
EnricoPaglia Jun 14, 2022
ff70e8c
Cleanup
EnricoPaglia Jun 14, 2022
c4f8cbb
Working Python Hierarchy with updated bayesmix
EnricoPaglia Jun 15, 2022
6817914
Cleaning old code
EnricoPaglia Jun 15, 2022
061130a
Refactoring hierarchy.py
EnricoPaglia Jun 15, 2022
6bd673c
Renaming and removing old files
EnricoPaglia Jun 15, 2022
9db9f1f
Renaming and cleanup
EnricoPaglia Jun 15, 2022
9ea4163
Minor correction
EnricoPaglia Jun 15, 2022
15e934c
Moving the implementation of Python Hierarchis in the docs/examples f…
EnricoPaglia Jun 15, 2022
9a8145e
Extented to conjugate implementation example
EnricoPaglia Jun 15, 2022
8901341
Removing unnecessary static_casts
EnricoPaglia Jun 15, 2022
b180f6d
Removed submodule
EnricoPaglia Jun 16, 2022
c305194
Removing external bayesmix
EnricoPaglia Jun 16, 2022
f61069b
New Structure
EnricoPaglia Jun 16, 2022
0ebf0a6
Chane of structure final implementation
EnricoPaglia Jun 16, 2022
2779d6a
Removing examples, docs, tests and benchmarks folders
EnricoPaglia Jun 16, 2022
54c0477
Moving initialization of pybind objects and modules in the initialize…
EnricoPaglia Jun 17, 2022
c4c86fc
Changer in c++ instead of python
EnricoPaglia Jun 17, 2022
810fe15
Reordering python_hierarchy part 1
EnricoPaglia Jun 17, 2022
ab91e3e
Reordering part 2
EnricoPaglia Jun 17, 2022
cf11117
Reordering PythonHierarchy
EnricoPaglia Jun 17, 2022
57e2ed8
Update test_run.py
EnricoPaglia Jun 17, 2022
4cee826
Changing example files
EnricoPaglia Jun 18, 2022
d59420c
refactored
taguhiM Jun 18, 2022
1075dc7
added argument build
taguhiM Jun 18, 2022
23f80dd
implemented update_hypers
gbpollam Jun 19, 2022
315cf9f
Refactoring
gbpollam Jun 19, 2022
6642f0c
Changing where the hier_implementation file name is given
EnricoPaglia Jun 21, 2022
7fa80bc
Pass no longer needed when implementing python hierarchies
EnricoPaglia Jun 21, 2022
26285e3
total reformatting of .py files with pycharm
taguhiM Jun 21, 2022
fcd9d6e
total reformatting of c++ files with clion
taguhiM Jun 21, 2022
9d4320f
more reformatting
taguhiM Jun 21, 2022
288e5c4
Compiling with c++17
EnricoPaglia Jun 21, 2022
c03a026
Correcting implementation of NNIG Hierarchies
EnricoPaglia Jun 21, 2022
e8a4fea
Small changes in hier implementations
EnricoPaglia Jun 21, 2022
11ee715
reformatting back the clion mess
taguhiM Jun 21, 2022
65c1c35
Small changes in test_run
EnricoPaglia Jun 22, 2022
e168d47
Deleting old files
EnricoPaglia Jun 22, 2022
48e6825
Adding documentation of LapNIG_Hierarchy.py
EnricoPaglia Jun 22, 2022
428711e
Clear_summary_statistics back to c++
EnricoPaglia Jun 22, 2022
75cc2b3
Adding docs for NNIG implementations
EnricoPaglia Jun 22, 2022
8cf576a
Changing change_module to change_hier in algorithm wrapper
EnricoPaglia Jun 22, 2022
12f52d7
change in how cluster_data_values is emptied
EnricoPaglia Jun 22, 2022
629df75
Change hier_change name and new documentation style
EnricoPaglia Jun 24, 2022
3b87cc7
Adding docs and clean up
EnricoPaglia Jun 24, 2022
3f559e9
Adding docs
EnricoPaglia Jun 24, 2022
40f94f8
Fix of last commits
EnricoPaglia Jun 24, 2022
a21cebf
updated docs to NumPy style
gbpollam Jun 27, 2022
f5eaf50
Renaming
EnricoPaglia Jun 29, 2022
718e865
style
EnricoPaglia Jun 29, 2022
e1f2ba5
style
EnricoPaglia Jun 29, 2022
9b78e4e
Added readme file
EnricoPaglia Jun 29, 2022
6172d7f
removed find_package pybind11, was not needed
EnricoPaglia Jun 30, 2022
dc0cc66
change convert proto to conda prefix
EnricoPaglia Jun 30, 2022
47a3d0c
swichted back to original bayesmix submodule
taguhiM Jul 1, 2022
5c0c239
updated submodules
taguhiM Jul 1, 2022
54ff21c
small modifications
taguhiM Jul 1, 2022
7a5a626
refactoring
taguhiM Jul 1, 2022
912b083
added notebook for python hierarchy
taguhiM Jul 1, 2022
b45ee2d
Adding examples to notebooks
EnricoPaglia Jul 2, 2022
0748829
fixed path in the notebook
taguhiM Jul 2, 2022
aa27008
fixed 2to3 path
taguhiM Jul 3, 2022
71f1474
updated README
taguhiM Jul 4, 2022
a2b571a
pwd in convert proto
EnricoPaglia Jul 5, 2022
2646232
path in the notebooks
EnricoPaglia Jul 5, 2022
57f3ade
moving installation in main README
EnricoPaglia Jul 6, 2022
a993822
minor changes
EnricoPaglia Jul 6, 2022
a78ef71
change header guards
EnricoPaglia Jul 6, 2022
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -130,3 +130,9 @@ dmypy.json

# Pyre type checker
.pyre/

# PyCharm
.idea/

# 2to3 path
convert_proto.sh
9 changes: 4 additions & 5 deletions .gitmodules
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
[submodule "pybmix/src/bayesmix"]
path = pybmix/core/pybmixcpp/bayesmix
url = https://github.com/bayesmix-dev/bayesmix.git
depth = 1
update = merge
[submodule "lib/pybind11"]
path = lib/pybind11
depth = 1
url = https://github.com/pybind/pybind11.git
[submodule "pybmix/core/pybmixcpp/bayesmix"]
path = pybmix/core/pybmixcpp/bayesmix
url = https://github.com/bayesmix-dev/bayesmix.git
depth = 1
47 changes: 24 additions & 23 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,48 +1,48 @@
cmake_minimum_required(VERSION 3.13.0)
project(pybmixcpp)

set (CMAKE_CXX_STANDARD 14)
set(CMAKE_CXX_STANDARD 17)
set(COMPILE_OPTIONS -D_REENTRANT -fPIC)
set(CMAKE_BUILD_TYPE Release)
set(CMAKE_CXX_FLAGS_RELEASE "-O3 -funroll-loops -ftree-vectorize")
set(CMAKE_FIND_PACKAGE_PREFER_CONFIG TRUE)


SET(SOURCE_DIR "${CMAKE_CURRENT_LIST_DIR}/pybmix/core/pybmixcpp")
add_subdirectory(${SOURCE_DIR}/bayesmix)
add_subdirectory(${SOURCE_DIR})
include_directories(${SOURCE_DIR})
SET_SOURCE_FILES_PROPERTIES(${PROTO_HEADERS} ${PROTO_SOURCES} PROPERTIES GENERATED TRUE)

# Generate python module
add_subdirectory(lib/pybind11)
pybind11_add_module(pybmixcpp ${SOURCES}
"${SOURCE_DIR}/module.cpp"
"${SOURCE_DIR}/algorithm_wrapper.hpp"
"${SOURCE_DIR}/algorithm_wrapper.cpp"
"${SOURCE_DIR}/serialized_collector.hpp"
"${SOURCE_DIR}/serialized_collector.cpp"
${PROTO_HEADERS} ${PROTO_SOURCES})
"${SOURCE_DIR}/module.cpp"
"${SOURCE_DIR}/algorithm_wrapper.hpp"
"${SOURCE_DIR}/algorithm_wrapper.cpp"
"${SOURCE_DIR}/serialized_collector.hpp"
"${SOURCE_DIR}/serialized_collector.cpp"
${PROTO_HEADERS} ${PROTO_SOURCES})

# generate Python's proto classes
set(PY_PROTO_DIR "${CMAKE_CURRENT_LIST_DIR}/pybmix/proto")
set(PROTO_PYS)
message("ProtoFiles: ${ProtoFiles}")
foreach(PROTO_FILE IN LISTS ProtoFiles)
get_filename_component(PROTO_DIR ${PROTO_FILE} DIRECTORY)
get_filename_component(PROTO_NAME ${PROTO_FILE} NAME_WE)
set(PROTO_PY ${PY_PROTO_DIR}/${PROTO_NAME}_pb2.py)
message(STATUS "GENERATING PYTHON protoc proto(cc): ${PROTO_FILE} --> ${PROTO_PY}")
add_custom_command(
OUTPUT ${PROTO_PY}
COMMAND protobuf::protoc "--proto_path=${SOURCE_DIR}/bayesmix/src/proto"
${PROTO_DIRS} "--python_out=${PY_PROTO_DIR}" ${PROTO_FILE}
DEPENDS ${PROTO_FILE} protobuf::protoc
COMMENT "Generate Python protocol buffer for ${PROTO_FILE}"
VERBATIM)
foreach (PROTO_FILE IN LISTS ProtoFiles)
get_filename_component(PROTO_DIR ${PROTO_FILE} DIRECTORY)
get_filename_component(PROTO_NAME ${PROTO_FILE} NAME_WE)
set(PROTO_PY ${PY_PROTO_DIR}/${PROTO_NAME}_pb2.py)
message(STATUS "GENERATING PYTHON protoc proto(cc): ${PROTO_FILE} --> ${PROTO_PY}")
add_custom_command(
OUTPUT ${PROTO_PY}
COMMAND protobuf::protoc "--proto_path=${SOURCE_DIR}/bayesmix/src/proto"
${PROTO_DIRS} "--python_out=${PY_PROTO_DIR}" ${PROTO_FILE}
DEPENDS ${PROTO_FILE} protobuf::protoc
COMMENT "Generate Python protocol buffer for ${PROTO_FILE}"
VERBATIM)
list(APPEND PROTO_PYS ${PROTO_PY})
endforeach()
endforeach ()

find_package (TBB EXACT PATHS ${TBB_ROOT})
find_package(TBB EXACT PATHS ${TBB_ROOT})
find_package(OpenMP REQUIRED)

message("INCLUDE_PATHS" ${INCLUDE_PATHS})
Expand All @@ -52,4 +52,5 @@ target_compile_definitions(pybmixcpp PRIVATE VERSION_INFO=${EXAMPLE_VERSION_INFO
target_link_libraries(pybmixcpp PUBLIC bayesmixlib ${BAYESMIX_LINK_LIBRARIES})
target_compile_options(pybmixcpp PUBLIC ${BAYESMIX_COMPILE_OPTIONS})

add_custom_target(genterate_protos ALL DEPENDS ${PROTO_PYS})
add_custom_target(generate_protos ALL DEPENDS ${PROTO_PYS})
add_custom_target(two_to_three ALL COMMAND ${CMAKE_CURRENT_LIST_DIR}/convert_proto.sh DEPENDS generate_protos)
33 changes: 22 additions & 11 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,20 +5,31 @@ A Python interface to [bayesmix](https://github.com/bayesmix-dev/bayesmix/)

## Installation

First, clone this repository with its submodules
```shell
git clone --recurse-submodule [email protected]:bayesmix-dev/pybmix.git
1. install ```cmake>=3.21.0``` from source following the official documentation
2. install ```libtbb-dev=2020.1-2``` (e.g. for Linux ```sudo apt install libtbb-dev=2020.1-2```)

3. clone the repository
```
Ideally things should work by simply typing
```shell
pip3 install -e .
git clone --recurse-submodules [email protected]:bayesmix-dev/pybmix.git
```
from the root folder of this repo.

## Getting Started
4. setup a python environment with ```python=3.9``` and install the following packages with ```pip```
```
pip3 install numpy==1.22.4 scipy==1.7.3 matplotlib==3.5.2 2to3==1.0
```

See our [tutorials](https://pybmix.readthedocs.io/en/docs/)!
5. install ```protobuf==3.14.0``` and ```libprotobuf=3.14.0``` (e.g. ```conda install protobuf==3.14.0``` will install both)

## Contributing

Just get in touch with us (email in setup.cfg), open a PR or an Issue!
6. add the path for ```2to3``` to the ```PATH``` environment variable, e.g.
```
export PYTHONPATH="path/to/2to3/"
```

7. finally, to build the library
```
./build_pybmix.sh build
```

Note that, the argument ```build``` substitutes ```mkdir build```, thus you can skip it in subsequent builds if only the
new changes need to be compiled.
21 changes: 21 additions & 0 deletions build_pybmix.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
#!/usr/bin/env bash

if [ -z "$1" ]; then
cd build/ || exit
cmake .. -DDISABLE_DOCS=ON -DDISABLE_BENCHMARKS=ON -DDISABLE_TESTS=ON -DDISABLE_EXAMPLES=ON
make pybmixcpp
make generate_protos
make two_to_three
else
if [[ $1 == build ]]; then
rm -rf $1
mkdir $1
cd $1 || exit
cmake .. -DDISABLE_DOCS=ON -DDISABLE_BENCHMARKS=ON -DDISABLE_TESTS=ON -DDISABLE_EXAMPLES=ON
make pybmixcpp
make generate_protos
make two_to_three
else
echo "wrong argument, pass build"
fi
fi
4 changes: 4 additions & 0 deletions convert_proto.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
SCRIPT_DIR=$(pwd)/..

# 2to3 must be in the path (e.g. export PYTHONPATH="path/to/2to3/")
2to3 --output-dir=$SCRIPT_DIR/pybmix/proto -W -n $SCRIPT_DIR/pybmix/proto
8 changes: 3 additions & 5 deletions docs/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,11 @@
#
import os
import sys

sys.path.insert(0, os.path.abspath('.'))
sys.path.insert(0, os.path.abspath('../'))
sys.path.insert(0, os.path.join(os.path.abspath('../'),
"pybmix/core/pybmixcpp/bayesmix"))


"pybmix/core/pybmixcpp/bayesmix_"))

# -- Project information -----------------------------------------------------

Expand All @@ -28,7 +27,6 @@
# The full version, including alpha/beta/rc tags
release = '0.0.1'


# -- General configuration ---------------------------------------------------

# Add any Sphinx extension module names here, as strings. They can be
Expand All @@ -53,7 +51,7 @@
# directories to ignore when looking for source files.
# This pattern also affects html_static_path and html_extra_path.
exclude_patterns = [
'_build', 'Thumbs.db', '.DS_Store', '../lib',
'_build', 'Thumbs.db', '.DS_Store', '../lib',
'../pybmix/core/pybmixcpp']

# html_extra_path = ["protos.html"]
Expand Down
Loading