PySparQ.pysparq.dynamic_operator.operator_wrapper¶
动态算子包装模块
使用 ctypes 调用动态库中的 C++ 算子,创建 Python 代理类。
Attributes¶
Exceptions¶
动态算子错误 |
|
工厂函数调用错误 |
|
动态库加载错误 |
Classes¶
C++ 算子包装器 |
Functions¶
清理所有活跃的动态算子实例 |
|
|
创建动态算子 Python 类 |
Module Contents¶
- exception PySparQ.pysparq.dynamic_operator.operator_wrapper.DynamicOperatorError[源代码]¶
Bases:
Exception动态算子错误
Initialize self. See help(type(self)) for accurate signature.
- exception PySparQ.pysparq.dynamic_operator.operator_wrapper.DynamicOperatorFactoryError[源代码]¶
Bases:
DynamicOperatorError工厂函数调用错误
Initialize self. See help(type(self)) for accurate signature.
- exception PySparQ.pysparq.dynamic_operator.operator_wrapper.DynamicOperatorLoadError[源代码]¶
Bases:
DynamicOperatorError动态库加载错误
Initialize self. See help(type(self)) for accurate signature.
- class PySparQ.pysparq.dynamic_operator.operator_wrapper.CppOperatorWrapper(lib_path: str)[源代码]¶
C++ 算子包装器
负责加载动态库、调用工厂函数创建/销毁 C++ 算子对象
初始化包装器
- 参数:
lib_path -- 动态库路径
- apply(ptr: int, state_cpp_ptr: int)[源代码]¶
应用算子到 SparseState
- 参数:
ptr -- 算子对象地址
state_cpp_ptr -- C++ SparseState* 指针(通过 state._cpp_ptr() 获取)
- apply_dag(ptr: int, state_cpp_ptr: int)[源代码]¶
应用 dagger 到 SparseState
- 参数:
ptr -- 算子对象地址
state_cpp_ptr -- C++ SparseState* 指针(通过 state._cpp_ptr() 获取)
- load(arg_types: List[str] = None)[源代码]¶
加载动态库
- 参数:
arg_types -- 构造函数参数类型列表
- 抛出:
DynamicOperatorLoadError -- 加载失败
- PySparQ.pysparq.dynamic_operator.operator_wrapper.create_operator_class(name: str, lib_path: str, base_class: str = 'BaseOperator', constructor_args: List[Tuple[str, str]] = None) Type[源代码]¶
创建动态算子 Python 类
- 参数:
name -- 算子类名
lib_path -- 动态库路径
base_class -- 基类名 ("BaseOperator" 或 "SelfAdjointOperator")
constructor_args -- 构造函数参数列表 [(type, name), ...]
- 返回:
动态创建的算子类