Skip to content

Issues regarding plugging in own Python model (BMI connection & debugging mode) #571

@RY4GIT

Description

@RY4GIT

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

  1. 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.
  1. 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

  1. Ngen adapts to the latest bmi_python (especially Bmi_Py_Adapter)
  2. When the debugging flag is enabled in NGen, Python warning or error statements get printed in the terminal output

Steps to replicate behavior

  1. Git clone the Python model of interest
    git clone https://github.com/NWC-CUAHSI-Summer-Institute/cfe_py/tree/add-bmi2
  2. Build python environment using cfe_py/environment.yml
    conda env create -f environment.yml
  3. Activate the venv conda activate cfe
  4. 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
  5. 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
  1. Inside the cfe_py directory, install the Python model of interest
    pip install -e .
  2. 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
  3. 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
  1. 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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions