Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Quick Start Guide - Inference run - ModuleNotFoundError: No module named 'gempyor' #214

Closed
jeffstazer opened this issue Apr 22, 2024 · 10 comments

Comments

@jeffstazer
Copy link

I have been following the Quick Start Guide and have been able to execute the Non-Inference run. But when I try the Inference run, I receive the messages and error below.

Sorry if this issue has already been posted, I did a search and didn't find anything. Unfortunately, I do not have R experience to be able to debug this further.

I appreciate any help you can offer. I am working on this as a project for Harry Hochheiser at the MIDAS Coordination Center.

Best,
Jeff Stazer

Rscript $FLEPI_PATH/flepimop/main_scripts/inference_main.R -c config_sample_2pop_inference.yml
Warning messages:
1: replacing previous import ‘foreach::when’ by ‘purrr::when’ when loading ‘flepicommon’
2: replacing previous import ‘foreach::accumulate’ by ‘purrr::accumulate’ when loading ‘flepicommon’
[1] "Starting"
[1] "Running 16 jobs in parallel"
[1] "Making cluster with 16 cores."
seir_modifiers_scenarios : Ro_all
outcome_modifiers_scenarios : test_limits
slots : 1
config : config_sample_2pop_inference.yml
run_id : 20240422_152334EDT
seir_modifiers_scenarios : all
outcome_modifiers_scenarios : all
jobs : 16
iterations_per_slot : 1
this_slot : 1
this_block : 1
stoch_traj_flag : FALSE
ground_truth_start :
ground_truth_end :
flepi_path : /Users/jbs82/Documents/dev/flepimop/flepiMoP/
python : python3
rpath : Rscript
is-resume : FALSE
is-interactive : FALSE
reset_chimeric_on_accept : TRUE
save_seir : FALSE
save_hosp : TRUE
memory_profiling : FALSE
memory_profiling_iters : 100
subpop_len : 5
help : FALSE
Error in py_module_import(module, convert = convert) :
ModuleNotFoundError: No module named 'gempyor'
Run reticulate::py_last_error() for details.
Calls: -> py_module_import
Error in unserialize(socklist[[n]]) : error reading from connection
Calls: %dopar% ... recvOneData -> recvOneData.SOCKcluster -> unserialize
Execution halted

@alsnhll
Copy link
Collaborator

alsnhll commented Apr 22, 2024

Hi Jeff, can you check that you have your paths to the directories where the code is set up correctly? You might have one too many levels of "flepimop"? This line seems to be finding your config correctly, which means you must be correctly in the project path directory. But then it's going to look for gempyor in $FLEPI_PATH/flepimop/gempyor_pkg ie $/Users/jbs82/Documents/dev/flepimop/flepiMoP/flepimop/gempyor_pkg. Is that where you have it? And did you open R and install all the required packages and make sure there were no errors?

Also (separate issue), if you are running the config config_sample_2pop_inference.yml it would be easier if you move it out of the config library into the PROJECT_PATH directory (ie right into flepimop_sample), because otherwise file paths within it might not work. I will add a note on this to the documentation - we just keep configs in that subdirectory so it's more organized but should be moved out to be run.

Thanks for trying things out and please report any other issues you encounter here - we are still very much a work in progress of making things functionally accessible to others!

@jeffstazer
Copy link
Author

Thanks for your quick reply.

correct...
$FLEPI_PATH/flepiMoP/flepimop/gempyor_pkg/ is equivalent to /Users/jbs82/Documents/dev/flepimop/flepiMoP/flepimop/gempyor_pkg/

I didn't have any issues with R installation, nor the libraries, in terms of the listed instructions. I had issues with curl, and I am working on a mac, so with arrow. But those were resolved and eventually didn't have any errors.

Yes, I did copy config_sample_2pop_inference.yml into the project_path.

I will move my FLEPIMOP_PATH in the morning and retry.

Thank you very much for your help. It is appreciated.

@jcblemai
Copy link
Collaborator

