dtamayo / reboundx

A library for adding additional forces to the REBOUND N-body integration package
GNU General Public License v3.0
80 stars 60 forks source link

Error with setting gr.params in GR notebook #124

Closed wenhaoxuan closed 2 months ago

wenhaoxuan commented 4 months ago

Hi,

I'm getting an Attribute Error when following the GR notebook here: https://github.com/dtamayo/reboundx/blob/main/ipython_examples/GeneralRelativity.ipynb. The error occurs when I try to set the speed of light in the correct units. By the way, I get the same error when trying to set the tidal constants in the tides notebook.

I'm using rebound version 4.3.2 and reboundx version 4.1.0.


AttributeError Traceback (most recent call last) /var/folders/kj/l6tq3fh11zxc4hbpxhp1j3th0000gn/T/ipykernel_33784/910477082.py in 1 from reboundx import constants ----> 2 gr.params["c"] = constants.C

~/opt/anaconda3/envs/orbit/lib/python3.8/site-packages/reboundx/extras.py in params(self) 306 @property 307 def params(self): --> 308 params = Params(self) 309 return params 310

~/opt/anaconda3/envs/orbit/lib/python3.8/site-packages/reboundx/params.py in init(self, parent) 23 extrasvp = parent._sim.contents.extras 24 if not extrasvp: # .extras = None ---> 25 raise AttributeError("Need to attach reboundx.Extras instance to simulation before setting params.") 26 else: 27 self.rebx = cast(extrasvp, POINTER(Extras))

AttributeError: Need to attach reboundx.Extras instance to simulation before setting params

dtamayo commented 4 months ago

Hi Jerry,

what version of python are you using? I think there’s an issue with the installation wheels, which I’m trying to track down.

Does it work if you instead install REBOUNDx from source with

pip install reboundx —no-cache-dir

?

wenhaoxuan commented 4 months ago

Hi Dan,

Thanks for the quick reply. It still does not work if I install with pip install reboundx —no-cache-dir, I get the same error.

My python version is 3.8.11.

dtamayo commented 4 months ago

That’s odd. Are you using conda or virtualenv? If so, can you try installing in a new environment and install REBOUNDx with the command again to see if the problem persists?

wenhaoxuan commented 4 months ago

Yes I am using conda. I made a new environment, and installed with pip install reboundx --no-cache-dir. However, I still get the same error.

Should I try a different python version?

wenhaoxuan commented 4 months ago

I went ahead and tried python 3.7 and 3.9, and it does work with these. So looks like there's something odd in python 3.8.

dtamayo commented 4 months ago

Thanks, this is helpful for debugging the issue. Yes could you try

conda create -n testenv python=3.11

?

wenhaoxuan commented 4 months ago

python 3.11 also works fine.

dtamayo commented 4 months ago

Thanks this is really helpful

wenhaoxuan commented 4 months ago

no problem, thanks for helping debug this!

zyrxvo commented 2 months ago

I was also having this AttributeError: Need to attach reboundx.Extras instance to simulation before setting params issue using python 3.10. I tried various incantations of pip install flags, and I eventually got it to work. If someone else is having issues it may be related to the pip build environment and/or the specific version of rebound or reboundx that is being installed (I have not tested all combinations).

This is what eventually worked for me:

pip3.10 uninstall rebound reboundx
pip3.10 install --no-binary :all: --no-build-isolation --upgrade --no-cache-dir rebound
pip3.10 install --no-binary :all: --no-build-isolation --upgrade --no-cache-dir reboundx

I had to specify specifically which pip python version to use for my environment, but you may not need to. You also may not need all the flags. Ultimately what might be necessary is that when pip installs rebound and reboundx it may need to actually compile and build each package (not in isolated build environments). It may also help to have pip download the most recent package instead of using a cached package.

dtamayo commented 2 months ago

Thanks so much Garett. I think unfortunately all 3 flags are necessary. I think there are problems with compatibility between different wheels, which I have not been able to sort out. I think I might just remove all the wheels so things always install from source...

dtamayo commented 2 months ago

REBOUNDx 4.2.0 should help fix these issues