coopihc.bundle.Bundle.Bundle

class Bundle(*args, task=None, user=None, assistant=None, **kwargs)[source]

Bases: coopihc.bundle.BaseBundle.BaseBundle

Modifies the interface of the BaseBundle class.

A bundle combines a task with a user and an assistant. The bundle creates the game_state by combining the task, user and assistant states with the turn index and both agent’s actions.

The bundle takes care of all the messaging between classes, making sure the gamestate and all individual states are synchronized at all times.

The bundle implements a forced reset mechanism, where each state of the bundle can be forced to a particular state via a dictionnary mechanism (see :py:func:reset)

The bundle also takes care of rendering each of the three component in a single place.

Parameters

Methods

close

Close the bundle once the game is finished.

quarter_step

render

Combines all render methods.

reset

Reset bundle.

step

Play a round

Attributes

parameters

round_number

The round number in the game (0 to N)

state

turn_dict

turn_number

The turn number in the game (0 to 3)

close()

Close the bundle once the game is finished.

render(mode, *args, **kwargs)

Combines all render methods.

Parameters
  • mode – “text” or “plot”

  • type – string

reset(go_to=None, start_after=None, task=True, user=True, assistant=True, dic={}, random_reset=False)

Reset bundle.

  1. Reset the game and start at a specific turn number.

  2. select which components to reset

  3. forced reset mechanism using dictionnaries

Example:

new_target_value = self.game_state["task_state"]["targets"]
new_fixation_value = self.game_state["task_state"]["fixation"]
)
reset_dic = {"task_state": {"targets": new_target_value, "fixation": new_fixation_value}}
self.reset(dic=reset_dic, turn = 1)

Will set the substates “targets” and “fixation” of state “task_state” to some value.

Note

If subclassing BaseBundle, make sure to call super().reset() in the new reset method.

Parameters
  • turn (int, optional) – game turn number. Can also be set globally at the bundle level by passing the “reset_turn” keyword argument, defaults to 0

  • start_after (int, optional) – which turn to start at (allows skipping some turns during reset), defaults to 0

  • task (bool, optional) – reset task?, defaults to True

  • user (bool, optional) – reset user?, defaults to True

  • assistant (bool, optional) – reset assistant?, defaults to True

  • dic (dict, optional) – reset_dic, defaults to {}

  • random_reset (bool, optional) – whether during resetting values should be randomized or not if not set by a reset dic, default to False

Returns

new game state

Return type

State

property round_number

The round number in the game (0 to N)

Returns

turn number

Return type

numpy.ndarray

step(user_action=None, assistant_action=None, go_to=None, **kwargs)

Play a round

Play a round of the game. A round consists in 4 turns. If go_to is not None, the round is only played until that turn. If a user action and assistant action are passed as arguments, then these are used as actions to play the round. Otherwise, these actions are sampled from each agent’s policy.

Parameters
  • action (assistant) – user action

  • action – assistant action

  • go_to (int, optional) – turn at which round stops, defaults to None

Type

any

Type

any

Returns

gamestate, reward, game finished flag

Return type

tuple(State, collections.OrderedDict, boolean)

property turn_number

The turn number in the game (0 to 3)

Returns

turn number

Return type

numpy.ndarray