paretorium 0.1.0__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- paretorium-0.1.0/LICENSE +21 -0
- paretorium-0.1.0/PKG-INFO +94 -0
- paretorium-0.1.0/README.md +68 -0
- paretorium-0.1.0/pyproject.toml +43 -0
- paretorium-0.1.0/src/paretorium/__init__.py +72 -0
- paretorium-0.1.0/src/paretorium/__main__.py +206 -0
- paretorium-0.1.0/src/paretorium/analysis.py +152 -0
- paretorium-0.1.0/src/paretorium/concepts.py +220 -0
- paretorium-0.1.0/src/paretorium/importance.py +345 -0
- paretorium-0.1.0/src/paretorium/interchange.py +374 -0
- paretorium-0.1.0/src/paretorium/models.py +121 -0
- paretorium-0.1.0/src/paretorium/parameters.py +266 -0
- paretorium-0.1.0/src/paretorium/study.py +370 -0
- paretorium-0.1.0/src/paretorium/thrust.py +118 -0
- paretorium-0.1.0/src/paretorium/utility.py +228 -0
- paretorium-0.1.0/src/paretorium/visualization/__init__.py +58 -0
- paretorium-0.1.0/src/paretorium/visualization/_density.py +111 -0
- paretorium-0.1.0/src/paretorium/visualization/_format.py +11 -0
- paretorium-0.1.0/src/paretorium/visualization/_labels.py +124 -0
- paretorium-0.1.0/src/paretorium/visualization/_table_html.py +177 -0
- paretorium-0.1.0/src/paretorium/visualization/decisions.py +121 -0
- paretorium-0.1.0/src/paretorium/visualization/export.py +34 -0
- paretorium-0.1.0/src/paretorium/visualization/grid.py +185 -0
- paretorium-0.1.0/src/paretorium/visualization/html.py +118 -0
- paretorium-0.1.0/src/paretorium/visualization/importance.py +113 -0
- paretorium-0.1.0/src/paretorium/visualization/layers.py +178 -0
- paretorium-0.1.0/src/paretorium/visualization/notebook.py +58 -0
- paretorium-0.1.0/src/paretorium/visualization/outcomes.py +725 -0
- paretorium-0.1.0/src/paretorium/visualization/overlays.py +284 -0
- paretorium-0.1.0/src/paretorium/visualization/parameters.py +276 -0
- paretorium-0.1.0/src/paretorium/visualization/pdf.py +201 -0
- paretorium-0.1.0/src/paretorium/visualization/report.py +56 -0
- paretorium-0.1.0/src/paretorium/visualization/tables.py +54 -0
- paretorium-0.1.0/src/paretorium/visualization/theme.py +110 -0
- paretorium-0.1.0/src/paretorium/visualization/utility.py +155 -0
- paretorium-0.1.0/src/paretorium/visualization/views.py +656 -0
paretorium-0.1.0/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Paretorium contributors
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
|
@@ -0,0 +1,94 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: paretorium
|
|
3
|
+
Version: 0.1.0
|
|
4
|
+
Summary: Author and run modular systems engineering trade studies
|
|
5
|
+
License-Expression: MIT
|
|
6
|
+
License-File: LICENSE
|
|
7
|
+
Requires-Dist: openpyxl>=3.1,<4 ; extra == 'excel'
|
|
8
|
+
Requires-Dist: paretorium[visualization] ; extra == 'notebook'
|
|
9
|
+
Requires-Dist: ipython>=8,<10 ; extra == 'notebook'
|
|
10
|
+
Requires-Dist: scipy>=1.16.3,<2 ; extra == 'propulsion'
|
|
11
|
+
Requires-Dist: altair>=5,<7 ; extra == 'visualization'
|
|
12
|
+
Requires-Dist: contourpy>=1.3,<2 ; extra == 'visualization'
|
|
13
|
+
Requires-Dist: numpy>=2,<3 ; extra == 'visualization'
|
|
14
|
+
Requires-Dist: pypdf>=6,<7 ; extra == 'visualization'
|
|
15
|
+
Requires-Dist: reportlab>=4.4,<5 ; extra == 'visualization'
|
|
16
|
+
Requires-Dist: scipy>=1.16.3,<2 ; extra == 'visualization'
|
|
17
|
+
Requires-Dist: vl-convert-python>=1.8,<2 ; extra == 'visualization'
|
|
18
|
+
Requires-Python: >=3.13
|
|
19
|
+
Project-URL: Documentation, https://paretorium.stoppani.name/
|
|
20
|
+
Project-URL: Source, https://github.com/GaretJax/paretorium
|
|
21
|
+
Provides-Extra: excel
|
|
22
|
+
Provides-Extra: notebook
|
|
23
|
+
Provides-Extra: propulsion
|
|
24
|
+
Provides-Extra: visualization
|
|
25
|
+
Description-Content-Type: text/markdown
|
|
26
|
+
|
|
27
|
+
# Paretorium
|
|
28
|
+
|
|
29
|
+
A Python framework for defining and evaluating your own architecture trade studies. You supply the choices, parameters, model equations, scenarios, and decision criteria; the framework assembles compatible concepts, resolves model dependencies, propagates uncertainty, and compares the results.
|
|
30
|
+
|
|
31
|
+
## Documentation
|
|
32
|
+
|
|
33
|
+
Browse the [Paretorium documentation](https://paretorium.stoppani.name/),
|
|
34
|
+
or start with the [workshop tutorial](docs/example.md) or the
|
|
35
|
+
[Colab tutorial](docs/colab.md) in this repository. See
|
|
36
|
+
[local build and deployment instructions](docs-deployment.md) to preview
|
|
37
|
+
the site.
|
|
38
|
+
|
|
39
|
+
## Add a study
|
|
40
|
+
|
|
41
|
+
Copy [the workshop backup example](studies/example_backup.py) to `studies/my_study.py` and replace its input definitions and equations. Your module can live anywhere Python can import it. It only needs to expose a `Study` object; there is no registry to edit.
|
|
42
|
+
|
|
43
|
+
```bash
|
|
44
|
+
uv sync --locked
|
|
45
|
+
uv run --locked python -m paretorium studies.example_backup --check
|
|
46
|
+
uv run --locked python -m paretorium studies.example_backup \
|
|
47
|
+
--samples 100 --seed 42 --summary-only --out runs/example-backup.json
|
|
48
|
+
```
|
|
49
|
+
|
|
50
|
+
Replace `studies.example_backup` with `studies.my_study` to run your own. The same API works from Python: import your `study` and call `study.run(samples=100, seed=42)`.
|
|
51
|
+
|
|
52
|
+
See the [study authoring guide](docs/authoring.md) for the interfaces, units, assumptions, and output semantics. The core is independent of PEARL, Google, and the course workbooks, and has no third-party runtime dependencies on Python 3.13+.
|
|
53
|
+
|
|
54
|
+
## Export tabular results
|
|
55
|
+
|
|
56
|
+
Use `--format csv --out runs/backup-csv` for a CSV bundle. JSON remains
|
|
57
|
+
the default. The optional `excel` extra writes Excel workbooks from
|
|
58
|
+
architectural-importance results. See the
|
|
59
|
+
[export guide](docs/evaluation.md#export-a-run-as-csv).
|
|
60
|
+
|
|
61
|
+
## Visualize a study
|
|
62
|
+
|
|
63
|
+
The optional visualization package includes composable Altair layers,
|
|
64
|
+
tradespaces and tables, a parameter atlas, and interactive HTML and PDF
|
|
65
|
+
report publishers. Generate the workshop or synthetic satellite review:
|
|
66
|
+
|
|
67
|
+
```bash
|
|
68
|
+
uv run --locked --extra visualization python -m studies.visualize_backup
|
|
69
|
+
uv run --locked --extra visualization python -m studies.visualize_satellite
|
|
70
|
+
```
|
|
71
|
+
|
|
72
|
+
Reports go under `runs/workshop-visualization/` and `runs/satellite-review/`.
|
|
73
|
+
Start with [Create your first tradespace](docs/visualization-tutorial.md),
|
|
74
|
+
or see [How visualization is organized](docs/visualization-concepts.md)
|
|
75
|
+
to choose a view.
|
|
76
|
+
|
|
77
|
+
## Work in a notebook
|
|
78
|
+
|
|
79
|
+
Install with `uv sync --locked --extra notebook` and use
|
|
80
|
+
`paretorium.visualization.display_notebook` to show charts, sortable tables,
|
|
81
|
+
atlases, or whole reports in an output cell. Follow the
|
|
82
|
+
[Colab speed–power tutorial](docs/colab.md) to build a small study step by step.
|
|
83
|
+
|
|
84
|
+
## License and releases
|
|
85
|
+
|
|
86
|
+
Paretorium is distributed under the [MIT License](LICENSE). See the
|
|
87
|
+
[release guide](publishing.md) for the PyPI Trusted Publishing setup.
|
|
88
|
+
|
|
89
|
+
## Tests
|
|
90
|
+
|
|
91
|
+
```bash
|
|
92
|
+
uv run --locked python -m unittest discover -s tests -p test_framework.py -v
|
|
93
|
+
uv run --locked --all-extras python -m unittest discover -s tests -v
|
|
94
|
+
```
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
# Paretorium
|
|
2
|
+
|
|
3
|
+
A Python framework for defining and evaluating your own architecture trade studies. You supply the choices, parameters, model equations, scenarios, and decision criteria; the framework assembles compatible concepts, resolves model dependencies, propagates uncertainty, and compares the results.
|
|
4
|
+
|
|
5
|
+
## Documentation
|
|
6
|
+
|
|
7
|
+
Browse the [Paretorium documentation](https://paretorium.stoppani.name/),
|
|
8
|
+
or start with the [workshop tutorial](docs/example.md) or the
|
|
9
|
+
[Colab tutorial](docs/colab.md) in this repository. See
|
|
10
|
+
[local build and deployment instructions](docs-deployment.md) to preview
|
|
11
|
+
the site.
|
|
12
|
+
|
|
13
|
+
## Add a study
|
|
14
|
+
|
|
15
|
+
Copy [the workshop backup example](studies/example_backup.py) to `studies/my_study.py` and replace its input definitions and equations. Your module can live anywhere Python can import it. It only needs to expose a `Study` object; there is no registry to edit.
|
|
16
|
+
|
|
17
|
+
```bash
|
|
18
|
+
uv sync --locked
|
|
19
|
+
uv run --locked python -m paretorium studies.example_backup --check
|
|
20
|
+
uv run --locked python -m paretorium studies.example_backup \
|
|
21
|
+
--samples 100 --seed 42 --summary-only --out runs/example-backup.json
|
|
22
|
+
```
|
|
23
|
+
|
|
24
|
+
Replace `studies.example_backup` with `studies.my_study` to run your own. The same API works from Python: import your `study` and call `study.run(samples=100, seed=42)`.
|
|
25
|
+
|
|
26
|
+
See the [study authoring guide](docs/authoring.md) for the interfaces, units, assumptions, and output semantics. The core is independent of PEARL, Google, and the course workbooks, and has no third-party runtime dependencies on Python 3.13+.
|
|
27
|
+
|
|
28
|
+
## Export tabular results
|
|
29
|
+
|
|
30
|
+
Use `--format csv --out runs/backup-csv` for a CSV bundle. JSON remains
|
|
31
|
+
the default. The optional `excel` extra writes Excel workbooks from
|
|
32
|
+
architectural-importance results. See the
|
|
33
|
+
[export guide](docs/evaluation.md#export-a-run-as-csv).
|
|
34
|
+
|
|
35
|
+
## Visualize a study
|
|
36
|
+
|
|
37
|
+
The optional visualization package includes composable Altair layers,
|
|
38
|
+
tradespaces and tables, a parameter atlas, and interactive HTML and PDF
|
|
39
|
+
report publishers. Generate the workshop or synthetic satellite review:
|
|
40
|
+
|
|
41
|
+
```bash
|
|
42
|
+
uv run --locked --extra visualization python -m studies.visualize_backup
|
|
43
|
+
uv run --locked --extra visualization python -m studies.visualize_satellite
|
|
44
|
+
```
|
|
45
|
+
|
|
46
|
+
Reports go under `runs/workshop-visualization/` and `runs/satellite-review/`.
|
|
47
|
+
Start with [Create your first tradespace](docs/visualization-tutorial.md),
|
|
48
|
+
or see [How visualization is organized](docs/visualization-concepts.md)
|
|
49
|
+
to choose a view.
|
|
50
|
+
|
|
51
|
+
## Work in a notebook
|
|
52
|
+
|
|
53
|
+
Install with `uv sync --locked --extra notebook` and use
|
|
54
|
+
`paretorium.visualization.display_notebook` to show charts, sortable tables,
|
|
55
|
+
atlases, or whole reports in an output cell. Follow the
|
|
56
|
+
[Colab speed–power tutorial](docs/colab.md) to build a small study step by step.
|
|
57
|
+
|
|
58
|
+
## License and releases
|
|
59
|
+
|
|
60
|
+
Paretorium is distributed under the [MIT License](LICENSE). See the
|
|
61
|
+
[release guide](publishing.md) for the PyPI Trusted Publishing setup.
|
|
62
|
+
|
|
63
|
+
## Tests
|
|
64
|
+
|
|
65
|
+
```bash
|
|
66
|
+
uv run --locked python -m unittest discover -s tests -p test_framework.py -v
|
|
67
|
+
uv run --locked --all-extras python -m unittest discover -s tests -v
|
|
68
|
+
```
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
[build-system]
|
|
2
|
+
requires = ["uv_build>=0.9.7,<0.10"]
|
|
3
|
+
build-backend = "uv_build"
|
|
4
|
+
|
|
5
|
+
[project]
|
|
6
|
+
name = "paretorium"
|
|
7
|
+
version = "0.1.0"
|
|
8
|
+
description = "Author and run modular systems engineering trade studies"
|
|
9
|
+
readme = "README.md"
|
|
10
|
+
license = "MIT"
|
|
11
|
+
license-files = ["LICENSE"]
|
|
12
|
+
requires-python = ">=3.13"
|
|
13
|
+
dependencies = []
|
|
14
|
+
|
|
15
|
+
[project.urls]
|
|
16
|
+
Documentation = "https://paretorium.stoppani.name/"
|
|
17
|
+
Source = "https://github.com/GaretJax/paretorium"
|
|
18
|
+
|
|
19
|
+
[project.optional-dependencies]
|
|
20
|
+
excel = ["openpyxl>=3.1,<4"]
|
|
21
|
+
notebook = ["paretorium[visualization]", "ipython>=8,<10"]
|
|
22
|
+
propulsion = ["scipy>=1.16.3,<2"]
|
|
23
|
+
visualization = [
|
|
24
|
+
"altair>=5,<7",
|
|
25
|
+
"contourpy>=1.3,<2",
|
|
26
|
+
"numpy>=2,<3",
|
|
27
|
+
"pypdf>=6,<7",
|
|
28
|
+
"reportlab>=4.4,<5",
|
|
29
|
+
"scipy>=1.16.3,<2",
|
|
30
|
+
"vl-convert-python>=1.8,<2",
|
|
31
|
+
]
|
|
32
|
+
|
|
33
|
+
[tool.ruff]
|
|
34
|
+
line-length = 79
|
|
35
|
+
|
|
36
|
+
[tool.pyright]
|
|
37
|
+
extraPaths = ["src"]
|
|
38
|
+
|
|
39
|
+
[dependency-groups]
|
|
40
|
+
docs = [
|
|
41
|
+
"mkdocstrings[python]>=1.0.8",
|
|
42
|
+
"zensical>=0.1.4",
|
|
43
|
+
]
|
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
"""Author and run domain-independent systems engineering trade studies."""
|
|
2
|
+
|
|
3
|
+
from .analysis import ConceptSummary, MetricSummary, pareto_front, summarize
|
|
4
|
+
from .concepts import (
|
|
5
|
+
Candidate,
|
|
6
|
+
CompatibilityRule,
|
|
7
|
+
Concept,
|
|
8
|
+
Decision,
|
|
9
|
+
DesignSpace,
|
|
10
|
+
Option,
|
|
11
|
+
)
|
|
12
|
+
from .importance import (
|
|
13
|
+
ArchitecturalImportance,
|
|
14
|
+
DecisionImportance,
|
|
15
|
+
OptionImportance,
|
|
16
|
+
PairImportance,
|
|
17
|
+
architectural_importance,
|
|
18
|
+
)
|
|
19
|
+
from .models import Metric, Model, Port
|
|
20
|
+
from .parameters import (
|
|
21
|
+
Beta,
|
|
22
|
+
Binomial,
|
|
23
|
+
Discrete,
|
|
24
|
+
Distribution,
|
|
25
|
+
Lognormal,
|
|
26
|
+
Parameter,
|
|
27
|
+
ParameterCase,
|
|
28
|
+
Triangular,
|
|
29
|
+
Uniform,
|
|
30
|
+
)
|
|
31
|
+
from .study import (
|
|
32
|
+
EvaluationError,
|
|
33
|
+
EvaluationResult,
|
|
34
|
+
RunResult,
|
|
35
|
+
Scenario,
|
|
36
|
+
Study,
|
|
37
|
+
)
|
|
38
|
+
|
|
39
|
+
__all__ = [
|
|
40
|
+
"ArchitecturalImportance",
|
|
41
|
+
"Beta",
|
|
42
|
+
"Binomial",
|
|
43
|
+
"Candidate",
|
|
44
|
+
"CompatibilityRule",
|
|
45
|
+
"Concept",
|
|
46
|
+
"ConceptSummary",
|
|
47
|
+
"Decision",
|
|
48
|
+
"DecisionImportance",
|
|
49
|
+
"DesignSpace",
|
|
50
|
+
"Discrete",
|
|
51
|
+
"Distribution",
|
|
52
|
+
"EvaluationError",
|
|
53
|
+
"EvaluationResult",
|
|
54
|
+
"Lognormal",
|
|
55
|
+
"Metric",
|
|
56
|
+
"MetricSummary",
|
|
57
|
+
"Model",
|
|
58
|
+
"Option",
|
|
59
|
+
"OptionImportance",
|
|
60
|
+
"PairImportance",
|
|
61
|
+
"Parameter",
|
|
62
|
+
"ParameterCase",
|
|
63
|
+
"Port",
|
|
64
|
+
"RunResult",
|
|
65
|
+
"Scenario",
|
|
66
|
+
"Study",
|
|
67
|
+
"Triangular",
|
|
68
|
+
"Uniform",
|
|
69
|
+
"architectural_importance",
|
|
70
|
+
"pareto_front",
|
|
71
|
+
"summarize",
|
|
72
|
+
]
|
|
@@ -0,0 +1,206 @@
|
|
|
1
|
+
"""Validate and run a trusted Python study definition."""
|
|
2
|
+
|
|
3
|
+
import argparse
|
|
4
|
+
import importlib
|
|
5
|
+
import json
|
|
6
|
+
import platform
|
|
7
|
+
from dataclasses import asdict
|
|
8
|
+
from pathlib import Path
|
|
9
|
+
from typing import Any
|
|
10
|
+
|
|
11
|
+
from .analysis import Statistic, pareto_front, summarize
|
|
12
|
+
from .interchange import export_run_csv
|
|
13
|
+
from .study import EvaluationError, RunResult, Study
|
|
14
|
+
|
|
15
|
+
|
|
16
|
+
def load_study(reference: str) -> Study:
|
|
17
|
+
module, sep, attr = reference.partition(":")
|
|
18
|
+
if not module or (sep and not attr):
|
|
19
|
+
raise ValueError("Specify a Python module or module:attribute")
|
|
20
|
+
study = getattr(importlib.import_module(module), attr or "study")
|
|
21
|
+
if not isinstance(study, Study):
|
|
22
|
+
raise TypeError(f"{reference!r} does not refer to a paretorium.Study")
|
|
23
|
+
return study
|
|
24
|
+
|
|
25
|
+
|
|
26
|
+
def document(
|
|
27
|
+
study: Study,
|
|
28
|
+
result: RunResult,
|
|
29
|
+
reference: str,
|
|
30
|
+
*,
|
|
31
|
+
statistic: Statistic,
|
|
32
|
+
min_feasibility: float,
|
|
33
|
+
include_samples: bool,
|
|
34
|
+
) -> dict[str, Any]:
|
|
35
|
+
summaries = summarize(result.evaluations)
|
|
36
|
+
fronts = {
|
|
37
|
+
case.id: pareto_front(
|
|
38
|
+
summaries,
|
|
39
|
+
study.metrics,
|
|
40
|
+
scenario=case.id,
|
|
41
|
+
statistic=statistic,
|
|
42
|
+
min_feasibility=min_feasibility,
|
|
43
|
+
)
|
|
44
|
+
for case in study.scenarios
|
|
45
|
+
}
|
|
46
|
+
return {
|
|
47
|
+
"schema_version": 1,
|
|
48
|
+
"study": study.id,
|
|
49
|
+
"module": reference,
|
|
50
|
+
"python": platform.python_version(),
|
|
51
|
+
"seed": result.seed,
|
|
52
|
+
"samples_per_concept_scenario": result.samples,
|
|
53
|
+
# Utility callbacks live in the study source, not the result document.
|
|
54
|
+
"metrics": [
|
|
55
|
+
{
|
|
56
|
+
"id": metric.id,
|
|
57
|
+
"units": metric.units,
|
|
58
|
+
"objective": metric.objective,
|
|
59
|
+
"minimum": metric.minimum,
|
|
60
|
+
"maximum": metric.maximum,
|
|
61
|
+
"name": metric.name,
|
|
62
|
+
}
|
|
63
|
+
for metric in study.metrics
|
|
64
|
+
],
|
|
65
|
+
"parameters": [
|
|
66
|
+
{"id": p.id, "name": p.name, "units": p.units, "source": p.source}
|
|
67
|
+
for p in study.parameters
|
|
68
|
+
],
|
|
69
|
+
"scenarios": [
|
|
70
|
+
{"id": s.id, "name": s.name, "source": s.source}
|
|
71
|
+
for s in study.scenarios
|
|
72
|
+
],
|
|
73
|
+
"rejected": [
|
|
74
|
+
{
|
|
75
|
+
"concept": choice.concept.id,
|
|
76
|
+
"design_id": choice.concept.design_id,
|
|
77
|
+
"choices": dict(choice.concept.choices),
|
|
78
|
+
"rules": [
|
|
79
|
+
{"id": r.id, "reason": r.reason}
|
|
80
|
+
for r in choice.rejected_by
|
|
81
|
+
],
|
|
82
|
+
}
|
|
83
|
+
for choice in result.rejected
|
|
84
|
+
],
|
|
85
|
+
"summaries": [
|
|
86
|
+
{
|
|
87
|
+
"concept": row.concept.id,
|
|
88
|
+
"design_id": row.concept.design_id,
|
|
89
|
+
"choices": dict(row.concept.choices),
|
|
90
|
+
"scenario": row.scenario_id,
|
|
91
|
+
"samples": row.samples,
|
|
92
|
+
"feasibility_rate": row.feasibility_rate,
|
|
93
|
+
"metrics": {k: asdict(v) for k, v in row.metrics.items()},
|
|
94
|
+
}
|
|
95
|
+
for row in summaries
|
|
96
|
+
],
|
|
97
|
+
"pareto": {
|
|
98
|
+
"statistic": statistic,
|
|
99
|
+
"min_feasibility": min_feasibility,
|
|
100
|
+
"by_scenario": {
|
|
101
|
+
case: [row.concept.id for row in front]
|
|
102
|
+
for case, front in fronts.items()
|
|
103
|
+
},
|
|
104
|
+
"design_ids_by_scenario": {
|
|
105
|
+
case: [row.concept.design_id for row in front]
|
|
106
|
+
for case, front in fronts.items()
|
|
107
|
+
},
|
|
108
|
+
},
|
|
109
|
+
**(
|
|
110
|
+
{
|
|
111
|
+
"evaluations": [
|
|
112
|
+
{
|
|
113
|
+
"concept": row.concept.id,
|
|
114
|
+
"design_id": row.concept.design_id,
|
|
115
|
+
"scenario": row.scenario_id,
|
|
116
|
+
"sample": row.sample_index,
|
|
117
|
+
"parameters": dict(row.parameters),
|
|
118
|
+
"outputs": dict(row.outputs),
|
|
119
|
+
"metrics": dict(row.metrics),
|
|
120
|
+
"violations": row.violations,
|
|
121
|
+
}
|
|
122
|
+
for row in result.evaluations
|
|
123
|
+
]
|
|
124
|
+
}
|
|
125
|
+
if include_samples
|
|
126
|
+
else {}
|
|
127
|
+
),
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
|
|
131
|
+
def main() -> None:
|
|
132
|
+
parser = argparse.ArgumentParser(description=__doc__)
|
|
133
|
+
parser.add_argument(
|
|
134
|
+
"study", help="Python module[:attribute]; default attribute: study"
|
|
135
|
+
)
|
|
136
|
+
parser.add_argument(
|
|
137
|
+
"--check", action="store_true", help="validate without sampling"
|
|
138
|
+
)
|
|
139
|
+
parser.add_argument("--samples", type=int, default=1)
|
|
140
|
+
parser.add_argument("--seed", type=int, default=0)
|
|
141
|
+
parser.add_argument(
|
|
142
|
+
"--statistic", choices=("mean", "p05", "p50", "p95"), default="mean"
|
|
143
|
+
)
|
|
144
|
+
parser.add_argument("--min-feasibility", type=float, default=1.0)
|
|
145
|
+
parser.add_argument("--summary-only", action="store_true")
|
|
146
|
+
parser.add_argument("--format", choices=("json", "csv"), default="json")
|
|
147
|
+
parser.add_argument(
|
|
148
|
+
"--out",
|
|
149
|
+
type=Path,
|
|
150
|
+
help="JSON output file (default: stdout) or CSV output directory",
|
|
151
|
+
)
|
|
152
|
+
args = parser.parse_args()
|
|
153
|
+
out: Path | None = args.out
|
|
154
|
+
try:
|
|
155
|
+
study = load_study(args.study)
|
|
156
|
+
if args.check:
|
|
157
|
+
study.validate()
|
|
158
|
+
print(f"Validated {study.id}")
|
|
159
|
+
return
|
|
160
|
+
if not 0 <= args.min_feasibility <= 1:
|
|
161
|
+
raise ValueError("min-feasibility must be in [0, 1]")
|
|
162
|
+
csv_directory = out if args.format == "csv" else None
|
|
163
|
+
if args.format == "csv" and csv_directory is None:
|
|
164
|
+
parser.error("--format csv requires --out DIRECTORY")
|
|
165
|
+
result = study.run(samples=args.samples, seed=args.seed)
|
|
166
|
+
if csv_directory is not None:
|
|
167
|
+
export_run_csv(
|
|
168
|
+
study,
|
|
169
|
+
result,
|
|
170
|
+
csv_directory,
|
|
171
|
+
statistic=args.statistic,
|
|
172
|
+
min_feasibility=args.min_feasibility,
|
|
173
|
+
include_samples=not args.summary_only,
|
|
174
|
+
module=args.study,
|
|
175
|
+
)
|
|
176
|
+
return
|
|
177
|
+
rendered = json.dumps(
|
|
178
|
+
document(
|
|
179
|
+
study,
|
|
180
|
+
result,
|
|
181
|
+
args.study,
|
|
182
|
+
statistic=args.statistic,
|
|
183
|
+
min_feasibility=args.min_feasibility,
|
|
184
|
+
include_samples=not args.summary_only,
|
|
185
|
+
),
|
|
186
|
+
indent=2,
|
|
187
|
+
allow_nan=False,
|
|
188
|
+
)
|
|
189
|
+
if out is None:
|
|
190
|
+
print(rendered)
|
|
191
|
+
else:
|
|
192
|
+
out.parent.mkdir(parents=True, exist_ok=True)
|
|
193
|
+
out.write_text(rendered + "\n", encoding="utf-8")
|
|
194
|
+
except (
|
|
195
|
+
ImportError,
|
|
196
|
+
AttributeError,
|
|
197
|
+
OSError,
|
|
198
|
+
ValueError,
|
|
199
|
+
TypeError,
|
|
200
|
+
EvaluationError,
|
|
201
|
+
) as exc:
|
|
202
|
+
parser.exit(2, f"paretorium: {exc}\n")
|
|
203
|
+
|
|
204
|
+
|
|
205
|
+
if __name__ == "__main__":
|
|
206
|
+
main()
|
|
@@ -0,0 +1,152 @@
|
|
|
1
|
+
"""Scenario-local uncertainty summaries and multiobjective comparison."""
|
|
2
|
+
|
|
3
|
+
from collections import Counter, defaultdict
|
|
4
|
+
from collections.abc import Iterable, Mapping
|
|
5
|
+
from dataclasses import dataclass
|
|
6
|
+
from math import floor
|
|
7
|
+
from statistics import mean
|
|
8
|
+
from types import MappingProxyType
|
|
9
|
+
from typing import Literal
|
|
10
|
+
|
|
11
|
+
from .concepts import Concept
|
|
12
|
+
from .models import Metric
|
|
13
|
+
from .study import EvaluationResult
|
|
14
|
+
|
|
15
|
+
type Statistic = Literal["mean", "p05", "p50", "p95"]
|
|
16
|
+
|
|
17
|
+
|
|
18
|
+
@dataclass(frozen=True)
|
|
19
|
+
class MetricSummary:
|
|
20
|
+
"""Statistics and limit failures for one metric.
|
|
21
|
+
|
|
22
|
+
Args:
|
|
23
|
+
mean: Arithmetic mean.
|
|
24
|
+
p05: Interpolated fifth percentile.
|
|
25
|
+
p50: Interpolated median.
|
|
26
|
+
p95: Interpolated 95th percentile.
|
|
27
|
+
violation_count: Number of samples outside this metric's limits.
|
|
28
|
+
Zero means no violations; `None` means counts were not supplied.
|
|
29
|
+
"""
|
|
30
|
+
|
|
31
|
+
mean: float
|
|
32
|
+
p05: float
|
|
33
|
+
p50: float
|
|
34
|
+
p95: float
|
|
35
|
+
violation_count: int | None = None
|
|
36
|
+
|
|
37
|
+
def value(self, statistic: Statistic) -> float:
|
|
38
|
+
match statistic:
|
|
39
|
+
case "mean":
|
|
40
|
+
return self.mean
|
|
41
|
+
case "p05":
|
|
42
|
+
return self.p05
|
|
43
|
+
case "p50":
|
|
44
|
+
return self.p50
|
|
45
|
+
case "p95":
|
|
46
|
+
return self.p95
|
|
47
|
+
case _:
|
|
48
|
+
raise ValueError(f"Unknown summary statistic: {statistic}")
|
|
49
|
+
|
|
50
|
+
|
|
51
|
+
@dataclass(frozen=True)
|
|
52
|
+
class ConceptSummary:
|
|
53
|
+
"""Sample count, joint feasibility rate, and metric summaries for one concept in one scenario.
|
|
54
|
+
|
|
55
|
+
Args:
|
|
56
|
+
concept: Architecture summarized.
|
|
57
|
+
scenario_id: Operating scenario ID.
|
|
58
|
+
samples: Number of evaluations included.
|
|
59
|
+
feasibility_rate: Fraction of samples meeting all metric limits.
|
|
60
|
+
metrics: Summary statistics keyed by metric ID.
|
|
61
|
+
"""
|
|
62
|
+
|
|
63
|
+
concept: Concept
|
|
64
|
+
scenario_id: str
|
|
65
|
+
samples: int
|
|
66
|
+
feasibility_rate: float
|
|
67
|
+
metrics: Mapping[str, MetricSummary]
|
|
68
|
+
|
|
69
|
+
|
|
70
|
+
def _quantile(values: list[float], fraction: float) -> float:
|
|
71
|
+
index = fraction * (len(values) - 1)
|
|
72
|
+
lo = floor(index)
|
|
73
|
+
f = index - lo
|
|
74
|
+
return values[lo] * (1 - f) + values[min(lo + 1, len(values) - 1)] * f
|
|
75
|
+
|
|
76
|
+
|
|
77
|
+
def summarize(
|
|
78
|
+
evaluations: Iterable[EvaluationResult],
|
|
79
|
+
) -> tuple[ConceptSummary, ...]:
|
|
80
|
+
groups: dict[tuple[str, str], list[EvaluationResult]] = defaultdict(list)
|
|
81
|
+
for record in evaluations:
|
|
82
|
+
groups[(record.scenario_id, record.concept.id)].append(record)
|
|
83
|
+
summaries = []
|
|
84
|
+
for (scenario, _), records in groups.items():
|
|
85
|
+
stats = {}
|
|
86
|
+
metric_ids = records[0].metrics.keys()
|
|
87
|
+
if any(record.metrics.keys() != metric_ids for record in records):
|
|
88
|
+
raise ValueError(
|
|
89
|
+
f"Inconsistent metric sets for {scenario}/{records[0].concept.id}"
|
|
90
|
+
)
|
|
91
|
+
violations = Counter(
|
|
92
|
+
key for record in records for key in set(record.violations)
|
|
93
|
+
)
|
|
94
|
+
for metric_id in metric_ids:
|
|
95
|
+
values = sorted(r.metrics[metric_id] for r in records)
|
|
96
|
+
stats[metric_id] = MetricSummary(
|
|
97
|
+
mean(values),
|
|
98
|
+
_quantile(values, 0.05),
|
|
99
|
+
_quantile(values, 0.50),
|
|
100
|
+
_quantile(values, 0.95),
|
|
101
|
+
violations[metric_id],
|
|
102
|
+
)
|
|
103
|
+
summaries.append(
|
|
104
|
+
ConceptSummary(
|
|
105
|
+
records[0].concept,
|
|
106
|
+
scenario,
|
|
107
|
+
len(records),
|
|
108
|
+
sum(r.feasible for r in records) / len(records),
|
|
109
|
+
MappingProxyType(stats),
|
|
110
|
+
)
|
|
111
|
+
)
|
|
112
|
+
return tuple(summaries)
|
|
113
|
+
|
|
114
|
+
|
|
115
|
+
def pareto_front(
|
|
116
|
+
summaries: Iterable[ConceptSummary],
|
|
117
|
+
metrics: Iterable[Metric],
|
|
118
|
+
*,
|
|
119
|
+
scenario: str,
|
|
120
|
+
statistic: Statistic = "mean",
|
|
121
|
+
min_feasibility: float = 1.0,
|
|
122
|
+
) -> tuple[ConceptSummary, ...]:
|
|
123
|
+
"""Non-dominated alternatives in one scenario, retaining exact ties."""
|
|
124
|
+
if not 0 <= min_feasibility <= 1:
|
|
125
|
+
raise ValueError("min_feasibility must be in [0, 1]")
|
|
126
|
+
objectives = [m for m in metrics if m.objective is not None]
|
|
127
|
+
if not objectives:
|
|
128
|
+
return ()
|
|
129
|
+
eligible = [
|
|
130
|
+
row
|
|
131
|
+
for row in summaries
|
|
132
|
+
if row.scenario_id == scenario
|
|
133
|
+
and row.feasibility_rate >= min_feasibility
|
|
134
|
+
]
|
|
135
|
+
points = [
|
|
136
|
+
tuple(
|
|
137
|
+
row.metrics[m.id].value(statistic)
|
|
138
|
+
* (1 if m.objective == "min" else -1)
|
|
139
|
+
for m in objectives
|
|
140
|
+
)
|
|
141
|
+
for row in eligible
|
|
142
|
+
]
|
|
143
|
+
|
|
144
|
+
def dominates(a: tuple[float, ...], b: tuple[float, ...]) -> bool:
|
|
145
|
+
pairs = tuple(zip(a, b, strict=True))
|
|
146
|
+
return all(x <= y for x, y in pairs) and any(x < y for x, y in pairs)
|
|
147
|
+
|
|
148
|
+
return tuple(
|
|
149
|
+
row
|
|
150
|
+
for row, point in zip(eligible, points, strict=True)
|
|
151
|
+
if not any(dominates(other, point) for other in points)
|
|
152
|
+
)
|