
Pyomo
Install this when you need to express LP, MILP, or NLP optimization models in Python and swap solvers (GLPK, IPOPT, Gurobi) without rewriting the model.
Install
npx skills add https://github.com/tondevrel/scientific-agent-skills --skill pyomoWhat is this skill?
- Natural syntax for Sets, Parameters, Variables, and Constraints decoupled from any single solver
- Supports LP, MILP, and NLP for planning, process, energy dispatch, and supply-chain problems
- Same model can target IPOPT, SCIP, Gurobi, CPLEX, or GLPK without structural rewrites
- COIN-OR ecosystem skill with explicit pip/conda prerequisite checks before modeling
- Stochastic and multi-period extensions for resource allocation and flow problems
Adoption & trust: 1 installs on skills.sh; 14 GitHub stars; 3/3 security scanners passed (skills.sh audits); trending (+100% hot-view momentum).
Recommended Skills
Journey fit
Pyomo is primarily a modeling library you implement in product code, so the canonical shelf is Build where backend and analytics logic live. Optimization models are formulated as executable Python with constraints and objectives—backend/analytics implementation rather than a one-off landing or ops dashboard.
Common Questions / FAQ
Is Pyomo safe to install?
skills.sh reports 3 of 3 security scanners passed. Review the Security Audits panel on this page before installing in production.
SKILL.md
READMESKILL.md - Pyomo
# Pyomo - Mathematical Optimization Modeling Pyomo allows you to define optimization problems using a natural mathematical syntax (Sets, Parameters, Variables, Constraints). It decouples the model from the solver, allowing the same model to be solved by different engines without code changes. ## FIRST: Verify Prerequisites ```bash pip install pyomo # Also install a solver (e.g., GLPK for linear/integer problems) # Conda: conda install -c conda-forge glpk ipopt ``` ## When to Use - **Strategic Planning**: Long-term resource allocation or investment planning. - **Process Engineering**: Optimizing chemical plants or refinery operations (Non-linear). - **Energy Systems**: Power grid dispatch and unit commitment problems. - **Supply Chain Optimization**: Multi-period, multi-commodity flow problems. - **Non-Linear Programming (NLP)**: When your constraints or objectives involve smooth curves (e.g., x², log(x)). - **Stochastic Programming**: Modeling uncertainty in optimization. - **Custom Solver Integration**: When you need to use specific solvers like IPOPT, SCIP, or Baron. ## Reference Documentation **Official docs**: http://www.pyomo.org/ **GitHub**: https://github.com/Pyomo/pyomo **Search patterns**: `pyo.ConcreteModel`, `pyo.Constraint`, `pyo.Objective`, `pyo.SolverFactory` ## Core Principles ### Concrete vs. Abstract Models - **ConcreteModel**: Data is defined at the time the model is built (most common in Python/Data Science). - **AbstractModel**: The structure is defined first, and data is loaded later (standard for large-scale industrial models). ### Components - **Var**: Unknowns the solver needs to find. - **Set/Param**: Data that defines the problem instance. - **Objective**: The function to minimize or maximize. - **Constraint**: Rules the variables must follow. ### Solvers Pyomo does not have its own solver. It requires external solvers (like glpk for LP/MIP or ipopt for NLP) installed on the system. ## Quick Reference ### Installation ```bash pip install pyomo # Also install a solver (e.g., GLPK for linear/integer problems) # Conda: conda install -c conda-forge glpk ipopt ``` ### Standard Imports ```python import pyomo.environ as pyo from pyomo.opt import SolverFactory ``` ### Basic Pattern - Simple Linear Model (Concrete) ```python import pyomo.environ as pyo # 1. Create Model model = pyo.ConcreteModel() # 2. Define Variables model.x = pyo.Var(within=pyo.NonNegativeReals) model.y = pyo.Var(within=pyo.NonNegativeReals) # 3. Define Objective (Minimize x + 2*y) model.obj = pyo.Objective(expr=model.x + 2*model.y, sense=pyo.minimize) # 4. Define Constraints model.con1 = pyo.Constraint(expr=3*model.x + 4*model.y >= 12) model.con2 = pyo.Constraint(expr=2*model.x + 5*model.y >= 10) # 5. Solve solver = pyo.SolverFactory('glpk') results = solver.solve(model) # 6. Access Results print(f"x = {pyo.value(model.x)}, y = {pyo.value(model.y)}") ``` ## Critical Rules ### ✅ DO - **Scale your problem** - Like all optimization, Pyomo works best if variables and constraints are within a similar order of magnitude (e.g., 0.1 to 100). - **Use pyo.value()** - Always wrap variables in `pyo.value(model.x)` to get their numerical result after solving. - **Check Solver Status** - Verify the solver reached an optimal solution using `results.solver.termination_condition`. - **Use pyo.Set and pyo.Param** - For complex