academy.exchange.proxystore¶
ProxyStoreExchange
¶
ProxyStoreExchange(
exchange: Exchange,
store: Store[Any],
should_proxy: Callable[[Any], bool],
*,
resolve_async: bool = False
)
Bases: ExchangeMixin
Wrap an Exchange with ProxyStore support.
Sending large action payloads via the exchange can result in considerable slowdowns. This Exchange wrapper can replace arguments in action requests and results in action responses with proxies to reduce communication costs.
Parameters:
-
exchange
(Exchange
) –Exchange to wrap.
-
store
(Store[Any]
) –Store to use for proxying data.
-
should_proxy
(Callable[[Any], bool]
) –A callable that returns
True
if an object should be proxied. This is applied to every positional and keyword argument and result value. -
resolve_async
(bool
, default:False
) –Resolve proxies asynchronously when received.
Source code in academy/exchange/proxystore.py
close
¶
register_agent
¶
register_agent(
behavior: type[BehaviorT],
*,
agent_id: AgentId[BehaviorT] | None = None,
name: str | None = None
) -> AgentId[BehaviorT]
Create a new agent identifier and associated mailbox.
Parameters:
-
behavior
(type[BehaviorT]
) –Type of the behavior this agent will implement.
-
agent_id
(AgentId[BehaviorT] | None
, default:None
) –Specify the ID of the agent. Randomly generated default.
-
name
(str | None
, default:None
) –Optional human-readable name for the agent. Ignored if
agent_id
is provided.
Returns:
-
AgentId[BehaviorT]
–Unique identifier for the agent's mailbox.
Source code in academy/exchange/proxystore.py
register_client
¶
terminate
¶
terminate(uid: EntityId) -> None
Close the mailbox for an entity from the exchange.
Note
This method is a no-op if the mailbox does not exist.
Parameters:
-
uid
(EntityId
) –Entity identifier of the mailbox to close.
Source code in academy/exchange/proxystore.py
discover
¶
Discover peer agents with a given behavior.
Parameters:
-
behavior
(type[Behavior]
) –Behavior type of interest.
-
allow_subclasses
(bool
, default:True
) –Return agents implementing subclasses of the behavior.
Returns:
Source code in academy/exchange/proxystore.py
get_mailbox
¶
Get a client to a specific mailbox.
Parameters:
-
uid
(EntityId
) –EntityId of the mailbox.
Returns:
-
Mailbox
–Mailbox client.
Raises:
-
BadEntityIdError
–if a mailbox for
uid
does not exist.
Source code in academy/exchange/proxystore.py
send
¶
Send a message to a mailbox.
Parameters:
Raises:
-
BadEntityIdError
–if a mailbox for
uid
does not exist. -
MailboxClosedError
–if the mailbox was closed.
Source code in academy/exchange/proxystore.py
get_handle
¶
get_handle(
aid: AgentId[BehaviorT],
) -> UnboundRemoteHandle[BehaviorT]
Create a new handle to an agent.
A handle enables a client to invoke actions on the agent.
Note
It is not possible to create a handle to a client since a handle is essentially a new client of a specific agent.
Parameters:
-
aid
(AgentId[BehaviorT]
) –EntityId of the agent to create an handle to.
Returns:
-
UnboundRemoteHandle[BehaviorT]
–Handle to the agent.
Raises:
Source code in academy/exchange/__init__.py
ProxyStoreMailbox
¶
ProxyStoreMailbox(
mailbox: Mailbox,
exchange: ProxyStoreExchange,
resolve_async: bool = False,
)
Bases: NoPickleMixin
Client protocol that listens to incoming messages to a mailbox.
Parameters:
-
mailbox
(Mailbox
) –The mailbox created by the wrapped exchange.
-
exchange
(ProxyStoreExchange
) –The wrapper exchange.
-
resolve_async
(bool
, default:False
) –Begin resolving proxies in action requests or responses asynchronously once the message is received.
Source code in academy/exchange/proxystore.py
close
¶
Close this mailbox client.
Warning
This does not close the mailbox in the exchange. I.e., the exchange will still accept new messages to this mailbox, but this client will no longer be listening for them.
Source code in academy/exchange/proxystore.py
recv
¶
Receive the next message in the mailbox.
This blocks until the next message is received or the mailbox is closed.
Parameters:
-
timeout
(float | None
, default:None
) –Optional timeout in seconds to wait for the next message. If
None
, the default, block forever until the next message or the mailbox is closed.
Raises:
-
MailboxClosedError
–if the mailbox was closed.
-
TimeoutError
–if a
timeout
was specified and exceeded.