From fd6594156e202f4eedc31b98d5581c29fa41ca80 Mon Sep 17 00:00:00 2001 From: Andy Maloney Date: Tue, 21 Feb 2023 11:50:45 -0600 Subject: [PATCH 01/13] PR merge test This PR is testing if we can merge PRs into `main`. The only thing that has changed is the `README.md` file. **No** content was changed, only formatting, which was done with `mdformat` with the standard line length defined by `black`, and standardization of the markdown. --- README.md | 24 ++++++++++++++++++------ 1 file changed, 18 insertions(+), 6 deletions(-) diff --git a/README.md b/README.md index af8c70aded..a53d0128e5 100644 --- a/README.md +++ b/README.md @@ -1,4 +1,5 @@ # Bean Machine +
@@ -7,13 +8,16 @@ [![Tests](https://github.com/facebookresearch/beanmachine/actions/workflows/test.yml/badge.svg)](https://github.com/facebookresearch/beanmachine/actions/workflows/test.yml) [![PyPI](https://img.shields.io/pypi/v/beanmachine)](https://pypi.org/project/beanmachine) - ## Overview -Bean Machine is a probabilistic programming language for inference over statistical models written in the Python language using a declarative syntax. Bean Machine is built on top of PyTorch and Bean Machine Graph, a custom C++ backend. -Check out our [tutorials](https://beanmachine.org/docs/overview/tutorials/Coin_flipping/CoinFlipping/) and [Quick Start](https://beanmachine.org/docs/overview/quick_start/) to get started! +Bean Machine is a probabilistic programming language for inference over statistical +models written in the Python language using a declarative syntax. Bean Machine is built +on top of PyTorch and Bean Machine Graph, a custom C++ backend. Check out our +[tutorials](https://beanmachine.org/docs/overview/tutorials/Coin_flipping/CoinFlipping/) +and [Quick Start](https://beanmachine.org/docs/overview/quick_start/) to get started! ## Installation + Bean Machine supports Python 3.7-3.10 and PyTorch 1.12. ### Install the Latest Release with Pip @@ -35,16 +39,23 @@ Then, you can choose from any of the following installation options. #### Package Managers (Anaconda and Vcpkg) -Installing Bean Machine from source requires three external dependencies: [Boost](https://www.boost.org/), [Eigen](https://eigen.tuxfamily.org/index.php?title=Main_Page), and [`range-v3`](https://github.com/ericniebler/range-v3). +Installing Bean Machine from source requires three external dependencies: +[Boost](https://www.boost.org/), +[Eigen](https://eigen.tuxfamily.org/index.php?title=Main_Page), and +[`range-v3`](https://github.com/ericniebler/range-v3). -For installing Boost and Eigen, we recommend using [conda](https://docs.conda.io/en/latest/) to manage the virtual environment and install the necessary build dependencies. +For installing Boost and Eigen, we recommend using +[conda](https://docs.conda.io/en/latest/) to manage the virtual environment and install +the necessary build dependencies. ```bash conda create -n {env name} python=3.8; conda activate {env name} conda install -c conda-forge boost-cpp eigen=3.4.0 ``` -There are [multiple ways of installing `range-v3`](https://github.com/ericniebler/range-v3#building-range-v3---using-vcpkg), including through [`vcpkg`](https://github.com/Microsoft/vcpkg): +There are +[multiple ways of installing `range-v3`](https://github.com/ericniebler/range-v3#building-range-v3---using-vcpkg), +including through [`vcpkg`](https://github.com/Microsoft/vcpkg): ``` git clone https://github.com/Microsoft/vcpkg.git @@ -77,4 +88,5 @@ pytest . ``` ## License + Bean Machine is MIT licensed, as found in the [LICENSE](LICENSE) file. From 68d322e0f24738072db630da1877a2fa0cb996e1 Mon Sep 17 00:00:00 2001 From: Andy Maloney Date: Tue, 21 Feb 2023 13:53:19 -0600 Subject: [PATCH 02/13] Modify GitHub actions The commit modifies the GitHub actions to ensure the needed directory for `vcpkg` exists before running the `vcpkg integrate install` command. --- .github/workflows/docs.yml | 104 +++++++++++++++++-------------------- .github/workflows/lint.yml | 80 +++++++++++++--------------- .github/workflows/test.yml | 98 ++++++++++++++++------------------ 3 files changed, 127 insertions(+), 155 deletions(-) diff --git a/.github/workflows/docs.yml b/.github/workflows/docs.yml index d140d0584d..64e4bbfb88 100644 --- a/.github/workflows/docs.yml +++ b/.github/workflows/docs.yml @@ -1,11 +1,9 @@ name: Documentation - on: push: - branches: [ main ] + branches: [main] pull_request: - branches: [ main ] - + branches: [main] jobs: build_docs_job: runs-on: ubuntu-latest @@ -16,60 +14,52 @@ jobs: run: # https://github.com/conda-incubator/setup-miniconda/tree/v2#use-a-default-shell shell: bash -l {0} - steps: - - name: Checkout - uses: actions/checkout@v2 - - - name: Set up Miniconda with Python ${{ matrix.python-version }} - uses: conda-incubator/setup-miniconda@v2 - with: - auto-update-conda: true - miniconda-version: "latest" - python-version: ${{ matrix.python-version }} - activate-environment: test_env - - - name: Install range-v3 dependency - run: | - git clone https://github.com/Microsoft/vcpkg.git - cd vcpkg - ./bootstrap-vcpkg.sh - ./vcpkg integrate install - ./vcpkg install range-v3 - - - name: Install other dependencies - run: | - sudo apt-get install -y yarn - conda install -c conda-forge -y boost-cpp eigen=3.4.0 - python -m pip install --upgrade pip - python -m pip install setuptools - python -m pip install notebook - - - name: Install Bean Machine in editable mode - run: pip install -v -e .[dev] - - - name: Add tutorials to Docs - run: make tutorials - - - name: Check env - run: echo `which sphinx-build` - - - name: Build the Website - run: | - cd website - yarn install - make all - cd .. - - - name: Get output time - run: echo "The time was ${{ steps.build.outputs.time }}" - - - name: Deploy - if: | - github.event_name == 'push' && - github.repository == 'facebookresearch/beanmachine' - uses: JamesIves/github-pages-deploy-action@releases/v3 - with: + - name: Checkout + uses: actions/checkout@v2 + - name: Set up Miniconda with Python ${{ matrix.python-version }} + uses: conda-incubator/setup-miniconda@v2 + with: + auto-update-conda: true + miniconda-version: latest + python-version: ${{ matrix.python-version }} + activate-environment: test_env + - name: Install range-v3 dependency + run: | + git clone https://github.com/Microsoft/vcpkg.git + cd vcpkg + ./bootstrap-vcpkg.sh + # Ensure the .vcpkg directory exists, otherwise the next command will fail + mkdir -p ~/.vcpkg + ./vcpkg integrate install + ./vcpkg install range-v3 + - name: Install other dependencies + run: | + sudo apt-get install -y yarn + conda install -c conda-forge -y boost-cpp eigen=3.4.0 + python -m pip install --upgrade pip + python -m pip install setuptools + python -m pip install notebook + - name: Install Bean Machine in editable mode + run: pip install -v -e .[dev] + - name: Add tutorials to Docs + run: make tutorials + - name: Check env + run: echo `which sphinx-build` + - name: Build the Website + run: | + cd website + yarn install + make all + cd .. + - name: Get output time + run: echo "The time was ${{ steps.build.outputs.time }}" + - name: Deploy + if: | + github.event_name == 'push' && + github.repository == 'facebookresearch/beanmachine' + uses: JamesIves/github-pages-deploy-action@releases/v3 + with: ACCESS_TOKEN: ${{ secrets.GITHUB_TOKEN }} BRANCH: gh-pages # The branch the action should deploy to. FOLDER: website/build # The folder the action should deploy. diff --git a/.github/workflows/lint.yml b/.github/workflows/lint.yml index 1b9f51849a..8bbe185f7f 100644 --- a/.github/workflows/lint.yml +++ b/.github/workflows/lint.yml @@ -1,11 +1,9 @@ name: Lint - on: push: - branches: [ main ] + branches: [main] pull_request: - branches: [ main ] - + branches: [main] jobs: lint: runs-on: ubuntu-latest @@ -17,44 +15,38 @@ jobs: run: # https://github.com/conda-incubator/setup-miniconda/tree/v2#use-a-default-shell shell: bash -l {0} - steps: - - name: Checkout - uses: actions/checkout@v2 - - - name: Set up Miniconda with Python ${{ matrix.python-version }} - uses: conda-incubator/setup-miniconda@v2 - with: - auto-update-conda: true - miniconda-version: "latest" - python-version: ${{ matrix.python-version }} - activate-environment: test_env - - - name: Install Unix range-v3 dependency - if: matrix.os != 'windows-latest' - run: | - git clone https://github.com/Microsoft/vcpkg.git - cd vcpkg - ./bootstrap-vcpkg.sh - ./vcpkg integrate install - ./vcpkg install range-v3 - - - name: Install dependencies - run: | - conda install -c conda-forge -y boost-cpp eigen=3.4.0 - pip install torch --extra-index-url https://download.pytorch.org/whl/cpu - VERSION=$(grep "version" .pyre_configuration | sed -n -e 's/.*\(0\.0\.[0-9]*\).*/\1/p') - pip install pyre-check-nightly==$VERSION - pip install -v .[dev] - - - name: Print out package info to help with debug - run: pip list - - - name: Lint with flake8 - run: flake8 . --exclude ./vcpkg - - - name: Lint with ufmt (black + usort) - run: ufmt check .*/beanmachine/src - - - name: Run Pyre - run: pyre + - name: Checkout + uses: actions/checkout@v2 + - name: Set up Miniconda with Python ${{ matrix.python-version }} + uses: conda-incubator/setup-miniconda@v2 + with: + auto-update-conda: true + miniconda-version: latest + python-version: ${{ matrix.python-version }} + activate-environment: test_env + - name: Install Unix range-v3 dependency + if: matrix.os != 'windows-latest' + run: | + git clone https://github.com/Microsoft/vcpkg.git + cd vcpkg + ./bootstrap-vcpkg.sh + # Ensure the .vcpkg directory exists, otherwise the next command will fail + mkdir -p ~/.vcpkg + ./vcpkg integrate install + ./vcpkg install range-v3 + - name: Install dependencies + run: | + conda install -c conda-forge -y boost-cpp eigen=3.4.0 + pip install torch --extra-index-url https://download.pytorch.org/whl/cpu + VERSION=$(grep "version" .pyre_configuration | sed -n -e 's/.*\(0\.0\.[0-9]*\).*/\1/p') + pip install pyre-check-nightly==$VERSION + pip install -v .[dev] + - name: Print out package info to help with debug + run: pip list + - name: Lint with flake8 + run: flake8 . --exclude ./vcpkg + - name: Lint with ufmt (black + usort) + run: ufmt check .*/beanmachine/src + - name: Run Pyre + run: pyre diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 7e67e36336..7d805d767e 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -1,72 +1,62 @@ name: Tests - on: push: - branches: [ main ] + branches: [main] pull_request: - branches: [ main ] - + branches: [main] env: PYTHONUNBUFFERED: 1 - PYTEST_ADDOPTS: "--color=yes" - + PYTEST_ADDOPTS: --color=yes jobs: conda-install: runs-on: ${{ matrix.os }} strategy: fail-fast: false matrix: - os: ["ubuntu-latest", "macos-latest", "windows-latest"] + os: ['ubuntu-latest', 'macos-latest', 'windows-latest'] python-version: ['3.7', '3.8', '3.9', '3.10'] defaults: run: # https://github.com/conda-incubator/setup-miniconda/tree/v2#use-a-default-shell shell: bash -l {0} - steps: - - name: Checkout - uses: actions/checkout@v2 - - - name: Set up Miniconda with Python ${{ matrix.python-version }} - uses: conda-incubator/setup-miniconda@v2 - with: - auto-update-conda: true - miniconda-version: "latest" - python-version: ${{ matrix.python-version }} - activate-environment: test_env - - - name: Install Windows range-v3 dependency - if: matrix.os == 'windows-latest' - run: | - git clone https://github.com/Microsoft/vcpkg.git - cd vcpkg - bootstrap-vcpkg.bat - vcpkg integrate install - vcpkg install range-v3 - - - name: Install Unix range-v3 dependency - if: matrix.os != 'windows-latest' - run: | - git clone https://github.com/Microsoft/vcpkg.git - cd vcpkg - ./bootstrap-vcpkg.sh - ./vcpkg integrate install - ./vcpkg install range-v3 - - - name: Install other dependencies - run: | - conda install -c conda-forge -y boost-cpp eigen=3.4.0 - python -m pip install --upgrade pip - - - name: Install CPU PyTorch (only for Linux) - if: matrix.os == 'ubuntu-latest' - run: pip install torch --extra-index-url https://download.pytorch.org/whl/cpu - - - name: Install Bean Machine in editable mode - run: pip install -v -e .[dev] - - - name: Print out package info to help with debug - run: pip list - - - name: Run unit tests with pytest - run: pytest + - name: Checkout + uses: actions/checkout@v2 + - name: Set up Miniconda with Python ${{ matrix.python-version }} + uses: conda-incubator/setup-miniconda@v2 + with: + auto-update-conda: true + miniconda-version: latest + python-version: ${{ matrix.python-version }} + activate-environment: test_env + - name: Install Windows range-v3 dependency + if: matrix.os == 'windows-latest' + run: | + git clone https://github.com/Microsoft/vcpkg.git + cd vcpkg + bootstrap-vcpkg.bat + vcpkg integrate install + vcpkg install range-v3 + - name: Install Unix range-v3 dependency + if: matrix.os != 'windows-latest' + run: | + git clone https://github.com/Microsoft/vcpkg.git + cd vcpkg + ./bootstrap-vcpkg.sh + # Ensure the .vcpkg directory exists, otherwise the next command will fail + mkdir -p ~/.vcpkg + ./vcpkg integrate install + ./vcpkg install range-v3 + - name: Install other dependencies + run: | + conda install -c conda-forge -y boost-cpp eigen=3.4.0 + python -m pip install --upgrade pip + - name: Install CPU PyTorch (only for Linux) + if: matrix.os == 'ubuntu-latest' + run: pip install torch --extra-index-url https://download.pytorch.org/whl/cpu + - name: Install Bean Machine in editable mode + run: pip install -v -e .[dev] + - name: Print out package info to help with debug + run: pip list + - name: Run unit tests with pytest + run: pytest From 115974644838c4867f1864d688a53174e950dd2c Mon Sep 17 00:00:00 2001 From: Andy Maloney Date: Tue, 21 Feb 2023 15:21:47 -0600 Subject: [PATCH 03/13] Update failing test The `forward` method in the `Regression` class in module `tests/ppl/experimental/gp/inference_test.py` was failing due to an attribute error. This commit attempts to fix that. --- tests/ppl/experimental/gp/inference_test.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/ppl/experimental/gp/inference_test.py b/tests/ppl/experimental/gp/inference_test.py index acbbc97408..ba505c8f22 100644 --- a/tests/ppl/experimental/gp/inference_test.py +++ b/tests/ppl/experimental/gp/inference_test.py @@ -35,7 +35,7 @@ def forward(self, data): jitter = jitter.unsqueeze(0) mean = self.mean(data) cov = self.kernel(data) + jitter - if cov.ndim > mean.ndim + 1: + if cov.dim > mean.dim + 1: cov = cov.squeeze(0) return MultivariateNormal(mean, cov) From c6cf36909210222cc309d4d8ecee9abf5081caaf Mon Sep 17 00:00:00 2001 From: Andy Maloney Date: Wed, 22 Feb 2023 09:04:35 -0600 Subject: [PATCH 04/13] Fix failing test --- tests/ppl/experimental/gp/inference_test.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/ppl/experimental/gp/inference_test.py b/tests/ppl/experimental/gp/inference_test.py index ba505c8f22..7db899248f 100644 --- a/tests/ppl/experimental/gp/inference_test.py +++ b/tests/ppl/experimental/gp/inference_test.py @@ -35,7 +35,7 @@ def forward(self, data): jitter = jitter.unsqueeze(0) mean = self.mean(data) cov = self.kernel(data) + jitter - if cov.dim > mean.dim + 1: + if cov.dim() > mean.dim() + 1: cov = cov.squeeze(0) return MultivariateNormal(mean, cov) From e1e1eca8a91cdc374f805735cee4e3ea55054706 Mon Sep 17 00:00:00 2001 From: ntfrgl Date: Thu, 15 Sep 2022 12:50:45 -0700 Subject: [PATCH 05/13] Move GTest: src/beanmachine/*/tests/ -> tests/*/ This commit applies the same reasoning to the GTest suite for BMG/C++ as fb7a5564b (#1674) does to the Pytest suite for BM/Python. It leaves untouched the separate source tree of `minibmg/tests/`. --- {src/beanmachine/graph/tests => tests/graph}/cavi_test.cpp | 0 .../graph/distribution}/bernoulli_logit_test.cpp | 0 .../graph/distribution}/bernoulli_noisy_or_test.cpp | 0 .../tests => tests/graph/distribution}/beta_test.cpp | 0 .../tests => tests/graph/distribution}/bimixture_test.cpp | 0 .../tests => tests/graph/distribution}/binomial_test.cpp | 0 .../tests => tests/graph/distribution}/categorical_test.cpp | 0 .../tests => tests/graph/distribution}/cauchy_test.cpp | 0 .../tests => tests/graph/distribution}/dirichlet_test.cpp | 0 .../tests => tests/graph/distribution}/distribution_test.cpp | 0 .../tests => tests/graph/distribution}/flat_test.cpp | 0 .../tests => tests/graph/distribution}/gamma_test.cpp | 0 .../tests => tests/graph/distribution}/geometric_test.cpp | 0 .../tests => tests/graph/distribution}/half_cauchy_test.cpp | 0 .../tests => tests/graph/distribution}/half_normal_test.cpp | 0 .../tests => tests/graph/distribution}/lkj_cholesky_test.cpp | 0 .../tests => tests/graph/distribution}/log_normal_test.cpp | 0 .../graph/distribution}/multivariate_normal_test.cpp | 0 .../tests => tests/graph/distribution}/normal_test.cpp | 0 .../tests => tests/graph/distribution}/poisson_test.cpp | 0 .../tests => tests/graph/distribution}/product_test.cpp | 2 +- .../tests => tests/graph/distribution}/student_t_test.cpp | 0 .../factor/tests => tests/graph/factor}/exp_product_test.cpp | 0 .../graph/fluid/tests => tests/graph/fluid}/fluid_test.cpp | 0 .../tests => tests/graph/global}/conjugate_util_test.cpp | 4 ++-- .../global/tests => tests/graph/global}/conjugate_util_test.h | 0 .../global/tests => tests/graph/global}/global_state_test.cpp | 0 .../tests => tests/graph/global}/hmc_mass_matrix_test.cpp | 2 +- .../tests => tests/graph/global}/hmc_no_warmup_test.cpp | 2 +- .../tests => tests/graph/global}/hmc_step_size_test.cpp | 2 +- .../tests => tests/graph/global}/nuts_mass_matrix_test.cpp | 2 +- .../global/tests => tests/graph/global}/nuts_matrix_test.cpp | 0 .../tests => tests/graph/global}/nuts_multinomial_test.cpp | 2 +- .../graph/global/tests => tests/graph/global}/nuts_test.cpp | 2 +- .../tests => tests/graph/global/proposer}/hmc_util_test.cpp | 0 .../global/tests => tests/graph/global}/random_walk_test.cpp | 0 .../graph/global/tests => tests/graph/global}/util_test.cpp | 0 .../graph/tests => tests/graph}/graph_stat_test.cpp | 0 {src/beanmachine/graph/tests => tests/graph}/graph_test.cpp | 0 .../marginalization/marginalization_extensional_test.cpp | 2 +- .../graph/marginalization/marginalized_graph_test.cpp | 0 .../graph/marginalization/subgraph_test.cpp | 0 {src/beanmachine/graph/tests => tests/graph}/nmc_test.cpp | 0 .../operator/tests => tests/graph/operator}/gradient_test.cpp | 0 .../operator/tests => tests/graph/operator}/operator_test.cpp | 0 .../graph}/out_nodes_reflexive_transitive_closure_test.cpp | 0 .../beanmachine/graph/tests => tests/graph}/profiler_test.cpp | 0 .../proposer/tests => tests/graph/proposer}/gamma_test.cpp | 0 .../proposer/tests => tests/graph/proposer}/mixture_test.cpp | 0 .../tests => tests/graph/proposer}/trunc_cauchy_test.cpp | 0 .../graph/tests => tests/graph}/rejection_test.cpp | 0 {src/beanmachine/graph/tests => tests/graph}/support_test.cpp | 0 .../graph/tests => tests/graph}/testing_util_test.cpp | 2 +- .../graph/tests => tests/graph}/testing_util_test.h | 0 {src/beanmachine => tests}/graph/transform/transform_test.cpp | 0 {src/beanmachine/graph/tests => tests/graph}/util_test.cpp | 0 56 files changed, 11 insertions(+), 11 deletions(-) rename {src/beanmachine/graph/tests => tests/graph}/cavi_test.cpp (100%) rename {src/beanmachine/graph/distribution/tests => tests/graph/distribution}/bernoulli_logit_test.cpp (100%) rename {src/beanmachine/graph/distribution/tests => tests/graph/distribution}/bernoulli_noisy_or_test.cpp (100%) rename {src/beanmachine/graph/distribution/tests => tests/graph/distribution}/beta_test.cpp (100%) rename {src/beanmachine/graph/distribution/tests => tests/graph/distribution}/bimixture_test.cpp (100%) rename {src/beanmachine/graph/distribution/tests => tests/graph/distribution}/binomial_test.cpp (100%) rename {src/beanmachine/graph/distribution/tests => tests/graph/distribution}/categorical_test.cpp (100%) rename {src/beanmachine/graph/distribution/tests => tests/graph/distribution}/cauchy_test.cpp (100%) rename {src/beanmachine/graph/distribution/tests => tests/graph/distribution}/dirichlet_test.cpp (100%) rename {src/beanmachine/graph/distribution/tests => tests/graph/distribution}/distribution_test.cpp (100%) rename {src/beanmachine/graph/distribution/tests => tests/graph/distribution}/flat_test.cpp (100%) rename {src/beanmachine/graph/distribution/tests => tests/graph/distribution}/gamma_test.cpp (100%) rename {src/beanmachine/graph/distribution/tests => tests/graph/distribution}/geometric_test.cpp (100%) rename {src/beanmachine/graph/distribution/tests => tests/graph/distribution}/half_cauchy_test.cpp (100%) rename {src/beanmachine/graph/distribution/tests => tests/graph/distribution}/half_normal_test.cpp (100%) rename {src/beanmachine/graph/distribution/tests => tests/graph/distribution}/lkj_cholesky_test.cpp (100%) rename {src/beanmachine/graph/distribution/tests => tests/graph/distribution}/log_normal_test.cpp (100%) rename {src/beanmachine/graph/distribution/tests => tests/graph/distribution}/multivariate_normal_test.cpp (100%) rename {src/beanmachine/graph/distribution/tests => tests/graph/distribution}/normal_test.cpp (100%) rename {src/beanmachine/graph/distribution/tests => tests/graph/distribution}/poisson_test.cpp (100%) rename {src/beanmachine/graph/distribution/tests => tests/graph/distribution}/product_test.cpp (99%) rename {src/beanmachine/graph/distribution/tests => tests/graph/distribution}/student_t_test.cpp (100%) rename {src/beanmachine/graph/factor/tests => tests/graph/factor}/exp_product_test.cpp (100%) rename {src/beanmachine/graph/fluid/tests => tests/graph/fluid}/fluid_test.cpp (100%) rename {src/beanmachine/graph/global/tests => tests/graph/global}/conjugate_util_test.cpp (99%) rename {src/beanmachine/graph/global/tests => tests/graph/global}/conjugate_util_test.h (100%) rename {src/beanmachine/graph/global/tests => tests/graph/global}/global_state_test.cpp (100%) rename {src/beanmachine/graph/global/tests => tests/graph/global}/hmc_mass_matrix_test.cpp (96%) rename {src/beanmachine/graph/global/tests => tests/graph/global}/hmc_no_warmup_test.cpp (97%) rename {src/beanmachine/graph/global/tests => tests/graph/global}/hmc_step_size_test.cpp (97%) rename {src/beanmachine/graph/global/tests => tests/graph/global}/nuts_mass_matrix_test.cpp (97%) rename {src/beanmachine/graph/global/tests => tests/graph/global}/nuts_matrix_test.cpp (100%) rename {src/beanmachine/graph/global/tests => tests/graph/global}/nuts_multinomial_test.cpp (97%) rename {src/beanmachine/graph/global/tests => tests/graph/global}/nuts_test.cpp (97%) rename {src/beanmachine/graph/global/proposer/tests => tests/graph/global/proposer}/hmc_util_test.cpp (100%) rename {src/beanmachine/graph/global/tests => tests/graph/global}/random_walk_test.cpp (100%) rename {src/beanmachine/graph/global/tests => tests/graph/global}/util_test.cpp (100%) rename {src/beanmachine/graph/tests => tests/graph}/graph_stat_test.cpp (100%) rename {src/beanmachine/graph/tests => tests/graph}/graph_test.cpp (100%) rename {src/beanmachine => tests}/graph/marginalization/marginalization_extensional_test.cpp (99%) rename {src/beanmachine => tests}/graph/marginalization/marginalized_graph_test.cpp (100%) rename {src/beanmachine => tests}/graph/marginalization/subgraph_test.cpp (100%) rename {src/beanmachine/graph/tests => tests/graph}/nmc_test.cpp (100%) rename {src/beanmachine/graph/operator/tests => tests/graph/operator}/gradient_test.cpp (100%) rename {src/beanmachine/graph/operator/tests => tests/graph/operator}/operator_test.cpp (100%) rename {src/beanmachine/graph/tests => tests/graph}/out_nodes_reflexive_transitive_closure_test.cpp (100%) rename {src/beanmachine/graph/tests => tests/graph}/profiler_test.cpp (100%) rename {src/beanmachine/graph/proposer/tests => tests/graph/proposer}/gamma_test.cpp (100%) rename {src/beanmachine/graph/proposer/tests => tests/graph/proposer}/mixture_test.cpp (100%) rename {src/beanmachine/graph/proposer/tests => tests/graph/proposer}/trunc_cauchy_test.cpp (100%) rename {src/beanmachine/graph/tests => tests/graph}/rejection_test.cpp (100%) rename {src/beanmachine/graph/tests => tests/graph}/support_test.cpp (100%) rename {src/beanmachine/graph/tests => tests/graph}/testing_util_test.cpp (97%) rename {src/beanmachine/graph/tests => tests/graph}/testing_util_test.h (100%) rename {src/beanmachine => tests}/graph/transform/transform_test.cpp (100%) rename {src/beanmachine/graph/tests => tests/graph}/util_test.cpp (100%) diff --git a/src/beanmachine/graph/tests/cavi_test.cpp b/tests/graph/cavi_test.cpp similarity index 100% rename from src/beanmachine/graph/tests/cavi_test.cpp rename to tests/graph/cavi_test.cpp diff --git a/src/beanmachine/graph/distribution/tests/bernoulli_logit_test.cpp b/tests/graph/distribution/bernoulli_logit_test.cpp similarity index 100% rename from src/beanmachine/graph/distribution/tests/bernoulli_logit_test.cpp rename to tests/graph/distribution/bernoulli_logit_test.cpp diff --git a/src/beanmachine/graph/distribution/tests/bernoulli_noisy_or_test.cpp b/tests/graph/distribution/bernoulli_noisy_or_test.cpp similarity index 100% rename from src/beanmachine/graph/distribution/tests/bernoulli_noisy_or_test.cpp rename to tests/graph/distribution/bernoulli_noisy_or_test.cpp diff --git a/src/beanmachine/graph/distribution/tests/beta_test.cpp b/tests/graph/distribution/beta_test.cpp similarity index 100% rename from src/beanmachine/graph/distribution/tests/beta_test.cpp rename to tests/graph/distribution/beta_test.cpp diff --git a/src/beanmachine/graph/distribution/tests/bimixture_test.cpp b/tests/graph/distribution/bimixture_test.cpp similarity index 100% rename from src/beanmachine/graph/distribution/tests/bimixture_test.cpp rename to tests/graph/distribution/bimixture_test.cpp diff --git a/src/beanmachine/graph/distribution/tests/binomial_test.cpp b/tests/graph/distribution/binomial_test.cpp similarity index 100% rename from src/beanmachine/graph/distribution/tests/binomial_test.cpp rename to tests/graph/distribution/binomial_test.cpp diff --git a/src/beanmachine/graph/distribution/tests/categorical_test.cpp b/tests/graph/distribution/categorical_test.cpp similarity index 100% rename from src/beanmachine/graph/distribution/tests/categorical_test.cpp rename to tests/graph/distribution/categorical_test.cpp diff --git a/src/beanmachine/graph/distribution/tests/cauchy_test.cpp b/tests/graph/distribution/cauchy_test.cpp similarity index 100% rename from src/beanmachine/graph/distribution/tests/cauchy_test.cpp rename to tests/graph/distribution/cauchy_test.cpp diff --git a/src/beanmachine/graph/distribution/tests/dirichlet_test.cpp b/tests/graph/distribution/dirichlet_test.cpp similarity index 100% rename from src/beanmachine/graph/distribution/tests/dirichlet_test.cpp rename to tests/graph/distribution/dirichlet_test.cpp diff --git a/src/beanmachine/graph/distribution/tests/distribution_test.cpp b/tests/graph/distribution/distribution_test.cpp similarity index 100% rename from src/beanmachine/graph/distribution/tests/distribution_test.cpp rename to tests/graph/distribution/distribution_test.cpp diff --git a/src/beanmachine/graph/distribution/tests/flat_test.cpp b/tests/graph/distribution/flat_test.cpp similarity index 100% rename from src/beanmachine/graph/distribution/tests/flat_test.cpp rename to tests/graph/distribution/flat_test.cpp diff --git a/src/beanmachine/graph/distribution/tests/gamma_test.cpp b/tests/graph/distribution/gamma_test.cpp similarity index 100% rename from src/beanmachine/graph/distribution/tests/gamma_test.cpp rename to tests/graph/distribution/gamma_test.cpp diff --git a/src/beanmachine/graph/distribution/tests/geometric_test.cpp b/tests/graph/distribution/geometric_test.cpp similarity index 100% rename from src/beanmachine/graph/distribution/tests/geometric_test.cpp rename to tests/graph/distribution/geometric_test.cpp diff --git a/src/beanmachine/graph/distribution/tests/half_cauchy_test.cpp b/tests/graph/distribution/half_cauchy_test.cpp similarity index 100% rename from src/beanmachine/graph/distribution/tests/half_cauchy_test.cpp rename to tests/graph/distribution/half_cauchy_test.cpp diff --git a/src/beanmachine/graph/distribution/tests/half_normal_test.cpp b/tests/graph/distribution/half_normal_test.cpp similarity index 100% rename from src/beanmachine/graph/distribution/tests/half_normal_test.cpp rename to tests/graph/distribution/half_normal_test.cpp diff --git a/src/beanmachine/graph/distribution/tests/lkj_cholesky_test.cpp b/tests/graph/distribution/lkj_cholesky_test.cpp similarity index 100% rename from src/beanmachine/graph/distribution/tests/lkj_cholesky_test.cpp rename to tests/graph/distribution/lkj_cholesky_test.cpp diff --git a/src/beanmachine/graph/distribution/tests/log_normal_test.cpp b/tests/graph/distribution/log_normal_test.cpp similarity index 100% rename from src/beanmachine/graph/distribution/tests/log_normal_test.cpp rename to tests/graph/distribution/log_normal_test.cpp diff --git a/src/beanmachine/graph/distribution/tests/multivariate_normal_test.cpp b/tests/graph/distribution/multivariate_normal_test.cpp similarity index 100% rename from src/beanmachine/graph/distribution/tests/multivariate_normal_test.cpp rename to tests/graph/distribution/multivariate_normal_test.cpp diff --git a/src/beanmachine/graph/distribution/tests/normal_test.cpp b/tests/graph/distribution/normal_test.cpp similarity index 100% rename from src/beanmachine/graph/distribution/tests/normal_test.cpp rename to tests/graph/distribution/normal_test.cpp diff --git a/src/beanmachine/graph/distribution/tests/poisson_test.cpp b/tests/graph/distribution/poisson_test.cpp similarity index 100% rename from src/beanmachine/graph/distribution/tests/poisson_test.cpp rename to tests/graph/distribution/poisson_test.cpp diff --git a/src/beanmachine/graph/distribution/tests/product_test.cpp b/tests/graph/distribution/product_test.cpp similarity index 99% rename from src/beanmachine/graph/distribution/tests/product_test.cpp rename to tests/graph/distribution/product_test.cpp index 864d2e5257..69df4affff 100644 --- a/src/beanmachine/graph/distribution/tests/product_test.cpp +++ b/tests/graph/distribution/product_test.cpp @@ -15,8 +15,8 @@ #include "beanmachine/graph/global/global_state.h" #include "beanmachine/graph/global/nuts.h" #include "beanmachine/graph/graph.h" -#include "beanmachine/graph/tests/testing_util_test.h" #include "beanmachine/graph/util.h" +#include "graph/testing_util_test.h" using namespace beanmachine::graph; using namespace beanmachine::distribution; diff --git a/src/beanmachine/graph/distribution/tests/student_t_test.cpp b/tests/graph/distribution/student_t_test.cpp similarity index 100% rename from src/beanmachine/graph/distribution/tests/student_t_test.cpp rename to tests/graph/distribution/student_t_test.cpp diff --git a/src/beanmachine/graph/factor/tests/exp_product_test.cpp b/tests/graph/factor/exp_product_test.cpp similarity index 100% rename from src/beanmachine/graph/factor/tests/exp_product_test.cpp rename to tests/graph/factor/exp_product_test.cpp diff --git a/src/beanmachine/graph/fluid/tests/fluid_test.cpp b/tests/graph/fluid/fluid_test.cpp similarity index 100% rename from src/beanmachine/graph/fluid/tests/fluid_test.cpp rename to tests/graph/fluid/fluid_test.cpp diff --git a/src/beanmachine/graph/global/tests/conjugate_util_test.cpp b/tests/graph/global/conjugate_util_test.cpp similarity index 99% rename from src/beanmachine/graph/global/tests/conjugate_util_test.cpp rename to tests/graph/global/conjugate_util_test.cpp index a22351a984..15786c8feb 100644 --- a/src/beanmachine/graph/global/tests/conjugate_util_test.cpp +++ b/tests/graph/global/conjugate_util_test.cpp @@ -7,10 +7,10 @@ #include -#include "beanmachine/graph/global/tests/conjugate_util_test.h" #include "beanmachine/graph/graph.h" -#include "beanmachine/graph/tests/testing_util_test.h" #include "beanmachine/graph/util.h" +#include "graph/testing_util_test.h" +#include "graph/global/conjugate_util_test.h" namespace beanmachine { namespace graph { diff --git a/src/beanmachine/graph/global/tests/conjugate_util_test.h b/tests/graph/global/conjugate_util_test.h similarity index 100% rename from src/beanmachine/graph/global/tests/conjugate_util_test.h rename to tests/graph/global/conjugate_util_test.h diff --git a/src/beanmachine/graph/global/tests/global_state_test.cpp b/tests/graph/global/global_state_test.cpp similarity index 100% rename from src/beanmachine/graph/global/tests/global_state_test.cpp rename to tests/graph/global/global_state_test.cpp diff --git a/src/beanmachine/graph/global/tests/hmc_mass_matrix_test.cpp b/tests/graph/global/hmc_mass_matrix_test.cpp similarity index 96% rename from src/beanmachine/graph/global/tests/hmc_mass_matrix_test.cpp rename to tests/graph/global/hmc_mass_matrix_test.cpp index bdc01ad253..11f2cfdb4d 100644 --- a/src/beanmachine/graph/global/tests/hmc_mass_matrix_test.cpp +++ b/tests/graph/global/hmc_mass_matrix_test.cpp @@ -8,8 +8,8 @@ #include #include "beanmachine/graph/global/hmc.h" -#include "beanmachine/graph/global/tests/conjugate_util_test.h" #include "beanmachine/graph/graph.h" +#include "graph/global/conjugate_util_test.h" using namespace beanmachine; using namespace graph; diff --git a/src/beanmachine/graph/global/tests/hmc_no_warmup_test.cpp b/tests/graph/global/hmc_no_warmup_test.cpp similarity index 97% rename from src/beanmachine/graph/global/tests/hmc_no_warmup_test.cpp rename to tests/graph/global/hmc_no_warmup_test.cpp index 1d72216f98..21d608daa0 100644 --- a/src/beanmachine/graph/global/tests/hmc_no_warmup_test.cpp +++ b/tests/graph/global/hmc_no_warmup_test.cpp @@ -8,8 +8,8 @@ #include #include "beanmachine/graph/global/hmc.h" -#include "beanmachine/graph/global/tests/conjugate_util_test.h" #include "beanmachine/graph/graph.h" +#include "graph/global/conjugate_util_test.h" using namespace beanmachine; using namespace graph; diff --git a/src/beanmachine/graph/global/tests/hmc_step_size_test.cpp b/tests/graph/global/hmc_step_size_test.cpp similarity index 97% rename from src/beanmachine/graph/global/tests/hmc_step_size_test.cpp rename to tests/graph/global/hmc_step_size_test.cpp index ef5d22773b..a9feae0294 100644 --- a/src/beanmachine/graph/global/tests/hmc_step_size_test.cpp +++ b/tests/graph/global/hmc_step_size_test.cpp @@ -9,8 +9,8 @@ #include #include "beanmachine/graph/global/hmc.h" -#include "beanmachine/graph/global/tests/conjugate_util_test.h" #include "beanmachine/graph/graph.h" +#include "graph/global/conjugate_util_test.h" using namespace beanmachine; using namespace graph; diff --git a/src/beanmachine/graph/global/tests/nuts_mass_matrix_test.cpp b/tests/graph/global/nuts_mass_matrix_test.cpp similarity index 97% rename from src/beanmachine/graph/global/tests/nuts_mass_matrix_test.cpp rename to tests/graph/global/nuts_mass_matrix_test.cpp index 8f16335a69..aab3c2c74f 100644 --- a/src/beanmachine/graph/global/tests/nuts_mass_matrix_test.cpp +++ b/tests/graph/global/nuts_mass_matrix_test.cpp @@ -8,8 +8,8 @@ #include #include #include "beanmachine/graph/global/nuts.h" -#include "beanmachine/graph/global/tests/conjugate_util_test.h" #include "beanmachine/graph/graph.h" +#include "graph/global/conjugate_util_test.h" using namespace beanmachine; using namespace graph; diff --git a/src/beanmachine/graph/global/tests/nuts_matrix_test.cpp b/tests/graph/global/nuts_matrix_test.cpp similarity index 100% rename from src/beanmachine/graph/global/tests/nuts_matrix_test.cpp rename to tests/graph/global/nuts_matrix_test.cpp diff --git a/src/beanmachine/graph/global/tests/nuts_multinomial_test.cpp b/tests/graph/global/nuts_multinomial_test.cpp similarity index 97% rename from src/beanmachine/graph/global/tests/nuts_multinomial_test.cpp rename to tests/graph/global/nuts_multinomial_test.cpp index 4de123a3a6..11a368cc9a 100644 --- a/src/beanmachine/graph/global/tests/nuts_multinomial_test.cpp +++ b/tests/graph/global/nuts_multinomial_test.cpp @@ -8,8 +8,8 @@ #include #include #include "beanmachine/graph/global/nuts.h" -#include "beanmachine/graph/global/tests/conjugate_util_test.h" #include "beanmachine/graph/graph.h" +#include "graph/global/conjugate_util_test.h" using namespace beanmachine; using namespace graph; diff --git a/src/beanmachine/graph/global/tests/nuts_test.cpp b/tests/graph/global/nuts_test.cpp similarity index 97% rename from src/beanmachine/graph/global/tests/nuts_test.cpp rename to tests/graph/global/nuts_test.cpp index 3fb579bddc..a753e1df29 100644 --- a/src/beanmachine/graph/global/tests/nuts_test.cpp +++ b/tests/graph/global/nuts_test.cpp @@ -8,8 +8,8 @@ #include #include #include "beanmachine/graph/global/nuts.h" -#include "beanmachine/graph/global/tests/conjugate_util_test.h" #include "beanmachine/graph/graph.h" +#include "graph/global/conjugate_util_test.h" using namespace beanmachine; using namespace graph; diff --git a/src/beanmachine/graph/global/proposer/tests/hmc_util_test.cpp b/tests/graph/global/proposer/hmc_util_test.cpp similarity index 100% rename from src/beanmachine/graph/global/proposer/tests/hmc_util_test.cpp rename to tests/graph/global/proposer/hmc_util_test.cpp diff --git a/src/beanmachine/graph/global/tests/random_walk_test.cpp b/tests/graph/global/random_walk_test.cpp similarity index 100% rename from src/beanmachine/graph/global/tests/random_walk_test.cpp rename to tests/graph/global/random_walk_test.cpp diff --git a/src/beanmachine/graph/global/tests/util_test.cpp b/tests/graph/global/util_test.cpp similarity index 100% rename from src/beanmachine/graph/global/tests/util_test.cpp rename to tests/graph/global/util_test.cpp diff --git a/src/beanmachine/graph/tests/graph_stat_test.cpp b/tests/graph/graph_stat_test.cpp similarity index 100% rename from src/beanmachine/graph/tests/graph_stat_test.cpp rename to tests/graph/graph_stat_test.cpp diff --git a/src/beanmachine/graph/tests/graph_test.cpp b/tests/graph/graph_test.cpp similarity index 100% rename from src/beanmachine/graph/tests/graph_test.cpp rename to tests/graph/graph_test.cpp diff --git a/src/beanmachine/graph/marginalization/marginalization_extensional_test.cpp b/tests/graph/marginalization/marginalization_extensional_test.cpp similarity index 99% rename from src/beanmachine/graph/marginalization/marginalization_extensional_test.cpp rename to tests/graph/marginalization/marginalization_extensional_test.cpp index 91b63c44d9..e762290482 100644 --- a/src/beanmachine/graph/marginalization/marginalization_extensional_test.cpp +++ b/tests/graph/marginalization/marginalization_extensional_test.cpp @@ -15,8 +15,8 @@ #include "beanmachine/graph/distribution/distribution.h" #include "beanmachine/graph/marginalization/marginalization_extensional.h" #include "beanmachine/graph/operator/operator.h" -#include "beanmachine/graph/tests/testing_util_test.h" #include "beanmachine/graph/util.h" +#include "graph/testing_util_test.h" using namespace beanmachine; using namespace graph; diff --git a/src/beanmachine/graph/marginalization/marginalized_graph_test.cpp b/tests/graph/marginalization/marginalized_graph_test.cpp similarity index 100% rename from src/beanmachine/graph/marginalization/marginalized_graph_test.cpp rename to tests/graph/marginalization/marginalized_graph_test.cpp diff --git a/src/beanmachine/graph/marginalization/subgraph_test.cpp b/tests/graph/marginalization/subgraph_test.cpp similarity index 100% rename from src/beanmachine/graph/marginalization/subgraph_test.cpp rename to tests/graph/marginalization/subgraph_test.cpp diff --git a/src/beanmachine/graph/tests/nmc_test.cpp b/tests/graph/nmc_test.cpp similarity index 100% rename from src/beanmachine/graph/tests/nmc_test.cpp rename to tests/graph/nmc_test.cpp diff --git a/src/beanmachine/graph/operator/tests/gradient_test.cpp b/tests/graph/operator/gradient_test.cpp similarity index 100% rename from src/beanmachine/graph/operator/tests/gradient_test.cpp rename to tests/graph/operator/gradient_test.cpp diff --git a/src/beanmachine/graph/operator/tests/operator_test.cpp b/tests/graph/operator/operator_test.cpp similarity index 100% rename from src/beanmachine/graph/operator/tests/operator_test.cpp rename to tests/graph/operator/operator_test.cpp diff --git a/src/beanmachine/graph/tests/out_nodes_reflexive_transitive_closure_test.cpp b/tests/graph/out_nodes_reflexive_transitive_closure_test.cpp similarity index 100% rename from src/beanmachine/graph/tests/out_nodes_reflexive_transitive_closure_test.cpp rename to tests/graph/out_nodes_reflexive_transitive_closure_test.cpp diff --git a/src/beanmachine/graph/tests/profiler_test.cpp b/tests/graph/profiler_test.cpp similarity index 100% rename from src/beanmachine/graph/tests/profiler_test.cpp rename to tests/graph/profiler_test.cpp diff --git a/src/beanmachine/graph/proposer/tests/gamma_test.cpp b/tests/graph/proposer/gamma_test.cpp similarity index 100% rename from src/beanmachine/graph/proposer/tests/gamma_test.cpp rename to tests/graph/proposer/gamma_test.cpp diff --git a/src/beanmachine/graph/proposer/tests/mixture_test.cpp b/tests/graph/proposer/mixture_test.cpp similarity index 100% rename from src/beanmachine/graph/proposer/tests/mixture_test.cpp rename to tests/graph/proposer/mixture_test.cpp diff --git a/src/beanmachine/graph/proposer/tests/trunc_cauchy_test.cpp b/tests/graph/proposer/trunc_cauchy_test.cpp similarity index 100% rename from src/beanmachine/graph/proposer/tests/trunc_cauchy_test.cpp rename to tests/graph/proposer/trunc_cauchy_test.cpp diff --git a/src/beanmachine/graph/tests/rejection_test.cpp b/tests/graph/rejection_test.cpp similarity index 100% rename from src/beanmachine/graph/tests/rejection_test.cpp rename to tests/graph/rejection_test.cpp diff --git a/src/beanmachine/graph/tests/support_test.cpp b/tests/graph/support_test.cpp similarity index 100% rename from src/beanmachine/graph/tests/support_test.cpp rename to tests/graph/support_test.cpp diff --git a/src/beanmachine/graph/tests/testing_util_test.cpp b/tests/graph/testing_util_test.cpp similarity index 97% rename from src/beanmachine/graph/tests/testing_util_test.cpp rename to tests/graph/testing_util_test.cpp index 7f03143f29..a99e6e048e 100644 --- a/src/beanmachine/graph/tests/testing_util_test.cpp +++ b/tests/graph/testing_util_test.cpp @@ -15,7 +15,7 @@ #include "beanmachine/graph/global/nuts.h" #include "beanmachine/graph/graph.h" #include "beanmachine/graph/operator/operator.h" -#include "beanmachine/graph/tests/testing_util_test.h" +#include "graph/testing_util_test.h" namespace beanmachine::util { diff --git a/src/beanmachine/graph/tests/testing_util_test.h b/tests/graph/testing_util_test.h similarity index 100% rename from src/beanmachine/graph/tests/testing_util_test.h rename to tests/graph/testing_util_test.h diff --git a/src/beanmachine/graph/transform/transform_test.cpp b/tests/graph/transform/transform_test.cpp similarity index 100% rename from src/beanmachine/graph/transform/transform_test.cpp rename to tests/graph/transform/transform_test.cpp diff --git a/src/beanmachine/graph/tests/util_test.cpp b/tests/graph/util_test.cpp similarity index 100% rename from src/beanmachine/graph/tests/util_test.cpp rename to tests/graph/util_test.cpp From 172ca24ee039b8a164dd51f2d438fb807afc175a Mon Sep 17 00:00:00 2001 From: ntfrgl Date: Mon, 27 Feb 2023 13:05:25 -0800 Subject: [PATCH 06/13] Update `setup.py` - reflect test relocation in e1e1eca8a - enable parallel compilation of Pybind11 extensions --- pyproject.toml | 2 +- setup.py | 8 +++++--- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/pyproject.toml b/pyproject.toml index d67f34a347..79703659c3 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -4,7 +4,7 @@ requires = ["setuptools", "wheel", "pybind11>=2.6.0"] build-backend = "setuptools.build_meta" [tool.pytest.ini_options] -minversion = "6.0" +minversion = "7.0" addopts = "-ra -q" testpaths = ["tests"] diff --git a/setup.py b/setup.py index 893b141c50..4afaef63b3 100644 --- a/setup.py +++ b/setup.py @@ -9,7 +9,7 @@ import sys from glob import glob -from pybind11.setup_helpers import build_ext, Pybind11Extension +from pybind11.setup_helpers import build_ext, Pybind11Extension, ParallelCompile from setuptools import find_packages, setup @@ -192,6 +192,9 @@ ) INCLUDE_DIRS.append(selected_range_v3_include_dirs[0]) + +ParallelCompile("NPY_NUM_BUILD_JOBS", default=0).install() + setup( name="beanmachine", version=version, @@ -230,8 +233,7 @@ Pybind11Extension( name="beanmachine.graph", sources=sorted( - set(glob("src/beanmachine/graph/**/*.cpp", recursive=True)) - - set(glob("src/beanmachine/graph/**/*_test.cpp", recursive=True)) + glob("src/beanmachine/graph/**/*.cpp", recursive=True) ), include_dirs=INCLUDE_DIRS, extra_compile_args=CPP_COMPILE_ARGS, From 366c0437f1755b887e8f8bf50972997e350c0568 Mon Sep 17 00:00:00 2001 From: ntfrgl Date: Tue, 28 Feb 2023 11:26:44 -0800 Subject: [PATCH 07/13] Add CMake build: BMG - Pybind + GTest --- CMakeLists.txt | 37 +++++++++++++++++++++++++++++++++++++ src/CMakeLists.txt | 18 ++++++++++++++++++ tests/CMakeLists.txt | 20 ++++++++++++++++++++ 3 files changed, 75 insertions(+) create mode 100644 CMakeLists.txt create mode 100644 src/CMakeLists.txt create mode 100644 tests/CMakeLists.txt diff --git a/CMakeLists.txt b/CMakeLists.txt new file mode 100644 index 0000000000..3b553bbc0d --- /dev/null +++ b/CMakeLists.txt @@ -0,0 +1,37 @@ +# Copyright (c) Meta Platforms, Inc. and affiliates. +# +# This source code is licensed under the MIT license found in the +# LICENSE file in the root directory of this source tree. + + +# NOTE +# ------------------------------------------------------------------------------ +# The primary purpose of this CMake build configuration is C++ testing. In +# particular, it provides an entry point to the GoogleTest suite for Bean +# Machine Graph (BMG), a C++ backend for Bean Machine (BM); see +# `.github/workflows/test.yml` for its usage. +# +# This build configuration is not relevant to end users, as the BMG library is +# already compiled and linked as a Pybind11Extension when installing the BM +# Python package. + +# Config +# ------------------------------------------------------------------------------ +cmake_minimum_required(VERSION 3.20) +project(beanmachine-graph LANGUAGES CXX VERSION 0.2.0) + +set(CMAKE_CXX_STANDARD 20) +set(CMAKE_CXX_STANDARD_REQUIRED ON) +set(CMAKE_INCLUDE_CURRENT_DIR ON) + +# Dependencies +# ------------------------------------------------------------------------------ +find_package(Boost REQUIRED COMPONENTS iostreams timer CONFIG) +find_package(Eigen3 REQUIRED CONFIG) +find_package(range-v3 REQUIRED CONFIG) +find_package(GTest REQUIRED CONFIG) + +# Targets +# ------------------------------------------------------------------------------ +add_subdirectory(src) +add_subdirectory(tests) diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt new file mode 100644 index 0000000000..ec0d4cb3a9 --- /dev/null +++ b/src/CMakeLists.txt @@ -0,0 +1,18 @@ +# Copyright (c) Meta Platforms, Inc. and affiliates. +# +# This source code is licensed under the MIT license found in the +# LICENSE file in the root directory of this source tree. + + +# Paths +# ------------------------------------------------------------------------------ +file(GLOB_RECURSE bmg_src beanmachine/graph/*.cpp) +list(FILTER bmg_src EXCLUDE REGEX ".*pybindings\.cpp$") + +# Targets +# ------------------------------------------------------------------------------ +add_library(bmg "") +target_compile_options(bmg PRIVATE -O2 -Werror) +target_link_libraries(bmg PUBLIC ${BOOST_LIBRARY} ${EIGEN3_LIBRARY} range-v3) +target_include_directories(bmg PUBLIC . ${CMAKE_PREFIX_PATH}/include/eigen3) +target_sources(bmg PRIVATE ${bmg_src}) diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt new file mode 100644 index 0000000000..7fb0897fbe --- /dev/null +++ b/tests/CMakeLists.txt @@ -0,0 +1,20 @@ +# Copyright (c) Meta Platforms, Inc. and affiliates. +# +# This source code is licensed under the MIT license found in the +# LICENSE file in the root directory of this source tree. + + +# Paths +# ------------------------------------------------------------------------------ +file(GLOB_RECURSE bmg_test_src graph/*_test.cpp) + +# Targets +# ------------------------------------------------------------------------------ +add_executable(bmg_test "") +target_compile_options(bmg_test PRIVATE -O2 -Werror) +target_link_libraries(bmg_test PRIVATE bmg GTest::gtest_main) +target_sources(bmg_test PRIVATE ${bmg_test_src}) + +enable_testing() +include(GoogleTest) +gtest_discover_tests(bmg_test) From 5718e7e6d562d6a2fe5995b73461ded37eec793a Mon Sep 17 00:00:00 2001 From: ntfrgl Date: Sat, 4 Mar 2023 23:14:37 -0800 Subject: [PATCH 08/13] Skip segfaulting tests: `marginalized_graph_test` Related: 05787af --- tests/graph/marginalization/marginalized_graph_test.cpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/tests/graph/marginalization/marginalized_graph_test.cpp b/tests/graph/marginalization/marginalized_graph_test.cpp index 903c97d5e3..ab22de3ab0 100644 --- a/tests/graph/marginalization/marginalized_graph_test.cpp +++ b/tests/graph/marginalization/marginalized_graph_test.cpp @@ -17,7 +17,7 @@ using namespace beanmachine; using namespace graph; -TEST(testmarginal, only_discrete) { +TEST(testmarginal, DISABLED_only_discrete) { /* Original graph digraph G { @@ -345,7 +345,7 @@ TEST(testmarginals, DISABLED_parent_and_children) { EXPECT_EQ(normal_2_node->out_nodes[0], n2_node); } -TEST(testmarginal, parent_and_long_child) { +TEST(testmarginal, DISABLED_parent_and_long_child) { /* Original graph: digraph G { @@ -464,7 +464,7 @@ TEST(testmarginal, parent_and_long_child) { EXPECT_EQ(n_node->in_nodes[0], normal_node); } -TEST(testmarginal, upstream_from_parents) { +TEST(testmarginal, DISABLED_upstream_from_parents) { /* Original graph: digraph G { From fe6522e3a2554945fa0d0b187348744ba5f8d76a Mon Sep 17 00:00:00 2001 From: ntfrgl Date: Mon, 27 Feb 2023 13:12:21 -0800 Subject: [PATCH 09/13] GH Actions: Extend `vcpkg` fix (68d322e0f) --- .github/workflows/deploy.yml | 9 ++++++--- .github/workflows/docs.yml | 2 +- .github/workflows/lint.yml | 2 +- .github/workflows/nightly.yml.disabled | 4 +++- .github/workflows/test.yml | 4 ++-- README.md | 1 + 6 files changed, 14 insertions(+), 8 deletions(-) diff --git a/.github/workflows/deploy.yml b/.github/workflows/deploy.yml index c72bb391fb..5f7e36ac30 100644 --- a/.github/workflows/deploy.yml +++ b/.github/workflows/deploy.yml @@ -53,7 +53,7 @@ jobs: run: | git clone https://github.com/Microsoft/vcpkg.git cd vcpkg - bootstrap-vcpkg.bat + bootstrap-vcpkg.bat -disableMetrics vcpkg integrate install vcpkg install range-v3 @@ -62,7 +62,9 @@ jobs: run: | git clone https://github.com/Microsoft/vcpkg.git cd vcpkg - ./bootstrap-vcpkg.sh + ./bootstrap-vcpkg.sh -disableMetrics + # Ensure the .vcpkg directory exists, otherwise the next command will fail + mkdir -p ~/.vcpkg ./vcpkg integrate install ./vcpkg install range-v3 sudo mv ./packages/range-v3_x64-linux/include /usr/include/range-v3 @@ -128,7 +130,8 @@ jobs: yum install -y curl zip unzip tar wget boost169-devel && git clone https://github.com/Microsoft/vcpkg.git && cd vcpkg && - ./bootstrap-vcpkg.sh && + ./bootstrap-vcpkg.sh -disableMetrics && + mkdir -p ~/.vcpkg && ./vcpkg integrate install && ./vcpkg install range-v3 && wget https://gitlab.com/libeigen/eigen/-/archive/3.4.0/eigen-3.4.0.tar.gz && diff --git a/.github/workflows/docs.yml b/.github/workflows/docs.yml index 64e4bbfb88..dd8f5f8300 100644 --- a/.github/workflows/docs.yml +++ b/.github/workflows/docs.yml @@ -28,7 +28,7 @@ jobs: run: | git clone https://github.com/Microsoft/vcpkg.git cd vcpkg - ./bootstrap-vcpkg.sh + ./bootstrap-vcpkg.sh -disableMetrics # Ensure the .vcpkg directory exists, otherwise the next command will fail mkdir -p ~/.vcpkg ./vcpkg integrate install diff --git a/.github/workflows/lint.yml b/.github/workflows/lint.yml index 8bbe185f7f..6c8dbd9755 100644 --- a/.github/workflows/lint.yml +++ b/.github/workflows/lint.yml @@ -30,7 +30,7 @@ jobs: run: | git clone https://github.com/Microsoft/vcpkg.git cd vcpkg - ./bootstrap-vcpkg.sh + ./bootstrap-vcpkg.sh -disableMetrics # Ensure the .vcpkg directory exists, otherwise the next command will fail mkdir -p ~/.vcpkg ./vcpkg integrate install diff --git a/.github/workflows/nightly.yml.disabled b/.github/workflows/nightly.yml.disabled index 827bc1f3e8..214e8bd604 100644 --- a/.github/workflows/nightly.yml.disabled +++ b/.github/workflows/nightly.yml.disabled @@ -36,7 +36,9 @@ jobs: run: | git clone https://github.com/Microsoft/vcpkg.git cd vcpkg - ./bootstrap-vcpkg.sh + ./bootstrap-vcpkg.sh -disableMetrics + # Ensure the .vcpkg directory exists, otherwise the next command will fail + mkdir -p ~/.vcpkg ./vcpkg integrate install ./vcpkg install range-v3 diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 7d805d767e..88410eba41 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -34,7 +34,7 @@ jobs: run: | git clone https://github.com/Microsoft/vcpkg.git cd vcpkg - bootstrap-vcpkg.bat + bootstrap-vcpkg.bat -disableMetrics vcpkg integrate install vcpkg install range-v3 - name: Install Unix range-v3 dependency @@ -42,7 +42,7 @@ jobs: run: | git clone https://github.com/Microsoft/vcpkg.git cd vcpkg - ./bootstrap-vcpkg.sh + ./bootstrap-vcpkg.sh -disableMetrics # Ensure the .vcpkg directory exists, otherwise the next command will fail mkdir -p ~/.vcpkg ./vcpkg integrate install diff --git a/README.md b/README.md index a53d0128e5..3a11820709 100644 --- a/README.md +++ b/README.md @@ -61,6 +61,7 @@ including through [`vcpkg`](https://github.com/Microsoft/vcpkg): git clone https://github.com/Microsoft/vcpkg.git cd vcpkg ./bootstrap-vcpkg.sh +mkdir -p ~/.vcpkg ./vcpkg integrate install ./vcpkg install range-v3 ``` From 105403b56ee75d73c1b23148ae9bbb228130dfdf Mon Sep 17 00:00:00 2001 From: ntfrgl Date: Mon, 27 Feb 2023 13:20:00 -0800 Subject: [PATCH 10/13] GH Actions: Update Python versions - multi-version Actions: add latest release - single-version Actions: move to oldest actively developed release --- .github/workflows/deploy.yml | 4 ++-- .github/workflows/docs.yml | 2 +- .github/workflows/lint.yml | 2 +- .github/workflows/nightly.yml.disabled | 2 +- .github/workflows/test.yml | 2 +- README.md | 2 +- 6 files changed, 7 insertions(+), 7 deletions(-) diff --git a/.github/workflows/deploy.yml b/.github/workflows/deploy.yml index 5f7e36ac30..2e231077bd 100644 --- a/.github/workflows/deploy.yml +++ b/.github/workflows/deploy.yml @@ -27,9 +27,9 @@ jobs: fail-fast: false matrix: os: [windows-latest] - python-version: ['3.7', '3.8', '3.9', '3.10'] + python-version: ['3.7', '3.8', '3.9', '3.10', '3.11'] include: - - python-version: '3.8' # source distribution only needs to be build once + - python-version: '3.10' # source distribution only needs to be built once os: ubuntu-latest defaults: run: diff --git a/.github/workflows/docs.yml b/.github/workflows/docs.yml index dd8f5f8300..501a3b7ddd 100644 --- a/.github/workflows/docs.yml +++ b/.github/workflows/docs.yml @@ -9,7 +9,7 @@ jobs: runs-on: ubuntu-latest strategy: matrix: - python-version: [3.7] + python-version: [3.10] defaults: run: # https://github.com/conda-incubator/setup-miniconda/tree/v2#use-a-default-shell diff --git a/.github/workflows/lint.yml b/.github/workflows/lint.yml index 6c8dbd9755..f7555f62fa 100644 --- a/.github/workflows/lint.yml +++ b/.github/workflows/lint.yml @@ -10,7 +10,7 @@ jobs: strategy: fail-fast: false matrix: - python-version: [3.7] + python-version: [3.10] defaults: run: # https://github.com/conda-incubator/setup-miniconda/tree/v2#use-a-default-shell diff --git a/.github/workflows/nightly.yml.disabled b/.github/workflows/nightly.yml.disabled index 214e8bd604..b2331e3871 100644 --- a/.github/workflows/nightly.yml.disabled +++ b/.github/workflows/nightly.yml.disabled @@ -13,7 +13,7 @@ jobs: runs-on: ubuntu-latest strategy: matrix: - python-version: [3.7] + python-version: [3.10] defaults: run: # https://github.com/conda-incubator/setup-miniconda/tree/v2#use-a-default-shell diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 88410eba41..6cb74c09b2 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -14,7 +14,7 @@ jobs: fail-fast: false matrix: os: ['ubuntu-latest', 'macos-latest', 'windows-latest'] - python-version: ['3.7', '3.8', '3.9', '3.10'] + python-version: ['3.7', '3.8', '3.9', '3.10', '3.11'] defaults: run: # https://github.com/conda-incubator/setup-miniconda/tree/v2#use-a-default-shell diff --git a/README.md b/README.md index 3a11820709..5ce64c1ba1 100644 --- a/README.md +++ b/README.md @@ -18,7 +18,7 @@ and [Quick Start](https://beanmachine.org/docs/overview/quick_start/) to get sta ## Installation -Bean Machine supports Python 3.7-3.10 and PyTorch 1.12. +Bean Machine supports Python 3.7-3.11 and PyTorch 1.12. ### Install the Latest Release with Pip From 16f48ab850c97ca4f80ebba9e4649b18af90448e Mon Sep 17 00:00:00 2001 From: ntfrgl Date: Tue, 28 Feb 2023 11:27:45 -0800 Subject: [PATCH 11/13] GH Actions: Add GTest suite - reuse installed dependencies: - from Conda: Boost, Eigen, GTest - from Vcpkg: range-v3 - execute GTest suite via CMake's test runner --- .github/workflows/test.yml | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 6cb74c09b2..b09efa5d49 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -7,6 +7,7 @@ on: env: PYTHONUNBUFFERED: 1 PYTEST_ADDOPTS: --color=yes + CMAKE_BUILD: build jobs: conda-install: runs-on: ${{ matrix.os }} @@ -49,7 +50,7 @@ jobs: ./vcpkg install range-v3 - name: Install other dependencies run: | - conda install -c conda-forge -y boost-cpp eigen=3.4.0 + conda install -c conda-forge -y boost-cpp eigen=3.4.0 gtest gmock python -m pip install --upgrade pip - name: Install CPU PyTorch (only for Linux) if: matrix.os == 'ubuntu-latest' @@ -60,3 +61,11 @@ jobs: run: pip list - name: Run unit tests with pytest run: pytest + - name: Compile GoogleTest suite + run: | + cmake -S . -B $CMAKE_BUILD -DCMAKE_PREFIX_PATH=$CONDA_PREFIX -DCMAKE_TOOLCHAIN_FILE=./vcpkg/scripts/buildsystems/vcpkg.cmake + cmake --build $CMAKE_BUILD -j + - name: Run unit tests with GoogleTest + run: | + cd $CMAKE_BUILD/tests + ctest From 2634a730efe118cc7184cbe5e3734c99e11b7286 Mon Sep 17 00:00:00 2001 From: ntfrgl Date: Sun, 5 Mar 2023 01:13:45 -0800 Subject: [PATCH 12/13] GH Actions: Fixup --- .github/workflows/docs.yml | 2 +- .github/workflows/lint.yml | 2 +- .github/workflows/nightly.yml.disabled | 2 +- .github/workflows/test.yml | 9 ++++++++- 4 files changed, 11 insertions(+), 4 deletions(-) diff --git a/.github/workflows/docs.yml b/.github/workflows/docs.yml index 501a3b7ddd..e547c86d77 100644 --- a/.github/workflows/docs.yml +++ b/.github/workflows/docs.yml @@ -9,7 +9,7 @@ jobs: runs-on: ubuntu-latest strategy: matrix: - python-version: [3.10] + python-version: '3.10' defaults: run: # https://github.com/conda-incubator/setup-miniconda/tree/v2#use-a-default-shell diff --git a/.github/workflows/lint.yml b/.github/workflows/lint.yml index f7555f62fa..6885337868 100644 --- a/.github/workflows/lint.yml +++ b/.github/workflows/lint.yml @@ -10,7 +10,7 @@ jobs: strategy: fail-fast: false matrix: - python-version: [3.10] + python-version: '3.10' defaults: run: # https://github.com/conda-incubator/setup-miniconda/tree/v2#use-a-default-shell diff --git a/.github/workflows/nightly.yml.disabled b/.github/workflows/nightly.yml.disabled index b2331e3871..bb08a8680e 100644 --- a/.github/workflows/nightly.yml.disabled +++ b/.github/workflows/nightly.yml.disabled @@ -13,7 +13,7 @@ jobs: runs-on: ubuntu-latest strategy: matrix: - python-version: [3.10] + python-version: '3.10' defaults: run: # https://github.com/conda-incubator/setup-miniconda/tree/v2#use-a-default-shell diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index b09efa5d49..e8a3d6256f 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -48,6 +48,11 @@ jobs: mkdir -p ~/.vcpkg ./vcpkg integrate install ./vcpkg install range-v3 + - name: Print out Conda info + run: | + echo $CONDA_PREFIX + conda info + conda config --show - name: Install other dependencies run: | conda install -c conda-forge -y boost-cpp eigen=3.4.0 gtest gmock @@ -58,7 +63,9 @@ jobs: - name: Install Bean Machine in editable mode run: pip install -v -e .[dev] - name: Print out package info to help with debug - run: pip list + run: | + conda list + pip list - name: Run unit tests with pytest run: pytest - name: Compile GoogleTest suite From a2f285ee62a4f8a42a4da277c2f53fa68fd71738 Mon Sep 17 00:00:00 2001 From: ntfrgl Date: Sun, 5 Mar 2023 02:28:09 -0800 Subject: [PATCH 13/13] GH Actions: Fixup --- .github/workflows/docs.yml | 2 +- .github/workflows/lint.yml | 2 +- .github/workflows/nightly.yml.disabled | 2 +- .github/workflows/test.yml | 1 + 4 files changed, 4 insertions(+), 3 deletions(-) diff --git a/.github/workflows/docs.yml b/.github/workflows/docs.yml index e547c86d77..677e9c5a5e 100644 --- a/.github/workflows/docs.yml +++ b/.github/workflows/docs.yml @@ -9,7 +9,7 @@ jobs: runs-on: ubuntu-latest strategy: matrix: - python-version: '3.10' + python-version: ['3.10'] defaults: run: # https://github.com/conda-incubator/setup-miniconda/tree/v2#use-a-default-shell diff --git a/.github/workflows/lint.yml b/.github/workflows/lint.yml index 6885337868..22c85044e4 100644 --- a/.github/workflows/lint.yml +++ b/.github/workflows/lint.yml @@ -10,7 +10,7 @@ jobs: strategy: fail-fast: false matrix: - python-version: '3.10' + python-version: ['3.10'] defaults: run: # https://github.com/conda-incubator/setup-miniconda/tree/v2#use-a-default-shell diff --git a/.github/workflows/nightly.yml.disabled b/.github/workflows/nightly.yml.disabled index bb08a8680e..f8c7f093af 100644 --- a/.github/workflows/nightly.yml.disabled +++ b/.github/workflows/nightly.yml.disabled @@ -13,7 +13,7 @@ jobs: runs-on: ubuntu-latest strategy: matrix: - python-version: '3.10' + python-version: ['3.10'] defaults: run: # https://github.com/conda-incubator/setup-miniconda/tree/v2#use-a-default-shell diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index e8a3d6256f..4118204e73 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -65,6 +65,7 @@ jobs: - name: Print out package info to help with debug run: | conda list + echo pip list - name: Run unit tests with pytest run: pytest