Skip to content

Commit

Permalink
Merge branch 'main' of https://github.com/USEPA/pybeepop
Browse files Browse the repository at this point in the history
  • Loading branch information
JeffreyMinucci committed Sep 27, 2024
2 parents b06578c + dc508fa commit d72b831
Show file tree
Hide file tree
Showing 16 changed files with 183 additions and 83 deletions.
65 changes: 0 additions & 65 deletions .github/workflows/build-and-publish.yml

This file was deleted.

3 changes: 2 additions & 1 deletion .github/workflows/build-beepop.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ jobs:
uses: actions/checkout@v4
with:
repository: quanted/vpoplib
ref: dev
- name: Build BeePop+
run: |
mkdir build
Expand All @@ -25,4 +26,4 @@ jobs:
name: compiled-${{ matrix.os }}
path: |
build/*.so
build/Release/*.dll
build/Release/*.dll
109 changes: 109 additions & 0 deletions .github/workflows/ci-build-publish.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,109 @@
name: CI-Build-Publish

on:
push:
branches:
- main
paths:
- pybeepop/**
- .github/workflows/ci-build-publish.yml
- pyproject.toml
- build.py
# tags:
# - '*.*.*'
pull_request:
release:
workflow_dispatch:

jobs:
build_wheels:
name: Build wheels on ${{ matrix.os }}
runs-on: ${{ matrix.os }}
strategy:
matrix:
os: [ubuntu-latest, windows-latest]

steps:
- uses: actions/checkout@v4

- name: Checkout BeePop+ code
uses: actions/checkout@v4
with:
repository: quanted/vpoplib
ref: dev
path: beepop

- name: Build wheels
uses: pypa/[email protected]
env:
CIBW_ARCHS: auto64
CIBW_BUILD_VERBOSITY: 1
CIBW_PROJECT_REQUIRES_PYTHON: ">=3.8"
with:
config-file: "pyproject.toml"

- uses: actions/upload-artifact@v4
with:
name: cibw-wheels-${{ matrix.os }}-${{ strategy.job-index }}
path: ./wheelhouse/*.whl

build_sdist:
name: Build source distribution
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4

- name: Build sdist
run: pipx run poetry build --format=sdist

- uses: actions/upload-artifact@v4
with:
name: cibw-sdist
path: dist/*.tar.gz

upload_testpypi:
needs: [build_wheels, build_sdist]
runs-on: ubuntu-latest
environment:
name: testpypi
url: https://test.pypi.org/p/pybeepop-plus
permissions:
id-token: write
# if: github.event_name == 'release' && github.event.action == 'created'
# or, alternatively, upload to PyPI on every tag starting with 'v' (remove on: release above to use this)
# if: github.event_name == 'push' && startsWith(github.ref, 'refs/tags/v')
steps:
- uses: actions/download-artifact@v4
with:
# unpacks all CIBW artifacts into dist/
pattern: cibw-*
path: dist
merge-multiple: true

- uses: pypa/gh-action-pypi-publish@release/v1
with:
repository-url: https://test.pypi.org/legacy/
skip-existing: true

upload_pypi:
needs: [build_wheels, build_sdist]
runs-on: ubuntu-latest
environment:
name: pypi
url: https://pypi.org/p/pybeepop-plus
permissions:
id-token: write
if: github.event_name == 'release' && github.event.action == 'published'
# or, alternatively, upload to PyPI on every tag starting with 'v' (remove on: release above to use this)
# if: github.event_name == 'push' && startsWith(github.ref, 'refs/tags/v')
steps:
- uses: actions/download-artifact@v4
with:
# unpacks all CIBW artifacts into dist/
pattern: cibw-*
path: dist
merge-multiple: true

- uses: pypa/gh-action-pypi-publish@release/v1
with:
skip-existing: true
5 changes: 3 additions & 2 deletions .github/workflows/run-tests-ubuntu.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
name: Run PyTests on Ubuntu

on: [push, pull_request]
#on: [push, pull_request]
on: workflow_dispatch

jobs:
build:
Expand All @@ -11,7 +12,7 @@ jobs:
python-version: ["3.x"]

steps:
- uses: actions/checkout@v3
- uses: actions/checkout@v4
- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v4
with:
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ for Linux are [below](#compiling-beepop-on-linux). Source code is available on [

1. **Install the package** into your Python environment using pip:

pip install git+https://github.com/usepa/pybeepop.git
pip install pybeepop-plus
2. **Import the PyBeePop class** in your python code, e.g.:

Expand Down
2 changes: 2 additions & 0 deletions build.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
def build(setup_kwargs):
print("Placehold build code!")
2 changes: 1 addition & 1 deletion paper/paper.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ bibliography: paper.bib

Honey bees (*Apis mellifera* L.) provide critical pollination services
for both natural and agricultural systems, with $50 billion USD of crops
completely dependent on pollination in the United Statates alone [@reilly:2020]. However, honey bees are facing a wide
completely dependent on pollination in the United States alone [@reilly:2020]. However, honey bees are facing a wide
range of stressors resulting in elevated colony failure rates including
climate change [@zapata:2024], pathogens [@evans:2011], habitat loss and
decreased food availability [@donkersley:2014; @goulson:2015], and exposure to
Expand Down
Binary file added pybeepop/lib/beepop_linux.so
Binary file not shown.
Binary file removed pybeepop/lib/beepop_rhel8.so
Binary file not shown.
Binary file removed pybeepop/lib/beepop_ubuntu.so
Binary file not shown.
Binary file modified pybeepop/lib/beepop_win64.dll
Binary file not shown.
10 changes: 6 additions & 4 deletions pybeepop/pybeepop.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,17 +46,18 @@ def __init__(
if self.platform == "Windows":
if platform.architecture()[0] == "32bit":
raise NotImplementedError(
"Windows x86 (32 bit) is not supported by BeePop+. Please run on an x64 platform."
"Windows x86 (32-bit) is not supported by BeePop+. Please run on an x64 platform."
)
else:
lib_file = os.path.join(self.parent, "lib/beepop_win64.dll")
elif self.platform == "Linux":
lib_file = os.path.join(self.parent, "lib/beepop_ubuntu.so") # try ubuntu
lib_file = os.path.join(self.parent, "lib/beepop_linux.so")
if self.verbose:
print(
"""
Running in Linux mode. Trying Ubuntu pre-compiled BeePop+.
You may need to compile your own version of BeePop+ from source and pass the path to your .so file with the lib_file option.
Running in Linux mode. Trying manylinux/musllinux version.
If you encounter errors, you may need to compile your own version of BeePop+ from source and pass the path to your
.so file with the lib_file option. Currently, only 64-bit architecture is supported.
See the pybeepop README for instructions.
"""
)
Expand All @@ -67,6 +68,7 @@ def __init__(
"""
BeePop+ shared object library does not exist or is not compatible with your operating system.
You may need to compile BeePop+ from source (see https://github.com/USEPA/pybeepop/blob/main/README.md for more info.)
Currently, only 64-bit architecture is supported.
"""
)
self.lib_file = lib_file
Expand Down
2 changes: 1 addition & 1 deletion pybeepop/tools.py
Original file line number Diff line number Diff line change
Expand Up @@ -237,7 +237,7 @@ def run_beepop(self):
self.lib.ClearResultsBuffer()
out_lines = []
for j in range(0, n_result_lines - 1):
out_lines.append(p_Results[j].decode("utf-8", errors="replace"))
out_lines.append(p_Results[j].decode("utf-8", errors="strict"))
out_str = io.StringIO("\n".join(out_lines))
out_df = pd.read_csv(
out_str, sep="\\s+", skiprows=3, names=colnames, dtype={"Date": str}
Expand Down
4 changes: 3 additions & 1 deletion pybeepop_example.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,9 @@
"id": "668d00a5",
"metadata": {},
"source": [
"### Set parameters, load example weather, parameter, and pesticide residue files"
"### Set parameters, load example weather, parameter, and pesticide residue files\n",
"\n",
"Example files are available on the project [GitHub page](https://github.com/USEPA/pybeepop/tree/main/example_data)."
]
},
{
Expand Down
50 changes: 47 additions & 3 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
[tool.poetry]
name = "pybeepop-plus"
version = "0.1.0"
version = "0.1.1"
description = "EPA's Python wrapper for the EPA/USDA honey bee colony model BeePop+"
authors = ["Jeffrey Minucci <[email protected]>"]
maintainers = ["Jeffrey Minucci <[email protected]>"]
license = "MIT"
readme = "README.md"
repository = "https://github.com/USEPA/pybeepop"
documentation = "https://usepa.github.io/pybeepop/"
packages = [
{ include = "pybeepop", from ="." },
Expand All @@ -13,12 +16,53 @@ classifiers = [
"Operating System :: Microsoft :: Windows",
"Operating System :: POSIX :: Linux",
"Programming Language :: Python",
"Intended Audience :: Science/Research",
]

[tool.poetry.dependencies]
python = "^3.9.0"
python = "^3.8.0"
pandas = "^2.0.0"

[build-system]
requires = ["poetry-core"]
requires = ["poetry-core", "setuptools"]
build-backend = "poetry.core.masonry.api"

[tool.poetry.build]
script = "build.py"
generate-setup-file = true

[tool.cibuildwheel.linux]
before-all = ["yum -y install cmake",
"cd beepop",
"mkdir build",
"cd build",
"cmake -DCMAKE_POSITION_INDEPENDENT_CODE=ON ..",
"cmake --build . --config Release",
"pwd",
"cp liblibvpop.so ../../pybeepop/lib",
"mv -f ../../pybeepop/lib/liblibvpop.so ../../pybeepop/lib/beepop_linux.so",
]

[tool.cibuildwheel.windows]
before-all = [
"cd beepop",
"mkdir build",
"cd build",
"cmake -DCMAKE_POSITION_INDEPENDENT_CODE=ON ..",
"cmake --build . --config Release",
"copy Release\\libvpop.dll ..\\..\\pybeepop\\lib",
"move /y ..\\..\\pybeepop\\lib\\libvpop.dll ..\\..\\pybeepop\\lib\\beepop_win64.dll",
]

[[tool.cibuildwheel.overrides]]
select = "*-musllinux*"
before-all = ["apk add cmake",
"cd beepop",
"mkdir build",
"cd build",
"cmake -DCMAKE_POSITION_INDEPENDENT_CODE=ON ..",
"cmake --build . --config Release",
"pwd",
"cp liblibvpop.so ../../pybeepop/lib",
"mv -f ../../pybeepop/lib/liblibvpop.so ../../pybeepop/lib/beepop_linux.so",
]
12 changes: 8 additions & 4 deletions tests/test_pybeepop.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@


def test_set_parameters():
beepop = PyBeePop()
beepop = PyBeePop(verbose=True)
print(beepop.lib_file)
test_parameters = {"ICWorkerAdults": 9999, "SimStart": "01/01/2020", "SimEnd": "10/31/2020"}
beepop.set_parameters(test_parameters)
params = beepop.get_parameters()
Expand Down Expand Up @@ -42,7 +43,8 @@ def test_invalid_parameter_in_file():


def test_run_model():
beepop = PyBeePop()
beepop = PyBeePop(verbose=True)
print(beepop.lib_file)

# Define inputs and file paths
START_DATE = "06/16/2014"
Expand All @@ -68,6 +70,8 @@ def test_run_model():

# run model
results = beepop.run_model()
print(results)
print(len(results))
results_initial = results.iloc[0, :]
results_last = results.iloc[len(results) - 1, :]
results_exposure = results.iloc[20, :]
Expand All @@ -78,9 +82,9 @@ def test_run_model():
assert results_initial["Capped Worker Brood"] == 8000
assert results_exposure["Colony Size"] == 17913
assert results_exposure["Capped Drone Brood"] == 219
assert results_exposure["Daylight hours"] == 13.7
assert round(results_exposure["Daylight hours"],1) == 13.7
assert results_exposure["Dead Foragers"] == 155
assert results_last["Date"] == "10/9/2014"
assert results_last["Date"] == "10/09/2014"
assert results_last["Colony Size"] == 43932
assert results_last["Adult Drones"] == 512
assert results_last["Average Temperature (C)"] == 16.66
Expand Down

0 comments on commit d72b831

Please sign in to comment.