Skip to main content

Diagnostic tools for CVXPY optimization problems

Project description

cvxpy-debug

Diagnostic tools for CVXPY optimization problems. When your problem is infeasible, unbounded, or numerically inaccurate, cvxpy-debug tells you why and how to fix it.

Installation

pip install cvxpy-debug

Quick Start

import cvxpy as cp
import cvxpy_debug

# Create an infeasible problem
x = cp.Variable(3, nonneg=True)
constraints = [
    cp.sum(x) <= 100,
    x[0] >= 50,
    x[1] >= 40,
    x[2] >= 30,  # Sum of minimums = 120 > 100
]
prob = cp.Problem(cp.Minimize(cp.sum(x)), constraints)

# Debug it - automatically solves and diagnoses
report = cvxpy_debug.debug(prob)

Output:

════════════════════════════════════════════════════════════════
                     INFEASIBILITY REPORT
════════════════════════════════════════════════════════════════

Problem has 4 constraints. Found 4 that conflict.

CONFLICTING CONSTRAINTS
───────────────────────
  Constraint              Slack needed
  ────────────────────    ─────────────
  sum(x) <= 100           20.0
  x[0] >= 50              0.0
  x[1] >= 40              0.0
  x[2] >= 30              0.0

SUGGESTED FIXES
───────────────
• Increase budget to at least 120
• Reduce one of the minimum bounds

Features

  • Infeasibility diagnosis: Find which constraints conflict using IIS (Irreducible Infeasible Subsystem)
  • Unboundedness diagnosis: Identify which variables are unbounded and in which direction
  • Numerical issues: Detect scaling problems, ill-conditioning, and constraint violations
  • Performance analysis: Detect anti-patterns like loop-generated constraints
  • Full cone support: Linear, SOC, SDP, and exponential cone constraints
  • Human-readable reports: Clear explanations and actionable fix suggestions

Examples

See the examples/ folder for comprehensive usage examples:

Quick Start Examples

Problem Type Examples

Real-World Scenarios

API

Main Function

cvxpy_debug.debug(
    problem,
    solver=None,              # Override solver for diagnostic solves
    find_minimal_iis=False,   # Find minimal conflicting constraint set
    include_conditioning=False,  # Analyze condition numbers (slower)
    include_performance=True,    # Include performance analysis
)

Focused Diagnostics

# Infeasibility analysis
cvxpy_debug.debug_infeasibility(problem, report)

# Unboundedness analysis
cvxpy_debug.debug_unboundedness(problem, report)

# Numerical issues analysis
cvxpy_debug.debug_numerical_issues(problem, report)

# Performance analysis
cvxpy_debug.debug_performance(problem, report)

License

Apache 2.0

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

cvxpy_debug-0.1.0.tar.gz (166.6 kB view details)

Uploaded Source

Built Distribution

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

cvxpy_debug-0.1.0-py3-none-any.whl (47.7 kB view details)

Uploaded Python 3

File details

Details for the file cvxpy_debug-0.1.0.tar.gz.

File metadata

  • Download URL: cvxpy_debug-0.1.0.tar.gz
  • Upload date:
  • Size: 166.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.14.0

File hashes

Hashes for cvxpy_debug-0.1.0.tar.gz
Algorithm Hash digest
SHA256 899df215baf6c7396f8cd1bf6b3edaa01d89b8cf53f1c419a35c486f7714c51f
MD5 309253a09299e86a706b0ababc5b1600
BLAKE2b-256 7d6d5000b8b2251534881af061cdf167c38873d12203648335d29a66f3267e3e

See more details on using hashes here.

File details

Details for the file cvxpy_debug-0.1.0-py3-none-any.whl.

File metadata

  • Download URL: cvxpy_debug-0.1.0-py3-none-any.whl
  • Upload date:
  • Size: 47.7 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.14.0

File hashes

Hashes for cvxpy_debug-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 942c3c1e3c98bff6172a7e469a297eb7dbc3441c8ebbf6554b433a5fe7593178
MD5 3ba16e4bdf4440f04e39916f939c38b4
BLAKE2b-256 12f4b7b970eaef947230cce3eccdf1cb7df633ab23a7b035d0bb57358fc1074b

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page