Skip to content

Commit

Permalink
Add language examples
Browse files Browse the repository at this point in the history
  • Loading branch information
dhadka committed Sep 4, 2024
1 parent 36eb4ec commit 8257ad0
Show file tree
Hide file tree
Showing 5 changed files with 48 additions and 26 deletions.
28 changes: 23 additions & 5 deletions .github/workflows/examples.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,16 @@ jobs:
fail-fast: false
matrix:
example: [
"Basic/dps_example.py",
"Basic/example_decorators.py",
"Basic/example_prallelization.py",
"Basic/example.py",
"Eijgenraam/eijgenram.py"]
"Basic/example_decorators.py",
"Basic/example_parallelization.py",
"Basic/sensitivity_analysis.py",
"Basic/dps_example.py",
"Eijgenraam/eijgenraam.py",
"Languages/Python/lakeModelInPython.py",
"Languages/R/lakeModelInR.py",
#"Languages/Excel/lakeModelInExcel.py" # requires Windows
"Languages/C/lakeModelInC.py"]

steps:
- uses: actions/checkout@v4
Expand All @@ -34,8 +39,21 @@ jobs:

- name: Install dependencies
run: |
sudo apt update
suto apt install -y graphviz r-base
pip install .[test]
- name: Run example
run: |
python examples/${{ matrix.example }}
EXAMPLE="examples/${{ matrix.example }}"
EXAMPLE_DIR=$(dirname "${EXAMPLE}")
EXAMPLE_FILE=$(basename "${EXAMPLE}")
pushd "${EXAMPLE_DIR}"
if [ -f "Makefile" ]; then
make
fi
LD_LIBRARY_PATH="$(pwd):${LD_LIBRARY_PATH}"
python "${EXAMPLE_FILE}"
27 changes: 14 additions & 13 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,19 +1,20 @@
.eggs/
.ipynb_checkpoints/
.settings/
build/
dist/
examples/Languages/C/src/boost_*
Rhodium.egg-info/
.project
.pydevproject
*.pyc
*_results.csv
*.cache
*.cache.bak
*.cache.dat
*.cache.dir
.settings/
.eggs/
build/
dist/
Rhodium.egg-info/
.ipynb_checkpoints/
examples/Languages/C/src/boost_1_56_0/
examples/Basic/*_results.csv
*.dll
*.o
*.pyc
*.so
.Rhistory
.DS_Store
libtest.so
test.dll
test.o
rhodium.cache
10 changes: 6 additions & 4 deletions examples/Languages/C/Makefile
Original file line number Diff line number Diff line change
@@ -1,14 +1,16 @@
CPP = g++
SRC_DIR = src
TARGET = lake.so
CPP_FLAGS = -m64 -O3 -Wno-unused-local-typedefs -I$(SRC_DIR) -I$(SRC_DIR)/boost_1_56_0
CPP_FLAGS = -m64 -fPIC -O3 -Wno-unused-local-typedefs -I$(SRC_DIR) -I$(SRC_DIR)/boost_1_56_0

all:
if [ ! -d "$(SRC_DIR)/boost_1_56_0" ]; \
then \
wget http://sourceforge.net/projects/boost/files/boost/1.56.0/boost_1_56_0.zip; \
unzip boost_1_56_0.zip; \
cd "$(SRC_DIR)"; \
wget "http://sourceforge.net/projects/boost/files/boost/1.56.0/boost_1_56_0.zip"; \
unzip "boost_1_56_0.zip"; \
cd ..; \
fi

$(CPP) $(CPP_FLAGS) -o $(TARGET) -shared -fPIC $(SRC_DIR)/main-lake.cpp
$(CPP) $(CPP_FLAGS) -o $(TARGET) -shared $(SRC_DIR)/main-lake.cpp

6 changes: 3 additions & 3 deletions examples/Languages/C/lakeModelInC.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import sys
from rhodium import *
from rhodium.ffi import NativeModel

# Provide the DLL/SO file and the function name. The appropriate extension,
# such as .dll or .so, will be automatically added.
model = NativeModel("lake", "lake_problem")
# Provide the DLL/SO file and the function name.
model = NativeModel("lake.so" if sys.platform == "linux" else "lake.dll", "lake_problem")

# List the inputs. The order matters!
model.parameters = [Parameter("pollution_limit", type="double*"),
Expand Down
3 changes: 2 additions & 1 deletion examples/Languages/R/lakeModelInR.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@
from rhodium.rbridge import RModel

# Provide the R file and function name
model = RModel("lake.R", "lake.eval", RCMD=r"C:\Program Files\R\R-3.2.1\bin\R.exe")
# TIP: If unable to locate R, the path can be set with RCMD=r"C:\Program Files\R\R-3.2.1\bin\R.exe"
model = RModel("lake.R", "lake.eval")

# The parameter names must match the R arguments exactly
model.parameters = [Parameter("pollution_limit"),
Expand Down

0 comments on commit 8257ad0

Please sign in to comment.