Skip to main content

optlang-copt

optlang-copt is a standalone adapter that makes Cardinal Optimizer (COPT) available through optlang and COBRApy without modifying either installed package.

Supported scope

  • Linear programming (LP)
  • Mixed-integer linear programming (MILP)
  • Linear and convex quadratic objectives (QP/MIQP)
  • Variable and constraint addition/removal
  • Bound, objective-coefficient, and constraint-coefficient changes
  • Primal values, objective values, LP dual values, and reduced costs
  • COBRApy FBA, pFBA, FVA, and common reaction-bound/knockout workflows
  • COBRApy linear and quadratic MOMA
  • COBRApy linear/integer ROOM and loopless linear/MILP workflows
  • Python 3.7+ with optlang 1.5.2+ and COPT 8.x

Quadratic constraints (QCP/MIQCP), indicator/SOS constraints, callbacks, native COPT model serialization, and advanced basis operations are not part of version 0.2.1.

Installation

COPT must be licensed on the machine. Install the adapter and its Python dependencies from PyPI:

python -m pip install optlang-copt

When coptpy was installed from the official offline COPT package, use:

python -m pip install --no-deps optlang-copt

Automatic discovery and COBRApy usage

The wheel installs a Python startup hook scoped to the current environment. It registers COPT with optlang and COBRApy automatically, so application code does not need import optlang_copt:

import cobra

model = cobra.io.load_model("textbook")
model.solver = "copt"

solution = model.optimize()
print(solution.status, solution.objective_value)

To make new COBRApy models use COPT by default in the current process:

import cobra

cobra.Configuration().solver = "copt"

This registration does not edit COBRApy files and does not remove Gurobi, GLPK, or other interfaces. Set OPTLANG_COPT_AUTO_REGISTER=0 before starting Python to disable the startup hook. Explicit import optlang_copt remains available when auto-registration is disabled.

MOMA

Existing COBRApy calls remain unchanged after selecting COPT:

from cobra.flux_analysis import moma, pfba

model.solver = "copt"
reference = pfba(model)

with model:
    model.reactions.PGI.knock_out()
    linear_result = moma(model, solution=reference, linear=True)

with model:
    model.reactions.PGI.knock_out()
    quadratic_result = moma(model, solution=reference, linear=False)

Version 0.2.1 removes LP/MIP variables in place, including variables introduced by constraint-coefficient edits. For models with a current or previous quadratic objective, it safely rebuilds the native COPT model when removing variables during context rollback. Replacing an objective clears previous quadratic terms. These fixes allow subsequent FBA, ROOM, or loopless calculations to continue on the same model without an application-side patch.

Configuration copies and missing solutions

Model cloning, copy.deepcopy, pickling, and native QP rebuilds preserve solver tolerances, timeout, presolve and LP method. Nondefault model parameters set directly through model.problem.setParam, such as MemLimit and RelGap, are also preserved. Multi-objective-specific parameters are outside this scope.

For attached models with no available solution, primal and objective values are NaN; detached variables/objectives continue to return None. Solver status remains unchanged. A time or node limit can still leave a feasible LP solution or MIP incumbent, whose values remain accessible. Applications must check status, finite values and their own acceptance criteria before using a result; a resource-limited incumbent is not necessarily optimal.

Building a local release

python -m pip install build
python -m build
python -m pip install --no-deps dist/optlang_copt-0.2.1-py3-none-any.whl

Direct optlang usage

import optlang

copt = optlang.copt_interface

x = copt.Variable("x", lb=0, ub=10)
y = copt.Variable("y", lb=0, ub=10)
model = copt.Model()
model.add([x, y, copt.Constraint(x + y, ub=12, name="capacity")])
model.objective = copt.Objective(3*x + 2*y, direction="max")
print(model.optimize(), model.objective.value)

Development test

pytest -q

This project is an independent compatibility layer and is not an official component of Cardinal Operations, optlang, or COBRApy.

Metadata

Release files for optlang-copt 0.2.1

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

Source distribution (sdist)

Source distribution for optlang-copt 0.2.1
File Size Uploaded Provenance Actions
optlang_copt-0.2.1.tar.gz 18.8 kB With provenance Details for optlang_copt-0.2.1.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for optlang-copt 0.2.1
File Interpreter ABI Platform Actions
optlang_copt-0.2.1-py3-none-any.whl Python 3 none any Details for optlang_copt-0.2.1-py3-none-any.whl

Total release size: 32.1 kB

Release files / optlang_copt-0.2.1.tar.gz

Download URL optlang_copt-0.2.1.tar.gz
Size 18.8 kB
Tags Source
SHA-256 checksum
How to use checksums
cbf5a12b4113d9b6d0d22b5b0cde8c8b3f5278145a55b9a42fe4371053757e8f
BLAKE2b-256 checksum
How to use checksums
a3a9b38a3b888cbbcd7433b49aec094312acb259b2afdb8919b0367159b5136b
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

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 27, 2026.

Transparency log

Release files / optlang_copt-0.2.1-py3-none-any.whl

Download URL optlang_copt-0.2.1-py3-none-any.whl
Size 13.2 kB
Tags Python 3
SHA-256 checksum
How to use checksums
86d682849046d4f5f39f4c5fb6a26cb559324ab14bad8dd0da1e301d021b6f99
BLAKE2b-256 checksum
How to use checksums
7eff280c1c556739ed2134cd446e99a50502146739d13e09687a23c527b5a9c4
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

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 27, 2026.

Transparency log

Security for optlang-copt 0.2.1

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.

Full provenance

Both files in this release have been uploaded with provenance metadata.

Select from 2 files

Attestation for optlang_copt-0.2.1.tar.gz

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 27, 2026.

Transparency log

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Release history Release notifications | RSS feed

This release

0.2.1 This release

2 release files Full provenance

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