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

DynamicOperatorError

Dynamic operator error.

DynamicOperatorFactoryError

Factory function invocation error.

DynamicOperatorLoadError

Dynamic library load error.

Classes

CppOperatorWrapper

C++ operator wrapper

Functions

cleanup_all_instances()

Clean up all active dynamic operator instances

create_operator_class(→ Type)

Create a dynamic operator Python class

Module Contents

exception PySparQ.pysparq.dynamic_operator.operator_wrapper.DynamicOperatorError[源代码]

Bases: Exception

Dynamic operator error.

Initialize self. See help(type(self)) for accurate signature.

exception PySparQ.pysparq.dynamic_operator.operator_wrapper.DynamicOperatorFactoryError[源代码]

Bases: DynamicOperatorError

Factory function invocation error.

Initialize self. See help(type(self)) for accurate signature.

exception PySparQ.pysparq.dynamic_operator.operator_wrapper.DynamicOperatorLoadError[源代码]

Bases: DynamicOperatorError

Dynamic library load error.

Initialize self. See help(type(self)) for accurate signature.

class PySparQ.pysparq.dynamic_operator.operator_wrapper.CppOperatorWrapper(lib_path: str)[源代码]

C++ operator wrapper

Loads the dynamic library and invokes the factory functions to create/destroy C++ operator objects

Initialize the wrapper

参数:

lib_path -- Dynamic library path

apply(ptr: int, state_cpp_ptr: int)[源代码]

Apply the operator to a SparseState

参数:
  • ptr -- Operator object address

  • state_cpp_ptr -- C++ SparseState* pointer (obtained via state._cpp_ptr())

apply_dag(ptr: int, state_cpp_ptr: int)[源代码]

Apply the dagger to a SparseState

参数:
  • ptr -- Operator object address

  • state_cpp_ptr -- C++ SparseState* pointer (obtained via state._cpp_ptr())

close()[源代码]

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[源代码]

Create a C++ operator instance

参数:

*args -- Constructor arguments

返回:

C++ object address (as a Python int)

destroy(ptr: int)[源代码]

Destroy a C++ operator instance

参数:

ptr -- C++ object address

get_base_class() → str[源代码]

Get the base class name.

get_name() → str[源代码]

Get the operator name.

load(arg_types: List[str] = None)[源代码]

Load the dynamic library

参数:

arg_types -- List of constructor argument types

抛出:

DynamicOperatorLoadError -- Load failed

lib_path[源代码]
PySparQ.pysparq.dynamic_operator.operator_wrapper.cleanup_all_instances()[源代码]

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[源代码]

Create a dynamic operator Python class

参数:
  • 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), ...]

返回:

The dynamically created operator class

PySparQ.pysparq.dynamic_operator.operator_wrapper.SparseState = None[源代码]