PySparQ.pysparq.dynamic_operator.operator_wrapper¶
Dynamic operator wrapper module
Calls C++ operators in dynamic libraries via ctypes and creates Python proxy classes.
Attributes¶
Exceptions¶
Dynamic operator error. |
|
Factory function invocation error. |
|
Dynamic library load error. |
Classes¶
C++ operator wrapper |
Functions¶
Clean up all active dynamic operator instances |
|
|
Create a dynamic operator Python class |
Module Contents¶
- exception PySparQ.pysparq.dynamic_operator.operator_wrapper.DynamicOperatorError[source]¶
Bases:
ExceptionDynamic operator error.
Initialize self. See help(type(self)) for accurate signature.
- exception PySparQ.pysparq.dynamic_operator.operator_wrapper.DynamicOperatorFactoryError[source]¶
Bases:
DynamicOperatorErrorFactory function invocation error.
Initialize self. See help(type(self)) for accurate signature.
- exception PySparQ.pysparq.dynamic_operator.operator_wrapper.DynamicOperatorLoadError[source]¶
Bases:
DynamicOperatorErrorDynamic library load error.
Initialize self. See help(type(self)) for accurate signature.
- class PySparQ.pysparq.dynamic_operator.operator_wrapper.CppOperatorWrapper(lib_path: str)[source]¶
C++ operator wrapper
Loads the dynamic library and invokes the factory functions to create/destroy C++ operator objects
Initialize the wrapper
- Parameters:
lib_path – Dynamic library path
- apply(ptr: int, state_cpp_ptr: int)[source]¶
Apply the operator to a SparseState
- Parameters:
ptr – Operator object address
state_cpp_ptr – C++ SparseState* pointer (obtained via state._cpp_ptr())
- apply_dag(ptr: int, state_cpp_ptr: int)[source]¶
Apply the dagger to a SparseState
- Parameters:
ptr – Operator object address
state_cpp_ptr – C++ SparseState* pointer (obtained via state._cpp_ptr())
- close()[source]¶
Close the dynamic library and release resources
Note: on Windows, all C++ objects must already be destroyed before the dynamic library file can be deleted successfully
- create(*args) int[source]¶
Create a C++ operator instance
- Parameters:
*args – Constructor arguments
- Returns:
C++ object address (as a Python int)
- load(arg_types: List[str] = None)[source]¶
Load the dynamic library
- Parameters:
arg_types – List of constructor argument types
- Raises:
DynamicOperatorLoadError – Load failed
- PySparQ.pysparq.dynamic_operator.operator_wrapper.cleanup_all_instances()[source]¶
Clean up all active dynamic operator instances
- 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[source]¶
Create a dynamic operator Python class
- Parameters:
name – Operator class name
lib_path – Dynamic library path
base_class – Base class name (“BaseOperator” or “SelfAdjointOperator”)
constructor_args – List of constructor arguments [(type, name), …]
- Returns:
The dynamically created operator class