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[source]

Bases: Exception

Dynamic operator error.

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

exception PySparQ.pysparq.dynamic_operator.operator_wrapper.DynamicOperatorFactoryError[source]

Bases: DynamicOperatorError

Factory function invocation error.

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

exception PySparQ.pysparq.dynamic_operator.operator_wrapper.DynamicOperatorLoadError[source]

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)[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)

destroy(ptr: int)[source]

Destroy a C++ operator instance

Parameters:

ptr – C++ object address

get_base_class() → str[source]

Get the base class name.

get_name() → str[source]

Get the operator name.

load(arg_types: List[str] = None)[source]

Load the dynamic library

Parameters:

arg_types – List of constructor argument types

Raises:

DynamicOperatorLoadError – Load failed

lib_path[source]
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

PySparQ.pysparq.dynamic_operator.operator_wrapper.SparseState = None[source]