Repository navigation
Description
Describe the bug
When sampling a poisson distribution with ak.random, Arkouda fails to parse the size parameter when it is passed as a tuple[int, ...]
To Reproduce
import numpy as np
import arkouda as ak
ak.connect(...)
np_rng = np.random.default_rng()
ak_rng = ak.random.default_rng()
# Case 1 -- Works as expected
print(f"Numpy: {np_rng.poisson(lam=1, size=5)}") # Prints a ndarray w/ shape `(5,)`
print(f"Arkouda: {ak_rng.poisson(lam=1, size=5)}") # Prints a pdarray w/ shape `(5,)`
# Case 2 -- Arkouda throws when failing to convert JSON list of strings to `int(64)`
print(f"Numpy: {np_rng.poisson(lam=1, size=(5,))}") # Prints a ndarray w/ shape `(5,)`
print(f"Arkouda: {ak_rng.poisson(lam=1, size=(5,))}") # Raises a `RuntimeError` wrapping a `TypeError`
# Case 3 -- Arkouda fails for the same reason as Case 2
print(f"Numpy: {np_rng.poisson(lam=1, size=(5, 3))}") # Prints a ndarray w/ shape `(5, 3)`
print(f"Arkouda: {ak_rng.poisson(lam=1, size=(5, 3))}") # Raises similar '`RuntimeError` wrapping `TypeError`' errorExpected behavior
Case 1 works as expected, Cases 2 and 3 should produce pdarrays with shape (5,) and (5, 3) respectively.
Error Message
Case 2 Error Message: Arkouda fails to cast '["5"]' to an int(64)
---------------------------------------------------------------------------
RuntimeError Traceback (most recent call last)
Cell In[15], line 2
1 print(f"Numpy: {np_rng.poisson(lam=1, size=(5,))}")
----> 2 print(f"Arkouda: {ak_rng.poisson(lam=1, size=(5,))}")
File [/lus/bnchlu1/drozt/playground/chpl/oo/scale/arkouda/venv/lib/python3.11/site-packages/arkouda/numpy/random/_generator.py:790](http://localhost:8888/lus/bnchlu1/drozt/playground/chpl/oo/scale/arkouda/venv/lib/python3.11/site-packages/arkouda/numpy/random/_generator.py#line=789), in Generator.poisson(self, lam, size)
787 if (lam < 0).any() if isinstance(lam, pdarray) else lam < 0:
788 raise TypeError("lam must be non-negative.")
--> 790 rep_msg = generic_msg(
791 cmd="poissonGenerator",
792 args={
793 "name": self._name_dict[akdtype("float64")],
794 "lam": lam,
795 "is_single_lambda": is_single_lambda,
796 "size": size,
797 "has_seed": self._seed is not None,
798 "state": self._state,
799 },
800 )
801 # we only generate one val using the generator in the symbol table
802 self._state += 1
File [/lus/bnchlu1/drozt/playground/chpl/oo/scale/arkouda/venv/lib/python3.11/site-packages/arkouda/client.py:1012](http://localhost:8888/lus/bnchlu1/drozt/playground/chpl/oo/scale/arkouda/venv/lib/python3.11/site-packages/arkouda/client.py#line=1011), in generic_msg(cmd, args, payload, send_binary, recv_binary)
1010 else:
1011 assert payload is None
-> 1012 return cast(Channel, channel).send_string_message(
1013 cmd=cmd, args=msg_args, size=size, recv_binary=recv_binary
1014 )
1015 except KeyboardInterrupt as e:
1016 # if the user interrupts during command execution, the socket gets out
1017 # of sync reset the socket before raising the interrupt exception
1018 cast(Channel, channel).connect(timeout=0)
File [/lus/bnchlu1/drozt/playground/chpl/oo/scale/arkouda/venv/lib/python3.11/site-packages/arkouda/client.py:534](http://localhost:8888/lus/bnchlu1/drozt/playground/chpl/oo/scale/arkouda/venv/lib/python3.11/site-packages/arkouda/client.py#line=533), in ZmqChannel.send_string_message(self, cmd, recv_binary, args, size, request_id)
532 # raise errors or warnings sent back from the server
533 if return_message.msgType == MessageType.ERROR:
--> 534 raise RuntimeError(return_message.msg)
535 elif return_message.msgType == MessageType.WARNING:
536 warnings.warn(return_message.msg)
RuntimeError: Error executing command: TypeError Line 243 In Message.toScalar: Json Argument '["5"]' cannot be cast as a scalar int(64)Presumably this should be casting to a List.list(int(64)) or similar
Case 3 Error Message: Arkouda fails to cast '["5", "3"]' to an int(64)
RuntimeError Traceback (most recent call last)
Cell In[16], line 2
1 print(f"Numpy: {np_rng.poisson(lam=1, size=(5,3))}")
----> 2 print(f"Arkouda: {ak_rng.poisson(lam=1, size=(5,3))}")
File [/lus/bnchlu1/drozt/playground/chpl/oo/scale/arkouda/venv/lib/python3.11/site-packages/arkouda/numpy/random/_generator.py:790](http://localhost:8888/lus/bnchlu1/drozt/playground/chpl/oo/scale/arkouda/venv/lib/python3.11/site-packages/arkouda/numpy/random/_generator.py#line=789), in Generator.poisson(self, lam, size)
787 if (lam < 0).any() if isinstance(lam, pdarray) else lam < 0:
788 raise TypeError("lam must be non-negative.")
--> 790 rep_msg = generic_msg(
791 cmd="poissonGenerator",
792 args={
793 "name": self._name_dict[akdtype("float64")],
794 "lam": lam,
795 "is_single_lambda": is_single_lambda,
796 "size": size,
797 "has_seed": self._seed is not None,
798 "state": self._state,
799 },
800 )
801 # we only generate one val using the generator in the symbol table
802 self._state += 1
File [/lus/bnchlu1/drozt/playground/chpl/oo/scale/arkouda/venv/lib/python3.11/site-packages/arkouda/client.py:1012](http://localhost:8888/lus/bnchlu1/drozt/playground/chpl/oo/scale/arkouda/venv/lib/python3.11/site-packages/arkouda/client.py#line=1011), in generic_msg(cmd, args, payload, send_binary, recv_binary)
1010 else:
1011 assert payload is None
-> 1012 return cast(Channel, channel).send_string_message(
1013 cmd=cmd, args=msg_args, size=size, recv_binary=recv_binary
1014 )
1015 except KeyboardInterrupt as e:
1016 # if the user interrupts during command execution, the socket gets out
1017 # of sync reset the socket before raising the interrupt exception
1018 cast(Channel, channel).connect(timeout=0)
File [/lus/bnchlu1/drozt/playground/chpl/oo/scale/arkouda/venv/lib/python3.11/site-packages/arkouda/client.py:534](http://localhost:8888/lus/bnchlu1/drozt/playground/chpl/oo/scale/arkouda/venv/lib/python3.11/site-packages/arkouda/client.py#line=533), in ZmqChannel.send_string_message(self, cmd, recv_binary, args, size, request_id)
532 # raise errors or warnings sent back from the server
533 if return_message.msgType == MessageType.ERROR:
--> 534 raise RuntimeError(return_message.msg)
535 elif return_message.msgType == MessageType.WARNING:
536 warnings.warn(return_message.msg)
RuntimeError: Error executing command: TypeError Line 243 In Message.toScalar: Json Argument '["5", "3"]' cannot be cast as a scalar int(64)Similar to last case, this should presumably be casting to a List.list(int(64)) or similar
Is this a Blocking Issue
No standard work around to my knowledge. You are can manually make 1D samples by passing size as an int and manually creating a tensor with the desired shape, but it would be nice to support taking in tuple[int, ...]s for consistency with NumPy
ak.get_config() Output
{'arkoudaVersion': 'v2025.01.13+50.geb3207007',
'chplVersion': '2.4.0 (14de6e2762)',
'pythonVersion': '3.11',
'ZMQVersion': '4.3.5',
'HDF5Version': '1.14.4',
'serverHostname': 'x1003c6s1b0n0',
'ServerPort': 5555,
'numLocales': 16,
'numPUs': 128,
'maxTaskPar': 128,
'physicalMemory': 458698493952,
'distributionType': 'BlockDom(1,int(64),one,unmanaged DefaultDist)',
'LocaleConfigs': [<Omitted for Conciseness>],
'authenticate': False,
'logLevel': 'INFO',
'logChannel': 'CONSOLE',
'regexMaxCaptures': 20,
'byteorder': 'little',
'autoShutdown': False,
'serverInfoNoSplash': False,
'maxArrayDims': 1,
'ARROW_VERSION': '19.0.0'}
Additional context
Arkouda built at commit eb32070
Activity
ajpotts commentedon Sep 12, 2025
This is due to the
randommodule not yet supporting the multi-dimensional case.Fixes handling of size/shape parameter in ak.random.poisson (#4916)
Enables multi-dim output from ak.random.standard_exponential (#4924)