investment
Climate-economics environment: Discrete investment options
Attributes
Classes
Base class of GFlowNet environments |
Module Contents
- investment.TECHS = ('power_COAL_noccs', 'power_COAL_ccs', 'power_NUCLEAR', 'power_OIL', 'power_GAS_noccs',...[source]
- class investment.InvestmentDiscrete(sectors=None, tags=None, techs=None, amounts=None, **kwargs)[source]
Bases:
gflownet.envs.base.GFlowNetEnvBase class of GFlowNet environments
- Parameters:
sectors (Iterable)
tags (Iterable)
techs (Iterable)
amounts (Iterable)
- 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:
- 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]