investment

Climate-economics environment: Discrete investment options

Attributes

CHOICES

SECTORS

TAGS

TECHS

AMOUNTS

ALLOWED_SECTOR2TAGS

ALLOWED_TAG2SECTOR

ALLOWED_SECTOR2TECH

ALLOWED_TAG2TECH

Classes

InvestmentDiscrete

Base class of GFlowNet environments

Module Contents

investment.CHOICES = ('SECTOR', 'TAG', 'TECH', 'AMOUNT')[source]
investment.SECTORS = ('POWER', 'ENERGY', 'VEHICLES', 'STORAGE', 'DAC')[source]
investment.TAGS = ('GREEN', 'BROWN', 'CCS')[source]
investment.TECHS = ('power_COAL_noccs', 'power_COAL_ccs', 'power_NUCLEAR', 'power_OIL', 'power_GAS_noccs',...[source]
investment.AMOUNTS = ('HIGH', 'MEDIUM', 'LOW', 'NONE')[source]
investment.ALLOWED_SECTOR2TAGS[source]
investment.ALLOWED_TAG2SECTOR[source]
investment.ALLOWED_SECTOR2TECH[source]
investment.ALLOWED_TAG2TECH[source]
class investment.InvestmentDiscrete(sectors=None, tags=None, techs=None, amounts=None, **kwargs)[source]

Bases: gflownet.envs.base.GFlowNetEnv

Base class of GFlowNet environments

Parameters:
  • sectors (Iterable)

  • tags (Iterable)

  • techs (Iterable)

  • amounts (Iterable)

choices = ('SECTOR', 'TAG', 'TECH', 'AMOUNT')[source]
n_sectors[source]
n_tags[source]
n_techs[source]
n_amounts[source]
idx2token_choices[source]
token2idx_choices[source]
idx2token_sectors[source]
token2idx_sectors[source]
idx2token_tags[source]
token2idx_tags[source]
idx2token_techs[source]
token2idx_techs[source]
idx2token_amounts[source]
token2idx_amounts[source]
source[source]
network_structure[source]
eos[source]
get_action_space()[source]

Constructs list with all possible actions, including eos.

An action is represented by a two-element tuple: the first element is the index of the element of the dictionary (state) to be changed; the second element is the value used to update the state.

For example, action (3, 2) sets for choice 3 (technology) the value at index 2 (coal power with CCS), starting from index 1.

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.

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

  • 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.

Parameters:
  • state (dict) – 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 environment format.

  • actions (list) – List of actions that lead to state for each parent in parents.

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) – If True, skip computing forward mask of invalid actions to check if the action is valid.

Returns:

  • self.state (dict) – The sequence after executing the action

  • action (tuple) – Action executed

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

Return type:

[Dict, Tuple[int], bool]

states2proxy(states)[source]

Prepares a batch of states in “environment format” for a proxy: the batch is simply converted into a tensor of indices.

Parameters:

states (list or tensor) – A batch of states in environment format, either as a list of states or as a list of tensors.

Returns:

A list containing all the states in the batch, represented themselves as lists.

Return type:

torchtyping.TensorType[batch, state_dim]

states2policy(states)[source]

Prepares a batch of states in “environment format” for the policy model: states are one-hot encoded.

Parameters:

states (list or tensor) – A batch of states in environment format, either as a list of states or as a list of tensors.

Returns:

A tensor containing all the states in the batch.

Return type:

torch.Tensor

state2readable(state=None)[source]

Converts a state into a human-readable string.

The output string contains the letter corresponding to each index in the state, separated by spaces.

Parameters:
  • states (tensor) – A state in environment format. If None, self.state is used.

  • state (Dict[str, int])

Returns:

A string of space-separated letters.

Return type:

str

readable2state(readable)[source]

Converts a state in readable format into the environment format (dict of indices).

Parameters:

readable (str) – A state in readable format, with fields separated by “ | “. Example: “POWER | UNASSIGNED_TAG | power_HYDRO | HIGH”

Returns:

dict – A state dictionary with indices for SECTOR, TAG, TECH, and AMOUNT.

Return type:

Dict[str, int]

get_uniform_terminating_states(n_states, seed=None)[source]

Constructs a batch of n states uniformly sampled in the sample space of the environment.

Parameters:
  • n_states (int) – The number of states to sample.

  • seed (int) – Random seed.

Return type:

List[Dict[str, int]]

well_defined_investment(state=None)[source]
Parameters:

state (Optional[Dict])

Return type:

bool

get_assigned_attributes(state=None)[source]
Parameters:

state (Optional[Dict])

Return type:

List[str]