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.0.
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.0 rebuilds the native COPT model when COBRApy removes QP auxiliary variables during context rollback. This avoids stale native quadratic references in COPT 8.0.6 and allows subsequent FBA, ROOM, or loopless calculations to continue on the same model.
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.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | |
|---|---|---|---|
| optlang_copt-0.2.0.tar.gz | 14.5 kB | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| optlang_copt-0.2.0-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 26.2 kB
Release files / optlang_copt-0.2.0.tar.gz
| Download URL | optlang_copt-0.2.0.tar.gz |
|---|---|
| Size | 14.5 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
9cefdb9771ed2cdd8cac907150a780f7d94916525b283f6b335c81a4c6abaf61
|
|
BLAKE2b-256 checksum How to use checksums |
71f4c54c9ae101d50641869fc52357af1bc49b87be7e132123297d52aa716e05
|
| 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 Sep 28, 2026.
Transparency logRelease files / optlang_copt-0.2.0-py3-none-any.whl
| Download URL | optlang_copt-0.2.0-py3-none-any.whl |
|---|---|
| Size | 11.7 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
f6ce3fdef9f9ddddfc97382d2c72d949fe45c31c9ac67c4b95be82993879f0a5
|
|
BLAKE2b-256 checksum How to use checksums |
da8352dfcf133d81ef9e9d8de7386a8caf2200edad6cb52f5c82982fc0a4ee96
|
| 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 Sep 28, 2026.
Transparency log