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.4.tar.gz (26.0 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.4-py3-none-any.whl (14.0 kB view details)

Uploaded Python 3

File details

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

File metadata

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

File hashes

Hashes for mathoptdev-0.1.4.tar.gz
Algorithm Hash digest
SHA256 b909a7ce36516daf91524df214841cae130378b908d699cd9acc455602b4e9c5
MD5 34266accd2caa21e1db7ae650bb23993
BLAKE2b-256 21e58c09895746a72eb56025827a159f33e83aa68237304b99922981f18c0c7a

See more details on using hashes here.

File details

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

File metadata

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

File hashes

Hashes for mathoptdev-0.1.4-py3-none-any.whl
Algorithm Hash digest
SHA256 5faf9e7eee9c26aa5f22db026bf4bab484b9e614984b24678242e0fc059f16ae
MD5 ee9b464a377d120fe022b2cff1e465c6
BLAKE2b-256 31ef767cd503885ef6d7ba2460493c32378e3e55e9dc457b31de5f5693a3ec21

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