You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
The example below works with numpy and cupy, but seems to crash with cunumeric.
Observed behavior
The code crashes. See below for a stack trace.
Example code or instructions
importcunumericasnpdefgenerate_gauss_2d(p, xi, yi):
arg=-(np.square(xi-p[1]) +np.square(yi-p[2])) / (2*p[3] *p[3])
y=p[0] *np.exp(arg) +p[4]
returnyif__name__=='__main__':
# number of fits and fit pointsnumber_fits=10000size_x=12number_points=size_x*size_xnumber_parameters=5# set input arguments# true parameterstrue_parameters=np.array((10, 5.5, 5.5, 3, 10), dtype=np.float32)
# initialize random number generatornp.random.seed(0)
# initial parameters (relative randomized, positions relative to width)initial_parameters=np.tile(true_parameters, (number_fits, 1))
initial_parameters[:, (1, 2)] +=true_parameters[3] * (-0.2+0.4*np.random.rand(number_fits, 2))
initial_parameters[:, (0, 3, 4)] *=0.8+0.4*np.random.rand(number_fits, 3)
# generate x and y valuesg=np.arange(size_x)
yi, xi=np.meshgrid(g, g, indexing='ij')
xi=xi.astype(np.float32)
yi=yi.astype(np.float32)
# generate datadata=generate_gauss_2d(true_parameters, xi, yi)
data=np.reshape(data, (1, number_points))
data=np.tile(data, (number_fits, 1))
# add Poisson noisedata=np.random.poisson(data)
data=data.astype(np.float32)
Stack traceback or browser console output
/sdf/group/lcls/ds/tools/conda_envs/cunumeric-mec/lib/python3.12/site-packages/legion_top.py:302: RuntimeWarning: cuNu$
eric has not implemented meshgrid and is falling back to canonical NumPy. You may notice significantly decreased perfo$
mance for this function call.
exec(code, module.__dict__, module.__dict__)
TypeError: only length-1 arrays can be converted to Python scalars
The above exception was the direct cause of the following exception:
Traceback (most recent call last):
File "/sdf/group/lcls/ds/tools/conda_envs/cunumeric-mec/lib/python3.12/site-packages/legion_top.py", line 482, in le$
ion_python_main
[0 - 7f8aa5be1000] 28.334343 {6}{python}: python exception occurred within task:
run_path(args[start], '__main__')
File "/sdf/group/lcls/ds/tools/conda_envs/cunumeric-mec/lib/python3.12/site-packages/legion_top.py", line 302, in ru$
_path
exec(code, module.__dict__, module.__dict__)
File "example.py", line 54, in <module>
data = np.random.poisson(data)
^^^^^^^^^^^^^^^^^^^^^^^
File "runtime.pyx", line 633, in legate.core._lib.runtime.runtime.track_provenance.decorator.wrapper
File "runtime.pyx", line 634, in legate.core._lib.runtime.runtime.track_provenance.decorator.wrapper
File "/sdf/group/lcls/ds/tools/conda_envs/cunumeric-mec/lib/python3.12/site-packages/cunumeric/_utils/coverage.py", $ine 111, in wrapper
return func(*args, **kwargs)
^^^^^^^^^^^^^^^^^^^^^
File "/sdf/group/lcls/ds/tools/conda_envs/cunumeric-mec/lib/python3.12/site-packages/cunumeric/random/_random.py", l$ne 956, in poisson
return get_static_generator().poisson(lam, size)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/sdf/group/lcls/ds/tools/conda_envs/cunumeric-mec/lib/python3.12/site-packages/cunumeric/random/_generator.py"$ line 278, in poisson
return self.bit_generator.poisson(lam, size)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/sdf/group/lcls/ds/tools/conda_envs/cunumeric-mec/lib/python3.12/site-packages/cunumeric/random/_bitgenerator.$y", line 187, in poisson
res._thunk.bitgenerator_poisson(
File "/sdf/group/lcls/ds/tools/conda_envs/cunumeric-mec/lib/python3.12/site-packages/cunumeric/_thunk/eager.py", lin$ 857, in bitgenerator_poisson
self.array.fill(np.random.poisson(lam))
ValueError: setting an array element with a sequence.
The text was updated successfully, but these errors were encountered:
import numpy as np
import cunumeric as cn
data = cn.ones((3,4))
cn.random.poisson(data)
The underlying issue here is that cunumeric.random.poisson (and other similar random distribution APIs) only accepts a single "lambda" parameter, whereas numpy.random.poisson also accepts arrays of parameters.
manopapad
changed the title
[BUG] TypeError: only length-1 arrays can be converted to Python scalars
[BUG] random.poisson doesn't accept arrays of lambda parameters
Aug 30, 2024
Software versions
cunumeric 24.06.00
Jupyter notebook / Jupyter Lab version
No response
Expected behavior
The example below works with numpy and cupy, but seems to crash with cunumeric.
Observed behavior
The code crashes. See below for a stack trace.
Example code or instructions
Stack traceback or browser console output
The text was updated successfully, but these errors were encountered: