Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions docs/assets/network_intel_node.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
1 change: 1 addition & 0 deletions docs/assets/network_intel_node_white.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
3 changes: 1 addition & 2 deletions docs/base_agent.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,4 @@ The `BaseAgent` class provides the foundational interface for all agents interac

All custom agents should extend this class and implement their decision-making logic by overriding a method like `choose_action` (see [Getting Started](getting_started.md#creating-your-first-agent) for an example).

::: netsecgame.agents.base_agent.BaseAgent
::: netsecgame.agents.parallel_base_agent.ParallelBaseAgent
::: netsecgame.agents.base_agent.BaseAgent
7 changes: 7 additions & 0 deletions docs/parallel_base_agent.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
# Parallel Base Agent

The `ParallelBaseAgent` class extends the concepts of the base agent to manage connections to multiple NetSecGame server instances simultaneously, enabling parallel environment interaction.

Unlike `BaseAgent` (which manages a single socket), this class maintains one TCP socket per environment and exposes vectorized versions of methods like `register()`, `make_step()`, and `request_game_reset()` that operate on lists of actions and observations.

::: netsecgame.agents.parallel_base_agent.ParallelBaseAgent
6 changes: 5 additions & 1 deletion mkdocs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ site_name: Network Security Game
theme:
name: material
user_color_mode_toggle: true
favicon: assets/network_intel_node.svg
logo: assets/network_intel_node_white.svg

nav:
- Home: index.md
Expand All @@ -11,7 +13,9 @@ nav:
- Global Defender: global_defender.md
- API Reference:
- Game Components: game_components.md
- Base Agent: base_agent.md
- Agents:
- Base Agent: base_agent.md
- Parallel Base Agent: parallel_base_agent.md
- Agent Server: agent_server.md
- Game Coordinator: game_coordinator.md
- Configuration Manager: configuration_manager.md
Expand Down
21 changes: 7 additions & 14 deletions netsecgame/agents/parallel_base_agent.py
Original file line number Diff line number Diff line change
Expand Up @@ -322,8 +322,7 @@ def _run_parallel(
args_per_env: Optional extra positional args per env index.

Returns:
List of results, one per ``self._num_envs``. Indices not included
in *env_indices* get ``None``.
List of results, one per ``self._num_envs``. Indices not included in *env_indices* get ``None``.
"""
if env_indices is None:
env_indices = [i for i in range(self._num_envs) if self._sockets[i] is not None]
Expand Down Expand Up @@ -367,9 +366,7 @@ def register(self) -> "Observation | None | List[Optional[Observation]]":
"""Register in all connected environments in parallel.

Returns:
In single-env mode: the initial ``Observation`` (or ``None``).
In multi-env mode: list of initial observations, positionally
aligned with ``game_ports``.
The initial ``Observation`` (or ``None``) in single-env mode, or a list of initial observations positionally aligned with ``game_ports`` in multi-env mode.
"""
results = self._run_parallel(self._register_single)
# Re-initialise done mask: failed envs stay done
Expand All @@ -383,19 +380,17 @@ def make_step(
) -> "Observation | None | List[Optional[Observation]]":
"""Execute one step in every **active** environment in parallel.

*Note: If you need to access the boolean done statuses across
all environments, you can use the `self.done_mask` property.*

Args:
actions: In single-env mode a single ``Action``; in multi-env
mode a list of ``Action`` objects (one per environment).
Actions at indices where the done mask is ``True`` are
**ignored** (no message is sent to that env).

Returns:
In single-env mode: a single ``Observation | None``.
In multi-env mode: list of observations positionally aligned
with ``game_ports``.

*Note: If you need to access the boolean done statuses across
all environments, you can use the `self.done_mask` property.*
A single ``Observation | None`` in single-env mode, or a list of observations positionally aligned with ``game_ports`` in multi-env mode.

Raises:
ValueError: If the number of actions doesn't match ``num_envs``.
Expand Down Expand Up @@ -444,9 +439,7 @@ def request_game_reset(
seed: RNG seed. Required when ``randomize_topology`` is True.

Returns:
In single-env mode: the initial ``Observation`` (or ``None``).
In multi-env mode: list of initial observations, positionally
aligned with ``game_ports``.
The initial ``Observation`` (or ``None``) in single-env mode, or a list of initial observations positionally aligned with ``game_ports`` in multi-env mode.
"""
if seed is None and randomize_topology:
raise ValueError(
Expand Down
Loading