Skip to content

Commit ba1eb2f

Browse files
authored
Merge pull request #429 from Cytnx-dev/dev-master
merge dev-master
2 parents da532f7 + e518b8b commit ba1eb2f

File tree

164 files changed

+4959
-27
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

164 files changed

+4959
-27
lines changed
Lines changed: 100 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,100 @@
1+
name: Tests and Codecov
2+
3+
on:
4+
workflow_dispatch:
5+
6+
jobs:
7+
BuildAndTest:
8+
runs-on: ubuntu-latest
9+
10+
defaults:
11+
run:
12+
shell: bash -l {0}
13+
14+
steps:
15+
- uses: actions/checkout@v3
16+
17+
- uses: conda-incubator/setup-miniconda@v2
18+
with:
19+
# Specify python version your environment will have. Remember to quote this, or
20+
# YAML will think you want python 3.1 not 3.10
21+
python-version: "3.11"
22+
# This uses *miniforge*, rather than *minicond*. The primary difference is that
23+
# the defaults channel is not enabled at all
24+
miniforge-version: latest
25+
# These properties enable the use of mamba, which is much faster and far less error
26+
# prone than conda while being completely compatible with the conda CLI
27+
use-mamba: true
28+
mamba-version: "*"
29+
30+
- name: Install dependencies
31+
shell: bash -l {0}
32+
run: |
33+
mamba install _openmp_mutex=*=*_llvm cmake make boost git compilers numpy mkl mkl-include mkl-service pybind11 libblas=*=*mkl beartype
34+
mamba install gcovr gtest
35+
36+
- name: CPU info
37+
shell: bash -l {0}
38+
run: lscpu
39+
40+
- name: Configure CMake
41+
shell: bash -l {0}
42+
run: cmake -S ${{github.workspace}} -B ${{github.workspace}}/build -DCMAKE_INSTALL_PREFIX=/home/runner/work/Cytnx_lib -DUSE_MKL=on -DUSE_HPTT=on -DHPTT_ENABLE_FINE_TUNE=on -DHPTT_ENABLE_AVX=off -DBUILD_PYTHON=on -DCMAKE_EXPORT_COMPILE_COMMANDS=1 -DRUN_TESTS=on
43+
44+
- name: Build
45+
shell: bash -l {0}
46+
working-directory: ${{github.workspace}}/build
47+
run: |
48+
cmake --version
49+
cmake --build . -j `nproc`
50+
51+
- name: Install
52+
shell: bash -l {0}
53+
working-directory: ${{github.workspace}}/build
54+
run: |
55+
make install
56+
57+
- name: Set python path
58+
run: |
59+
echo "PYTHONPATH=/home/runner/work/Cytnx_lib" >> $GITHUB_ENV
60+
61+
- name: Test with pytest
62+
shell: bash -l {0}
63+
run: |
64+
pip install pytest pytest-cov
65+
pytest pytests/ --doctest-modules --junitxml=junit/test-results.xml --cov=com --cov-report=xml --cov-report=html
66+
67+
# - name: Run CTest
68+
# shell: bash -l {0}
69+
# working-directory: ${{github.workspace}}/build
70+
# run: GTEST_COLOR=1 ctest --output-on-failure --output-junit junit.xml
71+
72+
# - name: Run gcovr
73+
# shell: bash -l {0}
74+
# working-directory: ${{github.workspace}}/build
75+
# run: |
76+
# gcovr -r .. . --xml gcovr.xml -e ".*_deps.*$"
77+
78+
# - name: Upload coverage to Codecov
79+
# uses: codecov/codecov-action@v3
80+
# with:
81+
# #token: ${{ secrets.CODECOV_TOKEN }} # not required for public repos
82+
# #directory: ${{runner.workspace}}/build
83+
# files: ${{github.workspace}}/build/gcovr.xml # optional
84+
# #working-directory: ${{runner.workspace}}/build
85+
# #root_dir: ${{runner.workspace}}
86+
# fail_ci_if_error: true # optional (default = false)
87+
# verbose: true # optional (default = false)
88+
# #version: "v0.1.15"
89+
90+
#- name: Upload gcovr files
91+
# uses: actions/upload-artifact@v3
92+
# with:
93+
# name: CMakeError.log
94+
# path: /home/runner/work/Cytnx/Cytnx/build/CMakeFiles/CMakeError.log
95+
96+
#- name: Upload junit files
97+
# uses: actions/upload-artifact@v3
98+
# with:
99+
# name: junit_xml
100+
# path: ${{github.workspace}}/build/junit.xml

