otf.runtime: Support functions for the runtime#

class otf.runtime.NamedReference(obj)#

Serialisable wrapper around a module, class or function.

NamedReference are serialised by copying the name to the wrapped object:

>>> import math
>>> fl = NamedReference(math.floor)
>>> dump_text(fl)
"otf.NamedReference('math.floor')"

If the wrapped object is callable then the wrapped will pass calls transparently to the object:

>>> fl(12.6)
12

Attribute accesses are also transparently passed through to the wrapped value:

>>> m = NamedReference(math)
>>> m.ceil(5.6)
6

This means that, in most cases, the NamedReference wrapper is transparent. Sometimes you actually need to access the wrapped value:

>>> WrappedComplex = NamedReference(complex)
>>> k = WrappedComplex(5)
>>> isinstance(k, WrappedComplex)
Traceback (most recent call last):
  ...
TypeError: isinstance() arg 2 must be a type, a tuple of types, or a union
>>>

You can use the ~ operator to access the wrapped value:

>>> ~WrappedComplex
<class 'complex'>
>>> isinstance(k, ~WrappedComplex)
True
Parameters

v (class|module|function) – The object that will be wrapped.

Raises
  • ValueError – if obj cannot be reloaded via its name (e.g.: if obj is defined inside a function).

  • TypeError – if obj is not a module, class or function or if obj is a lambda.

class otf.runtime.Task(function, args=<factory>, kwargs=<factory>)#

A deferred function application

static make(fn, /, *args, **kwargs)#

Create a Task.

This is useful when implementing schedulers. We capture the function, the arguments and the environment it runs in.