Skip to main content

CVXPY translation

This small library provides an alternative way to solve CVXPY problems by building solver's native models. It currently supports Gurobi and SCIP.

Usage

The library provides a solver that will translate a CVXPY Problem into a gurobipy.Model or a pyscipopt.Model, and solve using the direct interface:

import cvxpy as cp

problem = cp.Problem(cp.Maximize(cp.Variable(name="x", nonpos=True)))
cvxpy_translation.solve(problem, solver=cp.GUROBI)
assert problem.value == 0

This solver is a simple wrapper for the most common use case:

from cvxpy_translation import build_model, backfill_problem

model = build_model(problem, solver=cp.SCIP)
model.optimize()
backfill_problem(problem, model)
assert model.getObjVal() == problem.value

The build_model function provided by this library translates the Problem instance into an equivalent Model, and backfill_problem sets the optimal values on the original problem.

The output of the build_model function is a Model instance, which can be further customized prior to solving. This approach enables you to manage how the model will be optimized, set parameters, or use features that aren't available through CVXPY's interface.

Installation

pip install cvxpy-translation

CVXPY has an interface to Gurobi and SCIP, why is this needed?

When using CVXPY's interface, the problems fed to the solver have been pre-compiled by CVXPY, meaning the model is not exactly the same as the one you have written. This is great for solvers with low-level APIs, such as SCS or OSQP, but gurobipy and pyscipopt allow you to express your models at a higher-level.

Providing the raw model to the solver can be a better idea in general to let the solver use its own heuristics. The chosen algorithm can be different depending on the way it is modelled.

In addition, CVXPY does not give access to the model before solving it. CVXPY must therefore make some choices for you, such as setting some parameters on the generated model. Having access to the model can help if you want to handle the call to .optimize() in a non-standard way, e.g. by calling .optimizeAsync() in gurobipy or solveConcurrent() in pyscipopt. It is also required to set callbacks.

Another feature is the ability to use the latest features of the solvers, such as non-linear expressions in Gurobi, which are not yet supported by the Gurobi interface in CVXPY.

Example with Gurobi

Consider this QP problem:

import cvxpy as cp

x = cp.Variable(name="x")
problem = cp.Problem(cp.Minimize((x - 1) ** 2))

The problem will be sent to Gurobi as (in LP format):

Minimize
 [ 2 C0 ^2 ] / 2
Subject To
 R0: - C0 + C1 = 1
Bounds
 C0 free
 C1 free
End

Using this package, it will instead send:

Minimize
  - 2 x + Constant + [ 2 x ^2 ] / 2
Subject To
Bounds
 x free
 Constant = 1
End

Note that:

  • the variable's name matches the user-defined problem;
  • no extra (free) variables;
  • no extra constraints.

Why not use gurobipy or pyscipopt directly?

CVXPY has 2 main features: a modelling API and interfaces to many solvers. The modelling API has a great design, whereas gurobipy and pyscipopt feel like a thin layer over the C API. The interfaces to other solvers can be useful to not have to rewrite the problem when switching solvers.

Supported versions

All supported versions of Python and CVXPY should work.

The same goes for gurobipy. However, due to licensing restrictions, old versions of gurobipy cannot be tested in CI. If you run into a bug, please open an issue in this repo specifying the versions used.

Only versions of pyscipopt after 5.5.0 are supported as that is when the matrix API was introduced.

Contributing

Hatch is used for development. It will handle all the dependencies when testing on multiple versions.

For testing, run:

hatch run latest:tests

This will test the latest version of dependencies. You can also run hatch run oldest:tests to test the minimum required dependency versions.

Make sure any change is tested through a snapshot test. To add a new test case, build a simple CVXPY problem in tests/test_problems.py in the appropriate category, then run:

hatch run update-snapshots

You can then check the output in the tests/snapshots folder is as expected.

To lint the code, run:

ruff check

To format the code, run:

ruff format

Metadata

Release files for cvxpy-translation 2.0.3

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for cvxpy-translation 2.0.3
File Size Uploaded
cvxpy_translation-2.0.3.tar.gz 76.9 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for cvxpy-translation 2.0.3
File Interpreter ABI Platform
cvxpy_translation-2.0.3-py3-none-any.whl Python 3 none any Details

Total release size: 104.2 kB

Release files / cvxpy_translation-2.0.3.tar.gz

Download URL cvxpy_translation-2.0.3.tar.gz
Size 76.9 kB
Tags Source
SHA-256 checksum
How to use checksums
436ad550aee7715c094287ea641d3942a9c7e2154fffba75b6b418f2a3514e5d
BLAKE2b-256 checksum
How to use checksums
f3dc26297d20811ac04a9d229dbab334f1d47d71568f38c8b2f8829ab50c2bf9
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 Oct 13, 2026.

Transparency log

Release files / cvxpy_translation-2.0.3-py3-none-any.whl

Download URL cvxpy_translation-2.0.3-py3-none-any.whl
Size 27.4 kB
Tags Python 3
SHA-256 checksum
How to use checksums
16a252754d8e7ca4c89e588ef9b7acf7be7e990f3451f9d54582dd684d477297
BLAKE2b-256 checksum
How to use checksums
7ed456cd98b2ea2e044fb44f138b0ab3b9e7150056c4089f1eb1b6a102692ebd
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 Oct 13, 2026.

Transparency log

Release history Release notifications | RSS feed

This release

2.0.3 This release

2 release files

2.0.2

2 release files

2.0.1

2 release files

2.0.0

2 release 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