-
Notifications
You must be signed in to change notification settings - Fork 61
Description
Hi,
I've been struggling with this issue for a while, getting the errors like this when using gala to generate streams.
Traceback (most recent call last):
File "repro.py", line 44, in <module>
orbit1, _ = gen_pal5.run(w0,
File "/home/skoposov/pyenv_dir/pyenv310/lib/python3.10/site-packages/gala/dynamics/mockstream/mockstream_generator.py", line 247, in run
raw_nbody, raw_stream = mockstream_dop853(
File "gala/dynamics/mockstream/mockstream.pyx", line 54, in gala.dynamics.mockstream._mockstream.mockstream_dop853
File "gala/dynamics/mockstream/mockstream.pyx", line 144, in gala.dynamics.mockstream._mockstream.mockstream_dop853
File "gala/integrate/cyintegrators/dop853.pyx", line 76, in gala.integrate.cyintegrators.dop853.dop853_step
RuntimeError: Larger nmax is needed.
This error is somewhat unpredictable, sometimes happening, sometimes not.
While constructing the reproducer, I think I uncovered the underlying reason - when making the stream generator, my mass for the cluster was an array of one element, instead of being a scalar. And some bizarre reason that leads to this error (and also a slowdown)
Here's the code:
import astropy.coordinates as coord
import astropy.units as u
import numpy as np
import gala.potential as gp
from gala.units import galactic
import astropy.units as auni
import gala.dynamics as gd
from gala.dynamics import mockstream as ms
coord.galactocentric_frame_defaults.set("v4.0")
kms = u.km / u.s
pot = gp.CCompositePotential()
pot["disk"] = gp.MiyamotoNagaiPotential(
m=3.6e10 * u.Msun,
a=5.4 * u.kpc,
b=600 * u.pc,
units=galactic,
)
pot["bulge"] = gp.HernquistPotential(m=3.24e10, c=0.61 * u.kpc, units=galactic)
vxvyvz0 = [-1.87539782e02, -3.59878933e02, 1.08545075e02]
lmass, lrs, time, prog_lmass = [1.18426330e01, 2.77414236e-01, 1000, 8]
mass = 10**lmass
rs = 10**lrs
progenitor_mass = 10**prog_lmass
pot["halo"] = gp.NFWPotential(
mass * u.Msun,
r_s=rs * u.kpc,
units=galactic,
)
x0, y0, z0 = 39.54522670882826, -21.408405557971204, 67.2661672
vx0, vy0, vz0 = vxvyvz0
w0 = gd.PhaseSpacePosition(pos=np.array([x0, y0, z0]) * auni.kpc,
vel=np.array([vx0, vy0, vz0]) * kms)
progenitor_mass = np.array([progenitor_mass])
dw_mass = progenitor_mass * u.Msun
dw_pot = gp.PlummerPotential(m=dw_mass, b=50 * u.pc, units=galactic)
df = ms.ChenStreamDF()
gen_pal5 = ms.MockStreamGenerator(df, pot, progenitor_potential=dw_pot)
xorbit = pot.integrate_orbit(w0, dt=-time / 100 * auni.Myr, n_steps=100)
w0 = gd.PhaseSpacePosition(pos=xorbit.pos[-1], vel=xorbit.vel[-1])
xnsteps = 1000
orbit1, _ = gen_pal5.run(w0,
dw_mass,
dt=(time / xnsteps) * u.Myr,
n_steps=xnsteps,
n_particles=1)if remove the line where i make progenitor mass an array, the code works fine.
I don't think this is necessarily a bug per se, but I'd say this is probably unexpected behaviour.
I also haven't time to check the code, but I assume something like casting to scalar would be probably an appropriate fix.
FWIW numpy, scipy, gala versions:
2.2.4,1.15.2,1.9.1
Thanks,
S