Skip to content

Commit 69c4592

Browse files
authored
Update CLI, error handling, and documentation structure. (#56)
1 parent 9f09cf5 commit 69c4592

File tree

4 files changed

+277
-68
lines changed

4 files changed

+277
-68
lines changed

README.md

Lines changed: 261 additions & 63 deletions
Original file line numberDiff line numberDiff line change
@@ -37,22 +37,14 @@ This Python-based toolbox is designed to optimize geothermal reservoir developme
3737

3838
---
3939

40-
## Getting Started
40+
## Setup
4141

42-
### 1. Setup Prerequisites
43-
44-
To install basic dependencies (`git`, `curl`) essential for setup, run:
45-
46-
```shell
47-
make prerequisites
48-
```
49-
50-
---
51-
52-
### 2. Environment Installation
42+
### 1. Environment Installation
5343

5444
You can install either a **development environment** (recommended for developers) or a streamlined **release environment**.
5545

46+
> **Note:** Currently, Windows OS is not supported for this setup.
47+
5648
#### Development Environment:
5749

5850
This installs all the necessary tools, including development dependencies, pre-commit hooks, Docker, LaTeX, and Python/uv environments:
@@ -68,8 +60,6 @@ This command will specifically:
6860
- Install Docker, verifying its functionality.
6961
- Install all Python development dependencies and pre-commit hooks.
7062

71-
> **Note:** Currently, Windows OS is not supported for this setup.
72-
7363
#### Release Environment:
7464

7565
Installs only the dependencies necessary to run the application in a production setting. Run:
@@ -78,9 +68,15 @@ Installs only the dependencies necessary to run the application in a production
7868
make install-release
7969
```
8070

71+
This command will specifically:
72+
73+
- Install Python 3.12 and set up a virtual environment using `uv`.
74+
- Install Docker, verifying its functionality.
75+
- Install all Python development dependencies and pre-commit hooks.
76+
8177
---
8278

83-
### 3. Documentation Editing
79+
### 2. Documentation Editing
8480

8581
To edit the project documentation using TeXstudio, execute:
8682

@@ -96,80 +92,282 @@ make install-latex
9692

9793
---
9894

99-
### 4. Repository Health Checks
95+
### 3. Repository Health Checks
10096

101-
Maintain codebase quality by executing pre-commit hooks:
97+
Maintain codebase quality by executing pre-commit hooks, which will run set of the tools including pytest and coverage:
10298

10399
```shell
104100
make run-check
105101
```
106-
107102
---
108103

109-
### 5. Docker Installation and Verification
104+
## Getting started
110105

111-
Docker is necessary for building and containerizing deployments. Install it using:
106+
### 1. Supported Reservoir Simulators:
107+
- OpenDarts (1.1.3) [open_darts-1.1.3-cp310-cp310-linux_x86_64] (default)
112108

113-
```shell
114-
make install-docker
115-
```
109+
### 2. Reservoir simulation interoperability
110+
Interoperability between reservoir simulator and toolbox is established by the proper `Connector` [src/services/simulation_service/core/connectors].
111+
Connector allows exchange information (simulation configuration and simulation results) between toolbox and simulator.
116112

117-
After installation, verify Docker functionality with:
118113

119-
```shell
120-
make verify-docker
121-
```
114+
#### OpenDarts Connector
115+
1. Reservoir simulation must be run from the **main.py** file (user must preserve the file name)
116+
2. User should add the following dependencies in entry point for a simulation model:
122117

123-
---
118+
`from connectors.open_darts import OpenDartsConnector`
124119

125-
### Manual Virtual Environment Handling
120+
`from connectors.open_darts import open_darts_input_configuration_injector`
126121

127-
The `make install-dev` or `make install-release` targets will set up the Python virtual environment using `uv` and install git hooks.
122+
> **Note:** The `connectors` package will be automatically transfer from Toolbox to simulation model folder, no action
123+
> needed from User
128124
129-
If you need to run commands within this environment manually (e.g., a Python script or `pytest`), you can use `uv run`:
125+
3. Entry point for reservoir simulation must be decorated by `open_darts_input_configuration_injector`
130126

131-
```shell
132-
uv run python your_script.py
133-
uv run pytest
134-
```
127+
``` python
128+
@open_darts_input_configuration_injector
129+
def run_darts(injected_configuration) -> None:
130+
...
131+
```
135132

136-
To activate a shell session within the virtual environment, you can use:
133+
The `injected_configuration` contain the control vector for optimization proces. It's strongly recommended to pass
134+
`injected_configuration` to model initialization:
137135

138-
```shell
139-
uv shell
140-
```
136+
```python
137+
@open_darts_input_configuration_injector
138+
def run_darts(injected_configuration, ...) -> None:
139+
m = Model(configuration=injected_configuration)
140+
```
141+
and then
141142

142-
Additionally, if you need to manually install git hooks (e.g., if you skipped the `make install-*` targets initially or cloned to a new location without running them):
143+
```python
143144

144-
```shell
145-
uv run pre-commit install
146-
```
145+
class Model(DartsModel):
146+
def __init__(self, configuration, ...):
147147

148-
---
148+
self._configuration = configuration
149+
super().__init__()
150+
...
149151

150-
## Build and Test
152+
```
151153

152-
### Running Tests
154+
This allows having access to injected configuration in a whole DartsModel object.
153155

154-
Use `pytest` to run the project's test suite. The `make install-dev` target installs `pytest`. You can run tests using:
156+
4. Well(s) connections will be taken from `configuration` using `OpenDartsConnector.get_well_connection_cells(...)`, thus user must import
157+
`from connectors.open_darts import OpenDartsConnector`. Wells should be introduced in a simulation model in `def set_wells(self)` section:
155158

156-
```shell
157-
make run-check
158-
```
159-
This will also run tests as part of the pre-commit hooks. To run tests directly:
160-
```shell
161-
uv run pytest
162-
```
163-
Or, if you have activated the environment using `uv shell`:
164-
```shell
165-
pytest
166-
```
159+
```python
160+
def set_wells(self):
167161

168-
---
162+
wells = OpenDartsConnector.get_well_connection_cells(
163+
self._configuration, self.reservoir
164+
)
169165

170-
## Notes
166+
for well_name, cells in wells.items():
167+
self.reservoir.add_well(well_name)
168+
for cell in cells:
169+
i, j, k = cell
170+
self.reservoir.add_perforation(
171+
well_name, cell_index=(i, j, k), multi_segment=False
172+
)
171173

172-
- Familiarity with Unix commands and the `make` utility is assumed.
173-
- If you encounter issues during installation or operational errors, verify system compatibility and reread the instructions carefully.
174+
```
175+
176+
5. Whenever user want to return objective function to toolbox, the `broadcast_result` method from `OpenDartsConnector` should be used:
177+
178+
```python
179+
from connectors.common import SimulationResultType
180+
from connectors.open_darts import OpenDartsConnector
181+
...
182+
183+
OpenDartsConnector.broadcast_result(SimulationResultType.Heat, HeatValue)
184+
```
185+
186+
Then the heat value will be broadcasted back to toolbox with a proper flag from `SimulationResultType`.
187+
188+
> **Note:** Recently only "Heat" is supported in `SimulationResultType`
189+
190+
6. Simulation model implementation is read to run an optimization process using RiskManagementToolbox.
191+
7. All simulation model files must be archived in `.zip` format. User should ensure that after unpacking all simulation model files are accessible in folder without any additional subfolders.
192+
193+
### 3. Toolbox configuration file
194+
RiskManagementToolbox is designed to use JSON configuration file, where the user defines the optimization problem(s),
195+
initial state, and variable constrains.
196+
197+
Recently the following optimization problem(s) are supported:
198+
199+
1. **Well placement** - toolbox will try to find the optimal configuration of well(s): trajectory and perforation.
200+
201+
Well placement problem definition if following by individual well(s) used in simulation.
202+
203+
```json
204+
{
205+
"well_placement": [
206+
{
207+
"well_name": str,
208+
"initial_state": {
209+
210+
},
211+
"optimization_constrains": {
212+
213+
}
214+
},
215+
]
216+
}
217+
```
218+
219+
The initial state of the well defines the proper well type and all the mandatory well parameters neccessery to build well trajectory and define the completion intervals
220+
> **Note:** Recently only vertical well type `"well_type": "IWell"` is supported
221+
222+
The example vertical well configuration:
223+
224+
```json
225+
{
226+
"initial_state": {
227+
"well_type": "IWell",
228+
"md": 2500,
229+
"md_step": 10,
230+
"wellhead": {
231+
"x": 400,
232+
"y": 400,
233+
"z": 0
234+
}
235+
}
236+
}
237+
```
238+
> **Note:** If a user does not define a perforation interval, then by default the whole well md will be treated as perforated
239+
240+
If the user wants to define the perforation interval:
241+
242+
```json
243+
{
244+
"initial_state": {
245+
"well_type": "IWell",
246+
"md": 2500,
247+
"md_step": 10,
248+
"wellhead": {
249+
"x": 400,
250+
"y": 400,
251+
"z": 0
252+
},
253+
"perforations": [
254+
{
255+
"start_md": 1000,
256+
"end_md": 1200
257+
}
258+
]
259+
}
260+
}
261+
```
262+
> **Note:** Recently only one perforation range is supported
263+
264+
Each well initial state is followed by the optimization constrains part, where user can pick which parameters from
265+
well template will be used in an optimization process:
266+
267+
As an example, if a user decides to optimize the x and y position of wellhead as well as well md, the optimization constrains will take the following form:
268+
```json
269+
{
270+
"optimization_constrains": {
271+
"wellhead": {
272+
"x": {
273+
"lb": 10,
274+
"ub": 3190
275+
},
276+
"y": {
277+
"lb": 10,
278+
"ub": 3190
279+
}
280+
},
281+
"md": {
282+
"lb": 2000,
283+
"ub": 2700
284+
}
285+
}
286+
}
287+
```
288+
289+
where each parameter is bounded in lower (lb) and upper (ub) limit.
290+
291+
> **Note:** Parameters which are not listed in optimization constraints will not take part of an optimization process and remains the same as defined in the initial state
292+
293+
The complete example of well placement problem for two wells:
294+
```json
295+
{
296+
"well_placement": [
297+
{
298+
"well_name": "INJ",
299+
"initial_state": {
300+
"well_type": "IWell",
301+
"md": 2500,
302+
"md_step": 10,
303+
"wellhead": {
304+
"x": 400,
305+
"y": 400,
306+
"z": 0
307+
}
308+
},
309+
"optimization_constrains": {
310+
"wellhead": {
311+
"x": {
312+
"lb": 10,
313+
"ub": 3190
314+
},
315+
"y": {
316+
"lb": 10,
317+
"ub": 3190
318+
}
319+
}
320+
}
321+
},
322+
{
323+
"well_name": "PRO",
324+
"initial_state": {
325+
"well_type": "IWell",
326+
"md": 2500,
327+
"md_step": 10,
328+
"wellhead": {
329+
"x": 700,
330+
"y": 700,
331+
"z": 0
332+
}
333+
},
334+
"optimization_constrains": {
335+
"wellhead": {
336+
"x": {
337+
"lb": 10,
338+
"ub": 3190
339+
},
340+
"y": {
341+
"lb": 10,
342+
"ub": 3190
343+
}
344+
}
345+
}
346+
}
347+
]
348+
}
349+
```
350+
351+
### 4. Toolbox running
352+
353+
To run the RiskManagementToolbox the virtual environment corresponded with the repository must be
354+
activated
355+
356+
```URGENT_RiskManagementToolbox$ source .venv/bin/activate```
357+
358+
User must set:
359+
1. path to config file (--config-file)
360+
2. path to model archive(--model-file)
361+
362+
optionally:
363+
1. population size (--population-size)
364+
2. iteration count without progress (--patience)
365+
3. max generations count (-max-generations)
174366

175-
---
367+
```
368+
uv run src/main.py
369+
usage: main.py [-h] --config-file CONFIG_FILE --model-file MODEL_FILE [--population-size POPULATION_SIZE] [--patience PATIENCE] [--max-generations MAX_GENERATIONS]
370+
```
371+
372+
## Contact
373+
For issues or contributions, please open a GitHub issue or contact the maintainers.

pyproject.toml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,10 @@ cumulative_timing = false
7272
requires = ["setuptools>=42"]
7373
build-backend = "setuptools.build_meta"
7474

75+
[tool.uv]
76+
package = false
77+
78+
7579
[dependency-groups]
7680
dev = [
7781
"coverage==7.6.10",

0 commit comments

Comments
 (0)