From b34a1cfbd0a855cbfb4487d9a77c21932bc248f3 Mon Sep 17 00:00:00 2001 From: Brian Ward Date: Thu, 5 Aug 2021 14:29:45 -0400 Subject: [PATCH 01/10] Try cacheing --- .github/workflows/main.yml | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index c24a9bee..05d88a82 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -16,6 +16,13 @@ jobs: matrix: os: [ubuntu-latest, macos-latest, windows-latest] python-version: [3.6, 3.7, 3.8, 3.9] + include: + - os: ubuntu-latest + path: ~/.cache/pip + - os: macos-latest + path: ~/Library/Caches/pip + - os: windows-latest + path: ~\AppData\Local\pip\Cache fail-fast: false env: GITHUB_PAT: ${{ secrets.GITHUB_TOKEN }} @@ -27,7 +34,12 @@ jobs: uses: actions/setup-python@v2 with: python-version: ${{ matrix.python-version }} - + - uses: actions/cache@v2 + with: + path: ${{ matrix.path }} + key: ${{ runner.os }}-pip-${{ hashFiles('**/requirements*.txt') }} + restore-keys: | + ${{ runner.os }}-pip- - name: Install dependencies (python) run: | pip install --upgrade pip wheel From e76d9cc83b2ea0fb17d3f2678c8e49343e087593 Mon Sep 17 00:00:00 2001 From: Brian Ward Date: Thu, 5 Aug 2021 15:01:50 -0400 Subject: [PATCH 02/10] Test caching cmdstan --- .github/workflows/main.yml | 18 +++++++----------- 1 file changed, 7 insertions(+), 11 deletions(-) diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index 05d88a82..e3b7aca3 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -16,13 +16,6 @@ jobs: matrix: os: [ubuntu-latest, macos-latest, windows-latest] python-version: [3.6, 3.7, 3.8, 3.9] - include: - - os: ubuntu-latest - path: ~/.cache/pip - - os: macos-latest - path: ~/Library/Caches/pip - - os: windows-latest - path: ~\AppData\Local\pip\Cache fail-fast: false env: GITHUB_PAT: ${{ secrets.GITHUB_TOKEN }} @@ -34,12 +27,15 @@ jobs: uses: actions/setup-python@v2 with: python-version: ${{ matrix.python-version }} + - name: Get Cmdstan Version + id: check-cmdstan + run: | + echo "::set-output name=version::$(curl -s 'https://api.github.com/repos/stan-dev/cmdstan/releases/latest' | python -c 'import json,sys;obj=json.load(sys.stdin);print(obj["tag_name"])')" + shell: bash - uses: actions/cache@v2 with: - path: ${{ matrix.path }} - key: ${{ runner.os }}-pip-${{ hashFiles('**/requirements*.txt') }} - restore-keys: | - ${{ runner.os }}-pip- + path: ~/.cmdstan + key: ${{ runner.os }}-cmdstan-${{ steps.check-cmdstan.outputs.version }}-${{ hashFiles('**/install_cmdstan.py') }} - name: Install dependencies (python) run: | pip install --upgrade pip wheel From 401a5b5b5bae9897623142f70a4b86f64b30f0db Mon Sep 17 00:00:00 2001 From: Brian Ward Date: Thu, 5 Aug 2021 15:29:51 -0400 Subject: [PATCH 03/10] Try run with cached builds --- .github/workflows/main.yml | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index e3b7aca3..207dec48 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -32,7 +32,8 @@ jobs: run: | echo "::set-output name=version::$(curl -s 'https://api.github.com/repos/stan-dev/cmdstan/releases/latest' | python -c 'import json,sys;obj=json.load(sys.stdin);print(obj["tag_name"])')" shell: bash - - uses: actions/cache@v2 + - name: Cache cmdstan installation + uses: actions/cache@v2 with: path: ~/.cmdstan key: ${{ runner.os }}-cmdstan-${{ steps.check-cmdstan.outputs.version }}-${{ hashFiles('**/install_cmdstan.py') }} From 02d921e42351ede6bd36e636aa69d2bab2991aa9 Mon Sep 17 00:00:00 2001 From: Brian Ward Date: Thu, 5 Aug 2021 15:49:16 -0400 Subject: [PATCH 04/10] Test cache miss --- cmdstanpy/install_cmdstan.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/cmdstanpy/install_cmdstan.py b/cmdstanpy/install_cmdstan.py index 5b84e7f3..d014114f 100644 --- a/cmdstanpy/install_cmdstan.py +++ b/cmdstanpy/install_cmdstan.py @@ -35,6 +35,8 @@ EXTENSION = '.exe' if platform.system() == 'Windows' else '' +# test cache miss + class CmdStanRetrieveError(RuntimeError): pass From 3aef4df42a7b24855afe85b8406668028f93b483 Mon Sep 17 00:00:00 2001 From: Brian Ward Date: Thu, 5 Aug 2021 15:49:54 -0400 Subject: [PATCH 05/10] Revert "Test cache miss" This reverts commit 02d921e42351ede6bd36e636aa69d2bab2991aa9. --- cmdstanpy/install_cmdstan.py | 2 -- 1 file changed, 2 deletions(-) diff --git a/cmdstanpy/install_cmdstan.py b/cmdstanpy/install_cmdstan.py index d014114f..5b84e7f3 100644 --- a/cmdstanpy/install_cmdstan.py +++ b/cmdstanpy/install_cmdstan.py @@ -35,8 +35,6 @@ EXTENSION = '.exe' if platform.system() == 'Windows' else '' -# test cache miss - class CmdStanRetrieveError(RuntimeError): pass From c410d3cc7a166a9197d812970c776c303d8895eb Mon Sep 17 00:00:00 2001 From: Brian Ward Date: Thu, 5 Aug 2021 16:40:01 -0400 Subject: [PATCH 06/10] Don't delete bernoulli.exe after build --- .github/workflows/main.yml | 3 --- scripts/clean_examples.py | 21 --------------------- test/example_script.py | 2 +- 3 files changed, 1 insertion(+), 25 deletions(-) delete mode 100644 scripts/clean_examples.py diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index 207dec48..4fddd1e1 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -70,13 +70,11 @@ jobs: if: matrix.os != 'windows-latest' run: | python -m cmdstanpy.install_cmdstan - python scripts/clean_examples.py - name: Install CmdStan (Windows) if: matrix.os == 'windows-latest' run: | python -m cmdstanpy.install_cmdstan --compiler - python scripts/clean_examples.py - name: Run tests run: | @@ -89,7 +87,6 @@ jobs: cd run_tests python -m pip install -r ../requirements-optional.txt python ../test/example_script.py - python ../scripts/clean_examples.py - name: Submit codecov run: | diff --git a/scripts/clean_examples.py b/scripts/clean_examples.py deleted file mode 100644 index 199b925c..00000000 --- a/scripts/clean_examples.py +++ /dev/null @@ -1,21 +0,0 @@ -import glob -import os - -from cmdstanpy import cmdstan_path - - -def clean_examples(): - cmdstan_examples = os.path.join(cmdstan_path(), "examples") - for root, _, files in os.walk(cmdstan_examples): - for filename in files: - _, ext = os.path.splitext(filename) - if ext.lower() in (".o", ".hpp", ".exe", "") and ( - filename != ".gitignore" - ): - filepath = os.path.join(root, filename) - os.remove(filepath) - print("Deleted {}".format(filepath)) - - -if __name__ == "__main__": - clean_examples() diff --git a/test/example_script.py b/test/example_script.py index e69181c2..cf8e1f26 100644 --- a/test/example_script.py +++ b/test/example_script.py @@ -15,7 +15,7 @@ def run_bernoulli_fit(): cmdstan_path(), 'examples', 'bernoulli', 'bernoulli.stan' ) bernoulli_model = CmdStanModel(stan_file=bernoulli_path) - bernoulli_model.compile() + bernoulli_model.compile(force=True) # specify data, fit the model bernoulli_data = {'N': 10, 'y': [0, 1, 0, 0, 0, 0, 0, 0, 0, 1]} From 1c079fab6e5a2f21d97e230293c955d96fe43a54 Mon Sep 17 00:00:00 2001 From: Brian Ward Date: Fri, 6 Aug 2021 09:49:00 -0400 Subject: [PATCH 07/10] Alternative way of getting cmdstan version --- .github/workflows/main.yml | 26 +++++++++++++++----------- 1 file changed, 15 insertions(+), 11 deletions(-) diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index 4fddd1e1..15bc015a 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -27,16 +27,7 @@ jobs: uses: actions/setup-python@v2 with: python-version: ${{ matrix.python-version }} - - name: Get Cmdstan Version - id: check-cmdstan - run: | - echo "::set-output name=version::$(curl -s 'https://api.github.com/repos/stan-dev/cmdstan/releases/latest' | python -c 'import json,sys;obj=json.load(sys.stdin);print(obj["tag_name"])')" - shell: bash - - name: Cache cmdstan installation - uses: actions/cache@v2 - with: - path: ~/.cmdstan - key: ${{ runner.os }}-cmdstan-${{ steps.check-cmdstan.outputs.version }}-${{ hashFiles('**/install_cmdstan.py') }} + - name: Install dependencies (python) run: | pip install --upgrade pip wheel @@ -61,11 +52,24 @@ jobs: if: matrix.os == 'windows-latest' run: | $whl = Get-ChildItem -Path dist -Filter *.whl | Select-Object -First 1 - pip install "$whl" + pip install "$whl" - name: Show libraries run: python -m pip freeze + - name: Get Cmdstan Version + id: check-cmdstan + # get the latest cmdstan version to use as part of the cache key + run: | + echo "::set-output name=version::$(python -c 'import requests;print(requests.get("https://api.github.com/repos/stan-dev/cmdstan/releases/latest").json()["tag_name"][1:])')" + shell: bash + + - name: Cmdstan installation cacheing + uses: actions/cache@v2 + with: + path: ~/.cmdstan + key: ${{ runner.os }}-cmdstan-${{ steps.check-cmdstan.outputs.version }}-${{ hashFiles('**/install_cmdstan.py') }} + - name: Install CmdStan (Linux, macOS) if: matrix.os != 'windows-latest' run: | From bbdc0a3774bb95c89abdcdaf18ae91e7034d61f3 Mon Sep 17 00:00:00 2001 From: Brian Ward Date: Fri, 6 Aug 2021 10:12:54 -0400 Subject: [PATCH 08/10] Formatting; should be done --- .github/workflows/main.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index 15bc015a..ba219bc3 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -57,14 +57,14 @@ jobs: - name: Show libraries run: python -m pip freeze - - name: Get Cmdstan Version + - name: Get CmdStan version id: check-cmdstan # get the latest cmdstan version to use as part of the cache key run: | echo "::set-output name=version::$(python -c 'import requests;print(requests.get("https://api.github.com/repos/stan-dev/cmdstan/releases/latest").json()["tag_name"][1:])')" shell: bash - - name: Cmdstan installation cacheing + - name: CmdStan installation cacheing uses: actions/cache@v2 with: path: ~/.cmdstan From c762c281a9f44c80a9b437f22cf0cf49d4dac21f Mon Sep 17 00:00:00 2001 From: Brian Ward Date: Fri, 6 Aug 2021 11:07:24 -0400 Subject: [PATCH 09/10] Try only one api call? --- .github/workflows/main.yml | 22 ++++++++++++++-------- 1 file changed, 14 insertions(+), 8 deletions(-) diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index ba219bc3..62b21ef7 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -9,7 +9,20 @@ on: - '**' pull_request: jobs: + get-cmdstan-version: + name: version check + runs-on: ubuntu-latest + steps: + - name: Get CmdStan version + id: check-cmdstan + # get the latest cmdstan version to use as part of the cache key + run: | + echo "::set-output name=version::$(python -c 'import requests;print(requests.get("https://api.github.com/repos/stan-dev/cmdstan/releases/latest").json()["tag_name"][1:])')" + outputs: + version: ${{ steps.check-cmdstan.outputs.version }} + cmdstanpy: + needs: get-cmdstan-version name: tests runs-on: ${{ matrix.os }} strategy: @@ -57,18 +70,11 @@ jobs: - name: Show libraries run: python -m pip freeze - - name: Get CmdStan version - id: check-cmdstan - # get the latest cmdstan version to use as part of the cache key - run: | - echo "::set-output name=version::$(python -c 'import requests;print(requests.get("https://api.github.com/repos/stan-dev/cmdstan/releases/latest").json()["tag_name"][1:])')" - shell: bash - - name: CmdStan installation cacheing uses: actions/cache@v2 with: path: ~/.cmdstan - key: ${{ runner.os }}-cmdstan-${{ steps.check-cmdstan.outputs.version }}-${{ hashFiles('**/install_cmdstan.py') }} + key: ${{ runner.os }}-cmdstan-${{ needs.get-cmdstan-version.outputs.version }}-${{ hashFiles('**/install_cmdstan.py') }} - name: Install CmdStan (Linux, macOS) if: matrix.os != 'windows-latest' From 460ffd6d83ebb305a359b6eb0f30fba0a49599b4 Mon Sep 17 00:00:00 2001 From: Brian Ward Date: Fri, 6 Aug 2021 11:57:38 -0400 Subject: [PATCH 10/10] Cleanup --- .github/workflows/main.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index 62b21ef7..8901d10b 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -10,12 +10,12 @@ on: pull_request: jobs: get-cmdstan-version: - name: version check + # get the latest cmdstan version to use as part of the cache key + name: grab version runs-on: ubuntu-latest steps: - name: Get CmdStan version id: check-cmdstan - # get the latest cmdstan version to use as part of the cache key run: | echo "::set-output name=version::$(python -c 'import requests;print(requests.get("https://api.github.com/repos/stan-dev/cmdstan/releases/latest").json()["tag_name"][1:])')" outputs: