auckland-cosmo / PyUltraLight

Pseudo-spectral Python code to compute ultralight dark matter dynamics.
BSD 3-Clause "New" or "Revised" License
15 stars 8 forks source link

np.pi error #9

Open margiofabiolad opened 2 years ago

margiofabiolad commented 2 years ago

Hi,

I try to use PyUltraLight for some simulations but when I run

PyUltraLight.evolve(central_mass, num_threads, length, length_units, resol, duration, duration_units, step_factor, save_number, save_options, save_path, npz, npy, hdf5, s_mass_unit, s_position_unit, s_velocity_unit, solitons, start_time).Complete

I get the error:

AttributeError Traceback (most recent call last) Input In [5], in <cell line: 1>() ----> 1 PyUltraLight.evolve(central_mass, num_threads, length, length_units, resol, duration, duration_units, step_factor, save_number, save_options, save_path, npz, npy, hdf5, s_mass_unit, s_position_unit, s_velocity_unit, solitons, start_time)

File ~/anaconda3/envs/pyultralight/PyUltraLight/PyUltraLight.py:505, in evolve(central_mass, num_threads, length, length_units, resol, duration, duration_units, step_factor, save_number, save_options, save_path, npz, npy, hdf5, s_mass_unit, s_position_unit, s_velocity_unit, solitons, start_time) 503 rfft_rho = pyfftw.builders.rfftn(rho, axes=(0, 1, 2), threads=num_threads) 504 phik = rfft_rho(rho) # not actually phik but phik is defined in next line --> 505 phik = ne.evaluate("-4*np.pi*phik/rkarray2") 506 phik[0, 0, 0] = 0 507 irfft_phi = pyfftw.builders.irfftn(phik, axes=(0, 1, 2), threads=num_threads)

File ~/anaconda3/envs/pyultralight/lib/python3.9/site-packages/numexpr/necompiler.py:809, in evaluate(ex, local_dict, global_dict, out, order, casting, **kwargs) 807 expr_key = (ex, tuple(sorted(context.items()))) 808 if expr_key not in _names_cache: --> 809 _names_cache[expr_key] = getExprNames(ex, context) 810 names, ex_uses_vml = _names_cache[expr_key] 811 arguments = getArguments(names, local_dict, global_dict)

File ~/anaconda3/envs/pyultralight/lib/python3.9/site-packages/numexpr/necompiler.py:696, in getExprNames(text, context) 695 def getExprNames(text, context): --> 696 ex = stringToExpression(text, {}, context) 697 ast = expressionToAST(ex) 698 input_order = getInputOrder(ast, None)

File ~/anaconda3/envs/pyultralight/lib/python3.9/site-packages/numexpr/necompiler.py:289, in stringToExpression(s, types, context) 287 names.update(expressions.functions) 288 # now build the expression --> 289 ex = eval(c, names) 290 if expressions.isConstant(ex): 291 ex = expressions.ConstantNode(ex, expressions.getKind(ex))

File <expr>:1, in <module>

AttributeError: 'VariableNode' object has no attribute 'pi'

Is there any way to resolve this error?

regards, Margionet

Sifyrena commented 2 years ago

Hi Margionet,

Thanks for using PyUL and reaching out.

I think the quickest fix is just to replace the mention of np.pi inside the numexpr literal with an approximate value, like 3.1415926535897

Hope this helps, Frank