Skip to content

Commit 234b6a3

Browse files
committed
Add Python interface pydmrg
1 parent b050b0b commit 234b6a3

31 files changed

+18511
-3
lines changed

makefile

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ ifeq ($(notdir $(firstword $(CXX))),icpc)
8383
OPENMP_FLAGS= -openmp -D_OPENMP
8484
endif
8585
# Intel compiler
86-
OPT = -DNDEBUG -O3 -funroll-loops
86+
OPT = -DNDEBUG -O3 -funroll-loops -fPIC
8787
# OPT = -g
8888
CXX = icc
8989
endif
@@ -93,7 +93,7 @@ ifeq ($(notdir $(firstword $(CXX))),g++)
9393
OPENMP_FLAGS= -fopenmp -D_OPENMP
9494
endif
9595
# GNU compiler
96-
OPT = -DNDEBUG -O3
96+
OPT = -DNDEBUG -O3 -fPIC
9797
# OPT = -g
9898
endif
9999

@@ -146,11 +146,15 @@ OBJ_spin_library=$(SRC_spin_library:.C=.o)
146146

147147
all : $(EXECUTABLE) libqcdmrg.a OH
148148

149-
library : libqcdmrg.a $(NEWMATLIB)/libnewmat.a $(BTAS)/lib/libbtas.a
149+
library : libqcdmrg.a $(NEWMATLIB)/libnewmat.a $(BTAS)/lib/libbtas.a libqcdmrg.so
150150

151151
libqcdmrg.a : $(OBJ_spin_library)
152152
$(AR) $(ARFLAGS) $@ $^
153153
$(RANLIB) $@
154+
155+
libqcdmrg.so : $(OBJ_spin_library)
156+
$(CXX) -shared -o $@ $^ $(LIBS)
157+
154158
ifeq ($(USE_BTAS), yes)
155159

156160
OH : $(OBJ_OH) $(NEWMATLIB)/libnewmat.a $(BTAS)/lib/libbtas.a

pydmrg/ChangeLog

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
version 0.97 (2014-04-28):
2+
* First release Pydmrg the python wrapper for Block v0.97

pydmrg/README.md

Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
pydmrg
2+
======
3+
4+
Python wrapper for Block code
5+
6+
7+
Installation
8+
------------
9+
10+
* Prerequisites
11+
- Cmake version 2.8 or higher
12+
- Python version 2.6 or higher
13+
- Numpy version 1.6 or higher
14+
- Cython version 0.20 or higher (optional, to generate _pydmrg.cpp)
15+
16+
* Make patches to Block
17+
- in spinblock.h, change 'class SpinBlock', make members public
18+
- in input.h, change 'class Input', make members public
19+
20+
* Compile Block code with flag -fPIC to get libqcdmrg.so
21+
22+
make libqcdmrg.so
23+
24+
* Compile and install pydmrg
25+
26+
cd pydmrg/core
27+
mkdir build; cd build
28+
cmake ..
29+
make
30+
31+
* To make python be able to find pydmrg, add the path of Block code to
32+
PYTHONPATH, , e.g.
33+
34+
echo 'export PYTHONPATH=/home/opt/Block:$PYTHONPATH' >> ~/.bashrc
35+
36+
* Use Intel MKL as BLAS library
37+
- add '-lmkl_avx' or '-lmkl_mc -lmkl_def' in Block makefile e.g.
38+
39+
LAPACKBLAS = -L${MKLLIB} -lmkl_intel_lp64 -lmkl_sequential -lmkl_core -lmkl_avx
40+
41+
then compile libqcdmrg.so again
42+
43+
- cmake with options -DBLA_VENDOR=Intel10_64lp
44+
45+
cd build; cmake .. -DBLA_VENDOR=Intel10_64lp; make
46+
47+
48+
Structure
49+
---------
50+
+-----------------------------------------------+
51+
Pydmrg layer | pydmrg.Wavefunction, pydmrg.SpinBlock ... |
52+
+-----------------------------------------------+
53+
A | A | A |
54+
| V | V | V
55+
+-----------------------------------------------+
56+
Python C-API layer | _dmrg.RawWavefunction, _dmrg.RawSpinBlock ... |
57+
+-----------------------------------------------+
58+
A | A | A |
59+
| V | V | V
60+
+-----------------------------------------------+
61+
Block code layer | Block.Wavefunction, Block.SpinBlock ... |
62+
+-----------------------------------------------+
63+
64+
* _dmrg is a lower interface layer which directly access Block code.
65+
It provides the most basic functions or class to represent the
66+
intrinsic data structure of Block. The raw data are then wrapped in
67+
these xxx.py
68+
69+
* In _dmrg, a raw class use a pointer _this to save only one instance of
70+
the Block class. So the memory can be managed by GC of python through
71+
raw class.
72+
73+
* sanity check or complicated stuff in xxx.py

pydmrg/TODO

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
2014-04-30
2+
* natural way to handle global variables in global.h, e.g. v_1, v_2
3+
* direct access to dmrginp
4+
* fake input parser
5+
* restart
6+
* op_components.C

pydmrg/__init__.py

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
#
2+
# File: __init__.py
3+
# Author: Qiming Sun <[email protected]>
4+
#
5+
6+
from param import *
7+
from utils import *
8+
from wavefunction import Wavefunction
9+
from quanta import SpinQuantum
10+
from rotationmat import RotationMatrix
11+
from spinblock import SpinBlock, InitStartingBlock, InitNewSystemBlock, \
12+
InitNewEnvironmentBlock, InitBigBlock
13+
from stateinfo import StateInfo, CollectQuanta, TensorProduct
14+
from dmrg import DMRGEnv, dmrg_single
15+
from sweep import do_one, block_cycle, Startup, BlockAndDecimate, \
16+
RenormaliseFrom
17+

pydmrg/core/CMakeLists.txt

Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
cmake_minimum_required (VERSION 2.8)
2+
project (pydmrg)
3+
4+
set(BLOCKDIR ${PROJECT_SOURCE_DIR}/../..)
5+
message("Block src dir is ${BLOCKDIR}\n")
6+
7+
#jset(LAPACK_LIBRARIES "-L${MKL_LIB_PATH} -I${MKLINCLUDE} -lmkl_intel_lp64 -lmkl_sequential -lmkl_core -lpthread -lmkl_avx -lm")
8+
#jset(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} ${LAPACK_LIBRARIES}")
9+
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -g -O1 -std=c++0x")
10+
#set(CMAKE_CXX_COMPILER "/usr/bin/g++")
11+
set(CMAKE_VERBOSE_MAKEFILE OFF)
12+
13+
set(CMAKE_INCLUDE_CURRENT_DIR ON)
14+
include_directories(
15+
${BLOCKDIR}
16+
${BLOCKDIR}/include
17+
${BLOCKDIR}/newmat10
18+
${BLOCKDIR}/modules/twopdm
19+
${BLOCKDIR}/modules/onepdm
20+
${BLOCKDIR}/modules/four_index_ops
21+
${BLOCKDIR}/modules/npdm
22+
${BLOCKDIR}/modules/three_index_ops
23+
${BLOCKDIR}/modules/two_index_ops
24+
${BLOCKDIR}/modules/generate_blocks)
25+
26+
find_package(BLAS REQUIRED)
27+
28+
find_package(OpenMP)
29+
if (OPENMP_FOUND)
30+
set(_OPENMP 1)
31+
endif()
32+
33+
# without MPI
34+
set(SERIAL 1)
35+
36+
set(FAST_MTP 1)
37+
38+
find_package(PythonInterp REQUIRED)
39+
find_package(PythonLibs REQUIRED)
40+
execute_process(COMMAND ${PYTHON_EXECUTABLE} -c "import numpy; print numpy.get_include()"
41+
OUTPUT_VARIABLE NUMPY_INCLUDE)
42+
include_directories(${PYTHON_INCLUDE_DIRS} ${NUMPY_INCLUDE})
43+
44+
set(Boost_USE_STATIC_LIBS off)
45+
set(Boost_USE_MULTITHREADED off)
46+
#target_link_libraries(${Boost_LIBRARY_DIRS})
47+
set(Boost_COMPONENTS serialization filesystem system)
48+
find_package(Boost 1.47.0 COMPONENTS ${Boost_COMPONENTS})
49+
include_directories(${Boost_INCLUDE_DIRS})
50+
51+
configure_file(
52+
"${PROJECT_SOURCE_DIR}/config.h.in"
53+
"${PROJECT_BINARY_DIR}/config.h")
54+
55+
#execute_process(COMMAND cython --cplus _dmrg.pyx)
56+
57+
link_directories(
58+
${BLOCKDIR}/newmat10
59+
${BLOCKDIR})
60+
61+
add_library(_dmrg SHARED
62+
_dmrg.cpp quanta.cc rotmat.cc wavefn.cc stateinfo.cc spinblock.cc
63+
hacks.cc)
64+
set_target_properties(_dmrg PROPERTIES PREFIX ""
65+
LIBRARY_OUTPUT_DIRECTORY ${PROJECT_SOURCE_DIR}/../)
66+
67+
target_link_libraries(_dmrg
68+
qcdmrg newmat
69+
${Boost_LIBRARIES} ${BLAS_LIBRARIES})
70+

0 commit comments

Comments
 (0)