activelearning.sampler.gflownet.multi_fidelity_env_wrapper

Classes

MultiFidelityGFlowNetEnvWrapperBase

Common base environment for all the multi-fidelity environment wrappers.

MultiFidelityGFlowNetEnvWrapper

Turns any GFlowNet environment into a multi-fidelity environment.

MultiFidelityGFlowNetEnvWrapperFidFirst

Turns any GFlowNet environment into a multi-fidelity environment.

MultiFidelityGFlowNetEnvWrapperFidLast

Turns any GFlowNet environment into a multi-fidelity environment.

Functions

build_multi_fidelity_env_wrapper(...)

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

Common base environment for all the multi-fidelity environment wrappers.

Subclasses must define the following class-level attributes: idx_base_env (int) and idx_fidelity (int).

Note

Fidelity indexing convention

The fidelity sub-environment is a gflownet.envs.choice.Choice env with n_options=n_fidelities. The Choice env is 1-based: its source (uncommitted) state is 0, and choosing option i produces state i, so committed fidelity states span 1..n_fidelities. Callers that need to map these raw indices to domain-specific fidelity values (e.g. oracle keys {1, 2, 3}) should use proxy_states_to_candidates() with a fidelity_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 Choice sub-environment for each state. Values are 1-based (1..n_fidelities); 0 indicates 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. If None, self.state is used.

Returns:

  • state_base (Any) – The state of the base environment.

  • fidelity_index (int) – The raw fidelity index from the Choice sub-environment. 1-based: values are in 1..n_fidelities for committed states.

class activelearning.sampler.gflownet.multi_fidelity_env_wrapper.MultiFidelityGFlowNetEnvWrapper(
env_base_maker: Callable[Ellipsis, gflownet.envs.base.GFlowNetEnv],
n_fidelities: int,
**kwargs,
)[source]

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

Turns 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 FidFirst and FidLast variants, 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,
)[source]

Bases: gflownet.envs.composite.stack.Stack, MultiFidelityGFlowNetEnvWrapperBase

Turns 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,
)[source]

Bases: gflownet.envs.composite.stack.Stack, MultiFidelityGFlowNetEnvWrapperBase

Turns 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,
) → MultiFidelityGFlowNetEnvWrapperBase[source]

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:

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

MultiFidelityGFlowNetEnvWrapperBase

Raises:

ValueError – If fidelity_action is not one of "any", "first", "last".