Tessera
- mosaic.core.tessera.tessera(*args, **cmd_config)[source]
Decorator that transforms a standard class into a tessera-capable class.
The resulting class can still be instantiated as usual
Klass(...)
, which will generate a standard local instance, or onto the mosaic runtimeKlass.remote(...)
, which will instantiate the class in a remote endpoint and return a proxy to the user.A mosaic Parameter can also be instantiated by using
Klass.parameter(...)
.TODO - Better explanations and more examples.
- Returns
- Return type
Enriched class
Examples
>>> @tessera >>> class Klass: >>> def __init__(self, value): >>> self.value = value >>> >>> def add(self, other): >>> self.value += other >>> return self.value >>> >>> # We can still generate a standard local instance >>> local_instance = Klass(10) >>> >>> # but also a remote instance by invoking remote. >>> remote_proxy = Klass.remote(10) >>> >>> # The resulting proxy can be used to call the instance methods, >>> task = remote_proxy.add(5) >>> # which will return immediately. >>> >>> # We can do some work while the remote method is executed >>> # and then wait for it to end >>> await task >>> >>> # We can retrieve the result of the task invoking result on the task >>> await task.result() 15
- class mosaic.core.tessera.Tessera(cls, uid, *args, **kwargs)[source]
Bases:
mosaic.core.base.RemoteBase
A tessera is an actor in the mosaic parallelism model.
A tessera represents an object that is instantiated in a remote portion of the network, and which we reference through a proxy. This proxy allows us to execute methods on that remote object simply by calling the method.
A tessera is kept in memory at the worker for as long as there are proxy references to it. If none exist, it will be made available for garbage collection.
Objects of class Tessera should not be instantiated directly by the user and the
@mosaic.tessera
decorator should be used instead.- Parameters
cls (type) – Class of the remote object.
uid (str) – UID assigned to the tessera.
- async call_safe(sender_id, method, task)[source]
Call a method while handling exceptions, which will be sent back to the sender if they arise.
- Parameters
sender_id (str) – UID of the original caller.
method (callable) – Method to execute.
task (Task) – Task that has asked for the execution of the method.
- property collectable
Whether the object is ready for collection.
- get_attr(item)[source]
Access attributes from the underlying object.
- Parameters
item (str) – Name of the attribute.
- property is_parameter
- make_parameter()[source]
Transform the tessera into a parameter and return the object.
- Returns
- Return type
object
- property obj
Internal object.
- remote_runtime
Proxies that have references to this tessera.
- send_exception(sender_id=None, method=None, task=None)[source]
Context manager that handles exceptions by sending them back to the
uid
.- Parameters
sender_id (str) – Remote UID.
method (callable) – Method being executed.
task (Task) – Task that has asked for the execution of the method.
- set_attr(item, value)[source]
Set attributes on the underlying object.
- Parameters
item (str) – Name of the attribute.
value (object) –
- type = 'tessera'
- class mosaic.core.tessera.TesseraProxy(cls, *args, **kwargs)[source]
Bases:
mosaic.core.base.ProxyBase
Objects of this class represent connections to remote tessera, allowing us to call methods on them.
Objects of class TesseraProxy should not be instantiated directly by the user and the
@mosaic.tessera
decorator should be used instead.- Parameters
cls (type) – Class of the remote object.
args (tuple, optional) – Arguments for the instantiation of the remote tessera.
kwargs (optional) – Keyword arguments for the instantiation of the remote tessera.
- property collectable
Whether the object is ready for collection.
- get_attr(item)[source]
Get at attribute from the remote tessera.
- Parameters
item (str) –
- Returns
- Return type
AwaitableOnly
- property is_parameter
- make_parameter(*args, **kwargs)[source]
Transform the proxy into a parameter.
- Returns
- Return type
object
- remote_runtime
Proxy to the runtime where the tessera lives.
- property runtime_id
UID of the runtime where the tessera lives.
- async classmethod select_worker(runtime=None)[source]
Select an available worker.
- Parameters
runtime (str or Runtime, optional) – If a valid runtime is given, this will be selected as the target worker.
- Returns
UID of the target worker.
- Return type
str
- set_attr(item, value)[source]
Set an attribute on the remote tessera.
- Parameters
item (str) –
value (object) –
- type = 'tessera_proxy'
- class mosaic.core.tessera.ArrayProxy(cls, *args, **kwargs)[source]
Bases:
mosaic.core.base.CMDBase
Objects of this class represent more a set of remote tesserae that may live on one or more remote runtimes. An array proxy allows us to reference all of them together through a common interface, as well as map calls to them.
Objects of class ArrayProxy should not be instantiated directly by the user and the
@mosaic.tessera
decorator should be used instead.- Parameters
cls (type) – Class of the remote object.
args (tuple, optional) – Arguments for the instantiation of the remote tessera.
len (int, optional) – Length of the array, defaults to 1.
kwargs (optional) – Keyword arguments for the instantiation of the remote tessera.
- get_attr(item)[source]
Get at attribute from the remote tessera.
- Parameters
item (str) –
- Returns
- Return type
AwaitableOnly
- make_parameter(*args, **kwargs)[source]
Transform the proxy into a parameter.
- Returns
- Return type
list
- remote_runtime
Proxy to the runtime where the tessera lives.
- property runtime_id
UID of the runtime where the tessera lives.
- set_attr(item, value)[source]
Set an attribute on the remote tessera.
- Parameters
item (str) –
value (object) –
- type = 'tessera_proxy_array'
- class mosaic.core.tessera.ParameterMixin[source]
Bases:
object
A parameter is a Python object that, when moved across different runtimes in the mosaic network, will retain a reference to its original, root object.
This reference means that changes to a local object can be propagated to the root object using
obj.method(..., propagate=True)
.It also means that attributes of the root object can be changed using
obj.set('attr', value)
. The latest value of an attribute can be pulled from the root object by doingawait obj.get('attr')
.Objects of class Parameter should not be instantiated directly by the user and the
@mosaic.tessera
decorator should be used instead.- property cached
- property has_tessera
- property is_proxy
- property is_tessera
- property ref