Opt Base Framework
A config-driven Python framework for optimization problems built on Pyomo.
LP/MILP by default, but the core never assumes linearity — neither Rules, infeasibility
diagnostics, nor sensitivity analysis inspect the shape of an expression — so NLP works by
swapping only the solver_name (see the NLP pricing example, solved with
ipopt). Declare a new problem entirely in YAML + a thin
Rules class, and reuse the same core, without ever touching framework code.
Contents
- Features
- Installation
- Quickstart
- Using the framework in another project
- Documentation
- Logging
- Development
- License
Features
- Config-driven core. Sets, Parameters, Variables, Expressions, Constraints, and the
Objective are declared in YAML; a problem contributes only a
data_loader.py(data) and aRulesclass (the Pyomo math) — no framework code is ever touched. - Not LP/MILP-only. The same
build_model→solve→extract_solutionpipeline serves LP, MILP, and NLP — nothing in the core assumes linearity. Switch to a nonlinear problem by changingsolver_name. - Upfront config validation. Every YAML file is checked before a single
pyo.Constraintis built — missing Sets, unknowndataattributes, mismatchedrules_classmethods, all reported together in one error, not one crash at a time. - Solver-agnostic by design. Ships with HiGHS (
highspy, no system binary required) and supports Gurobi, CPLEX,ipopt, andcyipoptthrough the same adapter, which auto-detects which kwargs each solver interface actually accepts. - Automatic infeasibility diagnostics. On an infeasible solve, the framework picks a diagnostic strategy per solver — native IIS for Gurobi/CPLEX, elastic relaxation (Chinneck's method) for HiGHS/SCIP/others — and reports ranked candidate causes.
- Sensitivity analysis, warm start, scenario loops. Duals/reduced costs via fix-and-resolve, warm-started multi-scenario sweeps, and always-on solve metrics (wall time, bounds, gap) — all opt-in through config, at zero cost when unused.
- Scaffold CLI and
copiertemplate.optframework-new <name>generates a new problem's full layout; acopiertemplate bootstraps an entire consumer project in one command. - Opt-in structured logging. Built on loguru, disabled by default per library best practice — the consuming application decides sinks and format.
Installation
uv add opt-base-framework
or, with plain pip:
pip install opt-base-framework
Requires Python 3.12+.
Quickstart
uv sync
uv run python -m problems.exemplo_knapsack.run
Expected output (classic 0/1 knapsack instance — weights [10, 20, 30], values [60, 100, 120],
capacity 50):
Status: optimal
Itens selecionados: ['B', 'C'] # selected items
Valor total: 220 # total value
(The demo problem's own print labels are in Portuguese — only this README is translated; the values and behavior are what matter.)
Using the framework in another project
This repository is the core (src/optframework/) — not a template to clone. problems/
and tests/ here are just examples/fixtures for developing the framework itself; a new project
declares opt-base-framework as a dependency and never touches src/:
uv init my-project && cd my-project
uv add opt-base-framework
Upgrading is uv lock --upgrade-package opt-base-framework — you never copy src/. To pin a
version not yet published on PyPI (e.g. testing a branch), installing straight from Git still
works: uv add "opt-base-framework @ git+https://github.com/VictorNMou/opt-base-framework.git@v0.6.1".
To generate the structure for a new problem (config/ + data_loader.py + rules.py +
run.py), use optframework-new — installed alongside the dependency:
uv run optframework-new fleet_routing
uv run python -m problems.fleet_routing.run # already runs: placeholder minimize sum(x)
--dest changes the root folder (default problems) and --force overwrites an existing
problems/<name>/. See Creating a new problem for
what to fill in next, and Project bootstrap for the copier template that
runs uv init + uv add + optframework-new in a single command.
Documentation
| Architecture | How the core is layered, creating a new problem, integrating with external platforms |
| Configuration reference | Full YAML reference: defaults, bounds/within, expressions, indexed/dynamic constraints, validation |
| Solve-time behavior | Infeasibility diagnostics, sensitivity, warm start, solver kwarg compatibility |
| Examples | NLP pricing example, self-contained cyipopt setup |
| Project bootstrap | Full walkthrough of the copier template |
Logging
The framework logs via loguru, disabled by default — the behavior loguru's own docs recommend for libraries. Two ways to turn it on:
from optframework.logging import configure_logging
configure_logging() # ready-made setup: colored stderr sink, INFO level
configure_logging(level="DEBUG", sink="app.log") # custom level and sink
Or, if the project already uses loguru for itself:
from loguru import logger
logger.enable("optframework") # sinks already configured by the application also start
# receiving the framework's logs
Development
uv sync # install dependencies (test + dev groups by default)
uv run pytest # tests (~100% coverage on src/optframework/)
uv run ruff check . # lint
uv run pylint src problems tests # complexity/duplication (not covered by Ruff)
Branching model: main (protected, only receives merges from develop) ← develop ←
feat/<name> (one branch per feature). CI (GitHub Actions) runs lint + tests on every PR/push to
main/develop.
License
MIT.
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file opt_base_framework-0.7.0.tar.gz.
File metadata
- Download URL: opt_base_framework-0.7.0.tar.gz
- Upload date:
- Size: 106.8 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via:
twine/7.0.0 CPython/3.13.14
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
5454dc683e34712e435a15d3a426118cc99b94a5f510f23f01b33c696a09c9ea
|
|
| MD5 |
0f4b17183f345be66cbb20818fe1eb60
|
|
| BLAKE2b-256 |
d965e27ebe6e30ab23c52399dde7e73356dd9eedb94e29e4f6774c31ba5ec29f
|
Provenance
The following attestation bundles were made for opt_base_framework-0.7.0.tar.gz:
Publisher:
release.yml on VictorNMou/opt-base-framework
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
opt_base_framework-0.7.0.tar.gz -
Subject digest:
5454dc683e34712e435a15d3a426118cc99b94a5f510f23f01b33c696a09c9ea - Sigstore transparency entry: 2535461401
- Sigstore integration time:
-
Permalink:
VictorNMou/opt-base-framework@a3a7541be443d7ec243c07eb513266d1e7770148 -
Branch / Tag:
refs/tags/v0.7.0 - Owner: https://github.com/VictorNMou
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
release.yml@a3a7541be443d7ec243c07eb513266d1e7770148 -
Trigger Event:
release
-
Statement type:
File details
Details for the file opt_base_framework-0.7.0-py3-none-any.whl.
File metadata
- Download URL: opt_base_framework-0.7.0-py3-none-any.whl
- Upload date:
- Size: 44.5 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via:
twine/7.0.0 CPython/3.13.14
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
89eca5f0469b287f392c713e3277e07d04c144cfccc09d3e134fbdfb5df80c7d
|
|
| MD5 |
c15fd24213e2ef6a9bc6b68af3f731b9
|
|
| BLAKE2b-256 |
f8ccf8ba99d1ead7b9de32e271c25e01b71b0211ab0869210f9b54244e35b19d
|
Provenance
The following attestation bundles were made for opt_base_framework-0.7.0-py3-none-any.whl:
Publisher:
release.yml on VictorNMou/opt-base-framework
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
opt_base_framework-0.7.0-py3-none-any.whl -
Subject digest:
89eca5f0469b287f392c713e3277e07d04c144cfccc09d3e134fbdfb5df80c7d - Sigstore transparency entry: 2535461475
- Sigstore integration time:
-
Permalink:
VictorNMou/opt-base-framework@a3a7541be443d7ec243c07eb513266d1e7770148 -
Branch / Tag:
refs/tags/v0.7.0 - Owner: https://github.com/VictorNMou
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
release.yml@a3a7541be443d7ec243c07eb513266d1e7770148 -
Trigger Event:
release
-
Statement type: