![]() |
YAC 3.7.0
Yet Another Coupler
|
For a module reference see yac.
This package provides Python bindings for the YAC coupler. They are generated using cython and can be enabled with the --enable-python-bindings
configure flag. This enables the configure checks, the compilation of the Python extension module (.so file) and the corresponding tests. Hard dependencies for the Python bindings are the packages
cython
numpy
For the test suite also matplotlib
are recommended. For the function Component.comp_comm
and get_comps_comm
the module mpi4py
is required. mpi4py
must be compiled with the same MPI version as YAC to function properly. To convert the iso8601 date/time strings returned by YAC functions, e.g. YAC.start_datetime
to a Python datetime format we recommend isodate or the Python bindings of mtime. All packages (except for mtime) can be installed by pip
.
To use the Python bindings in a Python program, add the path containing the Python extension module file to the PYTHONPATH
environment variable. Alternatively, you can install the extension module by executing pip install .
in the python
sub-directory of your build directory. This can also be used to install yac into a virtual environment. (In some cases it might be necessary to install the wheel
package before executing the before mentioned command.)
The bindings are designed to build a thin layer between Python and YAC. I.e. methods are directly forwarded to the corresponding YAC functions with a few exceptions:
numpy.ascontiguousarray
(involving a copy if it is not already contiguous) and converted to a cython memory view to extract the size and pointer.mpi4py.MPI.Comm
and vice-versa.The Python interface provides the coroutines yac::Field::get_coro and yac::Field::put_coro that can be used to write asynchronous code. This is in particular useful if multiple fields with different timesteps need to be handled. The following example shows how to use the coroutines assuming a source field field_source
and target field field_target
are defined.
Note that the code does not need to know anything about the timestepping. Both fields are processed independendly from each other. Effectively the event loop of ayncio spinns between the two coroutines and proceeds where possible.
Note: The Python binding coroutines do not depend on asyncio
and can also be used with other coroutine frameworks.
built-in the python logging
package into the python bindings. Most log records are triggered on the level DEBUG
. Note that due to a limitation in cython
the stack information that is passed to the logger is wrong (i.e. filename, module, etc.)
In the examples directory a framework of classes can be found that act as model component. To start a configuration with different components the driver.py can be used. It allows sequential coupling as well as parallel coupling.
The framework contains the following example components: