Resolvers

See the Message Resolution section of the Network guide for a description of how the BatchResolver works.

class phantom.resolvers.Resolver(enable_tracking=False)[source]

Network message resolver.

This type is responsible for resolution processing. That is, the order in which (and any special logic therein) messages are handled in a Network.

In many cases, this type can be arbitrary since the sequence doesn’t matter (i.e. the problem is not path dependent). In other cases, however, this is not the case; e.g. processing incoming market orders in an LOB.

Implementations of this class must provide implementations of the abstract methods below.

Parameters:

enable_tracking (bool) – If True, the resolver will save all messages in a time-ordered list that can be accessed with tracked_messages.

clear_tracked_messages()[source]

Clears any stored messages.

Useful for when incrementally processing/storing batches of tracked messages.

Return type:

None

abstract handle_push(message)[source]

Called by the resolver to handle batches of messages. Any further created messages (e.g. responses from agents) must be handled by being passed to the push method (not handle_push).

Return type:

None

push(message)[source]

Called by the Network to add messages to the resolver.

Return type:

None

abstract reset()[source]

Resets the resolver and clears any potential message queues. :rtype: None

Note

Does not clear any tracked messages.

abstract resolve(network, contexts)[source]

Process queues messages for a (sub) set of network contexts.

Parameters:
  • network (Network) – An instance of the Network class to resolve.

  • contexts (Mapping[Hashable, Context]) – The contexts for all agents for the current step.

Return type:

None

property tracked_messages: List[Message]

Returns all messages that have passed through the resolver if tracking is enabled.

class phantom.resolvers.BatchResolver(enable_tracking=False, round_limit=None, shuffle_batches=False)[source]

Resolver that handles messages in multiple discrete rounds. Each round, all agents have the opportunity to respond to previously received messages with new messages. These messages are held in a queue until all agents have been processed before being consumed in the next round. Messages for each agent are delivered in a batch, allowing the recipient agent to decide how to handle the messages within the batch.

Parameters:
  • enable_tracking (bool) – If True, the resolver will save all messages in a time-ordered list that can be accessed with tracked_messages.

  • round_limit (Optional[int]) – The maximum number of rounds of messages to resolve. If the limit is reached an exception will be thrown. By default the resolver will keep resolving until no more messages are sent.

  • shuffle_batches (bool) – If True, the order in which messages for a particular recipient are sent to the recipient will be randomised.

clear_tracked_messages()

Clears any stored messages.

Useful for when incrementally processing/storing batches of tracked messages.

Return type:

None

handle_push(message)[source]

Called by the resolver to handle batches of messages. Any further created messages (e.g. responses from agents) must be handled by being passed to the push method (not handle_push).

Return type:

None

push(message)

Called by the Network to add messages to the resolver.

Return type:

None

reset()[source]

Resets the resolver and clears any potential message queues. :rtype: None

Note

Does not clear any tracked messages.

resolve(network, contexts)[source]

Process queues messages for a (sub) set of network contexts.

Parameters:
  • network (Network) – An instance of the Network class to resolve.

  • contexts (Mapping[Hashable, Context]) – The contexts for all agents for the current step.

Return type:

None

property tracked_messages: List[Message]

Returns all messages that have passed through the resolver if tracking is enabled.