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

Need to attach reboundx.Extras instance to simulation before setting params. #112

Closed AstroEloy closed 11 months ago

AstroEloy commented 11 months ago

Now when I try to use reboundx in Python I get this error (with any of the examples):

"Need to attach reboundx.Extras instance to simulation before setting params."

It does not happen in reboundx-3.9.0

dtamayo commented 11 months ago

Hi Eloy,

Apologies for the slow response. I'm not able to reproduce this issue. Usually when you get errors like this, versions/installations have got mixed up. The first thing to try is to reinstall. If you make a new virtualenv or conda environment and you pip install reboundx, do you get this same error?

AstroEloy commented 11 months ago

From a clean installation in a new environment in MacOS with pip, I got the same error.

hannorein commented 11 months ago

Everything works fine when I try this:

rein@m1air:~ # mkdir eloytest
rein@m1air:~ # cd eloytest
rein@m1air:~/eloytest # python3 -m venv venv
rein@m1air:~/eloytest # source venv/bin/activate
rein@m1air:~/eloytest # pip install reboundx                                                                        eloytest|
Collecting reboundx
  Using cached reboundx-3.10.1.tar.gz (90 kB)
  Preparing metadata (setup.py) ... done
Collecting rebound>=3.23.0
  Using cached rebound-3.28.3-cp310-cp310-macosx_11_0_arm64.whl (221 kB)
Collecting numpy
  Using cached numpy-1.26.0-cp310-cp310-macosx_11_0_arm64.whl (14.0 MB)
Using legacy 'setup.py install' for reboundx, since package 'wheel' is not installed.
Installing collected packages: rebound, numpy, reboundx
  Running setup.py install for reboundx ... done
Successfully installed numpy-1.26.0 rebound-3.28.3 reboundx-3.10.1
WARNING: You are using pip version 22.0.4; however, version 23.2.1 is available.
You should consider upgrading via the '/Users/rein/eloytest/venv/bin/python3 -m pip install --upgrade pip' command.
rein@m1air:~/eloytest # python                                                                                      eloytest|
Python 3.10.5 (v3.10.5:f377153967, Jun  6 2022, 12:36:10) [Clang 13.0.0 (clang-1300.0.29.30)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import reboundx
>>> import rebound
>>> sim = rebound.Simulation()
>>> sim.add(m=1.)
>>> sim.add(a=1.)
>>> rebx = reboundx.Extras(sim)
>>> mm = rebx.load_operator("modify_mass")
>>> rebx.add_operator(mm)
>>> sim.particles[0].params["tau_mass"] = -1000
>>> gr = rebx.load_force("gr")
>>> rebx.add_force(gr)
>>> gr.params['c'] = 1.e4 # set speed of light
>>> sim.integrate(100.)

What version of MacOS and Python do you use?

AstroEloy commented 11 months ago

I am using Python 3.11.5 on macOS Monterey

AstroEloy commented 11 months ago

Ok, I tried and the error does not happen in Python 3.9. It should be the Python version

hannorein commented 11 months ago

I've tried it with python 3.11 and still see no problems. I'm not sure why it doesn't work on your side. My only guess is that you might have (accidentally) changed something in your python 3.11 installation.

AstroEloy commented 11 months ago

It looks like... But it is strange that reboundx version 3.9 does not give me this problem. Thank you for the help!

dtamayo commented 11 months ago

I also just tried a clean install with python 3.11 and it worked fine for me. It's so tricky to debug these kind of problems! I'll close this for now, but please feel free to open a new one if you run into more problems. Thanks Hanno.