Module pyrat

The pyRat Python module pyrat is split into several submodules.

Python and C++

The pyrat.rat submodule is the only submodule using C++. All other submodules are written in pure Python code within the pyrat/src/pyrat directory and are mostly helpers and tools for comfort using pyrat.rat.

CLI : pyrat.cli

The pyrat.cli command line interface submodule is used as a simple entry point for generating pyRat examples defined in the pyrat/src/pyrat/examples directory.

pyrat -e              # list all available examples
pyrat -e moon         # generate rat/dm/moon.py example
pyrat -e dmsh*        # generate rat/mdl/dmesher/{dmshcoil.py, dmshyoke1.py, dmshyoke2.py} examples
pyrat -e mdl/**       # generate all Rat-Models examples
pyrat -e rat-template # generate rat/rat-template/rat-template.py example
pyrat -e **           # generate all examples

Examples will be stored under a generated ./examples directory like so:

examples/
├── rat/
    ├── dm/
    ├── fmm/
    ├── mat/
    ├── mdl/
    |   ├── asbuild/
    |   ├── dmesher/
    |   ├── nlsolver/
    |   ├── other/
    |   ├── simple/
    ├── rat-template/

Color : pyrat.col

The pyrat.col color submodule can be used for simple message formatting, mimicing terminal color definitions from the rat-common/include/typedefs.hh header file with some additional escape sequences.

from pyrat.col import *
print(f"{KYEL}WARNING:{KNRM} Colors are nice.")

Log : pyrat.log

The pyrat.log logging submodule defines a simple base config for users to easily setup a logger with console and file handlers.

# Import pyRat logging module
import pyrat.log
# Get logger instance with basic configuration (console + file handlers)
plg = pyrat.log.config(__file__)
# Get logger instance with basic configuration (console handler only)
plg = pyrat.log.config(__file__, file_h=0)
# Get logger instance with basic configuration (file handler only)
plg = pyrat.log.config(__file__, console_h=0)

Python offers a nice standard logging module that is very flexible, although easy to make complex rather quickly.

Meta : pyrat.meta

The pyrat.meta metadata submodule gathers information about the pyrat Python module such as versions of Rat or CUDA, ASCII logos and more.

Rat : pyrat.rat

The pyrat.rat core module contains the binding to Rat C++ libraries made with pybind11. It is of course the heart of the magnetic simulations and bridges Python code to the original C++ Code.