gflownet.envs.constant

Base class for constant environments: simple, helper environment where the source state is the final state and the only valid action is EOS.

Classes

Constant

Constant environment.

Module Contents

class gflownet.envs.constant.Constant(state, **kwargs)[source]

Bases: gflownet.envs.base.GFlowNetEnv

Constant environment.

states2policy, states2proxy, states2readable and readable2state are not implemented in this meta-class. Depending on the state, the default methods may work or not.

Parameters:

state (Any)

state

The state which will be set as constant, that is as source and final state.

Type:

list, dict, tensor, array

source[source]
eos = (0,)[source]
get_action_space()[source]

Constructs list with all possible actions, including eos.

The action space consists of the EOS action only.

Return type:

List[Tuple]

get_mask_invalid_actions_forward(state=None, done=None)[source]
Returns a list of length the action space with values:
  • True if the forward action is invalid from the current state.

  • False otherwise.

The only possible action (EOS) is only valid if the environmet is not done.

Parameters:
  • state (list, dict, tensor, array) – Ignored.

  • done (bool) – Whether the trajectory is done. If None, self.done is used.

Returns:

A list of boolean values.

Return type:

List[bool]

get_parents(state=None, done=None, action=None)[source]

Determines all parents and actions that lead to state.

If the environment is done, the only parent is the state, with EOS action. Otherwise, the source state has no parents, like all environments.

Parameters:
  • state (list, dict, tensor, array) – Input state. If None, self.state is used.

  • done (bool) – Whether the trajectory is done. If None, self.done is used.

  • action (None) – Ignored

Returns:

  • parents (list) – List of parents in state format. This environment has a single parent per state.

  • actions (list) – List of actions that lead to state for each parent in parents. This environment has a single parent per state.

Return type:

Tuple[List, List]

step(action, skip_mask_check=False)[source]

Executes step given an action.

Parameters:
  • action (tuple) – Action to be executed.

  • skip_mask_check (bool) – Ignored.

Returns:

  • self.state (list, dict, tensor, array) – The state after executing the action

  • action (tuple) – Action executed

  • valid (bool) – False, if the action is not allowed for the current state.

Return type:

[List[int], Tuple[int], bool]