Skip to content

Commit

Permalink
Merge pull request #429 from Cytnx-dev/dev-master
Browse files Browse the repository at this point in the history
merge dev-master
  • Loading branch information
jeffry1829 authored May 6, 2024
2 parents da532f7 + e518b8b commit ba1eb2f
Show file tree
Hide file tree
Showing 164 changed files with 4,959 additions and 27 deletions.
100 changes: 100 additions & 0 deletions .github/workflows/ci-cmake_pytests.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,100 @@
name: Tests and Codecov

on:
workflow_dispatch:

jobs:
BuildAndTest:
runs-on: ubuntu-latest

defaults:
run:
shell: bash -l {0}

steps:
- uses: actions/checkout@v3

- uses: conda-incubator/setup-miniconda@v2
with:
# Specify python version your environment will have. Remember to quote this, or
# YAML will think you want python 3.1 not 3.10
python-version: "3.11"
# This uses *miniforge*, rather than *minicond*. The primary difference is that
# the defaults channel is not enabled at all
miniforge-version: latest
# These properties enable the use of mamba, which is much faster and far less error
# prone than conda while being completely compatible with the conda CLI
use-mamba: true
mamba-version: "*"

- name: Install dependencies
shell: bash -l {0}
run: |
mamba install _openmp_mutex=*=*_llvm cmake make boost git compilers numpy mkl mkl-include mkl-service pybind11 libblas=*=*mkl beartype
mamba install gcovr gtest
- name: CPU info
shell: bash -l {0}
run: lscpu

- name: Configure CMake
shell: bash -l {0}
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

- name: Build
shell: bash -l {0}
working-directory: ${{github.workspace}}/build
run: |
cmake --version
cmake --build . -j `nproc`
- name: Install
shell: bash -l {0}
working-directory: ${{github.workspace}}/build
run: |
make install
- name: Set python path
run: |
echo "PYTHONPATH=/home/runner/work/Cytnx_lib" >> $GITHUB_ENV
- name: Test with pytest
shell: bash -l {0}
run: |
pip install pytest pytest-cov
pytest pytests/ --doctest-modules --junitxml=junit/test-results.xml --cov=com --cov-report=xml --cov-report=html
# - name: Run CTest
# shell: bash -l {0}
# working-directory: ${{github.workspace}}/build
# run: GTEST_COLOR=1 ctest --output-on-failure --output-junit junit.xml

# - name: Run gcovr
# shell: bash -l {0}
# working-directory: ${{github.workspace}}/build
# run: |
# gcovr -r .. . --xml gcovr.xml -e ".*_deps.*$"

# - name: Upload coverage to Codecov
# uses: codecov/codecov-action@v3
# with:
# #token: ${{ secrets.CODECOV_TOKEN }} # not required for public repos
# #directory: ${{runner.workspace}}/build
# files: ${{github.workspace}}/build/gcovr.xml # optional
# #working-directory: ${{runner.workspace}}/build
# #root_dir: ${{runner.workspace}}
# fail_ci_if_error: true # optional (default = false)
# verbose: true # optional (default = false)
# #version: "v0.1.15"

#- name: Upload gcovr files
# uses: actions/upload-artifact@v3
# with:
# name: CMakeError.log
# path: /home/runner/work/Cytnx/Cytnx/build/CMakeFiles/CMakeError.log

#- name: Upload junit files
# uses: actions/upload-artifact@v3
# with:
# name: junit_xml
# path: ${{github.workspace}}/build/junit.xml
22 changes: 19 additions & 3 deletions .github/workflows/ci-cmake_tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,9 @@ jobs:
- name: Install dependencies
shell: bash -l {0}
run: |
mamba install _openmp_mutex=*=*_llvm cmake make boost git compilers numpy mkl mkl-include mkl-service pybind11 libblas=*=*mkl
mamba install _openmp_mutex=*=*_llvm cmake make boost git compilers numpy mkl mkl-include mkl-service pybind11 libblas=*=*mkl beartype
mamba install gcovr gtest
mamba install pytest pytest-cov
- name: CPU info
shell: bash -l {0}
Expand Down Expand Up @@ -64,9 +65,9 @@ jobs:
gcovr -r .. . --xml gcovr.xml -e ".*_deps.*$"
- name: Upload coverage to Codecov
uses: codecov/codecov-action@v3
uses: codecov/codecov-action@v4
with:
#token: ${{ secrets.CODECOV_TOKEN }} # not required for public repos
token: ${{ secrets.CODECOV_TOKEN }} # not required for public repos
#directory: ${{runner.workspace}}/build
files: ${{github.workspace}}/build/gcovr.xml # optional
#working-directory: ${{runner.workspace}}/build
Expand All @@ -75,6 +76,21 @@ jobs:
verbose: true # optional (default = false)
#version: "v0.1.15"

