Coder Social home page Coder Social logo

ornl / tasmanian Goto Github PK

View Code? Open in Web Editor NEW
64.0 6.0 23.0 31.5 MB

The Toolkit for Adaptive Stochastic Modeling and Non-Intrusive ApproximatioN

Home Page: https://ornl.github.io/TASMANIAN/

License: Other

CMake 3.58% Makefile 0.29% Shell 0.06% C++ 66.59% MATLAB 4.84% Python 13.25% Cuda 0.63% Fortran 9.65% CSS 0.21% HTML 0.08% C 0.38% SWIG 0.45%
uncertainty-quantification inverse-problems high-order-approximation-models reduced-order-models

tasmanian's Introduction

Tasmanian

Ubuntu-tested MacOSX-tested Windows-tested

The Toolkit for Adaptive Stochastic Modeling and Non-Intrusive ApproximatioN is a collection of robust libraries for high dimensional integration and interpolation as well as parameter calibration. This documentation focuses on the libraries and the software API, refer to the PDF document on the project web-page for specifics about the mathematics of the implemented methods.

Downloads

Visit us at https://github.com/ORNL/Tasmanian

Documentation: Latest Stable

Documentation: development (rolling)

Sparse Grids

Sparse Grids is a family of algorithms for constructing multidimensional quadrature and interpolation rules using multiple tensor products of one dimensional rules with varying degree of precision. The Tasmanian Sparse Grids Module implements a variety of grids that fall into five major categories:

  • Global grids use polynomials supported over the entire domain of integration or interpolation. Such grids are suitable for approximating functions with smooth response.
  • Sequence grids work much like Global grids, but use optimized internal data-structures for rules that are based on sequences of points formed from solving a greedy optimization problem
  • Local polynomial grids use hierarchical piece-wise polynomials with compact support. Such grids are suitable for approximating functions with localized sharp behavior.
  • Wavelet grids use special functions that form a Riesz basis which allows for more accurate local error estimations. Compared to Local polynomial grids, the wavelet basis can provide similar accuracy with significantly fewer points, but the advantage of the Riesz basis could also be negated from the higher Lebesgue constant near the domain boundary.
  • Fourier grids use trigonometric functions with varying frequency and rely on Discrete (complex) Fourier Transforms. Such grids are suitable for approximating periodic functions, since periodicity if preserved in the approximation.

DREAM

The DiffeRential Evolution Adaptive Metropolis is a method to draw samples from an arbitrary probability distribution defined by an arbitrary non-negative function (not necessarily normalized to integrate to 1). The DREAM approach is similar to the classical Markov Chain Monte Carlo, but it evolves a large number of chains simultaneously which leads to better parallelization and (potentially) faster convergence. In addition, multiple chains allow for better exploration of the probability domain, which is often advantageous when working with multi-modal distributions.

One of the main applications of DREAM is in the field of Bayesian inference, where samples are drawn from a posterior distribution comprised from a data-informed likelihood and an arbitrary model. The DREAM module of Tasmanian can use Tasmanian Sparse Grids approximation to either the model or the likelihood.

Math details

The online documentation focuses on the API and usage of the Tasmanian software. More detailed description of the mathematical capabilities and some of the terminology can be found at the Math Manual

https://mkstoyanov.github.io/tasmanian_aux_files/docs/TasmanianMathManual.pdf

Please cite us

If you use Tasmanian for your research, please cite the Manual and our work on global and locally adaptive grids.

https://github.com/mkstoyanov/tasmanian_aux_files/blob/main/docs/Tasmanian.bib

Download the .bib file:

https://mkstoyanov.github.io/tasmanian_aux_files/docs/Tasmanian.bib

Quick Install

See also the detailed Installation instructions.

  • The CMake way: see the detailed instruction for a full list of options
    • supported on Linux, MacOSX and Windows
  • The basic way: using GNU Make, g++ and /usr/bin/python3
    • supported only on Linux and MacOSX
    • enables only very basic features in C++, MATLAB and Python
  • Tasmanian is available through Python PIP, make sure you have the latest pip
  python3 -m pip install Tasmanian --user

Basic Usage of Tasmanian

  • See the Examples in the install prefix:
  <install-prefix>/share/Tasmanian/examples/
  • The Examples source code is in:
  <source-root>/<module>/Examples/

tasmanian's People

Contributors

dalg24 avatar mattrjackson avatar mkstoyanov avatar sethrj avatar vreshniak avatar wwkong avatar zbmorrow avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar

tasmanian's Issues

Asynchronous refinement procedure

Derive an algorithm for asynchronous refinement, where new samples are not handled in batches, but on the fly.

  • allow needed points (or any admissible set) of points to be added to the grid at any time
  • produce a list of candidate points (similar to needed), but also provide weights on importance

Probably use another class that will wrap around TasmanianSparseGrids, this class will need access to the internals, e.g., IndexSet for tensors and points.

Add long int support for data

No need to overhaul the index set class, only the values storage class and the associated load/unload commands. Check to see how this would affect the ML capabilities.

Update Sparse Grids examples

  • with the changes to the API many of the sparse grids examples need updating
  • examples date back many years ago, have to rethink a bit the presentation of the work-flow

Tests fail in gcc 11.2.0

All the tests fail while building with gcc-11.2.0 Here are the cmake options used. Same options works well for 9.3.0

cmake -D CMAKE_INSTALL_PREFIX:PATH=/home/TASMANIAN/install_prefix -D Tasmanian_ENABLE_PYTHON:BOOL=ON -D CMAKE_BUILD_TYPE:STRING=Release ..

Errors When Make Fortran on Mac OSX

Hi, all! I hope this is the right place to ask questions. Thanks for any help in advance.

I am running the following commands in terminal on Mac to install TASMANIAN.