.github/workflows/ci-cmake_tests.yml

Lines changed: 19 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -34,8 +34,9 @@ jobs:
3434
- name: Install dependencies
3535
shell: bash -l {0}
3636
run: |
37-
mamba install _openmp_mutex=*=*_llvm cmake make boost git compilers numpy mkl mkl-include mkl-service pybind11 libblas=*=*mkl
37+
mamba install _openmp_mutex=*=*_llvm cmake make boost git compilers numpy mkl mkl-include mkl-service pybind11 libblas=*=*mkl beartype
3838
mamba install gcovr gtest
39+
mamba install pytest pytest-cov
3940
4041
- name: CPU info
4142
shell: bash -l {0}
@@ -64,9 +65,9 @@ jobs:
6465
gcovr -r .. . --xml gcovr.xml -e ".*_deps.*$"
6566
6667
- name: Upload coverage to Codecov
67-
uses: codecov/codecov-action@v3
68+
uses: codecov/codecov-action@v4
6869
with:
69-
#token: ${{ secrets.CODECOV_TOKEN }} # not required for public repos
70+
token: ${{ secrets.CODECOV_TOKEN }} # not required for public repos
7071
#directory: ${{runner.workspace}}/build
7172
files: ${{github.workspace}}/build/gcovr.xml # optional
7273
#working-directory: ${{runner.workspace}}/build
@@ -75,6 +76,21 @@ jobs:
7576
verbose: true # optional (default = false)
7677
#version: "v0.1.15"
7778

79+
- name: Install for python tests
80+
shell: bash -l {0}
81+
working-directory: ${{github.workspace}}/build
82+
run: |
83+
make install
84+
85+
- name: Set python path
86+
shell: bash -l {0}
87+
run: |
88+
echo "PYTHONPATH=/home/runner/work/Cytnx_lib" >> $GITHUB_ENV
89+
90+
- name: Test with pytest
91+
shell: bash -l {0}
92+
run: |
93+
pytest pytests/ --doctest-modules --junitxml=junit/test-results.xml --cov=com --cov-report=xml --cov-report=html
7894
#- name: Upload gcovr files
7995
# uses: actions/upload-artifact@v3
8096
# with:

CMakeLists.txt

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -231,7 +231,9 @@ endif()
231231
# ## Python wrapper
232232
# #######
233233
IF(BUILD_PYTHON)
234-
find_package(PythonInterp REQUIRED)
234+
# PythonInterp is removed in newer version of cmake
235+
# find_package(PythonInterp REQUIRED)
236+
find_package (Python COMPONENTS Interpreter Development)
235237
find_package(pybind11 REQUIRED)
236238

237239
if(NOT pybind11_FOUND)

Install.sh

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,8 @@
33
#=========================================================
44
# [Note] Set the destination path for installation in Ins_dest
55
#----------------------------------------------
6-
Ins_dest="/usr/local/cytnx"
6+
# Ins_dest="/usr/local/cytnx"
7+
Ins_dest="~/Cytnx_lib"
78
FLAG="${FLAG} -DCMAKE_INSTALL_PREFIX=${Ins_dest}"
89
#-----------------------------------------------
910