- name: Install for python tests
shell: bash -l {0}
working-directory: ${{github.workspace}}/build
run: |
make install
- name: Set python path
shell: bash -l {0}
run: |
echo "PYTHONPATH=/home/runner/work/Cytnx_lib" >> $GITHUB_ENV
- name: Test with pytest
shell: bash -l {0}
run: |
pytest pytests/ --doctest-modules --junitxml=junit/test-results.xml --cov=com --cov-report=xml --cov-report=html
#- name: Upload gcovr files
# uses: actions/upload-artifact@v3
# with:
Expand Down
4 changes: 3 additions & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -231,7 +231,9 @@ endif()
# ## Python wrapper
# #######
IF(BUILD_PYTHON)
find_package(PythonInterp REQUIRED)
# PythonInterp is removed in newer version of cmake
# find_package(PythonInterp REQUIRED)
find_package (Python COMPONENTS Interpreter Development)
find_package(pybind11 REQUIRED)

if(NOT pybind11_FOUND)
Expand Down
24 changes: 13 additions & 11 deletions Install.sh
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@
#=========================================================
# [Note] Set the destination path for installation in Ins_dest
#----------------------------------------------
Ins_dest="/usr/local/cytnx"
# Ins_dest="/usr/local/cytnx"
Ins_dest="~/Cytnx_lib"
FLAG="${FLAG} -DCMAKE_INSTALL_PREFIX=${Ins_dest}"
#-----------------------------------------------

Expand All @@ -18,7 +19,7 @@ FLAG="${FLAG} -DCMAKE_INSTALL_PREFIX=${Ins_dest}"
# Please follow the guide from official mkl/oneMKL "post-installation" part
# to source the proper setvars.sh and/or vars.sh
#---------------------------
FLAG="${FLAG} -DUSE_MKL=OFF"
FLAG="${FLAG} -DUSE_MKL=ON"
#---------------------------
# 2-b) use OpenBLAS (DEFAULT = on (by settung DUSE_MKL=OFF above))
# [Note] By default it will automatically find openblas installed
Expand Down Expand Up @@ -154,7 +155,7 @@ FLAG="${FLAG} -DUSE_OMP=OFF"
#=========================================================
# [Note] Wheather to run cytnx tests (DEFAULT = OFF)
#-----------------------------------
DRUN_TESTS=OFF
DRUN_TESTS=ON
FLAG="${FLAG} -DRUN_TESTS=${DRUN_TESTS}"
#-----------------------------------

Expand Down Expand Up @@ -190,15 +191,16 @@ FLAG="${FLAG} -DUSE_DEBUG=OFF"
# Build commands
#=========================================================
echo ${FLAG}
# rm -rf build
rm -rf build
mkdir build
cd build
cmake ../ ${FLAG} #-DDEV_MODE=on
make -j${nproc}
make -j`nproc`
make install
#if DRUN_TESTS=ON, run tests
shopt -s nocasematch
case "${DRUN_TESTS}" in
"ON" ) ctest; gcovr -r ../ . --html-details cov.html;;
*) echo "Tests are skipped";;
esac
# if DRUN_TESTS=ON, run tests
# ctest
# shopt -s nocasematch
# case "${DRUN_TESTS}" in
# "ON" ) ctest; gcovr -r ../ . --html-details cov.html;;
# *) echo "Tests are skipped";;
# esac
24 changes: 19 additions & 5 deletions cytnx/Network_conti.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,26 @@
from .utils import *
from cytnx import *

import imp
try:
imp.find_module('graphviz')
from .NetGraph import *
except ImportError:
# import imp
# try:
# imp.find_module('graphviz')
# from .NetGraph import *
# except ImportError:
# from .NetGraph_empty import *

import importlib
spec = importlib.util.find_spec("graphviz")
if spec is None:
# print("Can't find the graphviz module.")
from .NetGraph_empty import *
else:
# If you chose to perform the actual import ...
module = importlib.util.module_from_spec(spec)
spec.loader.exec_module(module)

# Adding the module to sys.modules is optional.
#sys.modules["graphviz"] = module
from .NetGraph import *

import numpy as np

Expand Down
21 changes: 21 additions & 0 deletions example/Accessor/ex.cpp.out
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@

