Skip to main content

mosox

An LP matrix generator for GMPL (MathProg) and (by extension) AMPL.

Can be used in two ways:

  • Compile an MPS file for solving elsewhere
  • Solve directly with the HiGHS integration, no other binary needed

Currently a work-in-progress.

It works for a subset of GMPL (specifically the subset required to run Osemosys). See Known limitations section below.

There are a number of examples of varying complexity in the examples/ directory.

Developed by and for Climate Compatible Growth.

Quickstart

Installation

Using Cargo

cargo install mosox

Using Homebrew (macOS)

brew tap carderne/mosox-tap
brew install mosox

Pre-built binaries (macOS, Windows, Linux)

Binaries are built for a small set of systems and architectures. Available to download (compressed) from the Releases page. Please choose the appropriate archive.

Usage overview

Usage overview:

mosox help

MathProg Translation Kit

Usage: mosox <COMMAND>

Commands:
  compile    Load and output to MPS
  solve      Solve with HiGHS
  normalize  Normalize an MPS file for diffing
  compare    Compare two normalized MPS files with epsilon tolerance
  help       Print this message or the help of the given subcommand(s)

Options:
  -h, --help     Print help
  -V, --version  Print version

Compile MPS

Compile MPS for one of the examples in this repo. Output will be written to to the provided file:

mosox compile examples/basic/model.mod -o output.mps

Or an example with a separate data file, piping MPS to a file:

mosox compile examples/sets/model.mod examples/sets/data.dat -o output.mps

Solve a model

Results will be saved to the output file:

mosox solve examples/basic/model.mod -o output.txt

# Loading model from model.mod
# Generating matrix
# Matrix compiled in 666.625µs
# Matrix: 3 rows, 2 cols, 6 nonzero
# Solving matrix with HiGHS
# Solved in 1.939083ms
# Objective value: 2200
# Results output to f.txt

Python

Data can be passed from Python as pandas DataFrames (or Series, or pyarrow Tables) instead of a .dat file. Columns are read by position: for a param, the index columns then the value; for a set, the index columns (if indexed) then the members.

import pandas as pd
import mosox

model = mosox.Model.from_file("examples/2d_params/model.mod")
solution = model.solve({"supply": pd.DataFrame({"plant": ["P1", "P2"], "value": [100, 150]}), ...})
solution.objective
solution["ship"]  # DataFrame with columns p, w, value, marginal

Development

Please install cargo-make:

cargo install cargo-make

The most useful dev commands are listed in Makefile.toml.

You can view available commands by running cargo make.

Formatting, linting

cargo make fmt
cargo make lint

Testing

In addition to other tests, this will run mosox against all the examples under examples/ and confirm that the output is identical to the existing MPS files.

cargo make test

This will additionally run a regression test against examples/osemosys_large if present.

cargo make testlarge

Python bindings

Requires uv. uv run builds the extension (unoptimised) as needed.

cargo make py  # ruff format, ruff check, ty check, pytest

Benchmarks

Run performance benchmarks across all examples (except osemosys_large):

cargo make bench

Include osemosys_large (requires the example to be present):

cargo make benchlarge

Run with glpsol comparison (requires glpsol on PATH):

cargo make benchglpsol

Performance vs glpsol (median, release build, Macbook Air M2)

Note that some of the performance advantage over glpsol may be caused by the limitations enumerated below.

Example rows/cols/nonzero N glpsol mosox Speedup
osemosys_small 6k/7k/15k 50 68ms 17ms 4.0x
osemosys_atlantis 180k/230k/510k 10 2.4s 373ms 6.5x
osemosys_large 1M/5M/12M 4 130s 20s 6.5x

Memory usage

The matrix generator uses very roughly 2,000 bytes per non-zero. This is a significant overhead over the 12 bytes bytes per non-zero that would be needed in a format like CSC. However, as the table below shows, the matrix generator will rarely (if ever) use more memory than the solver.

Example Mosox matrix Glpsol matrix HiGHS solver Glpsol solver
osemosys_small 13 MB 12 MB 24 MB 16 MB
osemosys_atlantis 244 MB 287 MB 386 MB 416 MB
osemosys_large 5 GB 5.6 GB 6.5 GB ?

Known limitations

This list of limitations is made with reference to the GNU MathProg Language Reference which can be viewed here or downloaded from the original here.

It is intended that all of these will ultimately be supported, and most of them are "trivial" to add.

Functions

  • The following functions: abs, atan, ceil, cos, exp, floor, gmtime, length, log, prod, round, sin, sqrt, str2time, trunc, Irand224, Uniform, Normal.

Expressions

  • These arithmetic operators: less, div, mod
  • These symbolic operators: & (string concatenation)
  • These set expressions: conditional set expressions
  • String ordering comparisons (<, > etc. between symbolic values)

Sets

  • within and dimen are not enforced on computed sets that fail to evaluate at load (eg sets over tuple domains)

Parameters

  • Type specifiers, relational conditions and superset (in) expressions are only enforced on explicit data and constant defaults, not on computed params (:= expressions) or expression defaults
  • Plain-format data for multi-dimensional params without a slice (eg param p := a x 1 b y 2;) is not supported (it is caught as out-of-domain data)

Variables

  • Bounds specified as expressions (currently only constant accepted)

Constraints

  • Multiple expressions (comma-separated)

Other statements

Support for these statements is not planned (results should instead be parsed from the solver output): display, printf, for.

Metadata

Release files for mosox 0.7.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 mosox 0.7.1
File Size Uploaded Provenance Actions
mosox-0.7.1.tar.gz 537.6 kB With provenance Details for mosox-0.7.1.tar.gz

Built distributions (wheels)

Table of built distributions (wheels) for mosox 0.7.1
File Interpreter ABI Platform Actions
mosox-0.7.1-cp311-abi3-win_amd64.whl CPython 3.11 abi3 Windows x86-64 Details for mosox-0.7.1-cp311-abi3-win_amd64.whl
mosox-0.7.1-cp311-abi3-manylinux_2_39_x86_64.whl CPython 3.11 abi3 Linux glibc 2.39+ x86-64 Details for mosox-0.7.1-cp311-abi3-manylinux_2_39_x86_64.whl
mosox-0.7.1-cp311-abi3-macosx_11_0_arm64.whl CPython 3.11 abi3 macOS 11.0+ ARM64 Details for mosox-0.7.1-cp311-abi3-macosx_11_0_arm64.whl

Total release size: 38.6 MB

Release files / mosox-0.7.1.tar.gz

Download URL mosox-0.7.1.tar.gz
Size 537.6 kB
Tags Source
SHA-256 checksum
How to use checksums
fecc7d5debbe83e1a464fa9be2c9d24937ba55e92ca7d214cb9a816eed35962e
BLAKE2b-256 checksum
How to use checksums
1b0779e3e9ff64047bcea7110756560dfbb580a19338fed1d4eed230a4d55d45
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 10, 2026.

Transparency log

Release files / mosox-0.7.1-cp311-abi3-win_amd64.whl

Download URL mosox-0.7.1-cp311-abi3-win_amd64.whl
Size 5.3 MB
Tags CPython 3.11 Windows x86-64 abi3
SHA-256 checksum
How to use checksums
34ad2348872c000f7e18a9c8cc24896024abcbfc61aaca8c7ba165608c84adf3
BLAKE2b-256 checksum
How to use checksums
7c135a5f1e42e2ad6bf3ee3b3ff929441257c83b88cca394a84505ebe344ec74
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 10, 2026.

Transparency log

Release files / mosox-0.7.1-cp311-abi3-manylinux_2_39_x86_64.whl

Download URL mosox-0.7.1-cp311-abi3-manylinux_2_39_x86_64.whl
Size 27.8 MB
Tags CPython 3.11 Linux glibc 2.39+ x86-64 abi3
SHA-256 checksum
How to use checksums
bfcfd28bd2936853ec6cc4bb0ca6156cc3fd92f4b45a7003e06b43853ab1f70d
BLAKE2b-256 checksum
How to use checksums
7f78f8c7ae8be01b64f1f019cc11ec8138311c6824d35b6b4f6f25bc9f7bb88e
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 10, 2026.

Transparency log

Release files / mosox-0.7.1-cp311-abi3-macosx_11_0_arm64.whl

Download URL mosox-0.7.1-cp311-abi3-macosx_11_0_arm64.whl
Size 5.0 MB
Tags CPython 3.11 abi3 macOS 11.0+ ARM64
SHA-256 checksum
How to use checksums
fb106f010effa3d16b6650ccbb5888599cd6377bad2fb2ceb846b9f52af35826
BLAKE2b-256 checksum
How to use checksums
233633867ce428123a301955cf6804042231adcebd77790ad4dadd66c21c7376
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 10, 2026.

Transparency log

Security for mosox 0.7.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

All 4 files in this release have been uploaded with provenance metadata.

Select from 4 files

Attestation for mosox-0.7.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 10, 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.

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