Skip to main content

Python solver for Mathematical Programs with Complementarity Constraints (MPCC) using IPOPT via cyipopt

Project description

pympcc

PyPI CI Docs License: MIT

A Python solver for Mathematical Programs with Complementarity Constraints (MPCC) using IPOPT via cyipopt, with an optional SciPy backend.

Six reformulation strategies, certified MPCC multipliers, B-stationarity / SOSC diagnostics, parametric sensitivity, and a jax.custom_vjp-registered solve for end-to-end differentiability.

Problem form

min  f(x)
s.t. g(x) ≤ 0              (inequality constraints)
     h(x) = 0              (equality constraints)
     G(x) ≥ 0  }
     H(x) ≥ 0  }           (complementarity)
     G(x)ᵀ H(x) = 0  }

Install

Requirements: Python ≥ 3.11. The IPOPT backend also requires a working IPOPT installation.

brew install ipopt                           # macOS
sudo apt-get install coinor-libipopt-dev     # Linux

pip install "pympcc[ipopt]"                  # default backend
pip install "pympcc[scipy]"                  # SciPy backend only
pip install "pympcc[jax]"                    # solve_jax + JAX-AD derivatives
pip install "pympcc[dev]"                    # for development

See the documentation for the optional custom IPOPT linear-solver bridge and source builds.

Quickstart

import numpy as np
import pympcc

# min (x0-2)² + (x1-1)²   s.t.  x0 ≥ 0 ⊥ x1 ≥ 0
problem = pympcc.MPCCProblem(
    n=2, n_comp=1,
    x0=np.array([0.5, 0.5]),
    xl=np.zeros(2),
    objective=lambda x: (x[0] - 2)**2 + (x[1] - 1)**2,
    gradient=lambda x: np.array([2*(x[0]-2), 2*(x[1]-1)]),
    comp_G=lambda x: np.array([x[0]]),
    comp_G_jacobian=lambda x: np.array([[1.0, 0.0]]),
    comp_H=lambda x: np.array([x[1]]),
    comp_H_jacobian=lambda x: np.array([[0.0, 1.0]]),
)

result = pympcc.solve(problem, strategy="scholtes")
print(result.x, result.obj, result.success)   # [2. 0.] 1.0 True

Strategies

Strategy How it works Best for
"direct" G·H ≤ 0; single solve Quick feasibility checks
"scholtes" G·H ≤ ε, drives ε → 0 Default — most robust
"smoothing" Fischer-Burmeister φ_ε(G,H) = 0, drives ε → 0 Tight complementarity residuals
"lin_fukushima" G·H ≤ ε and G+H ≥ ε; preserves MPCC-MFCQ Degenerate problems
"augmented_lagrangian" PHR penalty in objective Problems where MFCQ fails
"slack" Lifts G, H to slacks; sparse comp rows Large-n problems (n ≫ n_comp)

Highlights

  • Certified stationaritytnlp_refine=True re-solves a tightened NLP with the active set fixed and extracts MPCC-clean multipliers; classifies S- / W-stationarity. (docs)
  • Diagnostics — MPCC-LICQ / MPCC-MFCQ check, B-stationarity by branch enumeration, MPCC-SOSC, multi-merit cross-check, condition numbers, degeneracy report. (docs)
  • Parametric sensitivitypympcc.sensitivity(result, problem, dgrad_L_dp=..., dc_dp=...) returns dx*/dp and dλ*/dp from a single KKT linear solve. (docs)
  • Differentiablepympcc.solve_jax(parametric, theta, ...) is jax.custom_vjp-registered: differentiate transparently through a converged MPCC. (docs)
  • Bilevelpympcc.bilevel.from_lower_level(...) compiles min_x F(x,y) s.t. y ∈ argmin_y f(x,y) to an MPCC by emitting lower-level KKT. (docs)
  • Sparse-friendly — COO-format Jacobians end-to-end; the slack strategy keeps the comp block at 2·n_comp nonzeros regardless of n.
  • AMPL .nl readerpympcc.frontend.ampl.from_nl(path) for MacMPEC-format inputs.
  • Multistart and presolvepympcc.multistart(...), presolve=True.

Documentation

Full user guide, API reference, and theory primer at pympcc.readthedocs.io.

Testing

uv run pytest tests/ -v

The suite covers all six strategies, all diagnostic modules, the MacMPEC benchmark collection, sensitivity, and solve_jax. The direct strategy tests are marked xfail(strict=False) because LICQ generically fails at MPCC feasible points.

References

  • Scholtes, S. (2001). Convergence properties of a regularization scheme for mathematical programs with complementarity constraints. SIAM J. Optim. 11(4), 918–936.
  • Lin, G.-H., & Fukushima, M. (2003). New relaxation method for mathematical programs with complementarity constraints. J. Optim. Theory Appl. 118(1), 81–116.
  • Fischer, A. (1992). A special Newton-type optimization method. Optimization 24(3–4), 269–284.
  • Luo, Z.-Q., Pang, J.-S., & Ralph, D. (1996). Mathematical Programs with Equilibrium Constraints. Cambridge University Press.
  • Leyffer, S. (2000). MacMPEC — AMPL collection of MPECs. Argonne National Laboratory.

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

pympcc-0.5.0.tar.gz (4.6 MB view details)

Uploaded Source

Built Distribution

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

pympcc-0.5.0-py3-none-any.whl (264.0 kB view details)

Uploaded Python 3

File details

Details for the file pympcc-0.5.0.tar.gz.

File metadata

  • Download URL: pympcc-0.5.0.tar.gz
  • Upload date:
  • Size: 4.6 MB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.9.27 {"installer":{"name":"uv","version":"0.9.27","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"macOS","version":null,"id":null,"libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}

File hashes

Hashes for pympcc-0.5.0.tar.gz
Algorithm Hash digest
SHA256 ab7bc64fae677173ac99dc1b9f1ca88483dba91e81c4d80a9a3b5c9529b14f0e
MD5 571ac14220a93da07d4a13ed8d991520
BLAKE2b-256 945f83e3d110464239a0cc7f354e5995a68d7e06879ec274e1019c8003bbbc35

See more details on using hashes here.

File details

Details for the file pympcc-0.5.0-py3-none-any.whl.

File metadata

  • Download URL: pympcc-0.5.0-py3-none-any.whl
  • Upload date:
  • Size: 264.0 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.9.27 {"installer":{"name":"uv","version":"0.9.27","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"macOS","version":null,"id":null,"libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}

File hashes

Hashes for pympcc-0.5.0-py3-none-any.whl
Algorithm Hash digest
SHA256 39cfa00713e57000003b432d673b49693dedc07c34714dce2cd09c5189cfa8f6
MD5 61cc4114334de5cafc399fcf071157c0
BLAKE2b-256 5862827c8f7fced1c858257c2fdd3540d80b8e2360f50348a5c3a5bef7184b7d

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