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

Adding a function to handle attribute access dynamically #1942

Draft
wants to merge 2 commits into
base: main
Choose a base branch
from
Draft
Changes from all 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
9 changes: 9 additions & 0 deletions python/cudaq/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,15 @@
from .visualization.bloch_visualize import add_to_bloch_sphere
from .visualization.bloch_visualize import show_bloch_sphere as show


def __getattr__(name):
if hasattr(cudaq_runtime, name):
return getattr(cudaq_runtime, name)
raise AttributeError(f"'{name}' is not supported for CUDA-Q in Python")
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The real issue is that there are functions that can only be called within cuda-q kernel code and not from host code. its not really about the function not being supported in Python.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks @amccaskey. Seems like this needs a bit of thinking as to get functions for the host and the kernel code. And then check against those to determine the error.



sys.modules[__name__].__getattr__ = __getattr__

# Add the parallel runtime types
parallel = cudaq_runtime.parallel

Expand Down
Loading