gflownet.envs.choices

An environment to sample a selection of elements from a given set of options.

The configuration of the environment must determine not only the set of options, but the maximum number of elements to be sampled, whether fewer than the maximum can be sampled and whether the selection must proceed with or without replacement.

If the selection is with replacement, then the environment operates as a SetFlex (without constraints). If the selection is without replacement, then the environment operates as a SetFix with constraints, such that options that have been already selected are made unavailable in the remaining environments.

Classes

ChoicesBase

Initializes a Choices environment.

ChoicesSetFix

Initializes a ChoicesSetFix environment inheriting from the SetFix.

ChoicesSetFlex

Initializes a ChoicesSetFlex environment inheriting from the SetFlex.

Functions

Choices([options, n_options, max_selection, ...])

Factory method to instantiate a Choices environment.

Module Contents

gflownet.envs.choices.Choices(options=None, n_options=3, max_selection=2, can_select_fewer_than_max=False, with_replacement=True, source_readable='<source>', **kwargs)[source]

Factory method to instantiate a Choices environment.

Parameters:
  • options (iterable (optional)) – The descrption of the options. If None, the options are simply described by their indices. In this case, n_options must be not None.

  • n_options (int) – The number of options, if options is None. Ignored otherwise.

  • max_selection (int) – The maximum number of options that may be selected.

  • can_select_fewer_than_max (bool) – Whether fewer options than the maximum can be selected.

  • with_replacement (bool) – Whether the selection proceeds with replacement (True, the same option can be selected more than once) or without replacement (False, each option can be selected only once).

  • source_readable (str) – The string to be used to represent the source state as a human-readable string. By default: <source>

class gflownet.envs.choices.ChoicesBase(options=None, n_options=3, max_selection=2, can_select_fewer_than_max=False, with_replacement=True, source_readable='<source>', **kwargs)[source]

Initializes a Choices environment.

Parameters:
  • options (iterable (optional)) – The descrption of the options. If None, the options are simply described by their indices. In this case, n_options must be not None.

  • n_options (int) – The number of options, if options is None. Ignored otherwise.

  • max_selection (int) – The maximum number of options that may be selected.

  • can_select_fewer_than_max (bool) – Whether fewer options than the maximum can be selected.

  • with_replacement (bool) – Whether the selection proceeds with replacement (True, the same option can be selected more than once) or without replacement (False, each option can be selected only once).

  • source_readable (str) – The string to be used to represent the source state as a human-readable string. By default: <source>

max_selection = 2[source]
can_select_fewer_than_max = False[source]
with_replacement = True[source]
options[source]
n_options[source]
source_readable[source]
property choice_env: gflownet.envs.choice.Choice[source]

Returns the unique Choice environment.

Returns:

Choice – The Choice environment that serves as unique environment of the Set.

Return type:

gflownet.envs.choice.Choice

get_options(state=None)[source]

Returns all the options that have already been chosen from the state.

Parameters:

state (dict) – A state of the global set environment.

Returns:

The set of options, as a tuple of integers.

Return type:

Tuple[int]

states2policy(states)[source]

Prepares a batch of states in environment format for the policy model.

The policy representation is the concatenation of the following elements: - A flag indicating whether no environment is active (-1), an environment is

active and not done (0), or an environment is active but done (1).

  • A vector of length self.n_options with the count of each selected option.

Parameters:

states (list) – A batch of states in environment format.

Returns:

A tensor containing all the states in the batch.

Return type:

torchtyping.TensorType[batch, state_policy_dim]

class gflownet.envs.choices.ChoicesSetFix(*args, **kwargs)[source]

Bases: ChoicesBase, gflownet.envs.composite.setfix.SetFix

Initializes a ChoicesSetFix environment inheriting from the SetFix.

class gflownet.envs.choices.ChoicesSetFlex(*args, **kwargs)[source]

Bases: ChoicesBase, gflownet.envs.composite.setflex.SetFlex

Initializes a ChoicesSetFlex environment inheriting from the SetFlex.