-
Notifications
You must be signed in to change notification settings - Fork 196
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
With python device kernel interoperability, users can write quantum kernels in C++ and bind them to python. In such cases, the common pattern is to have a C++ module that gets imported into a python module. For example, if we have a python package named `foo` to which we add C++ extensions using pybind11. The common pattern is to end up with a with a module named `_cppfoo` (or whaterver). Then, we import all of its symbols to `foo`: foo/__init__.py: from ._cppfoo import * Now, if `_cppfoo` contains a binded device kernel named `bar`, then users are able to access it using `foo.bar(...)`. This, however, is not the real path of `bar`, the real path is `foo._cppfoo.bar(..)`. Currently, binded device kernels get registered with their real path name, and thus when the python AST bridge parse another kernel that uses `foo.bar(...)`, it needs to figure it out if that is its real path or not. This commit attemps to improve the robustness of discovering this real path because as-is it fails on some simple cases. This is how it works: In Python, many objects have a module attribute, which indicates the module in which the object was defined. This should be the case for functions. Thus the idea here is to walk the provide path until we reach the function object and ask it for its `__module__`. Signed-off-by: boschmitt <[email protected]>
- Loading branch information
Showing
3 changed files
with
84 additions
and
47 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
# ============================================================================ # | ||
# Copyright (c) 2022 - 2024 NVIDIA Corporation & Affiliates. # | ||
# All rights reserved. # | ||
# # | ||
# This source code and the accompanying materials are made available under # | ||
# the terms of the Apache License 2.0 which accompanies this distribution. # | ||
# ============================================================================ # | ||
|
||
from cudaq_test_cpp_algo import * | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters