Metadata-Version: 2.4
Name: jupedsim-scenarios
Version: 0.3.4
Summary: Run, sweep, and analyze JuPedSim scenarios from the web-app JSON schema.
Author: Pedestrian Dynamics
License: MIT License
        
        Copyright (c) 2026 Pedestrian Dynamics
        
        Permission is hereby granted, free of charge, to any person obtaining a copy
        of this software and associated documentation files (the "Software"), to deal
        in the Software without restriction, including without limitation the rights
        to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
        copies of the Software, and to permit persons to whom the Software is
        furnished to do so, subject to the following conditions:
        
        The above copyright notice and this permission notice shall be included in all
        copies or substantial portions of the Software.
        
        THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
        IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
        FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
        AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
        LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
        OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
        SOFTWARE.
        
Project-URL: Repository, https://github.com/PedestrianDynamics/jupedsim-scenarios
Project-URL: Issues, https://github.com/PedestrianDynamics/jupedsim-scenarios/issues
Classifier: Development Status :: 3 - Alpha
Classifier: Intended Audience :: Science/Research
Classifier: License :: OSI Approved :: MIT License
Classifier: Programming Language :: Python :: 3
Classifier: Programming Language :: Python :: 3.11
Classifier: Programming Language :: Python :: 3.12
Classifier: Topic :: Scientific/Engineering
Requires-Python: >=3.11
Description-Content-Type: text/markdown
License-File: LICENSE
Requires-Dist: jupedsim>=1.4
Requires-Dist: shapely>=2.0
Requires-Dist: numpy>=1.24
Requires-Dist: pandas>=2.0
Requires-Dist: pedpy>=1.2
Requires-Dist: joblib>=1.3
Provides-Extra: dev
Requires-Dist: pytest>=8; extra == "dev"
Requires-Dist: ruff>=0.5; extra == "dev"
Dynamic: license-file

# jupedsim-scenarios

[![CI](https://github.com/PedestrianDynamics/jupedsim-scenarios/actions/workflows/ci.yml/badge.svg)](https://github.com/PedestrianDynamics/jupedsim-scenarios/actions/workflows/ci.yml)
[![PyPI version](https://img.shields.io/pypi/v/jupedsim-scenarios.svg)](https://pypi.org/project/jupedsim-scenarios/)
[![Python versions](https://img.shields.io/pypi/pyversions/jupedsim-scenarios.svg)](https://pypi.org/project/jupedsim-scenarios/)
[![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](LICENSE)

Python toolkit for running, sweeping, and analyzing
[JuPedSim](https://www.jupedsim.org/) scenarios authored in the
[Web-Based JuPedSim](https://github.com/PedestrianDynamics/jupedsim-web-community)
editor.

## Status

Alpha (`0.3.3`). Single-run (`run_scenario`), Monte Carlo sweeps
(`run_sweep` — now multiprocess), and a `jps-scenarios` CLI are shipped.
Restartable / resumable sweeps land in 0.4.0.

## Install

```bash
pip install jupedsim-scenarios
```

For development from a clone:

```bash
pip install -e ".[dev]"
```

## Single-run usage

```python
from jupedsim_scenarios import Scenario, run_scenario

scenario = Scenario(
    raw=data_dict,                          # the JSON exported by the web app
    walkable_area_wkt=data_dict["walkable_area_wkt"],
    model_type="CollisionFreeSpeedModel",
    seed=42,
    sim_params=data_dict["config"]["simulation_settings"]["simulationParams"],
    source_path="my_scenario.json",
)
result = run_scenario(scenario, seed=42)
print(result.metrics["evacuation_time"])
df = result.trajectory_dataframe()
result.cleanup()
```

A higher-level `load_scenario(path)` is available for zipped exports
(JSON + WKT file in the same archive or directory).

## Monte Carlo sweep

```python
from jupedsim_scenarios import load_scenario, run_sweep

base = load_scenario("faster_is_slower.zip")

sweep = run_sweep(
    base,
    axes={
        "v0":    [0.8, 1.2, 1.6, 1.8],
        "model": ["CollisionFreeSpeedModel", "AnticipationVelocityModel"],
    },
    apply={
        "v0":    lambda s, v: s.set_agent_params(0, desired_speed=v),
        "model": lambda s, v: s.set_model_type(v),
    },
    seeds=range(40, 50),
    output_dir="runs/",
)

df = sweep.to_dataframe()       # one row per (v0, model, seed) trial
print(df.groupby(["v0", "model"])["evacuation_time"].agg(["mean", "std"]))
sweep.cleanup()                 # delete the per-trial sqlite files
```

The library walks the cartesian product of the named axes, calls each
axis's `apply` function on an isolated `.copy()` of the base scenario,
runs the simulation, and tabulates the results. Anything the
`Scenario.set_*` mutators can change is fair game for sweeping.

Pass ``workers=N`` (or ``workers=0`` for one worker per CPU) to run
trials in parallel:

```python
sweep = run_sweep(base, axes=..., apply=..., seeds=range(40, 50), workers=4)
```

Mutations are applied in the calling process — only the resulting
mutated `Scenario` crosses the process boundary, so user `apply`
lambdas don't need to be picklable.

### Factory-style sweeps

If the scenario can't be expressed as one base mutated by axis values
— typically because the geometry itself depends on the trial parameters
— use `run_sweep_from_factory` instead. Each trial parameter dict is
handed to your factory; the factory builds a fresh `Scenario` and
optionally returns a payload that rides along on `Trial.extras`:

```python
from jupedsim_scenarios import run_sweep_from_factory

def build_loop(params):
    scenario, geometry = build_loop_scenario(
        num_agents=params["num_agents"],
        spacing=TRACK_LENGTH / params["num_agents"],
    )
    return scenario, geometry  # extras travel with the trial

sweep = run_sweep_from_factory(
    build_loop,
    trials=[{"num_agents": n} for n in (50, 100, 200, 400)],
    seeds=[42],
    workers=4,
)
df = sweep.to_dataframe()           # one row per trial; "num_agents" is a column
for t in sweep.trials:
    geometry = t.extras             # whatever the factory returned alongside
```

## Command line

```
jps-scenarios run scenario.json --seed 42 --out trajectory.sqlite
```

Runs a single scenario and prints a one-line JSON summary
(`evacuation_time`, agent counts, `sqlite_file`) to stdout. Useful in CI
or scripted pipelines; notebook workflows should stay on the Python API.

## Roadmap

| Release | Scope                                                              |
| ------- | ------------------------------------------------------------------ |
| 0.1.0   | Verbatim extraction of `Scenario` + `run_scenario` from web app.   |
| 0.2.0   | `run_sweep(scenario, axes={...}, seeds=...)`.                      |
| 0.3.0   | Multiprocess worker pool + `jps-scenarios` CLI.                    |
| 0.3.1   | Public aliases for helpers shared with Web-Based-Jupedsim.         |
| 0.3.2   | First PyPI release.                                                |
| 0.3.3   | Fix: checkpoints honored without journeys (#8).                    |
| 0.3.4   | `run_sweep_from_factory` for factory-style sweeps (this release, #11). |
| 0.4.0   | Restartable / resumable sweeps, persisted results.                 |

## License

MIT. See [LICENSE](LICENSE).