@@ -18,7 +19,7 @@ FLAG="${FLAG} -DCMAKE_INSTALL_PREFIX=${Ins_dest}"
1819
# Please follow the guide from official mkl/oneMKL "post-installation" part
1920
# to source the proper setvars.sh and/or vars.sh
2021
#---------------------------
21-
FLAG="${FLAG} -DUSE_MKL=OFF"
22+
FLAG="${FLAG} -DUSE_MKL=ON"
2223
#---------------------------
2324
# 2-b) use OpenBLAS (DEFAULT = on (by settung DUSE_MKL=OFF above))
2425
# [Note] By default it will automatically find openblas installed
@@ -154,7 +155,7 @@ FLAG="${FLAG} -DUSE_OMP=OFF"
154155
#=========================================================
155156
# [Note] Wheather to run cytnx tests (DEFAULT = OFF)
156157
#-----------------------------------
157-
DRUN_TESTS=OFF
158+
DRUN_TESTS=ON
158159
FLAG="${FLAG} -DRUN_TESTS=${DRUN_TESTS}"
159160
#-----------------------------------
160161

@@ -190,15 +191,16 @@ FLAG="${FLAG} -DUSE_DEBUG=OFF"
190191
# Build commands
191192
#=========================================================
192193
echo ${FLAG}
193-
# rm -rf build
194+
rm -rf build
194195
mkdir build
195196
cd build
196197
cmake ../ ${FLAG} #-DDEV_MODE=on
197-
make -j${nproc}
198+
make -j`nproc`
198199
make install
199-
#if DRUN_TESTS=ON, run tests
200-
shopt -s nocasematch
201-
case "${DRUN_TESTS}" in
202-
"ON" ) ctest; gcovr -r ../ . --html-details cov.html;;
203-
*) echo "Tests are skipped";;
204-
esac
200+
# if DRUN_TESTS=ON, run tests
201+
# ctest
202+
# shopt -s nocasematch
203+
# case "${DRUN_TESTS}" in
204+
# "ON" ) ctest; gcovr -r ../ . --html-details cov.html;;
205+
# *) echo "Tests are skipped";;
206+
# esac

cytnx/Network_conti.py

Lines changed: 19 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,26 @@
11
from .utils import *
22
from cytnx import *
33

4-
import imp
5-
try:
6-
imp.find_module('graphviz')
7-
from .NetGraph import *
8-
except ImportError:
4+
# import imp
5+
# try:
6+
# imp.find_module('graphviz')
7+
# from .NetGraph import *
8+
# except ImportError:
9+
# from .NetGraph_empty import *
10+
11+
import importlib
12+
spec = importlib.util.find_spec("graphviz")
13+
if spec is None:
14+
# print("Can't find the graphviz module.")
915
from .NetGraph_empty import *
16+
else:
17+
# If you chose to perform the actual import ...
18+
module = importlib.util.module_from_spec(spec)
19+
spec.loader.exec_module(module)
20+
21+
# Adding the module to sys.modules is optional.
22+
#sys.modules["graphviz"] = module
23+
from .NetGraph import *
1024

1125
import numpy as np
1226

example/Accessor/ex.cpp.out

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
2+
Total elem: 24
3+
type : Double (Float64)
4+
cytnx device: CPU
5+
Shape : (2,3,4)
6+
[[[0.00000e+00 1.00000e+00 2.00000e+00 3.00000e+00 ]
7+
[4.00000e+00 5.00000e+00 6.00000e+00 7.00000e+00 ]
8+
[8.00000e+00 9.00000e+00 1.00000e+01 1.10000e+01 ]]
9+
[[1.20000e+01 1.30000e+01 1.40000e+01 1.50000e+01 ]
10+
[1.60000e+01 1.70000e+01 1.80000e+01 1.90000e+01 ]
11+
[2.00000e+01 2.10000e+01 2.20000e+01 2.30000e+01 ]]]
12+
13+
14+
15+
Total elem: 6
16+
type : Double (Float64)
17+
cytnx device: CPU
18+
Shape : (3,2)
19+
[[0.00000e+00 1.00000e+00 ]
20+
[4.00000e+00 5.00000e+00 ]
21+
[8.00000e+00 9.00000e+00 ]]

