Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix issue when passing np.ndarray to Python kernels #1406

Merged
merged 7 commits into from
Mar 21, 2024
Merged
Show file tree
Hide file tree
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion python/cudaq/kernel/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -173,8 +173,11 @@ def mlirTypeFromPyType(argType, ctx, **kwargs):
return ComplexType.get(mlirTypeFromPyType(float, ctx))

if argType in [list, np.ndarray, List]:
if 'argInstance' not in kwargs or kwargs['argInstance'] == None:
if 'argInstance' not in kwargs:
return cc.StdvecType.get(ctx, mlirTypeFromPyType(float, ctx))
if argType != np.ndarray:
if kwargs['argInstance'] == None:
return cc.StdvecType.get(ctx, mlirTypeFromPyType(float, ctx))

argInstance = kwargs['argInstance']
argTypeToCompareTo = kwargs[
Expand Down
10 changes: 10 additions & 0 deletions python/tests/kernel/test_kernel_features.py
Original file line number Diff line number Diff line change
Expand Up @@ -900,3 +900,13 @@ def kernel(argument: float):

with pytest.raises(RuntimeError) as error:
print(cudaq.draw(kernel))


def test_no_valueerror_np_array():
@cudaq.kernel
def test(var : np.ndarray):
q = cudaq.qubit()
ry(var[0], q)
mz(q)

test(np.array([1.,2.]))
Loading