Total elem: 24
type : Double (Float64)
cytnx device: CPU
Shape : (2,3,4)
[[[0.00000e+00 1.00000e+00 2.00000e+00 3.00000e+00 ]
[4.00000e+00 5.00000e+00 6.00000e+00 7.00000e+00 ]
[8.00000e+00 9.00000e+00 1.00000e+01 1.10000e+01 ]]
[[1.20000e+01 1.30000e+01 1.40000e+01 1.50000e+01 ]
[1.60000e+01 1.70000e+01 1.80000e+01 1.90000e+01 ]
[2.00000e+01 2.10000e+01 2.20000e+01 2.30000e+01 ]]]



Total elem: 6
type : Double (Float64)
cytnx device: CPU
Shape : (3,2)
[[0.00000e+00 1.00000e+00 ]
[4.00000e+00 5.00000e+00 ]
[8.00000e+00 9.00000e+00 ]]
38 changes: 38 additions & 0 deletions example/Accessor/example.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
#include "cytnx.hpp"
#include <iostream>

using namespace cytnx;
using namespace std;
int main() {
// 1. handy alias:
typedef Accessor ac;

/*
2. Create a Tensor with
shape (3,4,5),
dtype =Type.Double [default],
device=Device.cpu [default]
*/
Tensor A = cytnx::arange(24);
A.reshape_({2, 3, 4});
cout << A << endl;

/*
3. Accessing elements using accessor
This is similar as python slices.
-> A[0,:,0:2:1]
*/
Tensor B = A(0, ac::all(), ac::range(0, 2, 1));
cout << B << endl;

/* [Note] Conversion from python slice to ac:
[::x] = ac::step(x)
[a::x] = ac::tilend(a,x)
[a::] = ac::tilend(a)
[:b:] = ac::range(0,b,1)
[a:b:x] = ac::range(a,b,x)
*/

return 0;
}
21 changes: 21 additions & 0 deletions example/Accessor/example.cpp.out
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@

Total elem: 24
type : Double (Float64)
cytnx device: CPU
Shape : (2,3,4)
[[[0.00000e+00 1.00000e+00 2.00000e+00 3.00000e+00 ]
[4.00000e+00 5.00000e+00 6.00000e+00 7.00000e+00 ]
[8.00000e+00 9.00000e+00 1.00000e+01 1.10000e+01 ]]
[[1.20000e+01 1.30000e+01 1.40000e+01 1.50000e+01 ]
[1.60000e+01 1.70000e+01 1.80000e+01 1.90000e+01 ]
[2.00000e+01 2.10000e+01 2.20000e+01 2.30000e+01 ]]]



Total elem: 6
type : Double (Float64)
cytnx device: CPU
Shape : (3,2)
[[0.00000e+00 1.00000e+00 ]
[4.00000e+00 5.00000e+00 ]
[8.00000e+00 9.00000e+00 ]]
13 changes: 13 additions & 0 deletions example/Accessor/example.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import sys
from pathlib import Path
home = str(Path.home())
sys.path.append(home + '/Cytnx_lib')
from cytnx import *

A = arange(24);
A.reshape_(2,3,4);
print(A)


B = A[0,:,0:2:1]
print(B)
22 changes: 22 additions & 0 deletions example/Accessor/example.py.out
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@

Total elem: 24
type : Double (Float64)
cytnx device: CPU
Shape : (2,3,4)
[[[0.00000e+00 1.00000e+00 2.00000e+00 3.00000e+00 ]
[4.00000e+00 5.00000e+00 6.00000e+00 7.00000e+00 ]
[8.00000e+00 9.00000e+00 1.00000e+01 1.10000e+01 ]]
[[1.20000e+01 1.30000e+01 1.40000e+01 1.50000e+01 ]
[1.60000e+01 1.70000e+01 1.80000e+01 1.90000e+01 ]
[2.00000e+01 2.10000e+01 2.20000e+01 2.30000e+01 ]]]




Total elem: 6
type : Double (Float64)
cytnx device: CPU
Shape : (3,2)
[[0.00000e+00 1.00000e+00 ]
[4.00000e+00 5.00000e+00 ]
[8.00000e+00 9.00000e+00 ]]
17 changes: 17 additions & 0 deletions example/Bond/.cpp.out
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
Dim = 10 |type: REGULAR

Dim = 5 |type: REGULAR

Dim = 50 |type: REGULAR

Dim = 3 |type: <BRA
U1:: +0 +2 -4
Z2:: +1 +0 +1

Dim = 4 |type: <BRA
U1:: +0 +2 -1 +3
Z2:: +0 +1 +1 +0

Dim = 12 |type: <BRA
U1:: +0 +2 -1 +3 +2 +4 +1 +5 -4 -2 -5 -1
Z2:: +1 +0 +0 +1 +0 +1 +1 +0 +1 +0 +0 +1
Loading

0 comments on commit ba1eb2f

Please sign in to comment.