Commit 0fde7173 authored by LAMBERT Jean-charles's avatar LAMBERT Jean-charles

add test procedure

parent fa308076
Pipeline #659 failed with stages
......@@ -14,7 +14,8 @@ py/unsio/py_unsio_wrap.cpp
dist
*egg-info*
__pycache__
py/unsio/version*
*.pyc
# tilda
*~
......
include py/unsio/numpy.i
include py/unsio/numpy.i py/unsio/py_unsio.i
include src/uns.h src/snapshotinterface.h src/componentrange.h src/userselection.h src/snapshotinterface.h src/ctools.h src/version.h
exclude py/unsio/py_unsio.py
exclude py/unsio/py_unsio.py py/unsio/version.py
......@@ -7,7 +7,8 @@ except:
import sys
print("Unable to import [unsio.py_unsio]....",file=sys.stderr)
from .version import version as __version__
#from . import test, csnapshot
#from .csnapshot import *
__version__ = '0.9.2'
This diff is collapsed.
from . import ctestunsio
#from . import ctestunsio
......@@ -8,6 +8,7 @@ import tempfile
import unsio
from unsio.csnapshot import *
from .check_platform import *
import subprocess
#
......@@ -24,17 +25,39 @@ class CTestunsio:
__1Dstars = [1,"metal","age"]
__1Dint = [1,"id"]
__comp = {'halo':[__1D,__3D],'gas':[__1D,__3D,__1Dgas],'stars':[__1D,__3D,__1Dstars],'disk':[__1D,__3D],'bndry':[__1D,__3D],'bulge':[__1D,__3D]}
__comp = {'halo':[__1D,__3D],'gas':[__1D,__3D,__1Dgas],'stars':[__1D,__3D,__1Dstars],
'disk':[__1D,__3D],'bndry':[__1D,__3D],'bulge':[__1D,__3D]}
__compNemo = { 'all':[__1D,__3D,__1Dgas] }
__fdout = None
__out = None
# -----------------------------------------------------
#
def __init__(self,nbody=None,seed=666,single=True,verbose=None, uns2uns=False):
def __init__(self,nbody=None,seed=666,single=True,verbose=None, uns2uns=False, out=None):
self.__nbody = nbody
self.__verbose = verbose
self.__seed = seed
self.__single = single
self.__uns2uns = uns2uns
self.__out = out
if out is not None:
try:
self.__fdout = open(out,"w")
except:
print("Impossible to write into file file[%s]\n"%(out))
sys.exit()
# print banner
print("\n\n-----------------------------------------------------------",file=self.__fdout)
print("Testing UNSIO library",file=self.__fdout)
print("library version [%s]"%(unsio.getVersion()),file=self.__fdout)
print("python-unsio version [%s]"%(unsio.__version__),file=self.__fdout)
print("-----------------------------------------------------------",file=self.__fdout)
# detect plateform
info=CPlateform(fdout=self.__fdout)
info.display()
self.__initSeed(self.__seed)
# -----------------------------------------------------
......@@ -83,13 +106,13 @@ class CTestunsio:
## SAVE FILE
# instantiate output object
if (single):
print("SINGLE precision floating values")
print("SINGLE precision floating values",file=self.__fdout)
self.__unso=unsio.CunsOut(self.__model_file,unstype); # output file
else:
print("DOUBLE precision floating values")
print("DOUBLE precision floating values",file=self.__fdout)
self.__unso=unsio.CunsOutD(self.__model_file,unstype); # output file
print("\nSaving in ",unstype," format......")
print("\nSaving in ",unstype," format......",file=self.__fdout)
self.__unso.setValueF("time",0) # save time
select_comp = self.__comp # comp for gadget2 gadget3
......@@ -98,21 +121,21 @@ class CTestunsio:
#for comp,all_array in select_comp.iteritems():
for comp,all_array in select_comp.items():
print ("[%-6s] : "%(comp),file=sys.stderr,end="")
print ("[%-6s] : "%(comp),file=self.__fdout,end="")
# save reals array
for block_array in all_array:
dim=block_array[0]
for array in block_array[1:]:
print(" %s"%(array),file=sys.stderr, end="")
print(" %s"%(array),file=self.__fdout, end="")
self.__saveArray(comp,array,dim,real=True) # save real
# save integer arrays
dim=self.__1Dint[0]
for array in self.__1Dint[1:]:
print(" %s"%(array), end="")
print(" %s"%(array),file=self.__fdout, end="")
self.__saveArray(comp,array,dim,real=False) # save integer
print("\n",file=sys.stderr)
print("\n",file=self.__fdout)
self.__unso.save() # trigger save ops
self.__unso.close()
......@@ -127,15 +150,17 @@ class CTestunsio:
else:
outfloat="float=f"
cmd="uns2uns in=%s out=%s select=%s type=%s %s"%(self.__model_file,myfile,"all",unstype,outfloat)
print("<%s>"%(cmd),file=sys.stderr)
if __verbose:
print("<%s>"%(cmd),file=self.__fdout)
#subprocess.call([cmd],shell=True)
subprocess.call(["uns2uns","in="+self.__model_file,"out="+myfile,"select=all","type="+unstype,outfloat])
#sys.exit()
os.remove(self.__model_file)
self.__model_file=myfile
print("Outfile = [%s]"%(self.__model_file))
if self.__verbose:
print("Outfile = [%s]"%(self.__model_file),file=self.__fdout)
# -----------------------------------------------------
#
......@@ -154,8 +179,8 @@ class CTestunsio:
#print (" <%s>"%(attr),file=sys.stderr,end="")
ok=(data_ref==data).all()
if not ok:
print("\nInconsitency: <%s> [%s]"%(comp,attr),data_ref.size,data.size,file=sys.stderr)
print(data_ref,data)
print("\n[ERROR !!!] Inconsitency: <%s> [%s]"%(comp,attr),data_ref.size,data.size,file=self.__fdout)
print(data_ref,data,file=self.__fdout)
sys.exit()
# -----------------------------------------------------
......@@ -167,7 +192,7 @@ class CTestunsio:
self.__initSeed() # reset random generator
if not os.path.isfile(self.__model_file):
print("File [%s] does not exist, aborting..\n"%(self.__model_file),file=sys.stderr)
print("File [%s] does not exist, aborting..\n"%(self.__model_file),file=self.__fdout)
sys.exit()
# instantiate CSnapshot object
......@@ -179,21 +204,21 @@ class CTestunsio:
select_comp = self.__compNemo # comp for nemo
for comp,all_array in select_comp.items():
print ("checking [%-6s] : "%(comp),file=sys.stderr,end="")
print ("checking [%-6s] : "%(comp),file=self.__fdout,end="")
# compare real array
for block_array in all_array:
dim=block_array[0]
for array in block_array[1:]:
print(" %s"%(array),file=sys.stderr, end="")
print(" %s"%(array),file=self.__fdout, end="")
self.__compareArray(comp,array,dim,real=True)
# compare integer arrays
dim=self.__1Dint[0]
for array in self.__1Dint[1:]:
print(" %s"%(array),file=sys.stderr, end="")
print(" %s"%(array),file=self.__fdout, end="")
self.__compareArray(comp,array,dim,real=False)
print("\n",file=sys.stderr)
print("\n",file=self.__fdout)
self.__unsi.close()
......@@ -206,9 +231,9 @@ class CTestunsio:
model=["gadget3","gadget2","nemo"]
for mm in model:
print ("Testing model [%s]"%(mm),file=sys.stderr)
print ("Testing model [%s]"%(mm),file=self.__fdout)
self.saveModel(unstype=mm,single=self.__single)
print ("\n\nComparing model [%s]"%(mm),file=sys.stderr)
print ("\n\nComparing model [%s]"%(mm),file=self.__fdout)
self.__compareModel(unstype=mm,single=self.__single)
# remove temporary file
os.remove(self.__model_file)
......@@ -221,6 +246,7 @@ def commandLine():
formatter_class=argparse.ArgumentDefaultsHelpFormatter)
# options
parser.add_argument('--nbody', help='#bodies to test', type=int, default=100000)
parser.add_argument('--out', help='save result in a file', type=str, default=None)
parser.add_argument('--verbose',help='verbose mode',dest="verbose", action="store_true", default=False)
parser.add_argument('--double',help='test with double real',dest="double", action="store_true", default=False)
parser.add_argument('--uns2uns',help='save intermediate file with uns2uns',dest="uns2uns", action="store_true", default=False)
......@@ -233,7 +259,7 @@ def commandLine():
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
# commandLine, parse the command line
def process(args):
uns=CTestunsio(nbody=args.nbody,single=not args.double, uns2uns=args.uns2uns)
uns=CTestunsio(nbody=args.nbody,single=not args.double, uns2uns=args.uns2uns, out=args.out)
#uns.saveModel("")
uns.testIO()
......
......@@ -5,14 +5,14 @@ UNSIO : Universal Nbody Snapshot Input Output
"""
from distutils.core import setup, Extension
import numpy,os,sys
from setuptools import setup, Extension, find_packages
import numpy
import os
import sys
from setuptools import setup, Extension
from setuptools.command.build_py import build_py as _build_py
#import setuptools.command.build_ext
# find out numpy include directory.
# find out numpy include directory.
try:
numpy_include = numpy.get_include()
except AttributeError:
......@@ -22,12 +22,12 @@ if sys.version_info[:2] < (2, 7) or (3, 0) <= sys.version_info[:2] < (3, 4):
raise RuntimeError("Python version 2.7 or >= 3.4 required.")
# detect python version (2 or 3)
pyversion="3"
if sys.version_info[0]<3 :
pyversion=""
pyversion = "3"
if sys.version_info[0] < 3:
pyversion = ""
long_description="""\
long_description = """\
UNSIO (*U*niversal *N*body *S*napshot *I*nput *O*utput) is an API which perform input/output operations in a generic way, and on different kind of nbody files format (nemo, Gadget binaries 1 and 2, Gadget hdf5, Ramses).
......@@ -37,67 +37,114 @@ It's not necessary anymore to know how is implemented a file format, UNSIO will
UNSIO comes with an integrated sqlite3 database which can be used to retrieve automatically all your data among terabytes of hard disks.
"""
# trick to add SWIG generated module
# see https://stackoverflow.com/questions/12491328/python-distutils-not-include-the-swig-generated-module
# and especially : https://stackoverflow.com/questions/29477298/setup-py-run-build-ext-before-anything-else/48942866#48942866
# and the fix for python2 https://stackoverflow.com/questions/1713038/super-fails-with-error-typeerror-argument-1-must-be-type-not-classobj-when/1713052#1713052
class build_py(_build_py):
class build_py(_build_py, object):
def run(self):
self.run_command("build_ext")
if pyversion=="": # python2
return super().run()
else: # python3
if pyversion == "": # python2
return super(build_py, self).run()
else: # python3
return super().run()
setup(
#name='python'+pyversion+'-unsio',
name='python-unsio',
version='0.9.2',
description='A python wrapper to unsio',
long_description=long_description,
author='Jean-Charles LAMBERT',
author_email='jean-charles.lambert@lam.fr',
url='https://projets.lam.fr/projects/unsio',
license='CeCILL2.1 (https://opensource.org/licenses/CECILL-2.1)',
classifiers = [
"Intended Audience :: Developers",
"Intended Audience :: Science/Research",
"Programming Language :: C",
"Programming Language :: C++",
"Programming Language :: Python",
"Programming Language :: Python :: 2.7",
"Programming Language :: Python :: 3.4",
"Programming Language :: Python :: 3.5",
"Programming Language :: Python :: 3.6",
"Programming Language :: Python :: 3.7",
"Topic :: Scientific/Engineering :: Astronomy",
"Topic :: Software Development"],
platforms = ["Linux", "Mac OS-X", "Unix"],
python_requires='>=2.7,!=3.0.*,!=3.1.*,!=3.2.*,!=3.3.*',
package_dir={'':'py'}, # all packages are under 'py' directory
packages=['unsio','unsio/test'],
#cmdclass = {'install':Build_ext_first},
#cmdclass={'build': CustomBuild, 'install': CustomInstall},
cmdclass = {'build_py' : build_py},
py_modules=['unsio/py_unsio'],
ext_modules = [
Extension("unsio/_py_unsio",
sources=[ "py/unsio/py_unsio.i"],
swig_opts=['-c++','-modern', '-Isrc','-I./py/unsio', '-Iswig'],
include_dirs = [numpy_include,'src'],
libraries=['unsio'],
library_dirs=['/Users/jcl/local/unsio/lib','/usr/lib64','/lib64'],
runtime_library_dirs=['/Users/jcl/local/unsio/lib','/usr/lib64','/lib64']
)
],
entry_points = {
"console_scripts": [
"test_unsio_lib = unsio.test.ctestunsio:commandLine",
],
},
#install_requires=['numpy'],
setup_requires=['numpy']
#
)
#
# version management
#
MAJOR = '0'
MINOR = '9'
MICRO = '2rc1'
VERSION = '%s.%s.%s' % (MAJOR, MINOR, MICRO)
#
# write_version : write unsio version in py/unsio/version.py file
# it's imported from __init__.py as __version__
def write_version_py(filename='py/unsio/version.py'):
cnt = """
# THIS FILE IS GENERATED FROM PYTHON-UNSIO SETUP.PY
#
version = '%(version)s'
"""
a = open(filename, 'w')
try:
a.write(cnt % {'version': VERSION})
finally:
a.close()
#
# setup_package :
#
def setup_package():
# generate version
write_version_py()
# metada for setup
metadata = dict(
# name='python'+pyversion+'-unsio',
name='python-unsio',
version=VERSION,
description='A python wrapper to unsio',
long_description=long_description,
author='Jean-Charles LAMBERT',
author_email='jean-charles.lambert@lam.fr',
url='https://projets.lam.fr/projects/unsio',
license='CeCILL2.1 (https://opensource.org/licenses/CECILL-2.1)',
classifiers=[
"Intended Audience :: Developers",
"Intended Audience :: Science/Research",
"Programming Language :: C",
"Programming Language :: C++",
"Programming Language :: Python",
"Programming Language :: Python :: 2.7",
"Programming Language :: Python :: 3.4",
"Programming Language :: Python :: 3.5",
"Programming Language :: Python :: 3.6",
"Programming Language :: Python :: 3.7",
"Topic :: Scientific/Engineering :: Astronomy",
"Topic :: Software Development"],
platforms=["Linux", "Mac OS-X", "Unix"],
python_requires='>=2.7,!=3.0.*,!=3.1.*,!=3.2.*,!=3.3.*',
package_dir={'': 'py'}, # all packages are under 'py' directory
packages=['unsio', 'unsio/test'],
# cmdclass = {'install':Build_ext_first},
# cmdclass={'build': CustomBuild, 'install': CustomInstall},
cmdclass={'build_py': build_py},
py_modules=['unsio/py_unsio'],
ext_modules=[
Extension("unsio/_py_unsio",
sources=["py/unsio/py_unsio.i"],
swig_opts=['-c++', '-modern', '-Isrc',
'-I./py/unsio', '-Iswig'],
include_dirs=[numpy_include, 'src'],
libraries=['unsio'],
library_dirs=[os.environ['HOME']+'/local/unsio/lib',
'/usr/lib64', '/lib64'],
runtime_library_dirs=[
os.environ['HOME']+'/local/unsio/lib', '/usr/lib64', '/lib64']
)
],
entry_points={
"console_scripts": [
"test_unsio_lib = unsio.test.ctestunsio:commandLine",
],
},
# install_requires=['numpy'],
setup_requires=['numpy']
#
)
setup(**metadata)
#
# main
#
if __name__ == '__main__':
setup_package()
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment