mathoptmodel
mathoptmodel is the Python package of
MathOptSolversCMake: Python
bindings for the solver-independent part of the library, its
MathOptModel optimization-model structure and its MPS, LP, JSON and AMPL
.nl readers and writers. No solver is bundled. Requires Python 3.12 or
newer (a single stable-ABI wheel per platform).
pip install mathoptmodel
import mathoptmodel as mom
model = mom.read("p0033.mps.gz") # format from the extension; .gz/.bz2 handled
print(model.number_of_variables, model.number_of_constraints)
# Arrays are read-only NumPy views onto the C++ model (no copy).
starts = model.constraints_starts
for i in range(model.number_of_constraints):
begin, end = starts[i], model.constraint_end(i)
variables = model.elements_variables[begin:end]
coefficients = model.elements_coefficients[begin:end]
print(model.constraint_name(i), model.constraint_class(i), dict(zip(variables, coefficients)))
mom.write(model, "p0033.lp")
The fields mirror MathOptModel in
mathopt.hpp,
which documents each of them, including the expression-tree layout of
nonlinear objectives and constraints. variables_types and
constraints_classes are int8 arrays of VariableType / ConstraintClass
values.
Building a model
A model can also be built from Python, in batches of NumPy arrays laid out
like MathOptModel's own fields, so that building it costs a few array
copies rather than one Python call per variable, constraint or term:
import numpy as np
import mathoptmodel as mom
model = mom.Model()
# max x + 2 y + 3 z, x in [0, 10] continuous, y binary, z in [0, 5] integer.
model.add_variables(
lower_bounds=0.0, # a scalar applies to the whole batch
upper_bounds=np.array([10.0, 1.0, 5.0]),
types=np.array([0, 1, 2], dtype=np.int8), # VariableType values
names=["x", "y", "z"])
model.set_objective(mom.ObjectiveDirection.Maximize, coefficients=np.array([1.0, 2.0, 3.0]))
# x + y + z <= 10 and x - y >= -3, in CSR form: the terms of all the rows
# concatenated, and the offset of each row's first term.
model.add_constraints(
lower_bounds=np.array([-np.inf, -3.0]),
upper_bounds=np.array([10.0, np.inf]),
starts=np.array([0, 3]),
variables=np.array([0, 1, 2, 0, 1]),
coefficients=np.array([1.0, 1.0, 1.0, 1.0, -1.0]))
# exp(x) + y^2 <= 4, as a pre-order expression tree (see mathopt.hpp).
model.add_constraints(
upper_bounds=4.0,
nonlinear_starts=[0],
nonlinear_operators=b"+evpvk",
nonlinear_number_of_children=[2, 1, 0, 2, 0, 0],
nonlinear_variables=[-1, -1, 0, -1, 1, -1],
nonlinear_values=[0, 0, 0, 0, 0, 2])
assert model.check()
mom.write(model, "model.nl")
add_variables()andadd_constraints()return the index of the first variable / constraint of the batch.- Quadratic constraint terms go through
quadratic_starts,quadratic_variables_1,quadratic_variables_2andquadratic_coefficients, laid out the same way. - Common subexpressions go through
add_defined_variables(). set_objective()replaces only the parts it is given: the direction, the linear coefficients, the quadratic terms and the expression tree.- Arrays of another dtype, non-contiguous arrays and lists are converted.
- Each batch is validated before the model is modified (
ValueErrorotherwise), and the copies run without the GIL.
Growing a model may reallocate its arrays: views such as
model.variables_lower_bounds obtained before a modification must not be used
after it (get them again).
Building from source
pip install .
pytest python/tests
Metadata
Release files for mathoptmodel 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 | Provenance | Actions |
|---|---|---|---|---|
| mathoptmodel-0.2.0.tar.gz | 122.7 kB | With provenance | Details for mathoptmodel-0.2.0.tar.gz |
Built distributions (wheels)
| File | Actions Reset | |||
|---|---|---|---|---|
| mathoptmodel-0.2.0-cp312-abi3-win_amd64.whl | CPython 3.12 | abi3 | Windows x86-64 | Details for mathoptmodel-0.2.0-cp312-abi3-win_amd64.whl |
| mathoptmodel-0.2.0-cp312-abi3-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl | CPython 3.12 | abi3 | Linux glibc 2.27+ x86-64, Linux glibc 2.28+ x86-64 | Details for mathoptmodel-0.2.0-cp312-abi3-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl |
| mathoptmodel-0.2.0-cp312-abi3-manylinux_2_26_aarch64.manylinux_2_28_aarch64.whl | CPython 3.12 | abi3 | Linux glibc 2.28+ ARM64, Linux glibc 2.26+ ARM64 | Details for mathoptmodel-0.2.0-cp312-abi3-manylinux_2_26_aarch64.manylinux_2_28_aarch64.whl |
| mathoptmodel-0.2.0-cp312-abi3-macosx_11_0_arm64.whl | CPython 3.12 | abi3 | macOS 11.0+ ARM64 | Details for mathoptmodel-0.2.0-cp312-abi3-macosx_11_0_arm64.whl |
| mathoptmodel-0.2.0-cp312-abi3-macosx_10_15_x86_64.whl | CPython 3.12 | abi3 | macOS 10.15+ x86-64 | Details for mathoptmodel-0.2.0-cp312-abi3-macosx_10_15_x86_64.whl |
Total release size: 1.6 MB
Release files / mathoptmodel-0.2.0.tar.gz
| Download URL | mathoptmodel-0.2.0.tar.gz |
|---|---|
| Size | 122.7 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
770e646f2c842b7abcc48d7aa924ca2ff5401988ddeec143bc23f6d905c0b660
|
|
BLAKE2b-256 checksum How to use checksums |
2371595d87387414d20f21bbf7f1d72aaa8dd5327fa9a2f0c255a1b8dca5f184
|
| 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 Nov 24, 2026.
Transparency logRelease files / mathoptmodel-0.2.0-cp312-abi3-win_amd64.whl
| Download URL | mathoptmodel-0.2.0-cp312-abi3-win_amd64.whl |
|---|---|
| Size | 413.8 kB |
| Tags | CPython 3.12 Windows x86-64 abi3 |
|
SHA-256 checksum How to use checksums |
2243ffb8e1b80082dd6866729c3d34e95e7a221f2df1d4e10bd9c857b69e5447
|
|
BLAKE2b-256 checksum How to use checksums |
b500a5622525fcc778f9ae10f49a387dd7ac2f784709a6f7dec28a90bbd7b4ef
|
| 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 Nov 24, 2026.
Transparency logRelease files / mathoptmodel-0.2.0-cp312-abi3-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl
| Download URL | mathoptmodel-0.2.0-cp312-abi3-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl |
|---|---|
| Size | 295.5 kB |
| Tags | CPython 3.12 Linux glibc 2.27+ x86-64 Linux glibc 2.28+ x86-64 abi3 |
|
SHA-256 checksum How to use checksums |
cea935a5d80283b997cd097eb1b7b17a6bc3dd1239b7109653eeadf948a5d399
|
|
BLAKE2b-256 checksum How to use checksums |
da2fb4e947917537ebee451583d9528dd05f45aaf658fefaad0b02810938f8a7
|
| 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 Nov 24, 2026.
Transparency logRelease files / mathoptmodel-0.2.0-cp312-abi3-manylinux_2_26_aarch64.manylinux_2_28_aarch64.whl
| Download URL | mathoptmodel-0.2.0-cp312-abi3-manylinux_2_26_aarch64.manylinux_2_28_aarch64.whl |
|---|---|
| Size | 264.1 kB |
| Tags | CPython 3.12 Linux glibc 2.26+ ARM64 Linux glibc 2.28+ ARM64 abi3 |
|
SHA-256 checksum How to use checksums |
a76a602f7158f955ed2eeecac8b62ce69cad7efc2a1a372c8d27bca5977a8d1b
|
|
BLAKE2b-256 checksum How to use checksums |
49197578fc9c04e34a60abfc4c277e71331f0d620e0bc164c029c6fe5bfa2e5e
|
| 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 Nov 24, 2026.
Transparency logRelease files / mathoptmodel-0.2.0-cp312-abi3-macosx_11_0_arm64.whl
| Download URL | mathoptmodel-0.2.0-cp312-abi3-macosx_11_0_arm64.whl |
|---|---|
| Size | 225.9 kB |
| Tags | CPython 3.12 abi3 macOS 11.0+ ARM64 |
|
SHA-256 checksum How to use checksums |
a6657229e3583204c1c5d3d7dbc9fdfc937944645d2fc0840c547ed2195bdf6b
|
|
BLAKE2b-256 checksum How to use checksums |
3076f59dc0e92dd515606628c14e7d361be152c9ba7d8bdd426fdafa52cf9e2a
|
| 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 Nov 24, 2026.
Transparency logRelease files / mathoptmodel-0.2.0-cp312-abi3-macosx_10_15_x86_64.whl
| Download URL | mathoptmodel-0.2.0-cp312-abi3-macosx_10_15_x86_64.whl |
|---|---|
| Size | 245.9 kB |
| Tags | CPython 3.12 abi3 macOS 10.15+ x86-64 |
|
SHA-256 checksum How to use checksums |
ef802caf8691c5a1c9e752e022a54365c9c63940ca551f20e4b9bd8fbbfc9c48
|
|
BLAKE2b-256 checksum How to use checksums |
8a43fa08c27af7035a74f3ac7cea193d5eddce4ad646911d5a2f297697e92934
|
| 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 Nov 24, 2026.
Transparency logSecurity for mathoptmodel 0.2.0
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
All 6 files in this release have been uploaded with provenance metadata.
Attestation for mathoptmodel-0.2.0.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 Nov 24, 2026.
Transparency logA 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.