Skip to main content

Python CLI and SDK for mathopt.dev the platform for mathematical optimization

Project description

MathOpt

To interact with mathopt, we provide a CLI and a Python SDK. It contains tools to help developers solve combinatorial problems in the cloud.

Installation

Install with pip

pip install mathoptdev

Install with uv (recommended package manager):

uv add mathoptdev 

This installs a CLI that you can call with:

opt --help 

or

alias opt="uv run opt" # set and alias for uv
opt --help 

Login

This command will guide you through the login process:

opt login 

We store the API token in the MATHOPT_API_TOKEN variable in your .env file.

After logging in, check the user with

opt user 

REST API

You can call the API directly with a HTTP POST request. You need to specify the x-mathopt-api-token header.

curl -X POST https://www.mathopt.dev/api \
  -H "x-mathopt-api-token: YOUR_MATHOPT_API_TOKEN" \
  -H "Content-Type: application/json" \
  -d '{
    "action": "get_user"
  }'

We also have a helper function in python

import mathoptdev as opt 
body = {
  "action": "get_user"
}
opt.send_request(body) 

Create problem instances

To get you started, we provide the following helper command that generates a Travelling Salesman Problem (TSP):

opt tsp -c 5 

The option -c corresponds to the number of cities in the problem. The MPS file will be saved in the tsp folder in your current directory.

Once instances are generated, upload them with the following command:

opt instance create tsp 

To verify that we successfully processed your instances, you can query the backend with the command:

opt instance list 

or in python

import mathoptdev as opt 
opt.queries.get_instances() 

Solve instances

To solve an instance, you need to create a job with its id and the id of the strategy you want to use to solve it.

The list of available strategies can be queried with

opt strategy list 

We provide an example on how to create and queue a set of jobs in these scripts:

Monitor your jobs

You can monitor your jobs with:

opt job list 

or

import mathoptdev as opt 
opt.queries.get_jobs() 

Download solutions

You can download the parquet file associated with a solution:

import mathoptdev as opt 
body = {
  "action": "download_solution",
  "solution_id": "my_solution_id"
}
opt.send_request(body) 

There is a full example at the link: download_solutions.py

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

mathoptdev-0.1.5.tar.gz (26.3 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

mathoptdev-0.1.5-py3-none-any.whl (14.7 kB view details)

Uploaded Python 3

File details

Details for the file mathoptdev-0.1.5.tar.gz.

File metadata

  • Download URL: mathoptdev-0.1.5.tar.gz
  • Upload date:
  • Size: 26.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.6.11

File hashes

Hashes for mathoptdev-0.1.5.tar.gz
Algorithm Hash digest
SHA256 74bd351016c697a867a9be199b8251b326b3ac854715134d70a221f022262e59
MD5 8d9d275758a46f937235700f9b8f05be
BLAKE2b-256 ff1127f1400e66254be6d9085b08c5eb0f5df2e238cc635bc52322b6fc82f1a7

See more details on using hashes here.

File details

Details for the file mathoptdev-0.1.5-py3-none-any.whl.

File metadata

  • Download URL: mathoptdev-0.1.5-py3-none-any.whl
  • Upload date:
  • Size: 14.7 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.6.11

File hashes

Hashes for mathoptdev-0.1.5-py3-none-any.whl
Algorithm Hash digest
SHA256 3515ef84b2ebfa53d857366fbbe7d0fd4f404996762de07e72063b2c1c3bed34
MD5 ba4dbe4277f7c883853fee6d7a1592c7
BLAKE2b-256 56f5dd80b1e82b11f648ade88f7a09d6aab49217cff07551becb9e6219dc1a29

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page