Skip to main content

Opt Base Framework

PyPI version Python versions CI License: MIT

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

  • 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 a Rules class (the Pyomo math) — no framework code is ever touched.
  • Not LP/MILP-only. The same build_modelsolveextract_solution pipeline serves LP, MILP, and NLP — nothing in the core assumes linearity. Switch to a nonlinear problem by changing solver_name.
  • Upfront config validation. Every YAML file is checked before a single pyo.Constraint is built — missing Sets, unknown data attributes, mismatched rules_class methods, 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, and cyipopt through 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 copier template. optframework-new <name> generates a new problem's full layout; a copier template 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) ← developfeat/<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

opt_base_framework-0.6.2.tar.gz (103.9 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

opt_base_framework-0.6.2-py3-none-any.whl (43.8 kB view details)

Uploaded Python 3

File details

Details for the file opt_base_framework-0.6.2.tar.gz.

File metadata

  • Download URL: opt_base_framework-0.6.2.tar.gz
  • Upload date:
  • Size: 103.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/7.0.0 CPython/3.13.14

File hashes

Hashes for opt_base_framework-0.6.2.tar.gz
Algorithm Hash digest
SHA256 ea9c1a11e575cd78212cbd093fef44f82b5ac101802c06e16f03c8e4cbc70664
MD5 fd03fd4dbb2c68f2a68f3dda2f507217
BLAKE2b-256 0cc051879cca8c00f741beae86c2cf657e49fe6f77854c37cd4b9fa40760e331

See more details on using hashes here.

Provenance

The following attestation bundles were made for opt_base_framework-0.6.2.tar.gz:

Publisher: release.yml on VictorNMou/opt-base-framework

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file opt_base_framework-0.6.2-py3-none-any.whl.

File metadata

File hashes

Hashes for opt_base_framework-0.6.2-py3-none-any.whl
Algorithm Hash digest
SHA256 4b80fe386916b030a6bb1880a87557b76d91493a0039ba56ba092dced6199aa2
MD5 ecc64020b3901c82bc7fe5830d616877
BLAKE2b-256 ca45d508ab6c1e449c5d2bfe056dd8675e31283e7ab2a5bc0467f7afb02e88fc

See more details on using hashes here.

Provenance

The following attestation bundles were made for opt_base_framework-0.6.2-py3-none-any.whl:

Publisher: release.yml on VictorNMou/opt-base-framework

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Release history Release notifications | RSS feed

0.7.0

2 files

This release

0.6.2 This release

2 files

0.6.1

2 files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page