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.
Metadata
Release files for opt-base-framework 0.7.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| opt_base_framework-0.7.0.tar.gz | 106.8 kB | With provenance | Details for opt_base_framework-0.7.0.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| opt_base_framework-0.7.0-py3-none-any.whl | Python 3 | none | any | Details for opt_base_framework-0.7.0-py3-none-any.whl |
Total release size: 151.2 kB
Release files / opt_base_framework-0.7.0.tar.gz
| Download URL | opt_base_framework-0.7.0.tar.gz |
|---|---|
| Size | 106.8 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
5454dc683e34712e435a15d3a426118cc99b94a5f510f23f01b33c696a09c9ea
|
|
BLAKE2b-256 checksum How to use checksums |
d965e27ebe6e30ab23c52399dde7e73356dd9eedb94e29e4f6774c31ba5ec29f
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.14
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Aug 20, 2026.
Transparency logRelease files / opt_base_framework-0.7.0-py3-none-any.whl
| Download URL | opt_base_framework-0.7.0-py3-none-any.whl |
|---|---|
| Size | 44.5 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
89eca5f0469b287f392c713e3277e07d04c144cfccc09d3e134fbdfb5df80c7d
|
|
BLAKE2b-256 checksum How to use checksums |
f8ccf8ba99d1ead7b9de32e271c25e01b71b0211ab0869210f9b54244e35b19d
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.14
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Aug 20, 2026.
Transparency logSecurity for opt-base-framework 0.7.0
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
Full provenance
All 2 files in this release have been uploaded with provenance metadata.
Attestation for opt_base_framework-0.7.0.tar.gz
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Aug 20, 2026.
Transparency logA note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.