From a148594e5389842108dbd849a2b538c63e8ce813 Mon Sep 17 00:00:00 2001 From: bruno Date: Tue, 27 Feb 2024 09:23:30 +0100 Subject: [PATCH] add a job to test KNI in pack-nsis --- .github/actions/test-kni/action.yml | 55 +++++++++++++++-------- .github/workflows/pack-nsis.yml | 21 ++++++++- .github/workflows/update-kni-tutorial.yml | 2 +- packaging/common/KNI/README.txt.in | 43 +++++++++--------- packaging/common/KNI/build-c-windows.cmd | 6 ++- packaging/common/KNI/build-java.sh | 5 +-- packaging/common/KNI/run-java-linux.sh | 3 +- packaging/common/KNI/run-java-windows.cmd | 3 ++ packaging/common/KNI/run-java-windows.sh | 1 - packaging/common/KNI/template-README.md | 39 ++++++++-------- packaging/install.cmake | 2 +- packaging/packaging.cmake | 6 +-- 12 files changed, 113 insertions(+), 73 deletions(-) create mode 100644 packaging/common/KNI/run-java-windows.cmd delete mode 100644 packaging/common/KNI/run-java-windows.sh diff --git a/.github/actions/test-kni/action.yml b/.github/actions/test-kni/action.yml index 6953d6dd6..07d2f2613 100644 --- a/.github/actions/test-kni/action.yml +++ b/.github/actions/test-kni/action.yml @@ -33,13 +33,23 @@ runs: shell: cmd run: | call "C:\\Program Files\\Microsoft Visual Studio\\2022\\Enterprise\\VC\\Auxiliary\\Build\\vcvars64.bat" - set KNI_HOME=%RUNNER_TEMP%\\KNI cd tutorial - call %GITHUB_WORKSPACE%/packaging/common/KNI/build-c--windows.cmd - - name: Test mono-table example + set KNI_HOME=%GITHUB_WORKSPACE%/KNI + call %GITHUB_WORKSPACE%/packaging/common/KNI/build-c-windows.cmd + - name: Run mono-table example (Linux) + if: runner.os == 'Linux' + shell: bash + run: | + ./tutorial/KNIRecodeFile tutorial/data/ModelingIris.kdic SNB_Iris tutorial/data/Iris.txt R_Iris.txt || true + - name: Run mono-table example (Windows) + if: runner.os == 'Windows' + shell: cmd + run: | + set path=%GITHUB_WORKSPACE%/KNI/bin;%path% + call %GITHUB_WORKSPACE%/tutorial/KNIRecodeFile.exe tutorial/data/ModelingIris.kdic SNB_Iris tutorial/data/Iris.txt R_Iris.txt + - name: Check mono-table example shell: bash run: | - ./tutorial/KNIRecodeFile tutorial/data/ModelingIris.kdic SNB_Iris tutorial/data/Iris.txt R_Iris.txt if [ ! -f R_Iris.txt ] ; then echo "::error::R_Iris.txt is missing" @@ -49,14 +59,25 @@ runs: then echo "Mono table recoding is OK" else - echo "::error::Recoding issue with Iris.txt" + echo "::error::Recoding issue with Iris.txt" false fi - - name: Test multi-tables example + - name: Run multi-tables example (Linux) + if: runner.os == 'Linux' shell: bash run: |- ./tutorial/KNIRecodeMTFiles -d tutorial/data/ModelingSpliceJunction.kdic SNB_SpliceJunction \ - -i tutorial/data/SpliceJunction.txt 1 -s DNA tutorial/data/SpliceJunctionDNA.txt 1 -o R_SpliceJunction.txt + -i tutorial/data/SpliceJunction.txt 1 -s DNA tutorial/data/SpliceJunctionDNA.txt 1 -o R_SpliceJunction.txt || true + - name: Run multi-tables example (Windows) + if: runner.os == 'Windows' + shell: cmd + run: |- + set path=%GITHUB_WORKSPACE%/KNI/bin;%path% + call %GITHUB_WORKSPACE%/tutorial/KNIRecodeMTFiles.exe -d tutorial/data/ModelingSpliceJunction.kdic SNB_SpliceJunction ^ + -i tutorial/data/SpliceJunction.txt 1 -s DNA tutorial/data/SpliceJunctionDNA.txt 1 -o R_SpliceJunction.txt + - name: Check multi-table example + shell: bash + run: | if [ ! -f R_SpliceJunction.txt ] ; then echo "::error::R_SpliceJunction.txt is missing" @@ -70,18 +91,14 @@ runs: false fi - name: setup jna - uses: nvoxland/jar-download-action@v1 - with: - groupId: net.java.dev.jna - artifactId: jna - version: 5.13.0 - outputDirectory: ./tutorial/java/ + shell: bash + run: | + curl https://repo1.maven.org/maven2/net/java/dev/jna/jna/5.13.0/jna-5.13.0.jar --output ./tutorial/jna.jar - name: Compile java example shell: bash run: | cd tutorial bash $GITHUB_WORKSPACE/packaging/common/KNI/build-java.sh - cd $GITHUB_WORKSPACE - name: Run java example (Linux) shell: bash if: runner.os == 'Linux' @@ -89,11 +106,12 @@ runs: cd tutorial bash $GITHUB_WORKSPACE/packaging/common/KNI/run-java-linux.sh - name: Test java example (Windows) - shell: bash + shell: cmd if: runner.os == 'Windows' run: | cd tutorial - bash $GITHUB_WORKSPACE/packaging/common/KNI/run-java-windows.sh + set KNI_HOME=%GITHUB_WORKSPACE%/KNI + call %GITHUB_WORKSPACE%/packaging/common/KNI/run-java-windows.cmd - name: Check java results shell: bash run: |- @@ -102,10 +120,11 @@ runs: echo "::error::R_Iris_java.txt is missing" false fi - if diff -q tutorial/R_Iris_java.txt $GITHUB_WORKSPACE/packaging/common/KNI/results.ref/R_Iris.txt > /dev/null ; + if diff -q tutorial/R_Iris_java.txt packaging/common/KNI/results.ref/R_Iris.txt > /dev/null ; then echo "Mono table recoding is OK" + true else - echo "::error::Recoding issue with java" + echo "::error::Recoding issue with java" false fi diff --git a/.github/workflows/pack-nsis.yml b/.github/workflows/pack-nsis.yml index fc558f61f..711f83e59 100644 --- a/.github/workflows/pack-nsis.yml +++ b/.github/workflows/pack-nsis.yml @@ -96,7 +96,7 @@ jobs: with: name: KNI path: ./build/windows-msvc-release/packages/KNI-${{ env.KHIOPS_VERSION }}.zip - test: + test-khiops: needs: build runs-on: windows-2019 steps: @@ -123,10 +123,27 @@ jobs: uses: actions/checkout@v4 - name: Test the installation uses: ./.github/actions/test-khiops-install + test-kni: + needs: build + runs-on: windows-2022 + steps: + - name: Checkout sources + uses: actions/checkout@v4 + - name: Download KNI zip + uses: actions/download-artifact@v4 + with: + name: KNI + - name: Install KNI + shell: bash + run: | + 7z x KNI-${{ needs.build.outputs.khiops-version }}.zip -o${GITHUB_WORKSPACE}/KNI + - name: Test KNI zip + uses: ./.github/actions/test-kni + # Release is only executed on tags release: if: github.ref_type == 'tag' - needs: [build, test] + needs: [build, test-khiops, test-kni] runs-on: ubuntu-latest permissions: contents: write diff --git a/.github/workflows/update-kni-tutorial.yml b/.github/workflows/update-kni-tutorial.yml index 8f939d38a..c58093003 100644 --- a/.github/workflows/update-kni-tutorial.yml +++ b/.github/workflows/update-kni-tutorial.yml @@ -1,5 +1,5 @@ --- -name: Update KhiopsNativeInterface-tutorial repository +name: Update KNI-tutorial repository on: workflow_dispatch: jobs: diff --git a/packaging/common/KNI/README.txt.in b/packaging/common/KNI/README.txt.in index 690cba173..66d6a94de 100644 --- a/packaging/common/KNI/README.txt.in +++ b/packaging/common/KNI/README.txt.in @@ -2,28 +2,31 @@ Khiops Native Interface @PROJECT_VERSION@ ============================== The purpose of Khiops Native Interface (KNI) is to allow a deeper integration -of Khiops in information systems, by mean of the C programming language, using -a dynamic link library (DLL). This relates specially to the problem of model -deployment, which otherwise requires the use of input and output data files -when using directly the Khiops tool in batch mode. See Khiops Guide for an -introduction to dictionary files, dictionaries, database files and deployment. - -The Khiops deployment features are thus made public through an API with a DLL. +of Khiops in information systems, by means of the C programming language, using +a shared library (`.dll` in Windows or `.so` in Linux). This relates specially +to the problem of model deployment, which otherwise requires the use of input +and output data files when using directly the Khiops tool in batch mode. See +Khiops Guide for an introduction to dictionary files, dictionaries, database files +and deployment. + +The Khiops deployment API is made public through a shared library. Therefore, a Khiops model can be deployed directly from any programming language, such as C, C++, Java, Python, Matlab, etc. This enables real time model deployment without the overhead of temporary data files or launching -executables. This is critical for certain applications in marketing or targeted -advertising on the web. +executables. This is critical for certain applications, such as marketing or +targeted advertising on the web.. All KNI functions are C functions for easy use with other programming languages. -They return a positive or null value in case of success, and a negative error -code in case of failure. The functions are not reentrant (thread-safe): the DLL +They return a positive or zero value in case of success, and a negative error +code in case of failure. + +**Warning** The functions are not reentrant (thread-safe): the library can be used simultaneously by several executables, but not simultaneously by several threads in the same executable. -See KhiopsNativeInterface.h for a detailed description of KNI functions and go -to https://github.com/KhiopsML/KNI-tutorial/tree/@PROJECT_VERSION@ to see how -to use the DLL with Java and C. +See KhiopsNativeInterface.h for a detailed description of KNI functions and +for examples of use in Java and C go to the KNI tutorial repo +https://github.com/KhiopsML/KNI-tutorial/tree/@PROJECT_VERSION@. Files ----- @@ -32,12 +35,12 @@ README.txt: this file LICENSE: license file -bin: DLL for windows - KhiopsNativeInterface64.dll: windows 64 bits - +bin: DLL for Windows + KhiopsNativeInterface.dll: windows 64 bits + include: include file, with a detailed description of KNI functions KhiopsNativeInterface.h -lib: - - librairy for windows C/C++ bindings: KhiopsNativeInterface64.lib (64 bits) - - shared library for linux libKhiopsNativeInterface.so.@PROJECT_VERSION@ +lib: + - library for Windows C/C++ bindings: KhiopsNativeInterface.lib (64 bits) + - shared library for Linux libKhiopsNativeInterface.so.@PROJECT_VERSION@ \ No newline at end of file diff --git a/packaging/common/KNI/build-c-windows.cmd b/packaging/common/KNI/build-c-windows.cmd index ef3535a4a..66c9712cd 100644 --- a/packaging/common/KNI/build-c-windows.cmd +++ b/packaging/common/KNI/build-c-windows.cmd @@ -1,2 +1,4 @@ -cl cpp/KNIRecodeFile.c %KNI_HOME%\lib\KhiopsNativeInterface64.lib -I %KNI_HOME%\include /link "/LIBPATH:%KNI_HOME%\bin" -cl cpp/KNIRecodeMTFiles.c %KNI_HOME%\lib\KhiopsNativeInterface64.lib -I %KNI_HOME%\include /link "/LIBPATH:%KNI_HOME%\bin" \ No newline at end of file +cl cpp/KNIRecodeFile.c %KNI_HOME%\lib\KhiopsNativeInterface.lib ^ + -I %KNI_HOME%\include /link "/LIBPATH:%KNI_HOME%\bin" +cl cpp/KNIRecodeMTFiles.c %KNI_HOME%\lib\KhiopsNativeInterface.lib ^ + -I %KNI_HOME%\include /link "/LIBPATH:%KNI_HOME%\bin" \ No newline at end of file diff --git a/packaging/common/KNI/build-java.sh b/packaging/common/KNI/build-java.sh index c4919695c..2cfcc2588 100644 --- a/packaging/common/KNI/build-java.sh +++ b/packaging/common/KNI/build-java.sh @@ -1,3 +1,2 @@ -cd java -javac -cp jna-5.13.0.jar KNIRecodeFile.java KNI.java -jar cf kni.jar *.class \ No newline at end of file +javac -cp jna.jar java/KNIRecodeFile.java java/KNI.java +jar cf kni.jar -C java KNI.class -C java KNIRecodeFile.class diff --git a/packaging/common/KNI/run-java-linux.sh b/packaging/common/KNI/run-java-linux.sh index f031f8366..078f5dc2c 100644 --- a/packaging/common/KNI/run-java-linux.sh +++ b/packaging/common/KNI/run-java-linux.sh @@ -1 +1,2 @@ -java -cp java/kni.jar:java/jna-5.13.0.jar KNIRecodeFile data/ModelingIris.kdic SNB_Iris data/Iris.txt R_Iris_java.txt 2>&1 \ No newline at end of file +java -cp kni.jar:jna.jar KNIRecodeFile data/ModelingIris.kdic SNB_Iris \ + data/Iris.txt R_Iris_java.txt \ No newline at end of file diff --git a/packaging/common/KNI/run-java-windows.cmd b/packaging/common/KNI/run-java-windows.cmd new file mode 100644 index 000000000..af27fba2d --- /dev/null +++ b/packaging/common/KNI/run-java-windows.cmd @@ -0,0 +1,3 @@ +set path=%KNI_HOME%/bin;%path% +java -cp kni.jar;jna.jar KNIRecodeFile data/ModelingIris.kdic ^ + SNB_Iris data/Iris.txt R_Iris_java.txt \ No newline at end of file diff --git a/packaging/common/KNI/run-java-windows.sh b/packaging/common/KNI/run-java-windows.sh deleted file mode 100644 index 56aeff0f5..000000000 --- a/packaging/common/KNI/run-java-windows.sh +++ /dev/null @@ -1 +0,0 @@ -java -cp java/kni.jar;java/jna-5.13.0.jar KNIRecodeFile data/ModelingIris.kdic SNB_Iris data/Iris.txt R_Iris_java.txt 2>&1 \ No newline at end of file diff --git a/packaging/common/KNI/template-README.md b/packaging/common/KNI/template-README.md index 26ad184a7..7a5d92998 100644 --- a/packaging/common/KNI/template-README.md +++ b/packaging/common/KNI/template-README.md @@ -3,19 +3,16 @@ This project provides all the basics to use the Khiops Native Interface (KNI): installation and examples. -The purpose of KNI is to allow a deeper integration of Khiops in information systems, by mean of the C programming language, using a dynamic link library (DLL). This relates specially to the problem of model deployment, which otherwise requires the use of input and output data files when using directly the Khiops tool in batch mode. See Khiops Guide for an introduction to dictionary files, dictionaries, database files and deployment. +The purpose of KNI is to allow a deeper integration of Khiops in information systems, by mean of the C programming language, using a shared library (`.dll` in Windows, `.so` in Linux). This relates specially to the problem of model deployment, which otherwise requires the use of input and output data files when using directly the Khiops tool in batch mode. See Khiops Guide for an introduction to dictionary files, dictionaries, database files and deployment. -The Khiops deployment features are thus made public through an API with a DLL. Therefore, a Khiops model can be deployed directly from any programming language, such as C, C++, Java, Python, Matlab, etc. This enables real time model deployment without the overhead of temporary data files or launching executables. This is critical for certain applications in marketing or targeted advertising on the web. +The Khiops deployment API is thus made public through a shared library. Therefore, a Khiops model can be deployed directly from any programming language, such as C, C++, Java, Python, Matlab, etc. This enables real time model deployment without the overhead of temporary data files or launching executables. This is critical for certain applications, such as marketing or targeted advertising on the web.. -All KNI functions are C functions for easy use with other programming languages. They return a positive or null value in case of success, and a negative error code in case of failure. +All KNI functions are C functions for easy use with other programming languages. They return a positive or zero value in case of success, and a negative error code in case of failure. See [KhiopsNativeInterface.h](include/KhiopsNativeInterface.h) for a detailed description of KNI functions. > [!CAUTION] -> The functions are not reentrant (thread-safe): the DLL can be used simultaneously by several executables, but not simultaneously by several threads in the same executable. - - - +> The functions are not reentrant (thread-safe): the library can be used simultaneously by several executables, but not simultaneously by several threads in the same executable. # KNI installation @@ -25,7 +22,7 @@ Download [KNI-@PROJECT_VERSION@.zip](https://github.com/KhiopsML/khiops/releases ## Linux -On linux, go to the [release page](https://github.com/KhiopsML/khiops/releases/tag/@PROJECT_VERSION@/) and download the kni package. The name of the package begins with **kni** and ends with the **code name** of the OS. The code name is in the release file of the distribution (here, it is jammy): +On Linux, go to the [release page](https://github.com/KhiopsML/khiops/releases/tag/@PROJECT_VERSION@/) and download the KNI package. The name of the package begins with **kni** and ends with the **code name** of the OS. The code name is in the release file of the distribution (here, it is "jammy"): ```bash $ cat /etc/os-release PRETTY_NAME="Ubuntu 22.04.4 LTS" @@ -41,9 +38,9 @@ BUG_REPORT_URL="https://bugs.launchpad.net/ubuntu/" PRIVACY_POLICY_URL="https://www.ubuntu.com/legal/terms-and-policies/privacy-policy" UBUNTU_CODENAME=jammy ``` -Download the package according to the code name of your OS and install it with dpkg or yum: -- on debian-like distros: `sudo dpkg -i kni*.deb` -- on fedora-like distros: `sudo yum localinstall kni*.rpm` +Download the package according to the code name of your OS and install it with `dpkg` or `yum`: +- on Debian-like distros: `sudo dpkg -i kni*.deb` +- on Fedora-like distros: `sudo yum localinstall kni*.rpm` # Application examples @@ -56,7 +53,7 @@ KNIRecodeFile [Error f # The error file may be useful for debugging purposes. It is optional and may be empty. ``` -A more complex example (available only in C) is `KNIRecodeMTFiles`, it recodes a set of multi-tables input files to an output file. +A more complex example (available only in C) is `KNIRecodeMTFiles`, it recodes the input files of multi-table dataset to a single output file. ```bash KNIRecodeMTFiles @@ -76,13 +73,13 @@ The files are located in [cpp directory](cpp/). They allow to build `KNIRecodeFi ## Building the examples -On linux: +On Linux: ```bash @BUILD_C_LINUX@ ``` -On windows, open a "Visual Studio Developer Console" and run: +On Windows, open a "Visual Studio Developer Console" and run: ```cmd @BUILD_C_WINDOWS@ @@ -90,17 +87,17 @@ On windows, open a "Visual Studio Developer Console" and run: ## Launch -Recode the iris dataset from the data directory using the SNB_Iris dictionary. +Recode the "Iris" dataset from the data directory using the SNB_Iris dictionary. ```bash KNIRecodeFile data/ModelingIris.kdic SNB_Iris data/Iris.txt R_Iris.txt ``` -Recode the splice junction multi-table dataset using the SNB_SpliceJunction dictionary. +Recode the "Splice Junction" multi-table dataset using the `SNB_SpliceJunction` classifier dictionary. ```bash -KNIRecodeMTFiles -d data/ModelingSpliceJunction.kdic SNB_SpliceJunction -i .data/SpliceJunction.txt 1 \ - -s DNA data/SpliceJunctionDNA.txt 1 -o R_SpliceJunction.txt +KNIRecodeMTFiles -d data/ModelingSpliceJunction.kdic SNB_SpliceJunction \ + -i .data/SpliceJunction.txt 1 -s DNA data/SpliceJunctionDNA.txt 1 -o R_SpliceJunction.txt ``` # Example with Java @@ -109,7 +106,7 @@ The files are located in [java directory](java/). They allow to build `KNIRecode ## Building the examples -To compile Java files and create kni.jar file: +To compile Java files and create the `kni.jar` file: ```bash @BUILD_JAVA@ @@ -117,7 +114,7 @@ To compile Java files and create kni.jar file: ## Launch -Recodes the iris dataset from the data directory using the SNB_Iris dictionary. +Recodes the "Iris" dataset from the data directory using the `SNB_Iris` classifier dictionary. On Linux: @@ -127,6 +124,6 @@ On Linux: On Windows: -```bash +```cmd @RUN_JAVA_WINDOWS@ ``` diff --git a/packaging/install.cmake b/packaging/install.cmake index f247e9425..79ac5e4c7 100644 --- a/packaging/install.cmake +++ b/packaging/install.cmake @@ -50,7 +50,7 @@ file(READ ${PROJECT_SOURCE_DIR}/packaging/common/KNI/build-c-linux.sh BUILD_C_LI file(READ ${PROJECT_SOURCE_DIR}/packaging/common/KNI/build-c-windows.cmd BUILD_C_WINDOWS) file(READ ${PROJECT_SOURCE_DIR}/packaging/common/KNI/build-java.sh BUILD_JAVA) file(READ ${PROJECT_SOURCE_DIR}/packaging/common/KNI/run-java-linux.sh RUN_JAVA_LINUX) -file(READ ${PROJECT_SOURCE_DIR}/packaging/common/KNI/run-java-windows.sh RUN_JAVA_WINDOWS) +file(READ ${PROJECT_SOURCE_DIR}/packaging/common/KNI/run-java-windows.cmd RUN_JAVA_WINDOWS) configure_file(${PROJECT_SOURCE_DIR}/packaging/common/KNI/README.txt.in ${TMP_DIR}/kni.README.txt @ONLY NEWLINE_STYLE UNIX) diff --git a/packaging/packaging.cmake b/packaging/packaging.cmake index 831e41dde..a734d3aeb 100644 --- a/packaging/packaging.cmake +++ b/packaging/packaging.cmake @@ -45,11 +45,11 @@ The Khiops deployment features are thus made public through an API with a DLL. Therefore, a Khiops model can be deployed directly from any programming language, such as C, C++, Java, Python, Matlab, etc. This enables real time model deployment without the overhead of temporary data files or launching -executables. This is critical for certain applications in marketing or targeted -advertising on the web. +executables. This is critical for certain applications, such as marketing or +targeted advertising on the web. . All KNI functions are C functions for easy use with other programming languages. -They return a positive or null value in case of success, and a negative error +They return a positive or zero value in case of success, and a negative error code in case of failure. The functions are not reentrant (thread-safe): the DLL can be used simultaneously by several executables, but not simultaneously by several threads in the same executable.