Hey Jeff,

Either gempyor is not installed, or it is installed but not in the python environment that reticulate (the R package that interfaces with python) sees:

Can you try to run python in a command line and do:

import gempyor

in the prompt that you get? you will either get an error or nothing (which means that gempyor is installed).

If you get an error, can you retry the installation step of gempyor with pip ?

If you don't get an error there, in R this time (either from Rstudio or typing R in the command line)

library(reticulate)
gempyor <- reticulate::import("gempyor")

does this snippet works? if not try adding reticulate::use_python(Sys.which('python'),require=TRUE) or for a conda environment: reticulate::use_condaenv('flepimop-env')

Let us know what error and output you encounter with these steps, and thanks for your patience as we are improving the flepiMoP installation.

@jeffstazer
Copy link
Author

Good morning. Thanks for your advice.

I could not import gempyor using python (version 3.12) which was set as my default. Changing to python3.11 libraries I was able to import gempyor. Maybe an issue with my 3.12 install?

I then created ~/.Renviron and specified: RETICULATE_PYTHON="/usr/local/bin/python3.11".
After restarting R, it was showing python as python3.11.

I ran the Inference run and it proceeded past the gempyor issue.

I then ran into the arrow issue our R person warned me about (which is a mac issue).

Error in parquet___WriterProperties___Builder__create() :
 Cannot call parquet___WriterProperties___Builder__create(). See https://arrow.apache.org/docs/r/articles/install.html for help installing Arrow C++ libraries.

After contacting her and going back and forth a bit, she had me...
install.packages("arrow", repos = c("https://apache.r-universe.dev", "https://cran.r-project.org"))
this got me past the arrow issue.

Received a whole host of Integration errors, and after those the following...

Integration error: rhs got a negative x (pos, time) (array([ 3, 10, 11]),) 213.0
Integration error: transition amounts negative (trans_idx, node) 0 0
Integration error: transition amounts negative (trans_idx, node) 0 1
Integration error: transition amounts negative (trans_idx, node) 1 1
213it [00:03, 69.53it/s]
CRITICAL:root:Integration error: negative values detected in epidemic integration result. Failing...
CRITICAL:root:Saving run configuration due to integration error
load the name space with: 
with open('integration_dump.pkl','rb') as fn_dump:
    states, states_daily_incid, ncompartments, nspatial_nodes, ndays, parameters, dt, transitions, proportion_info,  transition_sum_compartments, initial_conditions, seeding_data, seeding_amounts, mobility_data, mobility_row_indices, mobility_data_indices, population,  stochastic_p,  method = pickle.load(fn_dump)
