diff --git a/.ci/azure/linux.yml b/.ci/azure/linux.yml index 683515e8b29..d48aa25f5bb 100644 --- a/.ci/azure/linux.yml +++ b/.ci/azure/linux.yml @@ -232,7 +232,7 @@ jobs: - script: | export DATA_PATH=$(MODELS_PATH) export MODELS_PATH=$(MODELS_PATH) - . $(SETUPVARS) -pyver 3.8 && python3 -m pytest -s $(INSTALL_TEST_DIR)/pyngraph $(PYTHON_STATIC_ARGS) --junitxml=TEST-Pyngraph.xml --ignore=$(INSTALL_TEST_DIR)/pyngraph/tests/test_onnx/test_zoo_models.py --ignore=$(INSTALL_TEST_DIR)/pyngraph/tests/test_onnx/test_backend.py + . $(SETUPVARS) -pyver 3.8 && python3 -m pytest -s $(INSTALL_TEST_DIR)/pyngraph $(PYTHON_STATIC_ARGS) --junitxml=TEST-Pyngraph.xml --ignore=$(INSTALL_TEST_DIR)/pyngraph/tests/test_utils/test_utils.py --ignore=$(INSTALL_TEST_DIR)/pyngraph/tests/test_onnx/test_zoo_models.py --ignore=$(INSTALL_TEST_DIR)/pyngraph/tests/test_onnx/test_backend.py displayName: 'nGraph Python Bindings Tests' continueOnError: false diff --git a/inference-engine/ie_bridges/python/CMakeLists.txt b/inference-engine/ie_bridges/python/CMakeLists.txt index ac9a310c721..df85a0897f0 100644 --- a/inference-engine/ie_bridges/python/CMakeLists.txt +++ b/inference-engine/ie_bridges/python/CMakeLists.txt @@ -66,10 +66,6 @@ set (PYTHON_BRIDGE_SRC_ROOT ${CMAKE_CURRENT_SOURCE_DIR}) add_subdirectory (src/openvino/inference_engine) add_subdirectory (src/openvino/offline_transformations) -if (ENABLE_TESTS) - add_subdirectory(src/openvino/test_utils) -endif() - if(ENABLE_WHEEL) add_subdirectory(wheel) endif() @@ -86,7 +82,7 @@ install(FILES requirements.txt DESTINATION ${PYTHON_BRIDGE_CPACK_PATH}/${PYTHON_VERSION} COMPONENT ${PYTHON_COMPONENT}) -install(PROGRAMS ${PYTHON_BRIDGE_OUTPUT_DIRECTORY}/__init__.py +install(PROGRAMS ${PYTHON_BRIDGE_SRC_ROOT}/src/openvino/__init__.py DESTINATION ${PYTHON_BRIDGE_CPACK_PATH}/${PYTHON_VERSION}/openvino COMPONENT ${PYTHON_COMPONENT}) diff --git a/inference-engine/ie_bridges/python/cmake/utils/merge_init_files.py b/inference-engine/ie_bridges/python/cmake/utils/merge_init_files.py deleted file mode 100755 index 2e1b3914b44..00000000000 --- a/inference-engine/ie_bridges/python/cmake/utils/merge_init_files.py +++ /dev/null @@ -1,26 +0,0 @@ -#!/usr/bin/env python3 -# Copyright (C) 2021 Intel Corporation -# SPDX-License-Identifier: Apache-2.0 - -import argparse -import os - - -parser = argparse.ArgumentParser() - -parser.add_argument('-i', '--input_file', type=str, required=True) -parser.add_argument('-o', '--output_file', type=str, required=True) - -args = parser.parse_args() - -mode = 'a' if os.path.exists(args.output_file) else 'w' -with open(args.input_file) as input_file, open(args.output_file, mode) as output_file: - lines = input_file.readlines() - count = 0 - copied_lines = ["\n"] - for idx, line in enumerate(lines): - if line[0] == '#' and idx <= 2: - count += 1 - if idx > 2 and count == 3: - copied_lines.append(line) - output_file.writelines(copied_lines) diff --git a/inference-engine/ie_bridges/python/src/openvino/inference_engine/CMakeLists.txt b/inference-engine/ie_bridges/python/src/openvino/inference_engine/CMakeLists.txt index bd90ae05f42..e58827b11c2 100644 --- a/inference-engine/ie_bridges/python/src/openvino/inference_engine/CMakeLists.txt +++ b/inference-engine/ie_bridges/python/src/openvino/inference_engine/CMakeLists.txt @@ -63,15 +63,12 @@ endif() find_package(Python COMPONENTS Interpreter Development) # perform copy -# merge __init__.py files of new and old python api add_custom_command(TARGET ${TARGET_NAME} POST_BUILD COMMAND ${CMAKE_COMMAND} -E copy ${CMAKE_CURRENT_SOURCE_DIR}/__init__.py ${CMAKE_LIBRARY_OUTPUT_DIRECTORY}/__init__.py + COMMAND ${CMAKE_COMMAND} -E copy ${CMAKE_CURRENT_SOURCE_DIR}/../__init__.py ${CMAKE_LIBRARY_OUTPUT_DIRECTORY}/../__init__.py COMMAND ${CMAKE_COMMAND} -E copy ${PYTHON_BRIDGE_SRC_ROOT}/requirements.txt ${CMAKE_LIBRARY_OUTPUT_DIRECTORY}/../../requirements.txt COMMAND ${CMAKE_COMMAND} -E copy ${PYTHON_BRIDGE_SRC_ROOT}/requirements.txt ${PYTHON_BRIDGE_OUTPUT_DIRECTORY}/../../requirements.txt - COMMAND ${Python_EXECUTABLE} ${PYTHON_BRIDGE_SRC_ROOT}/cmake/utils/merge_init_files.py - -i ${PYTHON_BRIDGE_SRC_ROOT}/src/openvino/__init__.py - -o ${CMAKE_LIBRARY_OUTPUT_DIRECTORY}/../__init__.py ) # install diff --git a/inference-engine/ie_bridges/python/src/openvino/test_utils/__init__.py b/inference-engine/ie_bridges/python/src/openvino/test_utils/__init__.py deleted file mode 100644 index 66e65f9a057..00000000000 --- a/inference-engine/ie_bridges/python/src/openvino/test_utils/__init__.py +++ /dev/null @@ -1,7 +0,0 @@ -# -*- coding: utf-8 -*- -# Copyright (C) 2018-2021 Intel Corporation -# SPDX-License-Identifier: Apache-2.0 - -from .test_utils_api import * - -__all__ = ['CompareNetworks'] diff --git a/inference-engine/ie_bridges/python/src/openvino/test_utils/test_utils_api.pyx b/inference-engine/ie_bridges/python/src/openvino/test_utils/test_utils_api.pyx deleted file mode 100644 index 63cf6529f1a..00000000000 --- a/inference-engine/ie_bridges/python/src/openvino/test_utils/test_utils_api.pyx +++ /dev/null @@ -1,15 +0,0 @@ -# Copyright (C) 2018-2021 Intel Corporation -# SPDX-License-Identifier: Apache-2.0 - -from .cimport test_utils_api_impl_defs as C -from ..inference_engine.ie_api cimport IENetwork - -from libcpp cimport bool -from libcpp.string cimport string -from libcpp.pair cimport pair - - -def CompareNetworks(IENetwork lhs, IENetwork rhs): - cdef pair[bool, string] c_pair - c_pair = C.CompareNetworks(lhs.impl, rhs.impl) - return c_pair diff --git a/inference-engine/ie_bridges/python/src/openvino/test_utils/test_utils_api_impl.cpp b/inference-engine/ie_bridges/python/src/openvino/test_utils/test_utils_api_impl.cpp deleted file mode 100644 index f30a3e74d9c..00000000000 --- a/inference-engine/ie_bridges/python/src/openvino/test_utils/test_utils_api_impl.cpp +++ /dev/null @@ -1,13 +0,0 @@ -// Copyright (C) 2018-2021 Intel Corporation -// SPDX-License-Identifier: Apache-2.0 -// - -#include "test_utils_api_impl.hpp" - -#include -#include - -std::pair InferenceEnginePython::CompareNetworks(InferenceEnginePython::IENetwork lhs, - InferenceEnginePython::IENetwork rhs) { - return compare_functions(lhs.actual->getFunction(), rhs.actual->getFunction(), true, true, false, true, true); -} diff --git a/inference-engine/ie_bridges/python/src/openvino/test_utils/test_utils_api_impl.hpp b/inference-engine/ie_bridges/python/src/openvino/test_utils/test_utils_api_impl.hpp deleted file mode 100644 index bce3c2d00ae..00000000000 --- a/inference-engine/ie_bridges/python/src/openvino/test_utils/test_utils_api_impl.hpp +++ /dev/null @@ -1,14 +0,0 @@ -// Copyright (C) 2018-2021 Intel Corporation -// SPDX-License-Identifier: Apache-2.0 -// - -#pragma once - -#include "Python.h" -#include "ie_api_impl.hpp" - -namespace InferenceEnginePython { - -std::pair CompareNetworks(InferenceEnginePython::IENetwork, InferenceEnginePython::IENetwork); - -}; // namespace InferenceEnginePython diff --git a/inference-engine/ie_bridges/python/src/openvino/test_utils/test_utils_api_impl_defs.pxd b/inference-engine/ie_bridges/python/src/openvino/test_utils/test_utils_api_impl_defs.pxd deleted file mode 100644 index cb3d7704482..00000000000 --- a/inference-engine/ie_bridges/python/src/openvino/test_utils/test_utils_api_impl_defs.pxd +++ /dev/null @@ -1,11 +0,0 @@ -# Copyright (C) 2018-2021 Intel Corporation -# SPDX-License-Identifier: Apache-2.0 - -from libcpp cimport bool -from libcpp.string cimport string -from libcpp.pair cimport pair - -from ..inference_engine.ie_api_impl_defs cimport IENetwork - -cdef extern from "test_utils_api_impl.hpp" namespace "InferenceEnginePython": - cdef pair[bool, string] CompareNetworks(IENetwork lhs, IENetwork rhs) diff --git a/inference-engine/ie_bridges/python/tests/test_utils.py b/inference-engine/ie_bridges/python/tests/test_utils.py deleted file mode 100644 index e54648ecd73..00000000000 --- a/inference-engine/ie_bridges/python/tests/test_utils.py +++ /dev/null @@ -1,29 +0,0 @@ -# Copyright (C) 2018-2021 Intel Corporation -# SPDX-License-Identifier: Apache-2.0 - -from openvino.inference_engine import IECore, IENetwork - -import ngraph as ng -from ngraph.impl.op import Parameter -from ngraph.impl import Function, Shape, Type - -def get_test_cnnnetwork(): - element_type = Type.f32 - param = Parameter(element_type, Shape([1, 3, 22, 22])) - relu = ng.relu(param) - func = Function([relu], [param], 'test') - caps = Function.to_capsule(func) - - cnnNetwork = IENetwork(caps) - assert cnnNetwork != None - return cnnNetwork - - -def test_compare_networks(): - try: - from openvino.test_utils import CompareNetworks - net = get_test_cnnnetwork() - status, msg = CompareNetworks(net, net) - assert status - except: - print("openvino.test_utils.CompareNetworks is not available") diff --git a/src/bindings/python/src/CMakeLists.txt b/src/bindings/python/src/CMakeLists.txt index c7e71113d99..fa365348a89 100644 --- a/src/bindings/python/src/CMakeLists.txt +++ b/src/bindings/python/src/CMakeLists.txt @@ -2,5 +2,7 @@ # SPDX-License-Identifier: Apache-2.0 # +set(PYTHON_SOURCE_DIR ${CMAKE_CURRENT_SOURCE_DIR}) + add_subdirectory(compatibility) add_subdirectory(pyopenvino) diff --git a/src/bindings/python/src/openvino/test_utils/__init__.py b/src/bindings/python/src/openvino/test_utils/__init__.py new file mode 100644 index 00000000000..c6b385899bd --- /dev/null +++ b/src/bindings/python/src/openvino/test_utils/__init__.py @@ -0,0 +1,5 @@ +# -*- coding: utf-8 -*- +# Copyright (C) 2021 Intel Corporation +# SPDX-License-Identifier: Apache-2.0 + +from .test_utils_api import compare_functions diff --git a/src/bindings/python/src/pyopenvino/CMakeLists.txt b/src/bindings/python/src/pyopenvino/CMakeLists.txt index 36bf8300152..73142ab988f 100644 --- a/src/bindings/python/src/pyopenvino/CMakeLists.txt +++ b/src/bindings/python/src/pyopenvino/CMakeLists.txt @@ -44,9 +44,13 @@ if(NOT CMAKE_CXX_COMPILER_ID STREQUAL "MSVC") add_compile_options(-Wno-deprecated-declarations -Wno-undef) endif() +if(ENABLE_TESTS) + add_subdirectory(test_utils) +endif() + # create target -file(GLOB_RECURSE SOURCES *.cpp) +file(GLOB_RECURSE SOURCES core/*.cpp graph/*.cpp frontend/*.cpp pyopenvino.cpp) pybind11_add_module(${PROJECT_NAME} MODULE ${SOURCES}) diff --git a/inference-engine/ie_bridges/python/src/openvino/test_utils/CMakeLists.txt b/src/bindings/python/src/pyopenvino/test_utils/CMakeLists.txt similarity index 60% rename from inference-engine/ie_bridges/python/src/openvino/test_utils/CMakeLists.txt rename to src/bindings/python/src/pyopenvino/test_utils/CMakeLists.txt index 86dd25996b9..ff1d701e619 100644 --- a/inference-engine/ie_bridges/python/src/openvino/test_utils/CMakeLists.txt +++ b/src/bindings/python/src/pyopenvino/test_utils/CMakeLists.txt @@ -1,4 +1,4 @@ -# Copyright (C) 2018-2021 Intel Corporation +# Copyright (C) 2021 Intel Corporation # SPDX-License-Identifier: Apache-2.0 # @@ -8,25 +8,23 @@ set(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${PYTHON_BRIDGE_OUTPUT_DIRECTORY}/test_utils) set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY ${PYTHON_BRIDGE_OUTPUT_DIRECTORY}/test_utils) set(CMAKE_COMPILE_PDB_OUTPUT_DIRECTORY ${PYTHON_BRIDGE_OUTPUT_DIRECTORY}/test_utils) set(CMAKE_PDB_OUTPUT_DIRECTORY ${PYTHON_BRIDGE_OUTPUT_DIRECTORY}/test_utils) +set(PYTHON_BRIDGE_CPACK_PATH "python") -file(GLOB SOURCES ${CMAKE_CURRENT_SOURCE_DIR}/test_utils_api.pyx - ${CMAKE_CURRENT_SOURCE_DIR}/test_utils_api_impl.cpp - ${CMAKE_CURRENT_SOURCE_DIR}/test_utils_api_impl.hpp - ${CMAKE_CURRENT_SOURCE_DIR}/test_utils_api_impl_defs.pxd) +file(GLOB SOURCES ${CMAKE_CURRENT_SOURCE_DIR}/test_utils.cpp) -set_source_files_properties(${CMAKE_CURRENT_SOURCE_DIR}/test_utils_api.pyx - PROPERTIES CYTHON_IS_CXX ON) +if(NOT DEFINED OpenVINO_SOURCE_DIR) + find_package(InferenceEngineDeveloperPackage REQUIRED) +endif() # create target -cython_add_module(${TARGET_NAME} ${SOURCES}) +pybind11_add_module(${TARGET_NAME} MODULE ${SOURCES}) -add_dependencies(${TARGET_NAME} ie_api) -ov_python_disable_intel_warnings(${TARGET_NAME}) +add_dependencies(${TARGET_NAME} pyopenvino) if(COMMAND ie_add_vs_version_file) ie_add_vs_version_file(NAME ${TARGET_NAME} - FILEDESCRIPTION "Test Utils Python library") + FILEDESCRIPTION "Test Utils Python library") endif() if(InferenceEngineDeveloperPackage_FOUND) @@ -36,7 +34,6 @@ else() endif() target_include_directories(${TARGET_NAME} PRIVATE "${CMAKE_CURRENT_SOURCE_DIR}") -target_include_directories(${TARGET_NAME} SYSTEM PRIVATE "${CMAKE_CURRENT_SOURCE_DIR}/../inference_engine") target_link_libraries(${TARGET_NAME} PRIVATE ${link_libraries}) # Compatibility with python 2.7 which has deprecated "register" specifier @@ -46,12 +43,12 @@ endif() # perform copy add_custom_command(TARGET ${TARGET_NAME} - POST_BUILD - COMMAND ${CMAKE_COMMAND} -E copy ${PYTHON_BRIDGE_SRC_ROOT}/src/openvino/test_utils/__init__.py ${CMAKE_LIBRARY_OUTPUT_DIRECTORY}/__init__.py -) + POST_BUILD + COMMAND ${CMAKE_COMMAND} -E copy ${PYTHON_SOURCE_DIR}/openvino/test_utils/__init__.py ${CMAKE_LIBRARY_OUTPUT_DIRECTORY}/__init__.py + ) add_clang_format_target(${TARGET_NAME}_clang FOR_TARGETS ${TARGET_NAME} - EXCLUDE_PATTERNS ".*\\.cxx;.*\\.pxd;.*\\.pyx") + EXCLUDE_PATTERNS ".*\\.cxx") # install @@ -61,7 +58,7 @@ install(TARGETS ${TARGET_NAME} LIBRARY DESTINATION ${PYTHON_BRIDGE_CPACK_PATH}/${PYTHON_VERSION}/openvino/test_utils COMPONENT tests EXCLUDE_FROM_ALL) -install(PROGRAMS __init__.py +install(PROGRAMS ${PYTHON_SOURCE_DIR}/openvino/test_utils/__init__.py DESTINATION ${PYTHON_BRIDGE_CPACK_PATH}/${PYTHON_VERSION}/openvino/test_utils COMPONENT tests EXCLUDE_FROM_ALL) diff --git a/src/bindings/python/src/pyopenvino/test_utils/test_utils.cpp b/src/bindings/python/src/pyopenvino/test_utils/test_utils.cpp new file mode 100644 index 00000000000..7a232b1e0a4 --- /dev/null +++ b/src/bindings/python/src/pyopenvino/test_utils/test_utils.cpp @@ -0,0 +1,28 @@ +// Copyright (C) 2021 Intel Corporation +// SPDX-License-Identifier: Apache-2.0 +// + +#include + +#include + +#include "common_test_utils/ngraph_test_utils.hpp" + +namespace py = pybind11; + +PYBIND11_MODULE(test_utils_api, m) { + m.def( + "compare_functions", + [](const ov::Function& lhs, const ov::Function& rhs) { + const auto lhs_ptr = std::const_pointer_cast(lhs.shared_from_this()); + const auto rhs_ptr = std::const_pointer_cast(rhs.shared_from_this()); + + const auto fc = FunctionsComparator::with_default() + .enable(FunctionsComparator::ATTRIBUTES) + .enable(FunctionsComparator::CONST_VALUES); + const auto results = fc.compare(lhs_ptr, rhs_ptr); + return std::make_pair(results.valid, results.message); + }, + py::arg("lhs"), + py::arg("rhs")); +} diff --git a/src/bindings/python/tests/test_utils/test_utils.py b/src/bindings/python/tests/test_utils/test_utils.py new file mode 100644 index 00000000000..b312689aaa7 --- /dev/null +++ b/src/bindings/python/tests/test_utils/test_utils.py @@ -0,0 +1,26 @@ +# Copyright (C) 2021 Intel Corporation +# SPDX-License-Identifier: Apache-2.0 + +from openvino.runtime import Function +from openvino.runtime.impl import Shape, Type +from openvino.runtime.impl.op import Parameter +import openvino.runtime.opset8 as ops + + +def get_test_function(): + element_type = Type.f32 + param = Parameter(element_type, Shape([1, 3, 22, 22])) + relu = ops.relu(param) + func = Function([relu], [param], "test") + assert func is not None + return func + + +def test_compare_functions(): + try: + from openvino.test_utils import compare_functions + func = get_test_function() + status, msg = compare_functions(func, func) + assert status + except RuntimeError: + print("openvino.test_utils.compare_functions is not available") diff --git a/src/bindings/python/tox.ini b/src/bindings/python/tox.ini index c1a9b7eaafa..22a79879cd3 100644 --- a/src/bindings/python/tox.ini +++ b/src/bindings/python/tox.ini @@ -20,7 +20,7 @@ commands= flake8 {posargs:src/ setup.py} flake8 --ignore=D100,D101,D102,D103,D104,D105,D107,W503 tests/ tests_compatibility/ # ignore lack of docs in tests mypy --config-file=tox.ini {posargs:src/} - pytest --backend={env:NGRAPH_BACKEND} tests -v -k 'not _cuda' --ignore=tests/test_onnx/test_zoo_models.py --ignore=tests/test_inference_engine + pytest --backend={env:NGRAPH_BACKEND} tests -v -k 'not _cuda' --ignore=tests/test_onnx/test_zoo_models.py --ignore=tests/test_utils --ignore=tests/test_inference_engine pytest --backend={env:NGRAPH_BACKEND} tests_compatibility -v -k 'not _cuda' --ignore=tests_compatibility/test_onnx/test_zoo_models.py [testenv:zoo_models]