Doxygen
1.9.1
|
The Python interface uses c_types
and links to the C interface of Tasmanian as well as several additional C-style functions, e.g., when dealing with Addon templates. The C++ classes are converted to void*
pointers and then wrapped inside Python classes with near identical interface. The C++ vectors are replaced by 1D and 2D numpy.ndarray
structures, the enumerated types are replaced by strings, and the C++ std::function
and lambda
expressions by Python callable objects and lambdas. See the Fortran 2003 comments about the row major matrix format.
Python 3 is the only version currently tested and Tasmanian uses the following modules:
sys
c_types
numpy
matplotlib.pyplot
Tasmanian is also available through PIP: https://pypi.org/project/Tasmanian/; however, the PIP installation comes with additional requirements for facilitating the CMake build process. See the PIP section on the installation instructions page.
Starting with Tasmanian 7.0 all Python capabilities are included in a single module:
Note that the Tasmanian install path must be included in the Python search path:
Either path is sufficient if it is added to the environment variable PYTHONPATH
(e.g., via the TasmanianENVsetup.sh
script) or with the sys.path.append()
command.
Example for creating an instance of a sparse grid:
Example for using DREAM sampling:
See the Python examples in <install-prefix>/share/Tasmanian/examples/
.
Every class and method in Tasmanian comes with additional comments designed to be accessed with the Python help()
function, e.g.,
The Tasmanian Python module comes with a comprehensive error checking mechanisms where the validity of the inputs to every method are checked and TasmanianInputError
exception is raised whenever invalid input is encountered. The TasmanianInputError
class has two variables:
evaluate()
cannot be called before loadNeededPoints()
All acceleration modes are available through the Python interface and the same rules for thread safety apply as in the C++ interface. One point of difference is the SparseGrid.evaluate()
function, which on the Python side will link to SparseGrid.evaluateFast()
and therefore not safe to call from different threads. Safe evaluations can be performed with SparseGrid.evaluateThreadSafe()
.
The model callable inputs to load/reload and construct methods will be executed in parallel on most Python implementations.
If matplotlib.pyplot
module is available, Tasmanian.SparseGrid
will enable two plotting methods:
Note that matplotlib.pyplot
doesn't have to be available during build time, it can be installed later and still used with a current installation of Tasmanian.