/!\ Invalid integration, will cause problems for downstream users /!\ 
INFO:root:[SEIR.compute] completed in 3.09 s
INFO:root:[SEIR.postprocess] completed in 0.01 s
INFO:root:[onerun_delayframe_outcomes.compute] completed in 0.03 s
INFO:root:[onerun_delayframe_outcomes.postprocess] completed in 0.01 s
INFO:root:[>>> GEMPYOR onesim (loading file)] completed in 3.19 s
[1] "Current likelihood -2118.26 Proposed likelihood -2118.26"
[1] "**** GLOBAL ACCEPT (Recording) ****"
[1] "by default because it's the first iteration of a block 1"
[1] "Resetting chimeric values to global due to global acceptance"
[1] "Last accepted index is  1"
[1] "Time to run MCMC iteration 1 of slot 1  is  3.34  seconds"
[1] "Copying latest global files to final"
Error: File copy failed:FALSE seed_gf |TRUE init_gf |TRUE seir_gf |TRUE hosp_gf |TRUE llik_gf |TRUE snpi_gf |TRUE hnpi_gf |TRUE spar_gf |TRUE hpar_gf |FALSE seed_block |TRUE init_block |TRUE seir_block |TRUE hosp_block |TRUE llik_block |TRUE snpi_block |TRUE hnpi_block |TRUE spar_block |TRUE hpar_block |
/usr/local/Cellar/[email protected]/3.11.9/Frameworks/Python.framework/Versions/3.11/lib/python3.11/multiprocessing/resource_tracker.py:254: UserWarning: resource_tracker: There appear to be 1 leaked semaphore objects to clean up at shutdown
  warnings.warn('resource_tracker: There appear to be %d '
Error in unserialize(socklist[[n]]) : error reading from connection
Calls: %dopar% ... recvOneData -> recvOneData.SOCKcluster -> unserialize
Execution halted

Just got here a few minutes ago and have not looked into this at all yet.

@jcblemai
Copy link
Collaborator

That's a good call. There is an issue with this config.

  • The bounds the inference engines see for modifiers Ro_mod and Ro_lockdown (a and b) are between [-1, 1], which means that these multipliers can become negatives (so the transition with rate: ["Ro * gamma"] has a negative rate, which causes transition error.

Can you retry changing the a bound to zero? if that works, then we'll fix the config on our side. Sorry about that.
In the mean time, I opened an issue to make a clearer error message for this error: we should detect negative transition rates before the integration engine fails.

One more thing, as I see that you are building a containerized version, we are currently developing a full-python inference engine (see branch new_inference and pull request #203) which will be much easier to package (single pip line to install). That's in alpha at the moment.

@jcblemai
Copy link
Collaborator

jcblemai commented Apr 23, 2024

I just updated the config_sample_2pop_inference.yml so you should just pull flepimop_sample again to retry

@jeffstazer
Copy link
Author

I appreciate the update. Thank you.

Latest run...

INFO:root:[>>> GEMPYOR onesim (loading file)] completed in 3.50 s
[1] "Current likelihood -2248.62 Proposed likelihood -2248.62"
[1] "**** GLOBAL ACCEPT (Recording) ****"
[1] "by default because it's the first iteration of a block 1"
[1] "Resetting chimeric values to global due to global acceptance"
[1] "Last accepted index is  1"
[1] "Time to run MCMC iteration 1 of slot 1  is  3.64  seconds"
[1] "Copying latest global files to final"
Error: File copy failed:FALSE seed_gf |TRUE init_gf |TRUE seir_gf |TRUE hosp_gf |TRUE llik_gf |TRUE snpi_gf |TRUE hnpi_gf |TRUE spar_gf |TRUE hpar_gf |FALSE seed_block |TRUE init_block |TRUE seir_block |TRUE hosp_block |TRUE llik_block |TRUE snpi_block |TRUE hnpi_block |TRUE spar_block |TRUE hpar_block |
/usr/local/Cellar/[email protected]/3.11.9/Frameworks/Python.framework/Versions/3.11/lib/python3.11/multiprocessing/resource_tracker.py:254: UserWarning: resource_tracker: There appear to be 1 leaked semaphore objects to clean up at shutdown
  warnings.warn('resource_tracker: There appear to be %d '
Error in unserialize(socklist[[n]]) : error reading from connection
Calls: %dopar% ... recvOneData -> recvOneData.SOCKcluster -> unserialize
Execution halted

If you full output would be more helpful, just let me know. Or if there is any other info I can provide which could prove helpful.

Best,
Jeff

@jcblemai
Copy link
Collaborator

Sorry, I just asked and this error is not a "real" error (see issue #197). The program has finished to run and is checking for files to exist. Apparently theses check are not up to date with the new file structure so it fails even though it should not.

We will fix this asap, in the meantime you can safely discard this error and consider that inference slot has successfuly completed.

@jeffstazer
Copy link
Author

Sorry, I should have considered doing a search on that issue. My apologies.

Glad to hear it's not a concern. I very much appreciate your assistance.

Best,
Jeff

@jcblemai
Copy link
Collaborator

No really feel free to ask questions. I am closing this issue, but feel free to re-open if needed.
We will work on the remaining issues (#197 and #215).

If your usecase mandates parameter inference, we will soon propose ensemble (differential and affine avariant) mcmc sampler.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants