modelrunner.utils module

Miscellaneous utility methods.

hybridmethod

Decorator to use a method both as a classmethod and an instance method.

import_class

Import a class or module given an identifier.

class hybridmethod(fclass, finstance=None, doc=None)[source]

Bases: object

Decorator to use a method both as a classmethod and an instance method.

Note

The decorator can be used like so:

@hybridmethod
def method(cls, ...): ...

@method.instancemethod
def method(self, ...): ...

Adapted from https://stackoverflow.com/a/28238047

classmethod(fclass)[source]
instancemethod(finstance)[source]
import_class(identifier)[source]

Import a class or module given an identifier.

Parameters:

identifier (str) – The identifier can be a module or a class. For instance, calling the function with the string identifier == ‘numpy.linalg.norm’ is roughly equivalent to running from numpy.linalg import norm and would return a reference to norm.

is_serial_or_mpi_root()[source]

Function checking whether the current program is serial or an MPI root node.

Return type:

bool