Skip to content

Commit 73d784f

Browse files
authored
Merge pull request #28 from colmduff/0.1.5
0.1.5
2 parents 0b91ffc + 3cd9878 commit 73d784f

24 files changed

+402
-291
lines changed

.github/workflows/test.yml

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -23,11 +23,8 @@ jobs:
2323
python -m pip install --upgrade pip
2424
pip install poetry
2525
26-
- name: Install dependencies with Poetry
27-
run: poetry install --no-interaction --no-root
28-
29-
- name: Install optigob package (editable)
30-
run: poetry install --no-interaction
26+
- name: Install dependencies with Poetry (including HiGHS solver)
27+
run: poetry install --no-interaction -E solvers
3128

3229
- name: Run tests via Makefile in tests folder
3330
working-directory: tests

.gitignore

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -167,6 +167,14 @@ sankey.py
167167
#claude
168168
CLAUDE.md
169169
.claude_config.yaml
170+
goals.md
170171

171-
#test logs
172+
#test files/logs/data
172173
tests/data/logs/
174+
.solver_test
175+
.test_co2e_budget_confirmation.py
176+
.test_zero_budget_message.py
177+
.retest.py
178+
test_bugs_enhanced.py
179+
sip_bug1.yaml
180+
sip_bug2.yaml

CHANGELOG.md

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,26 @@
22

33
<!--next-version-placeholder-->
44

5+
## v0.1.5 (17/02/2026)
6+
7+
### Breaking Changes
8+
9+
- **Solver migration**: Replaced `cplex_direct` (previously a core dependency) with **HiGHS** as the recommended solver, now available as an optional extra
10+
- Install with `pip install "optigob[solvers]"` or `poetry install -E solvers`
11+
- Users without HiGHS can specify any Pyomo-compatible solver via the `solver_name` parameter in their SIP file
12+
13+
### Features
14+
15+
- **Configurable solver**: Users can now specify their preferred solver in the SIP input file (e.g., `solver_name: "highs"`, `solver_name: "glpk"`)
16+
- **Package-level imports**: Key classes (`Optigob`, `OptiGobDataManager`, `InputHelper`, `configure_logging`, `get_logger`) are now exported from `__init__.py` for cleaner imports (e.g., `from optigob import Optigob`)
17+
18+
### Documentation
19+
20+
- Fixed documentation inconsistencies across README, INSTALLATION, and CLAUDE.md
21+
- Added `limitations.md` to ReadTheDocs navigation
22+
- Updated Poetry extras install syntax in installation guide
23+
- Corrected module tree to reflect actual `substitution/` directory structure
24+
525
## v0.1.4 (05/11/2025)
626

727
### Features

INSTALLATION.md

Lines changed: 68 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ This guide will help you install and set up the `optigob` package for developmen
44

55
## Requirements
66

7-
- Python 3.9 or higher
7+
- Python 3.12 or higher
88
- [Poetry](https://python-poetry.org/) (recommended for development)
99
- (Optional) [pip](https://pip.pypa.io/) for standard installation
1010
- (Optional) [conda](https://docs.conda.io/) for environment management
@@ -17,6 +17,17 @@ You can install the latest release from PyPI:
1717
pip install optigob
1818
```
1919

20+
OptiGob requires a solver to run optimizations. The recommended option is
21+
**HiGHS**, which you can install alongside optigob:
22+
23+
```bash
24+
pip install "optigob[solvers]"
25+
```
26+
27+
Alternatively, install just optigob and choose your own Pyomo-compatible solver
28+
from the list provided below.
29+
30+
2031
## Development Install (Recommended for Contributors)
2132

2233
1. **Clone the repository:**
@@ -32,36 +43,82 @@ pip install optigob
3243
pip install poetry
3344
```
3445

35-
3. **Install dependencies and the package in editable mode:**
46+
3. **Install dependencies and the project (local-path install):**
3647

3748
```bash
3849
poetry install
3950
```
4051

41-
4. **Activate the Poetry shell (optional):**
52+
Poetry installs the project from your working directory (PEP 660
53+
editable-style), so local code changes are reflected immediately without
54+
a separate `-e` flag.
55+
56+
To include the recommended HiGHS solver:
4257

4358
```bash
44-
poetry shell
59+
poetry install -E solvers
4560
```
4661

47-
5. **Run tests to verify your installation:**
62+
4. **Run commands in the Poetry environment:**
4863

49-
```bash
50-
poetry run pytest
51-
```
64+
You have two options:
65+
66+
- **Use `poetry run` prefix** (recommended for single commands):
67+
```bash
68+
poetry run pytest
69+
poetry run python tests/example.py
70+
```
71+
72+
- **Or activate the Poetry shell** (for multiple commands in one session):
73+
```bash
74+
poetry shell
75+
pytest
76+
python tests/example.py
77+
exit # to leave the Poetry shell when done
78+
```
5279

5380
## Optional: Using Conda
5481

5582
If you prefer conda for environment management:
5683

5784
```bash
58-
conda create -n optigob python=3.10
85+
conda create -n optigob python=3.12
5986
conda activate optigob
6087
pip install poetry
6188
poetry install
6289
```
6390

64-
## Updating the Package
91+
To include the recommended HiGHS solver:
92+
93+
```bash
94+
poetry install -E solvers
95+
```
96+
97+
## Using Alternative Solvers
98+
99+
OptiGob requires a Pyomo-compatible solver to run optimizations. While **HiGHS** is
100+
the recommended built-in option (install with `pip install highspy` or
101+
`poetry install --with solvers`), you can use any solver supported by Pyomo.
102+
103+
To use a different solver, specify the `solver_name` parameter in your configuration:
104+
105+
```python
106+
from optigob import Optigob
107+
from optigob.resource_manager.optigob_data_manager import OptiGobDataManager
108+
109+
data = {
110+
# ... your scenario parameters ...
111+
'solver_name': 'glpk' # Use GLPK instead of HiGHS
112+
}
113+
data_manager = OptiGobDataManager(data)
114+
optigob = Optigob(data_manager)
115+
```
116+
117+
For a complete list of available Pyomo-compatible solvers, see the
118+
[Pyomo documentation](https://pyomo.readthedocs.io/en/stable/getting_started/solvers.html).
119+
120+
To use a specific solver, ensure it is installed in your environment, then
121+
specify it via `solver_name`.
65122

66123
To update to the latest version from PyPI:
67124

@@ -82,7 +139,7 @@ poetry update
82139

83140
## Additional Resources
84141

85-
- [OptiGob Documentation](https://github.com/colmduff/OptiGob#readme)
142+
- [OptiGob Documentation](https://optigob.readthedocs.io/en/latest/)
86143
- [Poetry Documentation](https://python-poetry.org/docs/)
87144

88145
If you have any questions or need help, please open an issue on GitHub or contact the maintainers.

README.md

Lines changed: 69 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -8,13 +8,13 @@
88
[GitHub](https://github.com/colmduff/OptiGob) |
99
[Documentation](https://optigob.readthedocs.io/en/latest/) |
1010

11-
A land use change and environmental assessment tool based on preconfigured data animal population numbers based on negative emissions allowance.
11+
`OptiGob` is a Python-based decision support tool for exploring Ireland's agriculture, forestry, and other land use (AFOLU) sector under different climate and land use transition pathways. It combines pre-computed scenario data from [GOBLIN Lite](https://github.com/colmduff/goblin_lite) (agriculture and land use), FERS-CBM (forestry carbon balance), and LCAD2.0 (anaerobic digestion) into a single interface that optimises livestock populations subject to land and emissions constraints — without requiring users to run the upstream modelling chains. It is designed for researchers, policymakers, and educators investigating environmental and economic trade-offs associated with net-zero and split-gas emissions targets.
1212

1313
---
1414

1515
## High-Level Architecture & Module Interaction
1616

17-
The `optigob` package is a modular land use and environmental assessment framework. It is designed to calculate, aggregate, and analyze greenhouse gas emissions, land use, protein, bioenergy, harvested wood products, and substitution impacts for both baseline and scenario cases. The system is built around a central API (`Optigob`), which coordinates specialized modules for each sector and data type.
17+
The `optigob` package is a modular land use and environmental assessment framework. It calculates greenhouse gas emissions, land use, protein output, bioenergy, harvested wood products, and substitution impacts for both baseline and scenario cases. The system is built around a central API (`Optigob`), which coordinates specialised modules for each sector and data type.
1818

1919
### Module Structure
2020

@@ -24,7 +24,8 @@ optigob/
2424
│ ├── baseline_emissions.py
2525
│ ├── emissions_budget.py
2626
│ ├── landarea_budget.py
27-
│ ├── econ_output.py
27+
│ └── econ_output.py
28+
├── substitution/
2829
│ └── substitution.py
2930
├── bioenergy/
3031
│ └── bioenergy_budget.py
@@ -54,7 +55,7 @@ optigob/
5455
- **budget_model/baseline_emissions.py**: Provides baseline emissions by sector for all gases.
5556
- **budget_model/landarea_budget.py**: Calculates land area (aggregated, disaggregated, HNV) by sector for baseline and scenario.
5657
- **budget_model/econ_output.py**: Calculates protein, bioenergy, harvested wood products, and livestock population by sector.
57-
- **budget_model/substitution.py**: Centralizes logic for substitution impacts (e.g., wood for fossil, protein crop substitution).
58+
- **substitution/substitution.py**: Centralizes logic for substitution impacts (e.g., wood for fossil, protein crop substitution).
5859
- **protein_crops/protein_crops_budget.py**: Handles protein crop area, yield, and protein output calculations.
5960
- **livestock/livestock_budget.py**: Calculates livestock sector budgets, including emissions, land use, and protein.
6061
- **forest/forest_budget.py**: Handles forest sector land area, emissions, and harvested wood product calculations.
@@ -90,9 +91,56 @@ optigob/
9091
- Substitution logic is centralized in `substitution.py` and called by emissions and output modules as needed.
9192
- Specialized sector modules (livestock, forest, protein crops, etc.) encapsulate sector-specific calculations and are used by the budget modules.
9293

93-
### Default Database
94+
### Input Data and Default Database
9495

95-
A default database offers multiple permutations of abatement and productivity scenarios, but certain parameters (e.g., wetland restoration, forestry on organic soils) are limited to predefined combinations. A helper function identifies valid options to prevent unsupported configurations. Custom databases can also be supplied, provided they follow the expected schema.
96+
`optigob` ships with a pre-built SQLite database (`src/optigob/database/optigob_default_0.1.1.db`) that is installed automatically with the package. **No additional data download is required.**
97+
98+
#### Data provenance
99+
100+
The bundled database does not contain raw observational data. It contains **derived scenario scaler tables** generated by three upstream, sector-specific models:
101+
102+
| Upstream model | Domain | Reference |
103+
|---|---|---|
104+
| [GOBLIN Lite](https://github.com/colmduff/goblin_lite) | Agriculture and land use emissions, areas, livestock productivity | Duffy et al. (2022, 2024) |
105+
| [FERS-CBM](https://www.ucd.ie/forestecosystemresearch/) | Forest carbon balance (afforestation, existing forest, harvested wood) | Black et al. (2025); Kurz et al. (2008) |
106+
| [LCAD2.0](https://github.com/GOBLIN-Proj/lcad_gob) | Anaerobic digestion area, emissions, and bioenergy output | Martinez-Acre et al. (2025) |
107+
108+
These models were run across a defined set of valid parameter combinations for **Ireland**, and reflect three levels of abatement (Baseline, MACC, Frontier). The resulting scaler tables were stored in the SQLite database. At runtime, `optigob` queries these scalers to parameterise its optimisation model — effectively acting as a surrogate that stitches together pre-computed sectoral outputs without re-running the upstream models.
109+
110+
#### Database contents
111+
112+
The database contains scaler tables for:
113+
114+
- Livestock emissions, area, and protein (by species, abatement type, productivity tier)
115+
- Forest emissions, area, harvested wood products, and wood CCS
116+
- Organic soil emissions and area
117+
- Anaerobic digestion emissions and area
118+
- Protein crop emissions, area, and protein output
119+
- Willow bioenergy area and output
120+
- Substitution impacts (wood-for-fossil, crop-for-animal protein)
121+
122+
#### Predefined combinations
123+
124+
Not all parameter combinations are valid — only those that were modelled by the upstream tools exist in the database. Use the `InputHelper` class to explore valid combinations:
125+
126+
```python
127+
from optigob.input_helper import InputHelper
128+
helper = InputHelper()
129+
helper.print_all_combos() # View all valid parameter sets
130+
```
131+
132+
See `INPUT_VARIABLES.md` for full parameter definitions and validation requirements.
133+
134+
#### Using a custom database
135+
136+
While the default database is supplied, users can update it or supply a custom database using `DatabaseManager`:
137+
138+
```python
139+
from optigob.resource_manager.database_manager import DatabaseManager
140+
db = DatabaseManager(database_path="/path/to/custom_database.db")
141+
```
142+
143+
The custom database must follow the same table schema as the default.
96144

97145
---
98146

@@ -109,15 +157,30 @@ A default database offers multiple permutations of abatement and productivity sc
109157

110158
To install the package, use pip:
111159

160+
```bash
161+
pip install "optigob[solvers]"
162+
```
163+
164+
if you would prefer to use an alternative solver to HiGHS, the install command is:
165+
112166
```bash
113167
pip install optigob
114168
```
115169

170+
Be sure to specify the solver in "solver_name" in the SIP.yaml.
171+
172+
For example:
173+
174+
```yaml
175+
solver_name: "highs"
176+
```
177+
116178
## Usage
117179
118180
Here is some example input data:
119181
120182
```yaml
183+
solver_name: "highs"
121184
AR: 5
122185
split_gas: true
123186
split_gas_frac: 0.3

docs/conf.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
# -- Project information -----------------------------------------------------
88

99
project = u"optigob"
10-
copyright = u"2025, Colm Duffy"
10+
copyright = u"2025-2026, Colm Duffy"
1111
author = u"Colm Duffy"
1212

1313
# -- General configuration ---------------------------------------------------

docs/data/sip.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
solver_name: "highs"
12
AR: 5
23
split_gas: true
34
split_gas_frac: 0.3

docs/example.ipynb

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
},
1212
{
1313
"cell_type": "code",
14-
"execution_count": 16,
14+
"execution_count": null,
1515
"metadata": {},
1616
"outputs": [
1717
{
@@ -53,9 +53,9 @@
5353
}
5454
],
5555
"source": [
56-
"from optigob.optigob import Optigob\n",
57-
"from optigob.resource_manager.optigob_data_manager import OptiGobDataManager\n",
58-
"from optigob.input_helper import InputHelper\n",
56+
"from optigob import Optigob\n",
57+
"from optigob import OptiGobDataManager\n",
58+
"from optigob import InputHelper\n",
5959
"\n",
6060
"print(\"OptiGob Budget Model Input Combinations\")\n",
6161
"\n",

docs/index.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,5 +11,6 @@ contributing.md
1111
conduct.md
1212
installation.md
1313
input_variables.md
14+
limitations.md
1415
autoapi/index
1516
```

0 commit comments

Comments
 (0)