Skip to main content

Opvious Python SDK

Project description

Opvious Python SDK CI Pypi badge

An optimization SDK for solving linear, mixed-integer, and quadratic models

Highlights

Declarative modeling API

  • Extensive static validations
  • Exportable to LaTeX
  • Extensible support for high-level patterns (activation variables, masks, ...)
import opvious.modeling as om

class BinPacking(om.Model):
  items = om.Dimension()  # All items to bin
  weight = om.Parameter.non_negative(items)  # Weight per item
  bins = om.interval(1, om.size(items), name="B")  # Available bins
  max_weight = om.Parameter.non_negative()  # Maximum weight for each bin

  assigned = om.Variable.indicator(bins, items)  # Bin to item assignment
  used = om.fragments.ActivationIndicator(assigned, projection=1)  # 1 if a bin is used

  @om.constraint
  def each_item_is_assigned_once(self):
    for i in self.items:
      yield om.total(self.assigned(b, i) for b in self.bins) == 1

  @om.constraint
  def bin_weights_are_below_max(self):
    for b in self.bins:
      bin_weight = om.total(self.weight(i) * self.assigned(b, i) for i in self.items)
      yield bin_weight <= self.max_weight()

  @om.objective
  def minimize_bins_used(self):
    return om.total(self.used(b) for b in self.bins)

Auto-generated specification:

Bin package LaTeX specification

Transparent remote solves

  • No local solver installation required
  • Real-time progress notifications
  • Seamless data import/export via native support for pandas
  • Flexible multi-objective support: weighted sums, epsilon constraints, ...
  • Built-in debugging capabilities: relaxations, fully annotated LP formatting, ...
import opvious

client = opvious.Client.from_environment()

response = await client.run_solve(
  specification=BinPacking().specification(),
  parameters={
    "weight": {"a": 10.5, "b": 22, "c": 48},
    "binMaxWeight": 50,
  },
)
solution = response.outputs.variable("assigned")  # Optimal assignment dataframe

Take a look at https://opvious.readthedocs.io for the full documentation or these notebooks to see the SDK in action.

Project details


Release history Release notifications | RSS feed

Download files

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

Source Distribution

opvious-0.12.10rc2.tar.gz (114.5 kB view details)

Uploaded Source

Built Distribution

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

opvious-0.12.10rc2-py3-none-any.whl (59.9 kB view details)

Uploaded Python 3

File details

Details for the file opvious-0.12.10rc2.tar.gz.

File metadata

  • Download URL: opvious-0.12.10rc2.tar.gz
  • Upload date:
  • Size: 114.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.2.2 CPython/3.10.11 Linux/5.15.0-1037-azure

File hashes

Hashes for opvious-0.12.10rc2.tar.gz
Algorithm Hash digest
SHA256 9a745f6494b693bdf9c91770ed98a7da06a360daae623caf7e446e78aea72d91
MD5 3907134d1f484ddf916d793543ae1839
BLAKE2b-256 92073dee76827f08e948bf838908e3c9e77ab2b7e9e931f86bb7ff35227c7523

See more details on using hashes here.

File details

Details for the file opvious-0.12.10rc2-py3-none-any.whl.

File metadata

  • Download URL: opvious-0.12.10rc2-py3-none-any.whl
  • Upload date:
  • Size: 59.9 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.2.2 CPython/3.10.11 Linux/5.15.0-1037-azure

File hashes

Hashes for opvious-0.12.10rc2-py3-none-any.whl
Algorithm Hash digest
SHA256 5b8d5dfcf301c6a0ff69e2c4628d9eaacb917a9c045c6c67c96b16121dd9de4c
MD5 c3a0ad0266df0f9281e39c63ea6df29c
BLAKE2b-256 0645ffbf4d6a57e096597b0a8bcd893e3785ffa41ca35d34b4a984309003fb9b

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