make make test (will fail if /usr/bin/env python is missing the numpy or ctypes modules) make matlab (optional: sets matlab work folder to ./tsgMatlabWorkFolder/) make python3 (optional: sets #!/usr/bin/env python3 in place of /usr/bin/env python) make fortran (optional: compile Fortran libraries) make examples make clean
But when I try to compile example_sparse_grids.f90 through Geany, errors show up:

mkdir -p Build && gfortran -O3 -Werror -Wno-unused -fimplicit-none -Wall -fcheck=bound,do -ffpe-trap=invalid,zero,overflow -I/usr/local/include/ -J"./Build" -c "example_sparse_grids.f90" -o "Build/example_sparse_grids.o" (in directory: /Users/xxxxx/Desktop/TASMANIAN-master/InterfaceFortran/Examples) example_sparse_grids.f90:31:6: USE TasmanianSG 1 Fatal Error: Can't open module file ‘tasmaniansg.mod’ for reading at (1): No such file or directory compilation terminated. Compilation failed.

I guess the reason is that I did not build up TASMANIAN correctly? Specifically, when I run make fortran, there are some warnings and errors:

cp ./Config/AltBuildSystems/TasmanianConfig.hpp ./SparseGrids/TasmanianConfig.hpp cp ./Config/AltBuildSystems/tasgridLogs.hpp ./SparseGrids/tasgridLogs.hpp cd SparseGrids; make g++ -O3 -std=c++14 -Wno-unknown-pragmas -fPIC -Wstrict-aliasing -c tsgIndexSets.cpp -o tsgIndexSets.o g++ -O3 -std=c++14 -Wno-unknown-pragmas -fPIC -Wstrict-aliasing -c tsgCoreOneDimensional.cpp -o tsgCoreOneDimensional.o g++ -O3 -std=c++14 -Wno-unknown-pragmas -fPIC -Wstrict-aliasing -c tsgIndexManipulator.cpp -o tsgIndexManipulator.o g++ -O3 -std=c++14 -Wno-unknown-pragmas -fPIC -Wstrict-aliasing -c tsgGridGlobal.cpp -o tsgGridGlobal.o g++ -O3 -std=c++14 -Wno-unknown-pragmas -fPIC -Wstrict-aliasing -c tsgSequenceOptimizer.cpp -o tsgSequenceOptimizer.o g++ -O3 -std=c++14 -Wno-unknown-pragmas -fPIC -Wstrict-aliasing -c tsgLinearSolvers.cpp -o tsgLinearSolvers.o g++ -O3 -std=c++14 -Wno-unknown-pragmas -fPIC -Wstrict-aliasing -c tsgGridSequence.cpp -o tsgGridSequence.o g++ -O3 -std=c++14 -Wno-unknown-pragmas -fPIC -Wstrict-aliasing -c tsgHardCodedTabulatedRules.cpp -o tsgHardCodedTabulatedRules.o g++ -O3 -std=c++14 -Wno-unknown-pragmas -fPIC -Wstrict-aliasing -c tsgHierarchyManipulator.cpp -o tsgHierarchyManipulator.o g++ -O3 -std=c++14 -Wno-unknown-pragmas -fPIC -Wstrict-aliasing -c tsgGridLocalPolynomial.cpp -o tsgGridLocalPolynomial.o g++ -O3 -std=c++14 -Wno-unknown-pragmas -fPIC -Wstrict-aliasing -c tsgRuleWavelet.cpp -o tsgRuleWavelet.o g++ -O3 -std=c++14 -Wno-unknown-pragmas -fPIC -Wstrict-aliasing -c tsgGridWavelet.cpp -o tsgGridWavelet.o g++ -O3 -std=c++14 -Wno-unknown-pragmas -fPIC -Wstrict-aliasing -c tsgGridFourier.cpp -o tsgGridFourier.o g++ -O3 -std=c++14 -Wno-unknown-pragmas -fPIC -Wstrict-aliasing -c tsgDConstructGridGlobal.cpp -o tsgDConstructGridGlobal.o g++ -O3 -std=c++14 -Wno-unknown-pragmas -fPIC -Wstrict-aliasing -c tsgAcceleratedDataStructures.cpp -o tsgAcceleratedDataStructures.o g++ -O3 -std=c++14 -Wno-unknown-pragmas -fPIC -Wstrict-aliasing -c TasmanianSparseGridWrapC.cpp -o TasmanianSparseGridWrapC.o g++ -O3 -std=c++14 -Wno-unknown-pragmas -fPIC -Wstrict-aliasing -c TasmanianSparseGrid.cpp -o TasmanianSparseGrid.o ar rcs ../libtasmaniansparsegrid.a tsgIndexSets.o tsgCoreOneDimensional.o tsgIndexManipulator.o tsgGridGlobal.o tsgSequenceOptimizer.o tsgLinearSolvers.o tsgGridSequence.o tsgHardCodedTabulatedRules.o tsgHierarchyManipulator.o tsgGridLocalPolynomial.o tsgRuleWavelet.o tsgGridWavelet.o tsgGridFourier.o tsgDConstructGridGlobal.o tsgAcceleratedDataStructures.o TasmanianSparseGridWrapC.o TasmanianSparseGrid.o g++ -O3 -std=c++14 -Wno-unknown-pragmas -fPIC -Wstrict-aliasing -c tasgrid_main.cpp -o tasgrid_main.o g++ -O3 -std=c++14 -Wno-unknown-pragmas -fPIC -Wstrict-aliasing -c tasgridTestFunctions.cpp -o tasgridTestFunctions.o g++ -O3 -std=c++14 -Wno-unknown-pragmas -fPIC -Wstrict-aliasing -c tasgridExternalTests.cpp -o tasgridExternalTests.o g++ -O3 -std=c++14 -Wno-unknown-pragmas -fPIC -Wstrict-aliasing -c tasgridWrapper.cpp -o tasgridWrapper.o g++ -O3 -std=c++14 -Wno-unknown-pragmas -fPIC -Wstrict-aliasing -L. tasgrid_main.o tasgridTestFunctions.o tasgridExternalTests.o tasgridWrapper.o -o ../tasgrid ../libtasmaniansparsegrid.a -lm g++ -O3 -std=c++14 -Wno-unknown-pragmas -fPIC -Wstrict-aliasing -c gridtest_main.cpp -o gridtest_main.o g++ -O3 -std=c++14 -Wno-unknown-pragmas -fPIC -Wstrict-aliasing -c tasgridUnitTests.cpp -o tasgridUnitTests.o g++ -O3 -std=c++14 -Wno-unknown-pragmas -fPIC -Wstrict-aliasing -c tasgridTestInterfaceC.cpp -o tasgridTestInterfaceC.o g++ -O3 -std=c++14 -Wno-unknown-pragmas -fPIC -Wstrict-aliasing -L. gridtest_main.o tasgridTestFunctions.o tasgridExternalTests.o tasgridUnitTests.o tasgridTestInterfaceC.o -o ../gridtest ../libtasmaniansparsegrid.a -lm cd ..; g++ -O3 -std=c++14 -Wno-unknown-pragmas -fPIC -Wstrict-aliasing ./SparseGrids/tsg*.o ./SparseGrids/Tasmanian*.o -shared -o libtasmaniansparsegrid.so -lm cd DREAM; make g++ -O3 -std=c++14 -Wno-unknown-pragmas -fPIC -Wstrict-aliasing -I../SparseGrids -c tsgDreamState.cpp -o tsgDreamState.o g++ -O3 -std=c++14 -Wno-unknown-pragmas -fPIC -Wstrict-aliasing -I../SparseGrids -c tsgDreamLikelyGaussian.cpp -o tsgDreamLikelyGaussian.o g++ -O3 -std=c++14 -Wno-unknown-pragmas -fPIC -Wstrict-aliasing -I../SparseGrids -c tsgDreamSampleWrapC.cpp -o tsgDreamSampleWrapC.o ar rcs ../libtasmaniandream.a tsgDreamState.o tsgDreamLikelyGaussian.o tsgDreamSampleWrapC.o g++ -O3 -std=c++14 -Wno-unknown-pragmas -fPIC -Wstrict-aliasing -I../SparseGrids -c dreamtest_main.cpp -o dreamtest_main.o g++ -O3 -std=c++14 -Wno-unknown-pragmas -fPIC -Wstrict-aliasing -I../SparseGrids -c tasdreamExternalTests.cpp -o tasdreamExternalTests.o g++ -O3 -std=c++14 -Wno-unknown-pragmas -fPIC -Wstrict-aliasing -L../ -L. dreamtest_main.o tasdreamExternalTests.o -o ../dreamtest ../libtasmaniandream.a ../libtasmaniansparsegrid.a -lm cd ..; g++ -O3 -std=c++14 -Wno-unknown-pragmas -fPIC -Wstrict-aliasing -L../ -L. ./DREAM/tsg*.o -shared -o libtasmaniandream.so ./libtasmaniansparsegrid.so -lm cd Addons; make g++ -O3 -std=c++14 -Wno-unknown-pragmas -fPIC -Wstrict-aliasing -I../SparseGrids -I../DREAM -c tsgCLoadNeededValues.cpp -o tsgCLoadNeededValues.o g++ -O3 -std=c++14 -Wno-unknown-pragmas -fPIC -Wstrict-aliasing -I../SparseGrids -I../DREAM -c tsgCConstructSurrogate.cpp -o tsgCConstructSurrogate.o cd ..; g++ -O3 -std=c++14 -Wno-unknown-pragmas -fPIC -Wstrict-aliasing -L../ ./Addons/tsg*.o -shared -o libtasmaniancaddons.so ./libtasmaniansparsegrid.so ./libtasmaniandream.so -lm g++ -O3 -std=c++14 -Wno-unknown-pragmas -fPIC -Wstrict-aliasing -I../SparseGrids -I../DREAM -c testAddons.cpp -o testAddons.o g++ -O3 -std=c++14 -Wno-unknown-pragmas -fPIC -Wstrict-aliasing -L../ testAddons.o -o ../addontester ../libtasmaniandream.a ../libtasmaniansparsegrid.a cd InterfaceFortran/; make g++ -O3 -std=c++14 -Wno-unknown-pragmas -fPIC -Wstrict-aliasing -I../SparseGrids -I../DREAM -I../Addons -c tsgC2Fortran.cpp -o tsgC2Fortran.o gfortran -O3 -fno-f2c -mtune=native -Wno-unknown-pragmas -fPIC -I../SparseGrids -I../DREAM -I../Addons -c TasmanianSG.f90 -o TasmanianSG.o f951: Warning: command line option ‘-Wno-unknown-pragmas’ is valid for C/C++/ObjC/ObjC++ but not for Fortran gfortran -O3 -fno-f2c -mtune=native -Wno-unknown-pragmas -fPIC -I../SparseGrids -I../DREAM -I../Addons -c tsgC2FortranBridge.f90 -o tsgC2FortranBridge.o f951: Warning: command line option ‘-Wno-unknown-pragmas’ is valid for C/C++/ObjC/ObjC++ but not for Fortran ar rcs ../libtasmanianfortran90.a tsgC2Fortran.o TasmanianSG.o tsgC2FortranBridge.o gfortran -O3 -fno-f2c -mtune=native -Wno-unknown-pragmas -fPIC -L../ tsgC2Fortran.o TasmanianSG.o tsgC2FortranBridge.o -shared -o ../libtasmanianfortran90.so ../libtasmaniansparsegrid.so ../libtasmaniansparsegrid.a ../libtasmaniandream.a -lm -lstdc++ Undefined symbols for architecture x86_64: "std::__1::__vector_base_common<true>::__throw_length_error() const", referenced from: _tsgsca_ in tsgC2Fortran.o "std::__1::locale::use_facet(std::__1::locale::id&) const", referenced from: _tsgrea_ in tsgC2Fortran.o std::__1::basic_ostream<char, std::__1::char_traits<char> >& std::__1::__put_character_sequence<char, std::__1::char_traits<char> >(std::__1::basic_ostream<char, std::__1::char_traits<char> >&, char const*, unsigned long) in tsgC2Fortran.o "std::__1::ios_base::getloc() const", referenced from: _tsgrea_ in tsgC2Fortran.o std::__1::basic_ostream<char, std::__1::char_traits<char> >& std::__1::__put_character_sequence<char, std::__1::char_traits<char> >(std::__1::basic_ostream<char, std::__1::char_traits<char> >&, char const*, unsigned long) in tsgC2Fortran.o "std::__1::basic_ostream<char, std::__1::char_traits<char> >::put(char)", referenced from: _tsgrea_ in tsgC2Fortran.o "std::__1::basic_ostream<char, std::__1::char_traits<char> >::flush()", referenced from: _tsgrea_ in tsgC2Fortran.o "std::__1::basic_ostream<char, std::__1::char_traits<char> >::sentry::sentry(std::__1::basic_ostream<char, std::__1::char_traits<char> >&)", referenced from: std::__1::basic_ostream<char, std::__1::char_traits<char> >& std::__1::__put_character_sequence<char, std::__1::char_traits<char> >(std::__1::basic_ostream<char, std::__1::char_traits<char> >&, char const*, unsigned long) in tsgC2Fortran.o "std::__1::basic_ostream<char, std::__1::char_traits<char> >::sentry::~sentry()", referenced from: std::__1::basic_ostream<char, std::__1::char_traits<char> >& std::__1::__put_character_sequence<char, std::__1::char_traits<char> >(std::__1::basic_ostream<char, std::__1::char_traits<char> >&, char const*, unsigned long) in tsgC2Fortran.o "std::__1::cerr", referenced from: _tsgrea_ in tsgC2Fortran.o "std::__1::cout", referenced from: _tsgpri_ in tsgC2Fortran.o "std::__1::ctype<char>::id", referenced from: _tsgrea_ in tsgC2Fortran.o std::__1::basic_ostream<char, std::__1::char_traits<char> >& std::__1::__put_character_sequence<char, std::__1::char_traits<char> >(std::__1::basic_ostream<char, std::__1::char_traits<char> >&, char const*, unsigned long) in tsgC2Fortran.o "std::__1::locale::~locale()", referenced from: _tsgrea_ in tsgC2Fortran.o std::__1::basic_ostream<char, std::__1::char_traits<char> >& std::__1::__put_character_sequence<char, std::__1::char_traits<char> >(std::__1::basic_ostream<char, std::__1::char_traits<char> >&, char const*, unsigned long) in tsgC2Fortran.o "std::__1::ios_base::__set_badbit_and_consider_rethrow()", referenced from: std::__1::basic_ostream<char, std::__1::char_traits<char> >& std::__1::__put_character_sequence<char, std::__1::char_traits<char> >(std::__1::basic_ostream<char, std::__1::char_traits<char> >&, char const*, unsigned long) in tsgC2Fortran.o "std::__1::ios_base::clear(unsigned int)", referenced from: std::__1::basic_ostream<char, std::__1::char_traits<char> >& std::__1::__put_character_sequence<char, std::__1::char_traits<char> >(std::__1::basic_ostream<char, std::__1::char_traits<char> >&, char const*, unsigned long) in tsgC2Fortran.o ld: symbol(s) not found for architecture x86_64 collect2: error: ld returned 1 exit status make[1]: *** [../libtasmanianfortran90.so] Error 1 make: *** [libtasmanianfortran90.so] Error 2

Sorry that the posting is long.

Could anyone give me some advice about how to fix it? Thank you!

OSError when Tasmanian is imported

Hello,

I installed with Python Pip and it installed successfully. I mainly want to use the library with Jupyter notebook. However I couldn't import the library and it shows the following error message:


OSError Traceback (most recent call last)
in
1 import numpy as np
----> 2 import Tasmanian
3 from scipy import interpolate
4 from scipy.stats import truncnorm
5 from scipy.optimize import fsolve

~/anaconda3/lib/python3.7/site-packages/Tasmanian.py in
41 SparseGrid = TasmanianSparseGrid
42
---> 43 import TasmanianDREAM as DREAM
44
45 from TasmanianAddons import *

~/anaconda3/lib/python3.7/site-packages/TasmanianDREAM.py in
29 ##############################################################################################################################################################################
30
---> 31 from TasmanianDreamLikely import *
32 from TasmanianDreamSampler import *
33 from TasmanianDreamState import DreamState as State

~/anaconda3/lib/python3.7/site-packages/TasmanianDreamLikely.py in
36 from TasmanianConfig import TasmanianInputError as InputError
37
---> 38 pLibDTSG = cdll.LoadLibrary(path_libdream)
39
40 pLibDTSG.tsgGetNumOutputs.restype = c_int

~/anaconda3/lib/python3.7/ctypes/init.py in LoadLibrary(self, name)
432
433 def LoadLibrary(self, name):
--> 434 return self._dlltype(name)
435
436 cdll = LibraryLoader(CDLL)

~/anaconda3/lib/python3.7/ctypes/init.py in init(self, name, mode, handle, use_errno, use_last_error)
354
355 if handle is None:
--> 356 self._handle = _dlopen(self._name, mode)
357 else:
358 self._handle = handle

OSError: /home/qingsong/.local/lib/libtasmaniandream.so: cannot open shared object file: No such file or directory

--------------------------------------------------------------------------------------------------------------------------end of error message

I am using ubuntu. Thanks!

Templates style and proper use

I have started using templates in some places:
SparseGrids/tsgCudaKernels.cpp
SparseGrids/tsgCudaMacros.hpp
SparseGrids/tsgRuleLocalPolynomial.hpp 9(used by tsgGridLocalPolynomial.hpp)

Since I have not used templates before, I would figure out any mistakes and style errors as early as possible. Could you please take a look at the above files and point out if I'm doing something fundamentally wrong.

Python and C error codes

Problem The Addon and Dream python modules rely on call-backs where python creates c-style of function pointers that are then used by the Tasmanian C++. However, each function is called in a different python environment, which is good for parallelism but bad for error caching. If an error occurs, the code keeps going to another call, which is probably also an error, and so on. If the user provided callable model is not absolutely correct, e.g., the output has incorrect dimension, then the code emits a ton of error messages and keeps going.

Proposed Solution Add a mechanism so that the Python call-back wrappers can indicate to C++ that an error occurred, so that C++ can then indicate the same problem to the main python thread/instance. The C++ wrappers can return an error code pass/fail (similar to the sparse-grid read() method), while the C++-Python callbacks can take an extra error-code variable.

Add adaptive refinement to Fourier grids

  • Requires a theoretical estimate for the relationship between trigonometric frequency, model properties (e.g., order of periodicity) and the approximation error.

Fortran Interface With Zero Needed Points

Hi Miroslav and all,

I am using the Fortran interface of TASMANIAN. And I tried the Example 9 code below (I use the cubic basis functions and the initial depth is equal to 3).

I find that when the number of needed points is zero, the estimated error is very large. I guess it is caused by CALL tsgLoadNeededPoints(grid1, values) and CALL tsgLoadNeededPoints(grid2, values).

I guess this can be fixed by adding an if condition by myself. But I am still a little worried about how the package works. Any comment is appreciated! Thanks!

Code:


PROGRAM TasmanianSGExample
  USE TasmanianSG
IMPLICIT NONE
  type(TasmanianSparseGrid) :: grid1, grid2
  INTEGER :: dims, outs, level
  INTEGER :: N1, N2
  INTEGER :: N, i, j
  DOUBLE PRECISION :: err1, err2
  DOUBLE PRECISION, pointer :: points(:,:), weights(:)
  DOUBLE PRECISION, allocatable :: values(:,:), tvalues(:,:)
  DOUBLE PRECISION, allocatable :: res2(:,:)
  DOUBLE PRECISION :: randPoints(4,1000), randPoints2(2,1000)

! prepare random samples for future tests
  call random_seed()
  call random_number(randPoints)

  ALLOCATE(tvalues(1,1000)) ! true values of f(x,y)
  DO i = 1, 1000
    randPoints2(1,i) = randPoints(1,i)
    randPoints2(2,i) = randPoints(2,i)
  END DO
  
  WRITE(*,*) 'Min randPoints2(1,:)=', MINVAL(randPoints2(1,:))
  WRITE(*,*) 'Max randPoints2(1,:)=', MAXVAL(randPoints2(1,:))
  WRITE(*,*) 'Min randPoints2(2,:)=', MINVAL(randPoints2(2,:))
  WRITE(*,*) 'Max randPoints2(2,:)=', MAXVAL(randPoints2(2,:))
  
  outs = 1

  ALLOCATE(res2(outs,1000)) ! 2-D result


  call tsgAllocateGrid(grid1)
  call tsgAllocateGrid(grid2)


! ==================================================================== !
! EXAMPLE 9:
! interpolate: f(x,y) = exp(-x) / (1 + 100 * exp(-10 * y))
! using different refinement schemes

! remake the true values for the next example
  DO i = 1, 1000
    tvalues(1,i) = exp(-randPoints2(1,i)) / (1.0 + 100.0 * exp(-10.0 * randPoints2(2,i)))
  END DO

  dims = 2
  outs = 1

  CALL tsgMakeLocalPolynomialGrid(grid1, dims, outs, 3, 3, tsg_localp)
  CALL tsgMakeLocalPolynomialGrid(grid2, dims, outs, 3, 3, tsg_localp)

  N = tsgGetNumNeeded(grid1)
  points => tsgGetNeededPoints(grid1)
  WRITE(*,*) 'N points of grid1 = ', N
  WRITE(*,*) 'points x of grid1 = ', points(1,:)
  WRITE(*,*) 'points y of grid1 = ', points(2,:)
  ALLOCATE(values(outs,N))
  DO i = 1, N
    values(1,i) = exp(-points(1,i)) / (1.0 + 100.0 * exp(-10.0 * points(2,i)))
  END DO
  CALL tsgLoadNeededPoints(grid1, values)
  CALL tsgLoadNeededPoints(grid2, values)
  DEALLOCATE(values)
  DEALLOCATE(points)

  WRITE(*,*) "-------------------------------------------------------------------------------------------------"
  WRITE(*,*) "Example 9: interpolate f(x,y) = exp(-x) / (1 + 100 * exp(-10 * y))"
  WRITE(*,*) "   the error is estimated as the maximum from 1000 random points"
  WRITE(*,*) "   tolerance is set at 1.E-5 and maximal order polynomials are used"
  WRITE(*,*)

  WRITE(*,*) "             Classic              FDS"
  WRITE(*,*) "iteration  points     error     points     error"

  DO j = 1, 7
    
    WRITE(*,*) 'j = ', j
    
    ! 1 below corresponds to classic refinement
    CALL tsgSetLocalSurplusRefinement(grid1, 1.D-5, tsg_classic)

    N = tsgGetNumNeeded(grid1)
    WRITE(*,*) 'N grid1 = ', N
    points => tsgGetNeededPoints(grid1)
    ALLOCATE(values(outs,N))
    DO i = 1, N
      values(1,i) = exp(-points(1,i)) / (1.0 + 100.0 * exp(-10.0 * points(2,i)))
    END DO
    CALL tsgLoadNeededPoints(grid1, values)
    DEALLOCATE(values)
    DEALLOCATE(points)

    CALL tsgEvaluateBatch(grid1, randPoints2, 1000, res2)
    err1 = 0.0
    DO i = 1, 1000
      IF(abs(res2(1,i) - tvalues(1,i)) .GT. err1)then
        err1 = abs(res2(1,i) - tvalues(1,i))
      ENDIF
    END DO

    CALL tsgSetLocalSurplusRefinement(grid2, 1.D-5, tsg_fds)

    N = tsgGetNumNeeded(grid2)
    WRITE(*,*) 'N grid2 = ', N
    points => tsgGetNeededPoints(grid2)
    ALLOCATE(values(outs,N))
    DO i = 1, N
      values(1,i) = exp(-points(1,i)) / (1.0 + 100.0 * exp(-10.0 * points(2,i)))
    END DO
    CALL tsgLoadNeededPoints(grid2, values)
    DEALLOCATE(values)
    DEALLOCATE(points)

    CALL tsgEvaluateBatch(grid2, randPoints2, 1000, res2)
    err2 = 0.0
    DO i = 1, 1000
      IF(abs(res2(1,i) - tvalues(1,i)) .GT. err2)then
        err2 = abs(res2(1,i) - tvalues(1,i))
      ENDIF
    END DO

    N1 = tsgGetNumPoints(grid1)
    N2 = tsgGetNumPoints(grid2)

    WRITE(*,"(I9,I9,E12.4,I9,E12.4)") j, N1, err1, N2, err2
  END DO
  WRITE(*,*)


  CALL tsgDeallocateGrid(grid1)
  CALL tsgDeallocateGrid(grid2)

! cleanup
  DEALLOCATE(res2)
  DEALLOCATE(tvalues)
  
  WRITE(*,*) "-------------------------------------------------------------------------------------------------"
  WRITE(*,*)
  
  
END PROGRAM TasmanianSGExample

Output:


 -------------------------------------------------------------------------------------------------
 Example 9: interpolate f(x,y) = exp(-x) / (1 + 100 * exp(-10 * y))
    the error is estimated as the maximum from 1000 random points
    tolerance is set at 1.E-5 and maximal order polynomials are used

              Classic              FDS
 iteration  points     error     points     error
 j =            1
 N grid1 =           36
 N grid2 =           36
        1       65  0.2974E-01       65  0.2974E-01
 j =            2
 N grid1 =           64
 N grid2 =           56
        2      129  0.5540E-02      121  0.5540E-02
 j =            3
 N grid1 =          114
 N grid2 =          108
        3      243  0.9817E-03      229  0.9817E-03
 j =            4
 N grid1 =          156
 N grid2 =          145
        4      399  0.1361E-03      374  0.1361E-03
 j =            5
 N grid1 =          196
 N grid2 =          190
        5      595  0.1361E-03      564  0.1361E-03
 j =            6
 N grid1 =          104
 N grid2 =           96
        6      699  0.1361E-03      660  0.1361E-03
 j =            7
 N grid1 =            0
 N grid2 =            0
        7      699  0.1155E+78      660  0.3073+232

 -------------------------------------------------------------------------------------------------

Figure out Doxygen quirks

  • Doxygen font sizes are not entirely consistent
  • Internal/external documentation is not always registered properly
  • Some of the \brief clauses come with extra punctuation

Add Support for Intel GPUs

  • CUDA and HIP follow similar paradigms
  • SYCL and DPC++ used in Intel platforms are quite a bit different

Add mixed precision evaluate options

  • many devices work much faster with single as opposed to double precision
  • double precision is needed for stability when constructing the surrogate
  • single precision should be sufficient when evaluating, especially local polynomial grids

Add MPI worker-only template

In the MPI construct surrogate, only the root method operates on the grid, yet the non-root methods also need a grid parameter.

  • consider a worker only template that accepts inputs about the MPI environment and the model lambda, but does not need a grid input

Fortran 2003 complex and GPU methods

  • add evaluateBatchGPU() to the Fortrain 2003 interface
  • test evaluateBatchGPU() (not sure how)
  • fix the complex compiler problem on the PGI compiler with the Fourier hierarchical coefficients

Improve the PIP installer

Main concerns

  • add testing for the pip in the inside nightly builds
  • see how to enable automatic dependencies download for numpy and scikit-build
    • maybe try requirements.txt in place of the pyproject.toml file

Secondary concerns

  • check if there is a reasonable way to show the correct license on the pip page
  • check scikit-build quirks to possibly enable cuda with an options, e.g., --install-option=-cuda
    • actually this works in off-line mode but under install from the web-page (and when install options are given) scikit seems to want to download and/or build CMake and CUDA; CMake fails under Linux and CUDA fails under Windows
    • must get scikit to first check for compatible versions of CUDA already installed
  • enable system-wide installs through pip, i.e., remove the --user tag
    • must figure out whether doing a user install or system-wide install

Progress report:

  • #504 fixes the requirements
  • nightly tests have been added
  • #525 added the compile options through environment variables
  • skipping the system-wide install

Python interface and PyTorch.tensor

Hi,

I use the Tasmanian library to interpolate highly non-linear functions in the contest of dynamic programming.
Since an optimizer requires Jacobian, I use the PyTorch's automatic gradient function, but there is a conflict with the python interface of Tasmanian because the interface assumes numpy.
For instance, in the following snippet:

policy_plus.evaluate(_stateplus)

Since _stateplus is a tensor variable, the Tasmanian claims the following error.

AttributeError: 'Tensor' object has no attribute '__array_interface__'

Do you have some hacks to have the tensor variable as the argument of the evaluate method?'

Tasmanian: version 7.0
Python 3.7

Thank you in advance.

Default install behavior

The current goal of Tasmanian is to support 4 installation modes: basic, easy, regular, and XSDK (I just made up the names)

Basic: on most standard Linux machines with g++ installed, Tasmanina should build with just "make".
Supported: core functionality and OpenMP. Interfaces are supported for Python, MATLAB, Fortran (only gfortran) using a corresponding "make " command.
Not supported: anything even slightly advanced, no automatic detection of Python or anything else, no "make install" as the install folder is set to the source folder, no acceleration from CUDA or BLAS.

Easy: run a ./install.sh script, the script will ensure basic sanity, i.e., provide install-prefix and check if the MATLAB work folder has read/write permissions; the script should attempt to enable as many features as possible and have easy switches to turn options on/off. This install will execute the full sequence "cmake; make; make test; make install; ./test_post_install.sh" and stop if tests fail.
Attempt to auto-enable: OpenMP, BLAS, CUDA, Pythoh, auto-disable any features if the corresponding find_package fails.
Manually allow: everything else, Fortran (there are issues with automatic fortran search), MATLAB (needs user specified folder), MPI (still somewhat experimental and a more advanced feature anyway)
NOTE: the install.sh script is good for auto-testing, once command builds, installs and tests and uses make -j for CUDA projects.

Regular: virtually the same as ./install.sh, just call cmake directly without the wrapper.

XSDK: called from cmake directly, default behavior changes so that everything is disabled by default unless explicitly enabled by XSDK_ENABLE commands. Never auto-disable anything, make all errors fatal.

Reasoning: the installation process is the time when the user is least experienced with the software and the time when the user is most likely to just give up on Tasmanian. If a user gets the core functionality with just "make", they can start doing something and only later switch to a more advanced install with more options. Currently, have users that don't know how to use cmake.
"I don't have cmake or I don't know what cmake is." - go for Basic install
"I have cmake, but I don't know how to use it or high performance is not a major concern." - go for Easy install
"I know how to use cmake, please don't hold my hand." - go for Regular or XSDK install

CUDA as a CMake lang

CMake is switching the support for "CUDA as a first class language", which actually comes with massive regression in capabilities. Pros and Cons must be weighted in a decision to switch to the new CMake way

  • Find all math-libraries and keep the script up-to-date with the CUDA standard
  • Find the run-time libraries to avoid extraneous requirements, e.g., nvcc should not be required to link to libtasmaniansparsegrid.so
  • Work-around the OpenMP flags, nvcc does not recognize those

Extrapolation rule for hierarchical interpolation

Hi Miroslav and all,

I am using the 'Local Polynomial Grids: Hierarchical interpolation' to apply the adaptive sparse grid method.

I need to maximize the interpolation function and should get some values out of the range of interpolation. But I did not find the extrapolation rule in the manual. Could you give me so advice on that? Thanks a lot!

Weighted/Guided refinement criterion

Tasmanian has already provided the customized refinement criterion and had the scale correction argument in the local version of the setSurplusRefinement() function; however, the python interface of this seems to be missing. I highly appreciate if you provide this function in python so that we can customize a refinement criterion depending on the specific needs of our applications.

MPI Build Issue in v7.0

  • there is an issue of how CMake handles lists and string with multiple flags, e.g.,
-fexceptions -pthread vs. "-fexceptions -pthread"

Minor points

  • Fortran coverage is over 80%, but more is needed
  • cmake 3.10 is set in the CI, but should be set in the nightly builds too

Initial points

  • figure out the Doxygen problem, why newer versions show strange scrollbar
  • add more tests to the Fortran refinement methods, cover more of the overloads
  • expand the nightly system to test newer versions of cmake
  • update the spack package

Build Tasmanian for apple m1

Hi,

First and foremost, I'd want to express my gratitude to the developer for their excellent job. I've utilized the Tasmanian library for several of my research projects. I recently acquired a machine with an Apple m1 processor. Installing Tasmanian straight from pip results in a broken library. I attempted to build the package using the build instructions. While the package was successfully built, I had the following issue while attempting to import Tasmanian:

OSError                                   Traceback (most recent call last)
<ipython-input-2-405aa3b9f3e0> in <module>
----> 1 import Tasmanian

/usr/local/share/Tasmanian/python/Tasmanian.py in <module>
     43 import TasmanianDREAM as DREAM
     44
---> 45 from TasmanianAddons import *
     46
     47 def useVerboseErrors(bVerbose):

/usr/local/share/Tasmanian/python/TasmanianAddons.py in <module>
     37 TasmanianInputError = TasmanianConfig.TasmanianInputError
     38
---> 39 pLibCTSG = cdll.LoadLibrary(TasmanianConfig.__path_libcaddons__)
     40
     41 type_1Dfunc = CFUNCTYPE(c_double, c_double)

/opt/homebrew/Caskroom/miniforge/base/envs/automatic_projection_filter/lib/python3.9/ctypes/__init__.py in LoadLibrary(self, name)
    458
    459     def LoadLibrary(self, name):
--> 460         return self._dlltype(name)
    461
    462     __class_getitem__ = classmethod(_types.GenericAlias)

/opt/homebrew/Caskroom/miniforge/base/envs/automatic_projection_filter/lib/python3.9/ctypes/__init__.py in __init__(self, name, mode, handle, use_errno, use_last_error, winmode)
    380
    381         if handle is None:
--> 382             self._handle = _dlopen(self._name, mode)
    383         else:
    384             self._handle = handle

OSError: dlopen(/usr/local/lib/libtasmaniancaddons.dylib, 0x0006): weak-def symbol not found '__ZN7TasGrid20TasmanianDenseSolver18solvesLeastSquaresINSt3__17complexIdEEEEvPKNS_19AccelerationContextEiiPT_iS9_'

How to solve this problem? Thanks

User provided handles

  • cuBlas, cuSparse, and Magma libraries use special handles and queues every time they are called
  • currently Tasmanian creates and owns such handles internally
  • add capability to assign handles externally

DREAM bindings for Python

  • create python bindings for Tasmanian DREAM
  • use the ctypes function pointer bindings for the lambda expressions

Use gfortran on Mac OSX

Hi Miroslav and all,

I have asked a question about using the Fortran interface on Mac OSX. And I learned that it's better to Cmake instead of gfortran to run the code because Cmake can correctly link to libstdc++.

But still, I was wondering whether there is any possibility to use gfortran? The reason is that I also want to link to other libraries except for TASMANINA. Specifically, I am using the following code to use an optimization package named IPOPT:

gfortran hs071.f90 -o hs071.out -L /usr/local/lib -lipopt -fbounds-check -O2

I search for using Cmake to link to this package, but it seems complicated for me. Hopefully, I can use gfortran for both packages. If gofrtran is not desirable, I also have ifort.

Any advice is appreciated. Thanks!

Interpolation results from 'grid.evaluate()' differ significantly after Anaconda upgrading

Hi there,

Apology in advance since I know I am vague about this question.

I didn't upgrade my Jupyter notebook since November, 2019. In the past few weeks, I have been using TASMANIAN sparse grid to solve a time iteration problem. I used the interpolation function like introduced in this example (https://ornl.github.io/TASMANIAN/stable/group__TasmanianSGExamples4.html). I expect at least some positive numbers, but in many cases, interpolation is negative. After I upgrade Anaconda to the latest version, this issue is fixed magically.

I reckon the source code of 'grid.evaluate()' performs differently with support of the 'latest' and 'not-so-latest' Jupyter Notebook. Is there any chance that I can get hints to look at specific libraries in Python to figure out why? If needed, I can send my code files. I know it is like a mission impossible. Thanks in advance for your patience and time.

Regards,
Qingsong

Public Docker image

I notice you have a docker directory. But I don't see any images on hub.docker.com that are clearly TASMANIAN related. Is it safe to assume that there are no public Docker images with pre-built tasgrid?

If so, are there any plans to create one? I've already built such an image and I was thinking about creating an auto-build public Docker image. But I don't want to create any confusion or do any extra work if there is already a public Docker image available and I'm just not seeing it...?

OSX Pip bug

Sparse grids example 6 fails with segfault when Tasmanian 7.1 is installed with Pip under OSX. Regular CMake install works fine, the bug doesn't appear with Pip under Mac or Windows.

Read Initialization

Currently, when issuing the read command, the internal API will initialize a bunch of classes to empty and then overwrite the empty with the data from the stream.

Objective:

  • combine the commands to a single read-initialize for all internal data-structures

Benefit:

  • improves internal consistency
  • lowers the dangers of wrong initialization or overly-complex reset-then-read logic
  • reduces the code

Collateral fixes:

  • while updating the logic, can simplify the padding-logic

Obstacles:

  • the current file-format does not respect the order of variables in the class structures
  • need to update the file format to be more consistent
    • base variables must come first
    • binary and ascii must have the same order (see surpluses and needed in localp grids)
  • initialization of inherited variables must be done with a constructor in the base class
  • template parameter deduction must be done with types (as opposed to bools)
  • must maintain backwards compatibility

Create a pip installer

  • create a pip-installer for Tasmanian
  • very appropriate given the expanded Python capabilities

Avoid negative interpolated values

Hi,
I'm using Tasmanian to construct a model of a function with high dimensional input (d=3 to 10) and
compute interpolated values. Since my function has a sharp interface, I apply a local polynomial grid of order 1 and spatial refinement (refine_fds / refine_parents_first for stability). Even though the function output is always positive, I get negative interpolated values. Is there a way to avoid negative interpolated values (other than just cropping them)?
Thanks!

Add Sobol Index Method for all Grid Types

Anisotropic coefficients are a good estimate for Global/Sequence/Fourier grids, but Local Polynomial and Wavelet grids do not have a good estimate.

  • the Sobol indexes can be estimated using Monte Carlo method easily, but it requires user code
  • look into analytic estimates of the indexes
  • if not analytic, then add the Monte Carlo method as an addon

Improved Fortran 2003

Moving over to automatically generated Fortran 2003 interface will help maintenance and porting new features. But testing is needed and a few enhancements.

  • check for a way to return pointers to points, i.e.,
! current API supports only this
allocate(points(grid%getNumDimensions(), grid%getNumPoints()))
call grid%getPoints(points(:,1))
! prefer to have this
points = grid%getPoints()
  • return a copy of the hierarchical coefficients and loaded points (work-around the complex case)
  • add testing for the methods
  • check for the dynamic returning methods, i.e., sparse basis matrix and construction points
  • see for a way to mimic lambdas using function pointers and void-pointer user data (capture)

Maybe add helper classes on the C++ side (wrapper around a std::vector) and have functional API to get the data from C++ and copy over to python.

Enable CUDA in the CI

Perform CI testing with CUDA, right now the docker image does not support cuda.

Note that cmake needs:
-D Tasmanian_ENABLE_CUBLAS:BOOL=ON (set by default)
-D CUDA_TOOLKIT_ROOT_DIR:PATH= (if FindCUDA doesn't find it automatically)

Off-line testing is currently done with 7.5, 8.0, 9.0, and 9.1. We can pick whatever is the easiest "default" by NVIDIA or latest version 9.1. It matters little for the CI.

We have to make sure Tasmanian build with cuda support and cmake did not automatically disable it. For example:
[[ -z tasgrid -v | grep cublas ]] || { echo "Tasmanian was not compiled with cublas support"; exit 1;}

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.