activelearning.sampler.gflownet.multi_fidelity_env_wrapper
Classes
Common base environment for all the multi-fidelity environment wrappers. |
|
Turns any GFlowNet environment into a multi-fidelity environment. |
|
Turns any GFlowNet environment into a multi-fidelity environment. |
|
Turns any GFlowNet environment into a multi-fidelity environment. |
Functions
Instantiate the appropriate multi-fidelity wrapper for fidelity_action. |
Module Contents
- class activelearning.sampler.gflownet.multi_fidelity_env_wrapper.MultiFidelityGFlowNetEnvWrapperBase(**kwargs)[source]
Bases:
gflownet.envs.composite.base.CompositeBase,abc.ABCCommon base environment for all the multi-fidelity environment wrappers.
Subclasses must define the following class-level attributes:
idx_base_env(int) andidx_fidelity(int).Note
Fidelity indexing convention
The fidelity sub-environment is a
gflownet.envs.choice.Choiceenv withn_options=n_fidelities. TheChoiceenv is 1-based: its source (uncommitted) state is0, and choosing optioniproduces statei, so committed fidelity states span1..n_fidelities. Callers that need to map these raw indices to domain-specific fidelity values (e.g. oracle keys{1, 2, 3}) should useproxy_states_to_candidates()with afidelity_map.- property idx_base_env: int
- Abstractmethod:
Index of the base environment among the composite sub-environments.
- property idx_fidelity: int
- Abstractmethod:
Index of the fidelity environment among the composite sub-environments.
- get_states_base_and_fidelities(states: Sequence) Tuple[List[Any], List[int]][source]
Retrieves the states of the base env and the fidelity indices of a batch of states.
- Parameters:
states (Sequence) – A batch of states in environment format.
- Returns:
states_base (List[Any]) – The states of the base environment in the batch.
fidelity_indices (List[int]) – The raw fidelity index from the
Choicesub-environment for each state. Values are 1-based (1..n_fidelities);0indicates the uncommitted source state, which should not appear in terminating states.
- get_state_base_and_fidelity(state: Any = None) Tuple[Any, int][source]
Retrieves the state of the base env and the fidelity index of a state.
This method constructs a dummy batch with the input state and calls
get_states_base_and_fidelities(); then returns the first element of the output.- Parameters:
state (Any or
None) – A state in environment format. IfNone,self.stateis used.- Returns:
state_base (Any) – The state of the base environment.
fidelity_index (int) – The raw fidelity index from the
Choicesub-environment. 1-based: values are in1..n_fidelitiesfor committed states.
- class activelearning.sampler.gflownet.multi_fidelity_env_wrapper.MultiFidelityGFlowNetEnvWrapper(
- env_base_maker: Callable[Ellipsis, gflownet.envs.base.GFlowNetEnv],
- n_fidelities: int,
- **kwargs,
Bases:
gflownet.envs.composite.setfix.SetFix,MultiFidelityGFlowNetEnvWrapperBaseTurns any GFlowNet environment into a multi-fidelity environment.
The wrapper is a SetFix GFlowNet environment whose sub-environments are the base environment and a Choice environment to model the discrete fidelity index.
Therefore, unlike the
FidFirstandFidLastvariants, the GFlowNet can choose fidelity at any point during the base-environment trajectory, rather than only before or after the base-environment object is generated.- idx_base_env = 0
Index of the base environment among the composite sub-environments.
- idx_fidelity = 1
Index of the fidelity environment among the composite sub-environments.
- env_base
- env_fidelity
- class activelearning.sampler.gflownet.multi_fidelity_env_wrapper.MultiFidelityGFlowNetEnvWrapperFidFirst(
- env_base_maker: Callable[Ellipsis, gflownet.envs.base.GFlowNetEnv],
- n_fidelities: int,
- **kwargs,
Bases:
gflownet.envs.composite.stack.Stack,MultiFidelityGFlowNetEnvWrapperBaseTurns any GFlowNet environment into a multi-fidelity environment.
The wrapper is a Stack GFlowNet environment whose sub-environments are: 1. A Choice environment to model the discrete fidelity index. 2. The base environment.
Therefore, the fidelity is sampled first, followed by the actions of the base environment.
- idx_fidelity = 0
Index of the fidelity environment among the composite sub-environments.
- idx_base_env = 1
Index of the base environment among the composite sub-environments.
- env_base
- env_fidelity
- class activelearning.sampler.gflownet.multi_fidelity_env_wrapper.MultiFidelityGFlowNetEnvWrapperFidLast(
- env_base_maker: Callable[Ellipsis, gflownet.envs.base.GFlowNetEnv],
- n_fidelities: int,
- **kwargs,
Bases:
gflownet.envs.composite.stack.Stack,MultiFidelityGFlowNetEnvWrapperBaseTurns any GFlowNet environment into a multi-fidelity environment.
The wrapper is a Stack GFlowNet environment whose sub-environments are: 1. The base environment. 2. A Choice environment to model the discrete fidelity index.
Therefore, the actions of the base environment are sampled first, and the fidelity is sampled at the end of the trajectory.
- idx_base_env = 0
Index of the base environment among the composite sub-environments.
- idx_fidelity = 1
Index of the fidelity environment among the composite sub-environments.
- env_base
- env_fidelity
- activelearning.sampler.gflownet.multi_fidelity_env_wrapper.build_multi_fidelity_env_wrapper(
- fidelity_action: Literal['any', 'first', 'last'],
- env_base_maker: Callable[Ellipsis, gflownet.envs.base.GFlowNetEnv],
- n_fidelities: int,
- **kwargs: Any,
Instantiate the appropriate multi-fidelity wrapper for fidelity_action.
- Parameters:
fidelity_action ({"any", "first", "last"}) –
Controls when the fidelity choice is made during a trajectory:
"any"—MultiFidelityGFlowNetEnvWrapper(SetFix): fidelity may be chosen at any point interleaved with base-env actions."first"—MultiFidelityGFlowNetEnvWrapperFidFirst(Stack): fidelity is chosen before any base-env action."last"—MultiFidelityGFlowNetEnvWrapperFidLast(Stack): fidelity is chosen after all base-env actions are complete.
env_base_maker (Callable[..., GFlowNetEnv]) – Callable (partial) that constructs a fresh base environment instance.
n_fidelities (int) – Number of possible fidelity choices.
**kwargs – Forwarded to the wrapper’s
__init__.
- Returns:
A freshly constructed wrapper of the appropriate type.
- Return type:
- Raises:
ValueError – If fidelity_action is not one of
"any","first","last".