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

I encountered an error while replicating the dismod_MR tool #36

Closed
yannie228 opened this issue Sep 22, 2022 · 13 comments
Closed

I encountered an error while replicating the dismod_MR tool #36

yannie228 opened this issue Sep 22, 2022 · 13 comments

Comments

@yannie228
Copy link

I hope to get your help. The error is as follows:
图片 1

@aflaxman
Copy link
Member

I'm sorry to hear that you are having trouble using the dismod_mr tool. I can't tell what is going wrong from this screenshot alone. Can you produce a "minimal complete verifiable example" of the issue you are having? https://stackoverflow.com/help/minimal-reproducible-example

@yannie228
Copy link
Author

Thanks for your prompt reply, maybe you can try running this ipynb file with your pd_sim_data folder?
DisMod-MR 2.1-Copy1.ipynb.zip

@aflaxman
Copy link
Member

aflaxman commented Oct 8, 2022

I had a little trouble getting the data to load (I had to change the directory to get dismod_mr.data.load('pd_sim_data') to succeed, but everything else in your notebook worked fine for me. Please try re-running everything in a fresh conda environment, following the directions on the README.md file, and see if there is perhaps something in your current python environment that is causing this issue.

@aflaxman
Copy link
Member

aflaxman commented Oct 11, 2022 via email

@fanwayne
Copy link

fanwayne commented Mar 4, 2023

Hello, I think I have the same issue when running the example code recently.

The code was copied from the page "A motivating example: descriptive epidemiological meta-regression of Parkinson's Disease".

model.vars += dismod_mr.model.asr(model, 'p')

And below error occurs when running the asr function.

`
IndexError Traceback (most recent call last)
File c:\ProgramData\miniconda3\lib\site-packages\pymc\model.py:197, in ContextMeta.get_context(cls, error_if_none)
196 try:
--> 197 candidate: Optional[T] = cls.get_contexts()[-1]
198 except IndexError as e:
199 # Calling code expects to get a TypeError if the entity
200 # is unfound, and there's too much to fix.

IndexError: list index out of range

During handling of the above exception, another exception occurred:

TypeError Traceback (most recent call last)
File c:\ProgramData\miniconda3\lib\site-packages\pymc\distributions\distribution.py:276, in Distribution.new(cls, name, rng, dims, initval, observed, total_size, transform, *args, **kwargs)
274 from pymc.model import Model
--> 276 model = Model.get_context()
277 except TypeError:

File c:\ProgramData\miniconda3\lib\site-packages\pymc\model.py:202, in ContextMeta.get_context(cls, error_if_none)
201 if error_if_none:
--> 202 raise TypeError(f"No {cls} on context stack")
203 return None

TypeError: No <class 'pymc.model.Model'> on context stack
...
283 )
285 if "testval" in kwargs:
286 initval = kwargs.pop("testval")

TypeError: No model on context stack, which is needed to instantiate distributions. Add variable inside a 'with model:' block, or use the '.dist' syntax for a standalone distribution.
`

@aflaxman
Copy link
Member

aflaxman commented Mar 4, 2023

Sorry for the challenge of getting it to work… I believe that this issue you are running into is because dismod_mr is based on an older version of pymc. Please see if uninstalling your pymc and installing an older version makes the example work for you:

pip uninstall pymc
pip install pymc==2.3.8

@aflaxman
Copy link
Member

aflaxman commented Mar 4, 2023

Note also that the best python version for this is 3.6, as pymc==2.3.8 has some issues with the most current version of python (3.11). My apologies again for the challenge of getting this to work!

@fanwayne
Copy link

fanwayne commented Mar 4, 2023

@aflaxman Many thanks for your support. It works fine in the local conda environment.

aflaxman added a commit that referenced this issue Apr 10, 2023
Also update docs to correspond; see issue #36 for details.
@xunluning
Copy link

Hello, I hope to get your help. The error is as follows:
pred=dismod_mr.model.predict_for(model,model.parameters['p'],'all',"female",2005,'GBR','female',2005,1.,model.vars['p'],0.,1.)
Traceback (most recent call last):
File "D:\Anaconda\envs\dismod_mr\lib\site-packages\networkx\classes\digraph.py", line 809, in successors
return iter(self._succ[n])
KeyError: 'GBR'
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "D:\Anaconda\envs\dismod_mr\lib\code.py", line 91, in runcode
exec(code, self.locals)
File "", line 1, in
File "D:\Anaconda\envs\dismod_mr\lib\site-packages\dismod_mr\model\covariates.py", line 389, in predict_for
leaves = [n for n in nx.traversal.bfs_tree(area_hierarchy, area) if area_hierarchy.successors(n) == []]
File "D:\Anaconda\envs\dismod_mr\lib\site-packages\networkx\algorithms\traversal\breadth_first_search.py", line 196, in bfs_tree
T.add_edges_from(edges_gen)
File "D:\Anaconda\envs\dismod_mr\lib\site-packages\networkx\classes\digraph.py", line 681, in add_edges_from
for e in ebunch_to_add:
File "D:\Anaconda\envs\dismod_mr\lib\site-packages\networkx\algorithms\traversal\breadth_first_search.py", line 145, in bfs_edges
for e in generic_bfs_edges(G, source, successors, depth_limit):
File "D:\Anaconda\envs\dismod_mr\lib\site-packages\networkx\algorithms\traversal\breadth_first_search.py", line 76, in generic_bfs_edges
queue = deque([(source, depth_limit, neighbors(source))])
File "D:\Anaconda\envs\dismod_mr\lib\site-packages\networkx\classes\digraph.py", line 811, in successors
raise NetworkXError("The node %s is not in the digraph." % (n,))
networkx.exception.NetworkXError: The node GBR is not in the digraph.

@aflaxman
Copy link
Member

I bet we are getting errors with modern versions of networkx now, too :( Can you check if your networkx version is 2.3?

@xunluning
Copy link

Thanks for your prompt reply, I have checked. Actually, the nextworkx version in my conda is 2.3.
AA

@xunluning
Copy link

Thanks. It works successfully now. Mybe there was some error when l used 'model.keep()' command.

@aflaxman
Copy link
Member

Yay! Mysterious, but I'll consider it a closed case. Please reopen if you have more trouble.

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

4 participants