Commit 9a93a9b1 authored by Osborn, Joe's avatar Osborn, Joe

Committing first pass at tensorRuntime test with pybind API

parent ed56551e
Pipeline #70828 passed with stage
in 4 minutes and 40 seconds
......@@ -27,10 +27,10 @@ target_link_libraries(_pyexatn PUBLIC CppMicroServices exatn)
target_link_libraries(_pyexatn PUBLIC CppMicroServices exatn-numerics)
if(APPLE)
set_target_properties(_pyexatn PROPERTIES INSTALL_RPATH "@loader_path/lib")
set_target_properties(_pyexatn PROPERTIES INSTALL_RPATH "@loader_path/lib;@loader_path/plugins")
set_target_properties(_pyexatn PROPERTIES LINK_FLAGS "-undefined dynamic_lookup")
else()
set_target_properties(_pyexatn PROPERTIES INSTALL_RPATH "$ORIGIN/lib")
set_target_properties(_pyexatn PROPERTIES INSTALL_RPATH "$ORIGIN/lib;$ORIGIN/plugins")
set_target_properties(_pyexatn PROPERTIES LINK_FLAGS "-shared")
endif()
......
......@@ -14,6 +14,12 @@ using namespace exatn;
using namespace exatn::numerics;
using namespace pybind11::literals;
/**
* This module provides the necessary bindings for the ExaTN classes and functionality to be used within
* python. The various classes are bound with pybind11 and, when this is included in CMake compilation,
* can be used to write python scripts which leverage the ExaTN functionality.
*/
/**
Trampoline class for abstract virtual functions in TensorOperation
......@@ -133,7 +139,8 @@ PYBIND11_MODULE(_pyexatn, m) {
py::class_<exatn::numerics::TensorOpFactory>(
m, "TensorOpFactory", "")
.def("registerTensorOp", &exatn::numerics::TensorOpFactory::registerTensorOp, "")
.def("get", &exatn::numerics::TensorOpFactory::get, "");
.def("get", &exatn::numerics::TensorOpFactory::get, py::return_value_policy::reference, "")
.def("createTensorOpShared", &exatn::numerics::TensorOpFactory::createTensorOpShared, "");
py::class_<exatn::numerics::TensorOpTransform,
std::shared_ptr<exatn::numerics::TensorOpTransform>,
......
# An example test file to show the functionality of the exatn::TensorRunTimeTester
# using the python PyBind wrapper API
import exatn
import numpy as np
#initialize ExaTN framework
print("Initialize ExaTN")
exatn.Initialize()
op_factory = exatn.TensorOpFactory.get()
print("Create the tensors")
tensor0 = exatn.Tensor("tensor0", exatn.TensorShape([16,32,16,32]))
tensor1 = exatn.Tensor("tensor1", exatn.TensorShape([16,16,64,64]))
tensor2 = exatn.Tensor("tensor2", exatn.TensorShape([32,64,64,32]))
print("Create tensor operations for actual tensor construction")
create_tensor0 = op_factory.createTensorOpShared(exatn.TensorOpCode.CREATE)
create_tensor0.setTensorOperand(tensor0)
create_tensor1 = op_factory.createTensorOpShared(exatn.TensorOpCode.CREATE)
create_tensor1.setTensorOperand(tensor1)
create_tensor2 = op_factory.createTensorOpShared(exatn.TensorOpCode.CREATE)
create_tensor2.setTensorOperand(tensor2)
print("Create tensor operation for contracting tensors")
contract_tensors = op_factory.createTensorOpShared(exatn.TensorOpCode.CONTRACT)
contract_tensors.setTensorOperand(tensor0)
contract_tensors.setTensorOperand(tensor1)
contract_tensors.setTensorOperand(tensor2)
contract_tensors.setScalar(0,np.cdouble(0.5j + 0))
contract_tensors.setIndexPattern("D(a,b,c,d)+=L(c,a,k,l)*R(d,l,k,b)")
destroy_tensor2 = op_factory.createTensorOpShared(exatn.TensorOpCode.DESTROY)
destroy_tensor2.setTensorOperand(tensor2)
destroy_tensor1 = op_factory.createTensorOpShared(exatn.TensorOpCode.DESTROY)
destroy_tensor1.setTensorOperand(tensor1)
destroy_tensor0 = op_factory.createTensorOpShared(exatn.TensorOpCode.DESTROY)
destroy_tensor0.setTensorOperand(tensor0)
numserver = exatn.getNumServer()
numserver.submit(create_tensor0)
numserver.submit(create_tensor1)
numserver.submit(create_tensor2)
numserver.submit(contract_tensors)
numserver.submit(destroy_tensor0)
numserver.submit(destroy_tensor1)
numserver.submit(destroy_tensor2)
print("Finalize ExaTN")
exatn.Finalize()
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment