3
0
mirror of https://github.com/triqs/dft_tools synced 2024-12-25 05:43:40 +01:00

move wrap_test to test/pytriqs

This commit is contained in:
Olivier Parcollet 2014-05-30 23:08:32 +02:00
parent 3e0d53564a
commit 2abf36a2ff
15 changed files with 113 additions and 46 deletions

View File

@ -1,4 +1,16 @@
enable_testing()
find_package(TestScriptHdf)
# Create a temporary copy of the python modules so that we can run before installation with the test
FILE(GLOB_RECURSE all_py_files RELATIVE ${CMAKE_SOURCE_DIR}/test/pytriqs *.py )
SET(py_copy_tar ${CMAKE_BINARY_DIR}/test/py_copy_test.tar)
add_custom_command (OUTPUT ${py_copy_tar} DEPENDS ${all_py_files}
COMMAND cd ${CMAKE_SOURCE_DIR}/test/pytriqs && tar cf ${py_copy_tar} ${all_py_files} && cd ${CMAKE_BINARY_DIR}/test/pytriqs && tar xf ${py_copy_tar} )
add_custom_target(py_copy_test ALL DEPENDS ${py_copy_tar})
find_package(PythonWrapperMacro)
add_custom_target(wrap_clean_test COMMAND find ${CMAKE_BINARY_DIR} -name \"*.cpp\" |xargs rm)
add_all_subdirectories_with_cmakelist()

View File

@ -1,39 +0,0 @@
import pytriqs.parameters.parameters as P
p = P.Parameters()
p['i'] = 10
p['d'] = 2.3
p['s'] = "my string"
print p
print p['i']
print p['d']
print p['s']
d = { 'a' : 10, 'b' : "good", 'c' : -9.2}
p.update(d)
print p
import numpy as np
a = np.array([[1,2],[3,4]])
p['A'] = a
p['Ad'] = 2.5*a
print " p['A'] = ", p['A']
p['A'][0,0] *=10
print " p['A'] = ", p['A']
print p
p2 = P.Parameters()
p2.update2( a = 4, b= "u")
p['sub'] = p2
p['sub2'] = { 'r' : 1, 'rrr' : 3}
print p['sub']
print p['sub2']
print p

View File

@ -18,5 +18,7 @@ add_dependencies(python_wrap_my_moduleB python_wrap_my_module)
include_directories( ${CMAKE_CURRENT_SOURCE_DIR} )
install (FILES ${CMAKE_SOURCE_DIR}/pytriqs/__init__.py.template DESTINATION "include/pytriqs/gf/local" RENAME __init__.py)
# A sample test with text output
add_triqs_test_txt(wrap_a)

View File

@ -1,9 +1,9 @@
from wrap_generator import *
# The module
mod = module_(full_name = "pytriqs.wrap_test.my_moduleB", doc = " Doc of my_module ")
mod = module_(full_name = "my_moduleB", doc = " Doc of my_module ")
mod.use_module('my_module')
mod.add_include("<triqs/../pytriqs/wrap_test/b.hpp>")
mod.add_include("<triqs/../test/pytriqs/wrap_test/b.hpp>")
mod.add_include("<pytriqs/converters/my_module.hpp>")
mod.add_function (name = "print_a2", signature = "void(A a)", doc = "DOC of print_a")

View File

@ -1,8 +1,8 @@
from wrap_generator import *
# The module
module = module_(full_name = "pytriqs.wrap_test.my_module", doc = " Doc of my_module ")
module.add_include("<triqs/../pytriqs/wrap_test/a.hpp>")
module = module_(full_name = "my_module", doc = " Doc of my_module ")
module.add_include("<triqs/../test/pytriqs/wrap_test/a.hpp>")
module.add_include("<triqs/arrays.hpp>")
# one class
@ -25,7 +25,7 @@ g.add_method(py_name = "m1", c_name = "m1", signature = "double (int u)", doc =
g.add_method(py_name = "m1", c_name = "m2", signature = "double (double u)", doc = "DOC of m1...")
# another version of the method, with some pre/post processing written in python
g.add_method(py_name = "m1p", c_name = "m1", signature = "double (int u, double y = 3)", doc = "DOC of mm", python_precall = "pytriqs.wrap_test.aux.ffg", python_postcall = "pytriqs.wrap_test.aux.post1")
g.add_method(py_name = "m1p", c_name = "m1", signature = "double (int u, double y = 3)", doc = "DOC of mm", python_precall = "aux.ffg", python_postcall = "aux.post1")
# demo of adding a simple piece of C++ code, there is no C++ method corresponding
g.add_method(py_name = "m1_x", calling_pattern = "bool result = (self_c.x >0) && (self_c.x < 10)" , signature = "bool()", doc = "A method which did not exist in C++")

View File

@ -2,7 +2,7 @@ from wrap_generator import *
# The module
module = module_(full_name = "pytriqs.wrap_test.test_g", doc = " Doc of my_module ")
module.add_include("<triqs/../pytriqs/wrap_test/g.hpp>")
module.add_include("<triqs/../test/pytriqs/wrap_test/g.hpp>")
module.add_include("<pytriqs/converters/gf.hpp>")
module.add_function (name = "make_bgf", signature = "block_gf_view<imfreq> (double a)", doc = "DOC of print_a")

View File

@ -0,0 +1,3 @@
import my_moduleB as B
B.print_a2(2)

View File

@ -0,0 +1,23 @@
calling m1 1 2
11.0
calling ffg, with :
(1, 2.0)
{}
calling m1 2 4
[19.0]
my a is 3
[0, 1, 2] [0, 2, 4]
[2, 4, 6, 8]
[2, 4, 6]
I am an A with x= 6
use_fnt ii
5
use_fnt ii
41
use_fnt iid
9
use_fnt iid
45
rereading from hdf5 I am an A with x= 6.9
'cmy_module\n__reduce_reconstructor__Ac\np0\n(I1\nF3.0\ntp1\nRp2\n.'
I am an A with x= 3

View File

@ -0,0 +1,55 @@
from my_module import *
a = Ac()
print a.m1(1,2.0)
print a.m1p(1,2.0)
print_a (a)
v1 = make_vector(3)
v2 = vector_x2(v1)
print v1, v2
print vector_x2([1,2,3,4])
print vector_x2((1,2,3))
print a+ a
#print_a (8)
f,s = a.__reduce__()
b = f(*s)
# lambda <-> std::function
fc = make_fnt_ii()
#print fc
use_fnt_ii(fc)
fp = lambda i,j : i + 20*j
use_fnt_ii(fp)
fc2 = make_fnt_iid()
#print fc2
use_fnt_iid(fc2)
fp2 = lambda i,j,a : a+ i + 20*j
use_fnt_iid(fp2)
from pytriqs.archive import *
import pytriqs.archive.hdf_archive_schemes
import numpy
R = HDFArchive('ess.h5', 'w') # Opens the file myfile.h5, in read/write mode
R['a'] = 2.3*a
del R
R2 = HDFArchive('ess.h5', 'r')
aa = R2['a']
print " rereading from hdf5 ", aa
import pickle
s = pickle.dumps(a)
print repr(s)
bb = pickle.loads(s)
print bb

View File

@ -0,0 +1,11 @@
from pytriqs.wrap_test.test_g import *
B = make_bgf(2.0)
pass_bgf(B+B)
# run in python the h5diff between the 2 files...
g = make_sgf(2.0)
pass_sgf(g)