diff --git a/.gitignore b/.gitignore index 408e166a55d53e732e01c3ad43439b8c5de59b45..04e38af8eabeb74636565371d2f097b1143b8827 100644 --- a/.gitignore +++ b/.gitignore @@ -18,5 +18,8 @@ *.exe *.bp *.out +*.pyc +*.bp +*.bp.dir build/ diff --git a/bindings/python/CMakeLists.txt b/bindings/python/CMakeLists.txt index 96eeb1dda34e582713b451de4dd3dc08f0d62e9b..93fd50a56e290e554dcc680468c983623f534c0b 100644 --- a/bindings/python/CMakeLists.txt +++ b/bindings/python/CMakeLists.txt @@ -24,13 +24,16 @@ if(ADIOS2_HAVE_MPI) endif() string(REGEX REPLACE "^${PYTHON_PREFIX}/" "" - python_package_dir "${PYTHON_SITE_PACKAGES}" + CMAKE_INSTALL_PYTHONDIR "${PYTHON_SITE_PACKAGES}" +) +set(CMAKE_INSTALL_PYTHONDIR "${CMAKE_INSTALL_PYTHONDIR}" + CACHE INTERNAL "" FORCE ) set_target_properties(adios2py PROPERTIES OUTPUT_NAME adios2 - LIBRARY_OUTPUT_DIRECTORY ${ADIOS2_BINARY_DIR}/${python_package_dir} - RUNTIME_OUTPUT_DIRECTORY ${ADIOS2_BINARY_DIR}/${python_package_dir} + LIBRARY_OUTPUT_DIRECTORY ${ADIOS2_BINARY_DIR}/${CMAKE_INSTALL_PYTHONDIR} + RUNTIME_OUTPUT_DIRECTORY ${ADIOS2_BINARY_DIR}/${CMAKE_INSTALL_PYTHONDIR} ) install(TARGETS adios2py - DESTINATION ${python_package_dir} + DESTINATION ${CMAKE_INSTALL_PYTHONDIR} ) diff --git a/cmake/ADIOSFunctions.cmake b/cmake/ADIOSFunctions.cmake index b0f6cb8e60f1edaee1b799af4739519f3a13f9c1..37b4cf2e02b2d01c9267f51e1a742efd752ab491 100644 --- a/cmake/ADIOSFunctions.cmake +++ b/cmake/ADIOSFunctions.cmake @@ -37,3 +37,12 @@ function(message_pad msg out_len out_msg) set(${out_msg} "${msg}${pad}" PARENT_SCOPE) endif() endfunction() + +function(python_add_test name script) + add_test(NAME ${name} + COMMAND ${PYTHON_EXECUTABLE} ${CMAKE_CURRENT_SOURCE_DIR}/${script} ${ARGN} + ) + set_property(TEST ${name} PROPERTY + ENVIRONMENT "PYTHONPATH=${ADIOS2_BINARY_DIR}/${CMAKE_INSTALL_PYTHONDIR}:$ENV{PYTHONPATH}" + ) +endfunction() diff --git a/testing/adios2/CMakeLists.txt b/testing/adios2/CMakeLists.txt index ef043c0c9c5223cb95f2dca238b0cf0687c6594e..f78866fa0d87db8eca34abf94b39e1cac4a25c3f 100644 --- a/testing/adios2/CMakeLists.txt +++ b/testing/adios2/CMakeLists.txt @@ -5,3 +5,4 @@ add_subdirectory(interface) add_subdirectory(engine) +add_subdirectory(bindings) diff --git a/testing/adios2/bindings/CMakeLists.txt b/testing/adios2/bindings/CMakeLists.txt new file mode 100644 index 0000000000000000000000000000000000000000..8aa1ecd22b23c1ddd515657bde6f8ac8c6ec7af1 --- /dev/null +++ b/testing/adios2/bindings/CMakeLists.txt @@ -0,0 +1,8 @@ +#------------------------------------------------------------------------------# +# Distributed under the OSI-approved Apache License, Version 2.0. See +# accompanying file Copyright.txt for details. +#------------------------------------------------------------------------------# + +if(ADIOS2_HAVE_Python) + add_subdirectory(python) +endif() diff --git a/testing/adios2/bindings/python/CMakeLists.txt b/testing/adios2/bindings/python/CMakeLists.txt new file mode 100644 index 0000000000000000000000000000000000000000..8da6af4e7613e9b777cfb092d9c805fa583282f5 --- /dev/null +++ b/testing/adios2/bindings/python/CMakeLists.txt @@ -0,0 +1,6 @@ +#------------------------------------------------------------------------------# +# Distributed under the OSI-approved Apache License, Version 2.0. See +# accompanying file Copyright.txt for details. +#------------------------------------------------------------------------------# + +python_add_test(PythonBPWrite TestBPWriteTypes.py) diff --git a/testing/adios2/bindings/python/TestBPWriteTypes.py b/testing/adios2/bindings/python/TestBPWriteTypes.py new file mode 100644 index 0000000000000000000000000000000000000000..842adacd8cf1e9b87c53a66725ab50d7b3269aef --- /dev/null +++ b/testing/adios2/bindings/python/TestBPWriteTypes.py @@ -0,0 +1,66 @@ +#!/usr/bin/env python + +# +# Distributed under the OSI-approved Apache License, Version 2.0. See +# accompanying file Copyright.txt for details. +# +# TestBPWriteTypes.py: test Python numpy types in ADIOS2 File Write +# Created on: Feb 2, 2017 +# Author: William F Godoy godoywf@ornl.gov + + +from adios2NPTypes import SmallTestData +import adios2 + + +# Test data +data = SmallTestData() + +adios = adios2.ADIOS(adios2.DebugON) + +bpIO = adios.DeclareIO("NPTypes") + +# ADIOS Variable name, shape, start, offset, constant dims +# All local variables +varI8 = bpIO.DefineVariable( + "varI8", [], [], [data.I8.size], adios2.ConstantDims) +varI16 = bpIO.DefineVariable( + "varI16", [], [], [data.I16.size], adios2.ConstantDims) +varI32 = bpIO.DefineVariable( + "varI32", [], [], [data.I32.size], adios2.ConstantDims) +varI64 = bpIO.DefineVariable( + "varI64", [], [], [data.I64.size], adios2.ConstantDims) + +varU8 = bpIO.DefineVariable( + "varUI8", [], [], [data.U8.size], adios2.ConstantDims) +varU16 = bpIO.DefineVariable( + "varUI16", [], [], [data.U16.size], adios2.ConstantDims) +varU32 = bpIO.DefineVariable( + "varUI32", [], [], [data.U32.size], adios2.ConstantDims) +varU64 = bpIO.DefineVariable( + "varUI64", [], [], [data.U64.size], adios2.ConstantDims) + +varR32 = bpIO.DefineVariable( + "varR32", [], [], [data.R32.size], adios2.ConstantDims) + +varR64 = bpIO.DefineVariable( + "varR64", [], [], [data.R64.size], adios2.ConstantDims) + + +# ADIOS Engine +bpFileWriter = bpIO.Open("npTypes.bp", adios2.OpenModeWrite) + +bpFileWriter.Write(varI8, data.I8) +bpFileWriter.Write(varI16, data.I16) +bpFileWriter.Write(varI32, data.I32) +bpFileWriter.Write(varI64, data.I64) + +bpFileWriter.Write(varU8, data.U8) +bpFileWriter.Write(varU16, data.U16) +bpFileWriter.Write(varU32, data.U32) +bpFileWriter.Write(varU64, data.U64) + +bpFileWriter.Write(varR32, data.R32) +bpFileWriter.Write(varR64, data.R64) + +bpFileWriter.Close() diff --git a/testing/adios2/bindings/python/adios2NPTypes.py b/testing/adios2/bindings/python/adios2NPTypes.py new file mode 100644 index 0000000000000000000000000000000000000000..a5e030f570affead816414d23e46a637c6bf64f4 --- /dev/null +++ b/testing/adios2/bindings/python/adios2NPTypes.py @@ -0,0 +1,46 @@ +# +# Distributed under the OSI-approved Apache License, Version 2.0. See +# accompanying file Copyright.txt for details. +# +# nptypes.py small test data for np types +# Created on: Feb 2, 2017 +# Author: William F Godoy godoywf@ornl.gov + +import numpy as np + + +class SmallTestData: + + def __init__(self): + self.I8 = np.array([0, 1, -2, 3, -4, 5, -6, 7, -8, 9], dtype=np.int8) + self.I16 = np.array( + [512, 513, -510, 515, -508, 517, -506, 519, -504, 521], + dtype=np.int16) + self.I32 = np.array( + [131072, 131073, -131070, 131075, -131068, + 131077, -131066, 131079, -131064, 131081], + dtype=np.int32) + self.I64 = np.array( + [8589934592, 8589934593, -8589934590, 8589934595, -8589934588, + 8589934597, -8589934586, 8589934599, -8589934584, 8589934601], + dtype=np.int64) + + self.U8 = np.array( + [128, 129, 130, 131, 132, 133, 134, 135, 136, 137], dtype=np.uint8) + self.U16 = np.array( + [32768, 32769, 32770, 32771, 32772, 32773, 32774, 32775, 32776, + 32777], + dtype=np.uint16) + self.U32 = np.array( + [2147483648, 2147483649, 2147483650, 2147483651, 2147483652, + 2147483653, 2147483654, 2147483655, 2147483656, 2147483657], + dtype=np.uint32) + self.U64 = np.array( + [9223372036854775808, 9223372036854775809, 9223372036854775810, + 9223372036854775811, 9223372036854775812, 9223372036854775813, + 9223372036854775814, 9223372036854775815, 9223372036854775816, + 9223372036854775817], dtype=np.uint64) + + self.R32 = np.array([0, 1, 2, 3, 4, 5, 6, 7, 8, 9], dtype=np.float32) + self.R64 = np.array([0, -1, -2, -3, -4, -5, -6, -7, -8, -9], + dtype=np.float64)