example/Accessor/example.cpp

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
#include "cytnx.hpp"
2+
#include <iostream>
3+
4+
using namespace cytnx;
5+
using namespace std;
6+
int main() {
7+
// 1. handy alias:
8+
typedef Accessor ac;
9+
10+
/*
11+
2. Create a Tensor with
12+
shape (3,4,5),
13+
dtype =Type.Double [default],
14+
device=Device.cpu [default]
15+
*/
16+
Tensor A = cytnx::arange(24);
17+
A.reshape_({2, 3, 4});
18+
cout << A << endl;
19+
20+
/*
21+
3. Accessing elements using accessor
22+
This is similar as python slices.
23+
-> A[0,:,0:2:1]
24+
25+
*/
26+
Tensor B = A(0, ac::all(), ac::range(0, 2, 1));
27+
cout << B << endl;
28+
29+
/* [Note] Conversion from python slice to ac:
30+
[::x] = ac::step(x)
31+
[a::x] = ac::tilend(a,x)
32+
[a::] = ac::tilend(a)
33+
[:b:] = ac::range(0,b,1)
34+
[a:b:x] = ac::range(a,b,x)
35+
*/
36+
37+
return 0;
38+
}

example/Accessor/example.cpp.out

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
2+
Total elem: 24
3+
type : Double (Float64)
4+
cytnx device: CPU
5+
Shape : (2,3,4)
6+
[[[0.00000e+00 1.00000e+00 2.00000e+00 3.00000e+00 ]
7+
[4.00000e+00 5.00000e+00 6.00000e+00 7.00000e+00 ]
8+
[8.00000e+00 9.00000e+00 1.00000e+01 1.10000e+01 ]]
9+
[[1.20000e+01 1.30000e+01 1.40000e+01 1.50000e+01 ]
10+
[1.60000e+01 1.70000e+01 1.80000e+01 1.90000e+01 ]
11+
[2.00000e+01 2.10000e+01 2.20000e+01 2.30000e+01 ]]]
12+
13+
14+
15+
Total elem: 6
16+
type : Double (Float64)
17+
cytnx device: CPU
18+
Shape : (3,2)
19+
[[0.00000e+00 1.00000e+00 ]
20+
[4.00000e+00 5.00000e+00 ]
21+
[8.00000e+00 9.00000e+00 ]]

example/Accessor/example.py

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
import sys
2+
from pathlib import Path
3+
home = str(Path.home())
4+
sys.path.append(home + '/Cytnx_lib')
5+
from cytnx import *
6+
7+
A = arange(24);
8+
A.reshape_(2,3,4);
9+
print(A)
10+
11+
12+
B = A[0,:,0:2:1]
13+
print(B)

example/Accessor/example.py.out

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
2+
Total elem: 24
3+
type : Double (Float64)
4+
cytnx device: CPU
5+
Shape : (2,3,4)
6+
[[[0.00000e+00 1.00000e+00 2.00000e+00 3.00000e+00 ]
7+
[4.00000e+00 5.00000e+00 6.00000e+00 7.00000e+00 ]
8+
[8.00000e+00 9.00000e+00 1.00000e+01 1.10000e+01 ]]
9+
[[1.20000e+01 1.30000e+01 1.40000e+01 1.50000e+01 ]
10+
[1.60000e+01 1.70000e+01 1.80000e+01 1.90000e+01 ]
11+
[2.00000e+01 2.10000e+01 2.20000e+01 2.30000e+01 ]]]
12+
13+
14+
15+
16+
Total elem: 6
17+
type : Double (Float64)
18+
cytnx device: CPU
19+
Shape : (3,2)
20+
[[0.00000e+00 1.00000e+00 ]
21+
[4.00000e+00 5.00000e+00 ]
22+
[8.00000e+00 9.00000e+00 ]]

0 commit comments

Comments
 (0)