Metadata-Version: 2.4
Name: palaestrai_mosaik
Version: 3.5.10
Summary: Mosaik Environment for palaestrAI.
Author-email: The ARL Developers <eric.veith@offis.de>
Project-URL: Homepage, http://docs.palaestr.ai
Project-URL: Bug Tracker, https://gitlab.com/arl2/palaestrai-mosaik/-/issues
Classifier: Development Status :: 4 - Beta
Classifier: Intended Audience :: Science/Research
Classifier: License :: OSI Approved :: GNU Lesser General Public License v2 (LGPLv2)
Classifier: Natural Language :: English
Classifier: Operating System :: POSIX :: Linux
Classifier: Programming Language :: Python
Classifier: Programming Language :: Python :: 3
Classifier: Programming Language :: Python :: 3.10
Classifier: Topic :: Scientific/Engineering
Classifier: Topic :: Scientific/Engineering :: Artificial Intelligence
Requires-Python: >=3.10
Description-Content-Type: text/markdown
License-File: LICENSE
Requires-Dist: midas-mosaik>=2.0.2
Requires-Dist: midas-palaestrai>=3.5.6.post1
Requires-Dist: mosaik>=3.4.0
Requires-Dist: mosaik-api
Requires-Dist: palaestrai>=3.5.18
Provides-Extra: dev
Requires-Dist: black; extra == "dev"
Requires-Dist: build; extra == "dev"
Requires-Dist: coverage; extra == "dev"
Requires-Dist: pytest; extra == "dev"
Requires-Dist: setuptools; extra == "dev"
Requires-Dist: sphinx; extra == "dev"
Requires-Dist: twine; extra == "dev"
Requires-Dist: palaestrai>=3.5.18; extra == "dev"
Dynamic: license-file

# Adversarial Resilience Learning --- Mosaik Environment

This projects contains the interface between palaestrAI and mosaik, 
the mosaik environment.

## Introduction

This package allows to use worlds created with the co-simulation 
framework mosaik as environment in palaestrAI. The package was 
developed with MIDAS in mind but should work for arbitrary mosaik
worlds. See documenation for more details on how to import a world.

## Installation

palaestrAI-mosaik is written in Python. Use, preferable in a
virtual environment:

```bash
pip install .
```

or, for development including Midas:

```bash
pip install -e .[dev,midas]
```

Alternatively, you can install it from pypi:

```bash
pip install palaestrai-mosaik
```

## Usage

Under tests, you find the `example_experiment_midas.yml` that should be
passed to the palaestrai command line interface::

```bash
palaestrai experiment-start /path/to/tests/example_experiment_midas.yml
```

## Absorbing power-flow failure

Both the asynchronous and multiprocessing bridges automatically subscribe to
entities exposing a `powerflow_failed` output. With the companion
`midas-powergrid` change, no extra agent sensor configuration is needed.
The monitoring channels do not change an agent's selected observation space.

On failure, the final environment state has:

```python
done = True
terminated = True
truncated = False
```

The environment publishes a `powerflow_failed` reward with value 1.0,
independently of its configured reward provider. The companion
`midas-palaestrai` ARL objectives turn this into attacker reward 1.0 and defender
reward 0.0. Healthy monitored transitions carry value 0.0. Failure cannot be
reclassified as horizon truncation by a terminal-classification callback.

Physical grid stepping freezes immediately. The bridge detects the signal at
its next synchronization point, retaining the original failure tick and date
from `powerflow_failure_time`. It delivers the final transition without another
agent action, drains in-flight final samples, joins scheduler tasks, and then
finalizes recorders. A terminal initial reading is retained for the first
`update()` rather than lost in the baseline handoff. Setup/constructor errors
and unrelated simulator errors still propagate.

Normal horizon endings use `terminated=False`, `truncated=True`. Existing
`terminal_condition` callbacks continue to classify endings only; a constant
classification callback does not stop healthy intermediate transitions.

Failure is deliberately an absorbing operational outcome. Nonconvergence does
not by itself prove a physical blackout. Full-horizon resilience evaluators
must extend terminal FOM=0 through the original horizon rather than treat a
shorter CSV as lower loss. Fixed setpoints are useful for diagnostics; final
evaluation can and should retain state-responsive attackers.

Deploy the terminal-failure changes in `midas-powergrid`, `palaestrai-mosaik`
and `midas-palaestrai` together. The real-grid/CSV regression tests in
`tests/unit/test_powerflow_end_to_end.py` run when the companion grid API is
installed; protocol and lifecycle tests also run without that optional update.
