Decoders

Decoders are used to translate actions received from the agent’s policy into messages that are sent in the network to other actors and mutators that can update the agent’s own state:

../_images/decoder.svg

Decoders are a fully optional feature of Phantom. There is no functional difference between defining an decode_action() method on an Agent and defining an Decoder (whose decode() method performs the same actions) and attaching it to the Agent.

Decoders are useful when many different Agents want to decode the same properties and code re-use is desirable. It is also possible to compose multiple decoders (see ChainedDecoder), allowing the construction of complex decoders from many smaller parts.

Base Decoder

class phantom.decoders.Decoder(*args, **kwds)[source]

A trait for types that decode raw actions into packets.

abstract property action_space: Space

The action/input space of the decoder type.

chain(others)[source]

Chains this decoder together with adjoint set of decoders.

This method returns a ChainedDecoder instance where the action space reduces to a tuple with each element given by the action space specified in each of the decoders provided.

Return type:

ChainedDecoder

abstract decode(ctx, action)[source]

Convert an action into a packet given a network context.

Parameters:
  • ctx (Context) – The local network context.

  • action (TypeVar(Action)) – An action instance which is an element of the decoder’s action space.

Return type:

List[Tuple[Hashable, MsgPayload]]

reset()[source]

Resets the decoder.

Provided Implementations

class phantom.decoders.EmptyDecoder(*args, **kwds)[source]

Converts any actions into empty packets.

property action_space: Space

The action/input space of the decoder type.

chain(others)

Chains this decoder together with adjoint set of decoders.

This method returns a ChainedDecoder instance where the action space reduces to a tuple with each element given by the action space specified in each of the decoders provided.

Return type:

ChainedDecoder

decode(_, action)[source]

Convert an action into a packet given a network context.

Parameters:
  • ctx – The local network context.

  • action (TypeVar(Action)) – An action instance which is an element of the decoder’s action space.

Return type:

List[Tuple[Hashable, MsgPayload]]

reset()

Resets the decoder.

class phantom.decoders.ChainedDecoder(decoders)[source]

Combines n decoders into a single decoder with a tuple action space.

decoders

An iterable collection of decoders which is flattened into a list.

property action_space: Space

The action/input space of the decoder type.

chain(others)[source]

Chains this decoder together with adjoint set of decoders.

This method returns a ChainedDecoder instance where the action space reduces to a tuple with each element given by the action space specified in each of the decoders provided.

Return type:

ChainedDecoder

decode(ctx, action)[source]

Convert an action into a packet given a network context.

Parameters:
  • ctx (Context) – The local network context.

  • action (Tuple) – An action instance which is an element of the decoder’s action space.

Return type:

List[Tuple[Hashable, MsgPayload]]

reset()[source]

Resets the decoder.