Python 绑定层(C++ 侧)¶
pybind11 绑定入口(PySparQ/core.cpp 生成的 pysparq._core 模块)¶
Auxiliary macro definitions for the PySparQ binding layer.
Defines registration macros reused by the pybind11 binding module (core.cpp): batch binding of controllable methods (BIND_CONTROLLABLE_METHODS), operator class registration (BIND_BASE_OPERATOR / BIND_SELF_ADJOINT_OPERATOR / BIND_BASE_OPERATOR_SUBNAME), and dagger method binding (BIND_DAG_METHODS)
Defines
-
BIND_CONTROLLABLE_METHODS(CLASS_NAME)¶
Batch-bind the conditional control methods and condition-variable attributes of a controllable (ClassControllable) operator class.
Expands to a single .def(...) chain containing: the four condition_variable_* read-only attributes, the four groups of overloaded condition-setting methods conditioned_by_nonzeros / conditioned_by_all_ones / conditioned_by_bit / conditioned_by_value, and the corresponding clear_control_* clearing methods
- 参数:
CLASS_NAME -- Name of the operator class whose controllable methods are to be bound
-
BIND_BASE_OPERATOR(NAME)¶
Register an operator class derived from BaseOperator.
- 参数:
NAME -- C++ class name (also used as the exported Python class name)
-
BIND_SELF_ADJOINT_OPERATOR(NAME)¶
Register a self-adjoint operator class derived from SelfAdjointOperator.
On Windows, additionally binds call (operator()) explicitly to work around the issue with calling the inherited operator() from Python (see the English note above)
- 参数:
NAME -- C++ class name (also used as the exported Python class name)
-
BIND_BASE_OPERATOR_SUBNAME(NAME, PYNAME)¶
Register an operator class derived from BaseOperator (with a custom Python class name)
- 参数:
NAME -- C++ class name
PYNAME -- Exported Python class name (may differ from the C++ class name)
-
BIND_DAG_METHODS(NAME)¶
Bind the dagger (adjoint/inverse) method dag(state) for an operator class.
- 参数:
NAME -- C++ class name
-
namespace literals¶
-
namespace std¶
绑定辅助宏(PySparQ/include/BindUtils.h)¶
警告
doxygenfile: Cannot find file "BindUtils.h
动态算子加载器(PySparQ/pysparq/dynamic_operator/include/dynamic_operator_loader.h)¶
C++ dynamic operator loader.
Loads compiled dynamic libraries (.so/.dll) at runtime and retrieves operator factory functions
-
namespace pysparq¶
Typedefs
-
using CreateOperatorFunc = void *(*)()¶
Factory function type alias.
Signature of a factory function that creates BaseOperator-derived objects
Functions
-
template<typename FuncType>
FuncType get_typed_symbol(DynamicOperatorLoader &loader, const std::string &name)¶ Typed symbol retrieval helper.
- 模板参数:
FuncType -- Function pointer type
- 参数:
loader -- Dynamic library loader
name -- Symbol name
- 返回:
Typed function pointer, or nullptr on failure
-
class DynamicOperatorLoader¶
- #include <dynamic_operator_loader.h>
Dynamic library loader.
Wraps platform-specific dynamic library loading, supporting Linux (dlopen), Windows (LoadLibrary), and macOS
Public Functions
-
explicit DynamicOperatorLoader(const std::string &lib_path)¶
Constructor, loads the specified dynamic library.
- 参数:
lib_path -- Dynamic library file path (.so/.dll/.dylib)
-
~DynamicOperatorLoader()¶
Destructor, automatically unloads the dynamic library.
-
DynamicOperatorLoader(const DynamicOperatorLoader&) = delete¶
-
DynamicOperatorLoader &operator=(const DynamicOperatorLoader&) = delete¶
-
DynamicOperatorLoader(DynamicOperatorLoader &&other) noexcept¶
-
DynamicOperatorLoader &operator=(DynamicOperatorLoader &&other) noexcept¶
-
void *get_symbol(const std::string &name)¶
Retrieves a symbol (factory function) from the dynamic library.
- 参数:
name -- Symbol name (e.g. "create_operator")
- 返回:
Pointer to the symbol, or nullptr on failure
-
bool is_valid() const¶
Checks whether the dynamic library was loaded successfully.
- 返回:
true if loading succeeded, false if it failed
-
explicit DynamicOperatorLoader(const std::string &lib_path)¶
-
using CreateOperatorFunc = void *(*)()¶