Skip to main content

Library for running OptHub problems locally.

Project description

日本語版 👈

opthub-runner-python

Skills

opthub-runner-python is a Python package that provides Evaluator for local execution.

  • Evaluator: Feature to evaluate solutions locally using Docker Image.

This repository describes how to install opthub-runner-python and use Evaluator.

Getting Started

First of all, you need to set up the following environment settings in advance.

  • Install Python 3.10 or newer.
  • Set up pip for package management.
  • Install and start Docker.*

*For Mac users, you can install and start Docker Desktop.

After completing the above environment setup, you can install opthub-runner-python from PyPI with the following command.

pip install opthub-runner-python

After installation, you can use the Evaluator class by importing it with Python code as follows.

from opthub_runner.evaluator import Evaluator

For specific usage of the Evaluator class, please refer to Usage Example, Options, and Execution Results.

Note that Docker must be started to run the code. It will not run properly unless Docker is started.

Usage Example

Here is an example how to evaluate a solution using the Sphere function with the optimal solution as [1, 1] below.

from opthub_runner.evaluator import Evaluator



evaluator = Evaluator("opthub/sphere:latest",
                      {"SPHERE_OPTIMA": [[1, 1]]}) # Initialize Evaluator

x = [0, 2] # Solution to evaluate
result = evaluator.run(x) # Evaluate

print(result) # {'objective': 2, 'feasible': None, 'constraint': None, 'info': None}

In the initialization of the Evaluator, the Docker Image opthub/sphere:latest of the Sphere function and the environment variable SPHERE_OPTIMA of the Docker process are set. The run method then starts the Docker process internally and evaluates the solution [0, 2].

Information on the solutions input to the run method and the Docker image to be used are described in each problem on OptHub.

Options

The options used to initialize the Evaluator class are listed in the table below (* is required).

Option Type Default Value Description
docker_image* str - Name of the Docker Image used for evaluation.
environment* dict[str, object] - Environment variables.
rm bool True Whether to remove the Docker Container after evaluation.
timeout int 43200 Timeout for evaluation using Docker Image. 

Execution Results

The run method of the Evaluator class returns the evaluation result. The evaluation result is represented by a dictionary object containing pairs of Key and the corresponding Value. The following table shows the Keys and the types of the Values corresponding to the Keys included in the evaluation result.

Key Type of Value Description
objective object Objective function value of the solution.
feasible bool or None Feasibility of the solution.
constraint object or None Information on solution constraints.
info object or None Information on evaluation.

Detailed descriptions of objective, constraint, feasible, and info are provided in each problem on OptHub.

Troubleshooting

If you receive the following error, Docker is most likely not running. Please start Docker and re-run it. if you are Mac users, you can start Docker by launching Docker Desktop.

docker.errors.DockerException: Error while fetching server API version: ('Connection aborted.', FileNotFoundError(2, 'No such file or directory'))

For Contributors

Follow these steps to set up the environment:

  1. Clone this repository.
  2. Set up Poetry.
  3. Run poetry install.
  4. Download the recommended VSCode Extensions.
  5. Disable the following VS Code Extensions for this workspace to avoid conflicts with other packages:
    • ms-python.pylint
    • ms-python.black-formatter
    • ms-python.flake8
    • ms-python.isort

Contact

If you have any questions or concerns, please feel free to contact us (Email: dev@opthub.ai).

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

opthub_runner-0.1.1.tar.gz (5.8 kB view details)

Uploaded Source

Built Distribution

opthub_runner-0.1.1-py3-none-any.whl (6.5 kB view details)

Uploaded Python 3

File details

Details for the file opthub_runner-0.1.1.tar.gz.

File metadata

  • Download URL: opthub_runner-0.1.1.tar.gz
  • Upload date:
  • Size: 5.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.8.3 CPython/3.12.1 Linux/6.5.0-1024-azure

File hashes

Hashes for opthub_runner-0.1.1.tar.gz
Algorithm Hash digest
SHA256 9cd233a42d0cda6b38aa52313802d19c5929c5f33594ad74320422a98ef090e4
MD5 e543d8da887826a1b8d99d1de9b792f5
BLAKE2b-256 c61cf09cd1df938d1ed50fad732f1a345cade2cb434ed2ca2068eed7114e68d1

See more details on using hashes here.

File details

Details for the file opthub_runner-0.1.1-py3-none-any.whl.

File metadata

  • Download URL: opthub_runner-0.1.1-py3-none-any.whl
  • Upload date:
  • Size: 6.5 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.8.3 CPython/3.12.1 Linux/6.5.0-1024-azure

File hashes

Hashes for opthub_runner-0.1.1-py3-none-any.whl
Algorithm Hash digest
SHA256 e5feba2f2869f28941956df10462bfdd4e526e3d91be7878c614b84859c68307
MD5 3759203adb7c94ace09c4f4b34289139
BLAKE2b-256 e2b9bce228bcb5a96658d9befe4704b998fdcf6425deb4f9872abaff29199778

See more details on using hashes here.

Supported by

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