Skip to content

Commit 30689d7

Browse files
committed
Refine README structure and runtime docs
1 parent e4d3de8 commit 30689d7

2 files changed

Lines changed: 111 additions & 42 deletions

File tree

README.md

Lines changed: 57 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
[![PyPI version](https://badge.fury.io/py/UQPyL.svg?icon=si%3Apython&icon_color=%2331aadd)](https://badge.fury.io/py/UQPyL) [![CI](https://github.com/smasky/UQPyL/actions/workflows/ci.yml/badge.svg)](https://github.com/smasky/UQPyL/actions/workflows/ci.yml) [![codecov](https://codecov.io/gh/smasky/UQPyL/branch/dev/graph/badge.svg)](https://codecov.io/gh/smasky/UQPyL) ![PyPI - Downloads](https://img.shields.io/pypi/dm/UQPyL) ![PyPI - License](https://img.shields.io/pypi/l/UQPyL) ![GitHub last commit](https://img.shields.io/github/last-commit/smasky/UQPyL) ![Static Badge](https://img.shields.io/badge/Author-wmtSky-orange) ![Static Badge](https://img.shields.io/badge/Contact-wmtsmasky%40gmail.com-blue)
66

7-
[English](README.md) | [中文](README_CN.md)
7+
[English](README.md) | [中文](README_CN.md) | [Documentation](https://uqpyl.readthedocs.io)
88

99
UQPyL is a Python library for uncertainty quantification, optimization, inference, calibration, and surrogate modeling.
1010
It defines problems once and reuses them across UQ workflows.
@@ -24,32 +24,27 @@ These workflows are common across model-based domains, especially in hydrology,
2424
| Calibrate simulation models | Compare simulated series with observations. | Calibration methods based on `ModelProblem`. |
2525
| Reduce expensive evaluations | Build a cheaper approximation of a slow model run. | Surrogate models and surrogate-assisted workflows. |
2626

27-
## Documentation
28-
29-
- Documentation: <https://uqpyl.readthedocs.io>
30-
- Source code: <https://github.com/smasky/UQPyL>
31-
3227
## Core idea: define once, reuse everywhere
3328

3429
UQPyL does not own your model logic. Instead, you wrap your model or decision problem as a shared `problem` definition with:
3530

3631
| Part | Meaning |
3732
|---|---|
3833
| Input space | Variables, bounds, labels, and variable types. |
39-
| Evaluation rule | How a batch of inputs becomes objectives, constraints, or simulations. |
34+
| Evaluation rule | How a batch of inputs becomes objectives, constraints, or extract required simulation data. |
4035
| Optimization direction | Whether each objective is minimized or maximized. |
4136
| Runtime identity | A name and metadata used by saved runs and summaries. |
4237

43-
Once defined, the same object can be reused by DOE, analysis, optimization, inference, surrogate workflows, and calibration. Some workflows also need explicit model-aware information such as simulations, observations, or masks.
38+
Once defined, the same object can be reused by DOE, analysis, optimization, inference, surrogate workflows, and calibration. Some workflows also need explicit model-aware information such as simulations and observations.
4439

4540
## Problem abstraction
4641

4742
The `problem` module is the conceptual entry point of UQPyL.
4843

49-
| Abstraction | Role |
44+
| Abstraction Python Class | Role |
5045
|---|---|
5146
| `Problem` | For methods that only need final objective or constraint values. |
52-
| `ModelProblem` | For methods that need explicit model-process semantics such as `sim`, `obs`, or masks. |
47+
| `ModelProblem` | For methods that need explicit model-process semantics such as `sim` or `obs`. |
5348

5449
Both abstractions share the same foundation:
5550

@@ -58,9 +53,9 @@ Both abstractions share the same foundation:
5853
| `Space` | Defines variables, bounds, labels, and variable types. |
5954
| `Eval` | Standard return object for evaluated results. |
6055

61-
The module also includes benchmark problems such as `Sphere`, `Ackley`, `ZDT`, and `DTLZ`.
56+
The module also includes benchmark problems such as `Sphere`, `Ackley` and so on for single-objective optimization; `ZDT`, and `DTLZ` for multi-objective optimization.
6257

63-
Use `Problem` when methods only need final objectives or constraints from candidate inputs. `Problem` can still be used for model-based problems when those final values are enough. Use `ModelProblem` only when methods need explicit simulations, observations, masks, or simulated-versus-observed comparison. In the current design, this mainly applies to calibration workflows.
58+
Use `Problem` when methods only need final objectives or constraints from candidate inputs. `Problem` can still be used for model-based problems when those final values are enough. Use `ModelProblem` only when methods need explicit simulations, observations or simulated-versus-observed comparison. In the current design, this mainly applies to calibration module (`IES`, `ES`, `GLUE`, `SUFI2`).
6459

6560
<p align="center">
6661
<img src="./docs_v2/assets/Problem.webp" alt="Problem and ModelProblem comparison" width="1000"/>
@@ -76,7 +71,7 @@ UQPyL is organized around one shared `problem` abstraction and a set of function
7671
<img src="./docs_v2/assets/architecture.png" alt="UQPyL architecture overview" width="1000"/>
7772
</p>
7873

79-
The figure summarizes the main idea: represent a modeling task as a shared `problem` definition, then reuse that definition across DOE, analysis, optimization, inference, calibration, and surrogate workflows, with unified outputs and optional runtime storage.
74+
The figure summarizes the main idea: represent a modeling task as a shared `problem` definition, then reuse that definition across DOE, analysis, optimization, inference, calibration, and surrogate workflows, with unified outputs and optional runtime storage. You can freely organize your workflows.
8075

8176
| Type | Module | Purpose |
8277
|---|---|---|
@@ -92,19 +87,18 @@ Visualization, runtime storage, logs, and readers are exposed through the functi
9287

9388
## Typical workflows
9489

95-
Common workflow patterns all lead to structured outputs and optional runtime storage. Workflows that only consume final objectives or constraints can use `Problem`, while workflows that need explicit `sim`, `obs`, or related comparison semantics use `ModelProblem`.
90+
Common workflows patterns all lead to structured outputs and optional runtime storage.
9691

9792
```text
9893
Problem -> DOE -> Analysis -> outputs
99-
Problem -> Optimization -> outputs
100-
Problem -> Inference -> outputs
94+
Problem -> DOE -> Analysis -> Inference -> outputs
10195
ModelProblem -> Calibration -> outputs
10296
Problem -> DOE -> Surrogate -> Optimization
10397
```
10498

10599
## Quick start examples
106100

107-
### Direct evaluation with `Problem`
101+
### Optimization with `Problem`
108102

109103
```python
110104
import numpy as np
@@ -125,7 +119,7 @@ problem = Problem(
125119
name="Sphere2D",
126120
)
127121

128-
algorithm = SCE_UA(maxFEs=200, verboseFlag=False, logFlag=False, saveFlag=False)
122+
algorithm = SCE_UA(maxFEs=200)
129123

130124
result = algorithm.run(problem, seed=123)
131125

@@ -146,7 +140,13 @@ obs = np.array([[1.0], [2.0], [3.0]])
146140

147141
def simFunc(X):
148142
X = np.atleast_2d(X)
149-
return X[:, :1][:, None, :] * obs[None, :, :]
143+
# Here we assume each parameter sample returns one simulated series
144+
# with 3 time steps, so the output shape is (n_samples, 3, 1).
145+
sim = np.zeros((X.shape[0], 3, 1))
146+
sim[:, 0, 0] = X[:, 0] * 1.0
147+
sim[:, 1, 0] = X[:, 0] * 2.0
148+
sim[:, 2, 0] = X[:, 0] * 3.0
149+
return sim
150150

151151

152152
problem = ModelProblem(
@@ -157,7 +157,7 @@ problem = ModelProblem(
157157
)
158158

159159
X = np.linspace(0.5, 1.5, 32).reshape(-1, 1)
160-
result = GLUE(metric="rmse", verboseFlag=False).run(problem, X, threshold=0.2)
160+
result = GLUE(metric="rmse").run(problem, X, threshold=0.2)
161161
```
162162

163163
Methods return structured result objects such as `OptResult`, `AnaResult`, `InfResult`, or `CalResult`.
@@ -183,7 +183,7 @@ Methods return structured result objects such as `OptResult`, `AnaResult`, `InfR
183183

184184
For many single-objective hydrological and engineering calibration problems, `SCE_UA` is a good starting point.
185185

186-
## Runtime output
186+
## Runtime output and saving
187187

188188
Most runnable methods expose three common runtime controls.
189189

@@ -193,8 +193,41 @@ Most runnable methods expose three common runtime controls.
193193
| `logFlag` | Write more complete runtime logs when supported. |
194194
| `saveFlag` | Save structured runtime results, usually sqlite. |
195195

196+
```python
197+
algorithm = SCE_UA(maxFEs=200, verboseFlag=True, logFlag=True, saveFlag=True)
198+
result = algorithm.run(problem, seed=123)
199+
```
200+
201+
Example terminal output:
202+
203+
```text
204+
Algorithm: SCE-UA
205+
Problem: Sphere2D
206+
nInput: 2
207+
nObj: 1
208+
maxFEs: 200
209+
maxIters: 1000
210+
SCE-UA | iter=10 eval=84 best=4.3210e-03 cv=0 time=0.0s
211+
SCE-UA | iter=20 eval=154 best=2.1500e-04 cv=0 time=0.0s
212+
Optimization finished
213+
algorithm : SCE-UA
214+
status : finished
215+
iterations : 27
216+
evaluations : 203
217+
best value : 1.0000e-04
218+
best X : [1.0000e-02, -0.0000e+00]
219+
constraint viol. : 0
220+
elapsed : 0.0s
221+
```
222+
196223
With `saveFlag=True`, a run can produce saved artifacts for later reading by module-specific readers.
197224

225+
| Save option | Rule |
226+
|---|---|
227+
| `saveFlag=True` | Enable structured result saving for the current run. |
228+
| `saveFreq` | For optimization methods, save intermediate snapshots every `saveFreq` iterations and always save the final result at the end. |
229+
| Reader access | Saved sqlite results can be loaded later with module-specific readers such as `OptReader`, `AnaReader`, or `CalReader`. |
230+
198231
## More examples
199232

200233
Sensitivity analysis with `Sobol`:
@@ -248,7 +281,9 @@ pip install .
248281

249282
## Citation
250283

251-
Citation information for UQPyL 2.x will be updated. For UQPyL 1.0, see:
284+
Citation information for **UQPyL 2** will be updated.
285+
286+
For UQPyL 1.0, see:
252287

253288
- <https://www.sciencedirect.com/science/article/pii/S1364815215300955>
254289

README_CN.md

Lines changed: 54 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
[![PyPI version](https://badge.fury.io/py/UQPyL.svg?icon=si%3Apython&icon_color=%2331aadd)](https://badge.fury.io/py/UQPyL) [![CI](https://github.com/smasky/UQPyL/actions/workflows/ci.yml/badge.svg)](https://github.com/smasky/UQPyL/actions/workflows/ci.yml) [![codecov](https://codecov.io/gh/smasky/UQPyL/branch/dev/graph/badge.svg)](https://codecov.io/gh/smasky/UQPyL) ![PyPI - Downloads](https://img.shields.io/pypi/dm/UQPyL) ![PyPI - License](https://img.shields.io/pypi/l/UQPyL) ![GitHub last commit](https://img.shields.io/github/last-commit/smasky/UQPyL) ![Static Badge](https://img.shields.io/badge/Author-wmtSky-orange) ![Static Badge](https://img.shields.io/badge/Contact-wmtsmasky%40gmail.com-blue)
66

7-
[English](README.md) | [中文](README_CN.md)
7+
[English](README.md) | [中文](README_CN.md) | [Documentation](https://uqpyl.readthedocs.io)
88

99
UQPyL 是一个面向不确定性量化、优化、推断、率定和代理建模的 Python 库。
1010
它强调问题定义一次,然后在不同 UQ 工作流中复用。
@@ -24,53 +24,48 @@ UQPyL 面向计算建模中的不确定性问题:不确定参数如何影响
2424
| 率定模拟模型 | 将模拟序列与观测进行比较。 | 基于 `ModelProblem` 的率定方法。 |
2525
| 降低高代价评估成本 | 为慢速模型建立更便宜的近似。 | 代理模型与代理辅助工作流。 |
2626

27-
## 文档
28-
29-
- Documentation: <https://uqpyl.readthedocs.io>
30-
- Source code: <https://github.com/smasky/UQPyL>
31-
3227
## 核心思想:定义一次,到处复用
3328

3429
UQPyL 不直接持有你的模型逻辑,而是把模型或决策问题包装成统一的 `problem` 定义,其中包括:
3530

3631
| 部分 | 含义 |
3732
|---|---|
3833
| 输入空间 | 变量、边界、标签和变量类型。 |
39-
| 评估规则 | 一批输入如何转换成目标、约束或模拟结果|
34+
| 评估规则 | 一批输入如何转换成目标、约束或提取想要的模拟数据|
4035
| 优化方向 | 每个目标是最小化还是最大化。 |
4136
| 运行信息 | 保存运行和结果摘要所用的问题名称与元数据。 |
4237

43-
一旦定义完成,同一个对象就可以被 DOE、分析、优化、推断、代理工作流和率定方法共同复用。有些工作流还需要更明确的模型语义,例如模拟结果、观测或掩码
38+
一旦定义完成,同一个对象就可以被 DOE、分析、优化、推断、代理工作流和率定方法共同复用。有些工作流还需要更明确的模型语义,例如模拟结果或观测
4439

4540
## Problem 抽象
4641

4742
`problem` 模块是理解 UQPyL 的概念入口。
4843

49-
| 抽象 | 作用 |
44+
| 抽象Python类 | 作用 |
5045
|---|---|
5146
| `Problem` | 适用于只需要最终目标值或约束值的方法。 |
52-
| `ModelProblem` | 适用于需要显式模型过程语义的方法,例如 `sim``obs` 或掩码|
47+
| `ModelProblem` | 适用于需要显式模型模拟结果的方法,例如 `sim``obs`|
5348

5449
这两个抽象共享同一套基础:
5550

5651
| 基础构件 | 作用 |
5752
|---|---|
58-
| `Space` | 定义变量、边界、标签和变量类型。 |
59-
| `Eval` | 标准评估返回对象|
53+
| `Space` | 定义变量、及其边界、标签和变量类型。 |
54+
| `Eval` | 评估的返回对象|
6055

61-
该模块还内置了一些基准问题, `Sphere``Ackley``ZDT``DTLZ`
56+
该模块还内置了一些基准问题,如单目标的 `Sphere``Ackley`等;多目标的`ZDT``DTLZ`套件
6257

63-
当方法只需要从候选输入获得最终目标或约束时,使用 `Problem`对于模型类问题,只要最终值已经足够,仍然可以使用 `Problem`。只有在方法明确需要模拟结果、观测或模拟与观测对比语义时,才使用 `ModelProblem`。在当前设计里,这主要对应Calibration模型
58+
当方法只需要从候选输入获得最终目标或约束时,使用 `Problem`因此,对于以数值模型为基础的问题,只要最终值已经足够,仍然可以使用 `Problem`。只有在方法明确需要模拟结果、观测或模拟与观测对比语义时,才使用 `ModelProblem`。在当前设计里,这主要对应Calibration模块(`IES`, `ES`, `GLUE`, `SUFI2`)
6459

6560
<p align="center">
6661
<img src="./docs_v2/assets/Problem.webp" alt="Problem 与 ModelProblem 对比" width="1000"/>
6762
</p>
6863

69-
对于水文模型来说,难点通常不在算法本身,而在模型连接这一层。针对这一层,我们推荐使用 [hydroPilot](https://github.com/smasky/hydroPilot)
64+
对于水文模型来说,难点通常不在算法本身,而在模型连接这一层。因此,我们强烈推荐使用 [hydroPilot](https://github.com/smasky/hydroPilot)来构建问题
7065

7166
## 架构概览
7267

73-
UQPyL 围绕统一的 `problem` 抽象组织,并在其上构建一组功能模块
68+
UQPyL 围绕统一的 `problem` 抽象组织,并在其上构建一套功能模块
7469

7570
<p align="center">
7671
<img src="./docs_v2/assets/architecture.png" alt="UQPyL 架构概览" width="1000"/>
@@ -92,7 +87,7 @@ UQPyL 围绕统一的 `problem` 抽象组织,并在其上构建一组功能模
9287

9388
## 典型工作流
9489

95-
常见工作流最终都会产出结构化结果,并可选配运行期存储。只消费最终目标或约束的工作流可以使用 `Problem`;需要显式 `sim``obs` 或相关比较语义的工作流使用 `ModelProblem`
90+
常见工作流最终都会产出结构化结果,并可选配运行期存储。
9691

9792
```text
9893
Problem -> DOE -> Analysis -> outputs
@@ -104,7 +99,7 @@ Problem -> DOE -> Surrogate -> Optimization
10499

105100
## 快速开始示例
106101

107-
### 使用 `Problem` 直接评估
102+
### 使用 `Problem` 做优化
108103

109104
```python
110105
import numpy as np
@@ -146,7 +141,13 @@ obs = np.array([[1.0], [2.0], [3.0]])
146141

147142
def simFunc(X):
148143
X = np.atleast_2d(X)
149-
return X[:, :1][:, None, :] * obs[None, :, :]
144+
# 这里假设每组参数都会返回 1 条模拟序列,
145+
# 一共有 3 个时刻,因此返回尺寸是 (n_samples, 3, 1)。
146+
sim = np.zeros((X.shape[0], 3, 1))
147+
sim[:, 0, 0] = X[:, 0] * 1.0
148+
sim[:, 1, 0] = X[:, 0] * 2.0
149+
sim[:, 2, 0] = X[:, 0] * 3.0
150+
return sim
150151

151152

152153
problem = ModelProblem(
@@ -183,7 +184,7 @@ result = GLUE(metric="rmse", verboseFlag=False).run(problem, X, threshold=0.2)
183184

184185
对于很多单目标水文和工程率定问题,`SCE_UA` 是一个很好的起点。
185186

186-
## Runtime Output
187+
## 运行输出与保存
187188

188189
大多数可运行方法都共享三个常见运行期控制选项。
189190

@@ -193,8 +194,41 @@ result = GLUE(metric="rmse", verboseFlag=False).run(problem, X, threshold=0.2)
193194
| `logFlag` | 在支持时写出更完整的运行日志。 |
194195
| `saveFlag` | 保存结构化结果,通常是 sqlite。 |
195196

197+
```python
198+
algorithm = SCE_UA(maxFEs=200, verboseFlag=True, logFlag=True, saveFlag=True)
199+
result = algorithm.run(problem, seed=123)
200+
```
201+
202+
终端输出示例如下:
203+
204+
```text
205+
Algorithm: SCE-UA
206+
Problem: Sphere2D
207+
nInput: 2
208+
nObj: 1
209+
maxFEs: 200
210+
maxIters: 1000
211+
SCE-UA | iter=10 eval=84 best=4.3210e-03 cv=0 time=0.0s
212+
SCE-UA | iter=20 eval=154 best=2.1500e-04 cv=0 time=0.0s
213+
Optimization finished
214+
algorithm : SCE-UA
215+
status : finished
216+
iterations : 27
217+
evaluations : 203
218+
best value : 1.0000e-04
219+
best X : [1.0000e-02, -0.0000e+00]
220+
constraint viol. : 0
221+
elapsed : 0.0s
222+
```
223+
196224
启用 `saveFlag=True`` 后,运行可以产出供对应 reader 后续读取的持久化结果。
197225

226+
| 保存选项 | 规则 |
227+
|---|---|
228+
| `saveFlag=True` | 为当前运行启用结构化结果保存。 |
229+
| `saveFreq` | 对优化方法,会每隔 `saveFreq` 次迭代保存一次中间快照,并在结束时始终保存最终结果。 |
230+
| Reader 读取 | 保存下来的 sqlite 结果后续可以通过 `OptReader``AnaReader``CalReader` 等模块 reader 读取。 |
231+
198232
## 更多示例
199233

200234
使用 `Sobol` 做敏感性分析:

0 commit comments

Comments
 (0)