pme-toolkit 1.2.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.
@@ -0,0 +1,149 @@
1
+ Metadata-Version: 2.4
2
+ Name: pme-toolkit
3
+ Version: 1.2.0
4
+ Summary: Python implementation of PME-toolkit with PME, PI-PME, and PD-PME workflows
5
+ Author-email: Andrea Serani <andrea.serani@cnr.it>
6
+ License: MIT
7
+ Project-URL: Homepage, https://cnr-inm-mao.github.io/pme-toolkit/
8
+ Project-URL: Documentation, https://cnr-inm-mao.github.io/pme-toolkit/
9
+ Project-URL: Repository, https://github.com/cnr-inm-mao/pme-toolkit
10
+ Project-URL: Issues, https://github.com/cnr-inm-mao/pme-toolkit/issues
11
+ Classifier: Development Status :: 4 - Beta
12
+ Classifier: Intended Audience :: Science/Research
13
+ Classifier: License :: OSI Approved :: MIT License
14
+ Classifier: Operating System :: OS Independent
15
+ Classifier: Programming Language :: Python :: 3
16
+ Classifier: Programming Language :: Python :: 3.10
17
+ Classifier: Programming Language :: Python :: 3.11
18
+ Classifier: Programming Language :: Python :: 3.12
19
+ Classifier: Topic :: Scientific/Engineering
20
+ Classifier: Topic :: Scientific/Engineering :: Mathematics
21
+ Requires-Python: >=3.10
22
+ Description-Content-Type: text/markdown
23
+ Requires-Dist: numpy>=1.24
24
+ Requires-Dist: scipy>=1.10
25
+ Requires-Dist: matplotlib>=3.7
26
+ Provides-Extra: dev
27
+ Requires-Dist: pytest>=7.4; extra == "dev"
28
+
29
+ # PME-toolkit (Python)
30
+
31
+ Python implementation of **PME-toolkit** for **design-space dimensionality reduction** in parametric shape optimization.
32
+
33
+ Supports:
34
+
35
+ * **PME (Parametric Model Embedding)**
36
+ * **PI-PME (Physics-Informed PME)**
37
+ * **PD-PME (Physics-Driven PME)**
38
+ * analytical **backmapping** to original design variables
39
+
40
+ ---
41
+
42
+ ## Overview
43
+
44
+ The Python package provides a fully functional implementation of PME-based workflows using a **JSON-driven interface** for reproducible studies.
45
+
46
+ It is aligned with the MATLAB implementation and validated through **cross-language regression tests**.
47
+
48
+ ---
49
+
50
+ ## Installation
51
+
52
+ ### From PyPI
53
+
54
+ ```
55
+ pip install pme-toolkit
56
+ ```
57
+
58
+ ### From source (development mode)
59
+
60
+ ```
61
+ pip install -e python/
62
+ ```
63
+
64
+ ---
65
+
66
+ ## Command-line interface
67
+
68
+ Run a PME case:
69
+
70
+ ```
71
+ pme-run tests/cases/test_glider.json
72
+ ```
73
+
74
+ Run backmapping:
75
+
76
+ ```
77
+ pme-back tests/cases/test_glider_back.json
78
+ ```
79
+
80
+ The CLI:
81
+
82
+ * parses the JSON configuration
83
+ * executes the PME workflow
84
+ * writes outputs to the specified `outdir`
85
+ * ensures consistency with MATLAB results
86
+
87
+ ---
88
+
89
+ ## Programmatic usage
90
+
91
+ Example:
92
+
93
+ ```
94
+ from pme_toolkit.model import fit_from_case
95
+
96
+ model = fit_from_case("tests/cases/test_glider.json")
97
+
98
+ print(model.nconf)
99
+ print(model.alpha_train.shape)
100
+ ```
101
+
102
+ ---
103
+
104
+ ## Repository integration
105
+
106
+ The Python implementation is part of the full PME-toolkit repository:
107
+
108
+ * shared **JSON configuration format**
109
+ * shared **datasets**
110
+ * shared **benchmark definitions**
111
+ * validated against MATLAB through **regression testing**
112
+
113
+ ---
114
+
115
+ ## Testing
116
+
117
+ From repository root:
118
+
119
+ ```
120
+ pytest tests/python -q
121
+ ```
122
+
123
+ Test suite covers:
124
+
125
+ * configuration loading
126
+ * PME workflows
127
+ * backmapping
128
+ * regression against MATLAB reference
129
+
130
+ ---
131
+
132
+ ## Datasets
133
+
134
+ * lightweight test dataset:
135
+
136
+ tests/data/
137
+
138
+ * benchmark datasets:
139
+
140
+ databases/
141
+
142
+ ---
143
+
144
+ ## Status
145
+
146
+ The Python implementation is **fully functional** for PME, PI-PME, and PD-PME within the current scope.
147
+
148
+ It is actively maintained and serves as a **production-ready interface** for reproducible PME workflows.
149
+
@@ -0,0 +1,121 @@
1
+ # PME-toolkit (Python)
2
+
3
+ Python implementation of **PME-toolkit** for **design-space dimensionality reduction** in parametric shape optimization.
4
+
5
+ Supports:
6
+
7
+ * **PME (Parametric Model Embedding)**
8
+ * **PI-PME (Physics-Informed PME)**
9
+ * **PD-PME (Physics-Driven PME)**
10
+ * analytical **backmapping** to original design variables
11
+
12
+ ---
13
+
14
+ ## Overview
15
+
16
+ The Python package provides a fully functional implementation of PME-based workflows using a **JSON-driven interface** for reproducible studies.
17
+
18
+ It is aligned with the MATLAB implementation and validated through **cross-language regression tests**.
19
+
20
+ ---
21
+
22
+ ## Installation
23
+
24
+ ### From PyPI
25
+
26
+ ```
27
+ pip install pme-toolkit
28
+ ```
29
+
30
+ ### From source (development mode)
31
+
32
+ ```
33
+ pip install -e python/
34
+ ```
35
+
36
+ ---
37
+
38
+ ## Command-line interface
39
+
40
+ Run a PME case:
41
+
42
+ ```
43
+ pme-run tests/cases/test_glider.json
44
+ ```
45
+
46
+ Run backmapping:
47
+
48
+ ```
49
+ pme-back tests/cases/test_glider_back.json
50
+ ```
51
+
52
+ The CLI:
53
+
54
+ * parses the JSON configuration
55
+ * executes the PME workflow
56
+ * writes outputs to the specified `outdir`
57
+ * ensures consistency with MATLAB results
58
+
59
+ ---
60
+
61
+ ## Programmatic usage
62
+
63
+ Example:
64
+
65
+ ```
66
+ from pme_toolkit.model import fit_from_case
67
+
68
+ model = fit_from_case("tests/cases/test_glider.json")
69
+
70
+ print(model.nconf)
71
+ print(model.alpha_train.shape)
72
+ ```
73
+
74
+ ---
75
+
76
+ ## Repository integration
77
+
78
+ The Python implementation is part of the full PME-toolkit repository:
79
+
80
+ * shared **JSON configuration format**
81
+ * shared **datasets**
82
+ * shared **benchmark definitions**
83
+ * validated against MATLAB through **regression testing**
84
+
85
+ ---
86
+
87
+ ## Testing
88
+
89
+ From repository root:
90
+
91
+ ```
92
+ pytest tests/python -q
93
+ ```
94
+
95
+ Test suite covers:
96
+
97
+ * configuration loading
98
+ * PME workflows
99
+ * backmapping
100
+ * regression against MATLAB reference
101
+
102
+ ---
103
+
104
+ ## Datasets
105
+
106
+ * lightweight test dataset:
107
+
108
+ tests/data/
109
+
110
+ * benchmark datasets:
111
+
112
+ databases/
113
+
114
+ ---
115
+
116
+ ## Status
117
+
118
+ The Python implementation is **fully functional** for PME, PI-PME, and PD-PME within the current scope.
119
+
120
+ It is actively maintained and serves as a **production-ready interface** for reproducible PME workflows.
121
+
@@ -0,0 +1,56 @@
1
+ [build-system]
2
+ requires = ["setuptools>=68", "wheel"]
3
+ build-backend = "setuptools.build_meta"
4
+
5
+ [project]
6
+ name = "pme-toolkit"
7
+ version = "1.2.0"
8
+ description = "Python implementation of PME-toolkit with PME, PI-PME, and PD-PME workflows"
9
+ readme = "README.md"
10
+ requires-python = ">=3.10"
11
+ authors = [
12
+ { name = "Andrea Serani", email = "andrea.serani@cnr.it" }
13
+ ]
14
+ license = { text = "MIT" }
15
+ classifiers = [
16
+ "Development Status :: 4 - Beta",
17
+ "Intended Audience :: Science/Research",
18
+ "License :: OSI Approved :: MIT License",
19
+ "Operating System :: OS Independent",
20
+ "Programming Language :: Python :: 3",
21
+ "Programming Language :: Python :: 3.10",
22
+ "Programming Language :: Python :: 3.11",
23
+ "Programming Language :: Python :: 3.12",
24
+ "Topic :: Scientific/Engineering",
25
+ "Topic :: Scientific/Engineering :: Mathematics",
26
+ ]
27
+ dependencies = [
28
+ "numpy>=1.24",
29
+ "scipy>=1.10",
30
+ "matplotlib>=3.7",
31
+ ]
32
+
33
+ [project.optional-dependencies]
34
+ dev = [
35
+ "pytest>=7.4",
36
+ ]
37
+
38
+ [project.scripts]
39
+ pme-run = "pme_toolkit.run_case:main"
40
+ pme-back = "pme_toolkit.run_back:main"
41
+
42
+ [project.urls]
43
+ Homepage = "https://cnr-inm-mao.github.io/pme-toolkit/"
44
+ Documentation = "https://cnr-inm-mao.github.io/pme-toolkit/"
45
+ Repository = "https://github.com/cnr-inm-mao/pme-toolkit"
46
+ Issues = "https://github.com/cnr-inm-mao/pme-toolkit/issues"
47
+
48
+ [tool.setuptools]
49
+ package-dir = { "" = "src" }
50
+
51
+ [tool.setuptools.packages.find]
52
+ where = ["src"]
53
+
54
+ [tool.pytest.ini_options]
55
+ testpaths = ["tests"]
56
+ pythonpath = ["src"]
@@ -0,0 +1,4 @@
1
+ [egg_info]
2
+ tag_build =
3
+ tag_date = 0
4
+
@@ -0,0 +1,55 @@
1
+ """
2
+ PME-toolkit Python package.
3
+
4
+ This package provides the Python implementation of the PME-toolkit
5
+ workflow, including PME, PI-PME, and PD-PME utilities.
6
+
7
+ The MATLAB implementation remains the project reference implementation.
8
+ """
9
+
10
+ from .config_loader import load_case_json, load_config
11
+ from .layout import parse_layout
12
+ from .io import load_mat_database, load_mat_range
13
+ from .model import PmeModel, fit_from_case, fit_model, fit_pme
14
+ from .report import build_report, print_report
15
+ from .plotting import (
16
+ plot_scree_plot,
17
+ plot_variance_retained,
18
+ plot_nmse_by_source,
19
+ plot_variance_by_source,
20
+ plot_variable_modes,
21
+ plot_modes,
22
+ save_all_plots,
23
+ source_colors,
24
+ )
25
+ from .filters import apply_filters, FilterResult
26
+ from .weights import build_weights, build_wf, build_wc
27
+ from .datasets import ensure_case_inputs
28
+
29
+ __all__ = [
30
+ "load_case_json",
31
+ "load_config",
32
+ "parse_layout",
33
+ "load_mat_database",
34
+ "load_mat_range",
35
+ "PmeModel",
36
+ "fit_model",
37
+ "fit_pme",
38
+ "fit_from_case",
39
+ "build_report",
40
+ "print_report",
41
+ "plot_scree_plot",
42
+ "plot_variance_retained",
43
+ "plot_nmse_by_source",
44
+ "plot_variance_by_source",
45
+ "plot_variable_modes",
46
+ "plot_modes",
47
+ "save_all_plots",
48
+ "source_colors",
49
+ "apply_filters",
50
+ "FilterResult",
51
+ "build_weights",
52
+ "build_wf",
53
+ "build_wc",
54
+ "ensure_case_inputs",
55
+ ]
@@ -0,0 +1,46 @@
1
+ import json
2
+ from pathlib import Path
3
+ import numpy as np
4
+
5
+
6
+ def backmapping(model, x, active_idx=None):
7
+ """
8
+ Perform PME backmapping from reduced variables x to original variables u.
9
+
10
+ Parameters
11
+ ----------
12
+ model : PMEModel
13
+ Trained PME model.
14
+ x : array_like
15
+ Reduced variables (Ndim,)
16
+ active_idx : array_like or None
17
+ Indices of active variables. If None all variables assumed active.
18
+
19
+ Returns
20
+ -------
21
+ u : ndarray
22
+ Reconstructed original variables.
23
+ """
24
+
25
+ x = np.asarray(x)
26
+
27
+ if active_idx is None:
28
+ u = model.inverse_full(x)
29
+ else:
30
+ u = model.inverse_active(x, active_idx)
31
+
32
+ return u
33
+
34
+
35
+ def run_backmapping(model, x, output_file=None):
36
+ """
37
+ Run backmapping and optionally save result.
38
+ """
39
+
40
+ u = backmapping(model, x)
41
+
42
+ if output_file is not None:
43
+ output_file = Path(output_file)
44
+ np.savetxt(output_file, u)
45
+
46
+ return u
@@ -0,0 +1,26 @@
1
+ import argparse
2
+
3
+ from .run_case import main as run_case_main
4
+ from .run_back import main as run_back_main
5
+
6
+
7
+ def main():
8
+ parser = argparse.ArgumentParser(prog="pme-toolkit")
9
+ subparsers = parser.add_subparsers(dest="command", required=True)
10
+
11
+ run_parser = subparsers.add_parser("run", help="Run a PME case from case.json")
12
+ run_parser.add_argument("config", help="Path to case.json")
13
+
14
+ back_parser = subparsers.add_parser("back", help="Run backmapping from backmapping.json")
15
+ back_parser.add_argument("config", help="Path to backmapping.json")
16
+
17
+ args = parser.parse_args()
18
+
19
+ if args.command == "run":
20
+ run_case_main(args.config)
21
+ elif args.command == "back":
22
+ run_back_main(args.config)
23
+
24
+
25
+ if __name__ == "__main__":
26
+ main()
@@ -0,0 +1,66 @@
1
+ from __future__ import annotations
2
+
3
+ import json
4
+ from pathlib import Path
5
+ from typing import Any
6
+
7
+
8
+ def _resolve_path(base_dir: Path, value: str | None) -> str | None:
9
+ """Resolve a possibly-relative path against the case.json directory."""
10
+ if value is None or value == "":
11
+ return None
12
+
13
+ path = Path(value).expanduser()
14
+ if path.is_absolute():
15
+ return str(path.resolve())
16
+
17
+ return str((base_dir / path).resolve())
18
+
19
+
20
+ def _resolve_case_paths(cfg: dict[str, Any], base_dir: Path) -> dict[str, Any]:
21
+ """Resolve the path-like fields used by the current repository schema."""
22
+ out = dict(cfg)
23
+
24
+ io_cfg = dict(out.get("io", {}) or {})
25
+ if "dbfile" in io_cfg:
26
+ io_cfg["dbfile"] = _resolve_path(base_dir, io_cfg.get("dbfile"))
27
+ if "outdir" in io_cfg and io_cfg.get("outdir"):
28
+ io_cfg["outdir"] = _resolve_path(base_dir, io_cfg.get("outdir"))
29
+ out["io"] = io_cfg
30
+
31
+ vars_cfg = dict(out.get("vars", {}) or {})
32
+ if "Urange_file" in vars_cfg:
33
+ vars_cfg["Urange_file"] = _resolve_path(base_dir, vars_cfg.get("Urange_file"))
34
+ out["vars"] = vars_cfg
35
+
36
+ return out
37
+
38
+
39
+ def load_case_json(case_json: str | Path) -> tuple[dict[str, Any], Path]:
40
+ """Load a case.json file and resolve repository-relative paths.
41
+
42
+ Returns
43
+ -------
44
+ cfg
45
+ Parsed JSON configuration with resolved paths.
46
+ base_dir
47
+ Directory containing case.json.
48
+ """
49
+ case_path = Path(case_json).expanduser().resolve()
50
+ if not case_path.is_file():
51
+ raise FileNotFoundError(f"case.json not found: {case_path}")
52
+
53
+ cfg = json.loads(case_path.read_text(encoding="utf-8"))
54
+ if not isinstance(cfg, dict):
55
+ raise TypeError("case.json must decode to a JSON object")
56
+
57
+ base_dir = case_path.parent
58
+ cfg = _resolve_case_paths(cfg, base_dir)
59
+
60
+ return cfg, base_dir
61
+
62
+
63
+ def load_config(case_json: str | Path) -> dict[str, Any]:
64
+ """Compatibility wrapper for the earlier scaffold test."""
65
+ cfg, _ = load_case_json(case_json)
66
+ return cfg