Auxiliaries

ProcessTableOutput

class simu.core.utilities.output.ProgressTableOutput

Based on defined column headings and printing format strings for the table elements, print the provided data successively to the given stream.

The header is not printed before the first row of data is provided. The space taken by the row elements then determines the individual column widths. Example:

>>> from simu import  Quantity
>>> from io import StringIO  # this is only required to make doctest happy.
>>> stream = StringIO()  # else, we could just use the default stream here.
>>> cols = {"m": ("Magnitude", "{:9.2g}"), "u": ("Unit", "{:>15s}")}
>>> table = ProgressTableOutput(cols, stream=stream)
>>> table.row(Quantity(20, "m/s"))
>>> table.row(Quantity(10, "degC"))
>>> print(stream.getvalue())
Row Magnitude           Unit
--- --------- --------------
  1        20 meter / second
  2        10 degree_Celsius
__init__(columns: ~collections.abc.Mapping[str, ~typing.Tuple[str, str]], row_dig: int | None = 3, row_head='Row', stream=<_io.TextIOWrapper name='<stdout>' mode='w' encoding='utf-8'>)

The constructor configures the table based on the following parameters:

Parameters:
  • columns – The keys of the dictionary are the names of the attributes to tabulate. THe value tuple represents the column header (first element) and the formatting string (second element).

  • row_dig – The number of digits to be reserved for the row number. If None, do not print the row number. Otherwise, the row will be the first column of the table.

  • row_head – The heading for the row column.

  • stream – The used output stream. If None, no output will be generated.

row(data: object, row: int = None)

Print a data row, whereas the attributes are extracted from the given object. If this is the first row of the table, the headers will be printed with it, and the column width thereby determined.

Parameters:
  • data – The object, which must have the attributes as defined as keys in the columns mapping given to the constructor.

  • row – The row number to be printed. If omitted, the row number is incremented from the previous row, starting with one.

Configurable

class simu.core.utilities.configurable.Configurable

In particular the numerical solvers offer a number of options that can be provided by the constructor but also explicitly set. This class offers such functionality and supports validation of the individual options given.

__init__(exclude: list[str] = None)

The constructor uses the inspect module to obtain the arguments of the subclass constructor and collects them into the options attribute after validation.

Arguments given in exclude are not included here.

set_option(name: str, value: Any)

Set the option with given name to the given value. A KeyError is raised if there is no argument with given name, and a ValueError is raised if the value is not accepted.

Only options defined as arguments in the constructor can be addressed with this method.