We (@RY4GIT and @taddyb) attempted to integrate our own Python model into NGen using the BMI Python. However, we encountered the following issues.
Current behavior
- Bmi_Py_Adapter is having issues connecting the Python to C++ code. It throws an error message
terminate called after throwing an instance of 'std::runtime_error'
what(): (Bmi_Py_Adapter) Failed determining analogous C++ type for Python model '0' type with size 8 bytes.
- Even with the debugging flag enabled (verbose mode), Python warning or error statements are not displayed in the terminal output. When issues arise, it prints only the error message from ngen and the message
Aborted. This makes it challenging to debug
Expected behavior
- Ngen adapts to the latest bmi_python (especially Bmi_Py_Adapter)
- When the debugging flag is enabled in NGen, Python warning or error statements get printed in the terminal output
Steps to replicate behavior
- Git clone the Python model of interest
git clone https://github.com/NWC-CUAHSI-Summer-Institute/cfe_py/tree/add-bmi2
- Build python environment using cfe_py/environment.yml
conda env create -f environment.yml
- Activate the venv
conda activate cfe
- Build the ngen following this instruction. Before running the building code (
cmake -B /ngen -S . && cmake --build . --target ngen), turn on the debugging option using target_compile_options (ngen PUBLIC -g) in the root CMakeList.txt, as described here
- Run the ngen
./ngen, and it prints the following.
Build Info:
NGen version: 0.1.0
Python active
Embedded interpreter version: 3.10.12
Python Environment Info:
VIRTUAL_ENV environment variable: (not set)
Discovered venv: None
System paths:
/home/flipl/miniconda3/lib/python310.zip
/home/flipl/miniconda3/lib/python3.10
/home/flipl/miniconda3/lib/python3.10/lib-dynload
/home/flipl/.local/lib/python3.10/site-packages
/home/flipl/miniconda3/lib/python3.10/site-packages
/home/flipl/cfe_py
- Inside the
cfe_py directory, install the Python model of interest
pip install -e .
- Run the ngen in the environment inside the
cfe_py using the following command
../ngen/ngen catchment_data.geojson "cat-67" nexus_data.geojson "nex-68" bmicfe_realization.json
- The following error will be displayed, demonstrating the current behavior (1) and (2), where error message from Python is not printed as well as BMI_PY is not connecting correctly:
NGen Framework 0.1.0
Building Nexus collection
Building Catchment collection
Not Using Routing
Catchment topology is dendritic.
Running Models
Running timestep 0
terminate called after throwing an instance of 'std::runtime_error'
what(): (Bmi_Py_Adapter) Failed determining analogous C++ type for Python model '0' type with size 8 bytes.
Aborted
- If we use other simpler Python model instead of
cfe_py, we didn't get the error what(): (Bmi_Py_Adapter) Failed
Some other info
NGen Framework 0.1.0
Usage:
ngen <catchment_data_path> <catchment subset ids> <nexus_data_path> <nexus subset ids> <realization_config_path>
Arguments for <catchment subset ids> and <nexus subset ids> must be given.
Use "all" as explicit argument when no subset is needed.
Build Info:
NGen version: 0.1.0
Fortran BMI enabled
Python active
Embedded interpreter version: 3.9.16
Routing active
Python Environment Info:
VIRTUAL_ENV environment variable: /opt/conda/lib/python3.9
Discovered venv: /opt/conda/lib/python3.9
System paths:
/home/jovyan/data
/opt/src/GB-RFSM
/opt/conda/lib/python39.zip
/opt/conda/lib/python3.9
/opt/conda/lib/python3.9/lib-dynload
/opt/conda/lib/python3.9/site-packages
/opt/src/clawpack_src/clawpack-v5-9-0
We (@RY4GIT and @taddyb) attempted to integrate our own Python model into NGen using the BMI Python. However, we encountered the following issues.
Current behavior
Aborted. This makes it challenging to debugExpected behavior
Steps to replicate behavior
git clone https://github.com/NWC-CUAHSI-Summer-Institute/cfe_py/tree/add-bmi2conda env create -f environment.ymlconda activate cfecmake -B /ngen -S . && cmake --build . --target ngen), turn on the debugging option usingtarget_compile_options (ngen PUBLIC -g)in the root CMakeList.txt, as described here./ngen, and it prints the following.cfe_pydirectory, install the Python model of interestpip install -e .cfe_pyusing the following command../ngen/ngen catchment_data.geojson "cat-67" nexus_data.geojson "nex-68" bmicfe_realization.jsoncfe_py, we didn't get the errorwhat(): (Bmi_Py_Adapter) FailedSome other info