Self-Hosted Service Client API Reference

Client

Service Client

class cuopt_sh_client.CuOptServiceSelfHostClient(ip: str = '0.0.0.0', port: str = '5000', use_https: bool = False, polling_interval=1, request_excess_timeout=600, only_validate=False)

This version of the CuOptServiceClient is an interface with a self hosted version of the cuOpt core service. This client allows users to make calls to a self hosted instance of the cuOpt service at a specific ip and port.

It closely emulates the interface of the managed service client, however it does not implement most of the managed service-specific features required for interaction with NVIDIA Cloud Functions.

Parameters:
ip (str, optional): The IP address of the cuOpt service.

Defaults to 0.0.0.0

port (str, optional): The port of the cuOpt service.

Defaults to 5000.

use_https (boolean, optional): Currently unimplemented.
polling_interval (int, optional): The duration in seconds between

consecutive polling attempts. Defaults to 1.

request_excess_timeout (int, optional): The time in seconds that

the client will poll for a result before exiting and returning a request id. The request id may be repolled in another call to the client. Defaults to 600.

only_validate (boolean, optional): Only validates input.

Defaults to False.

Methods

get_LP_Solve(cuopt_problem_json_data[, ...])

Get optimized routing solution for a given problem.

get_optimized_routes(cuopt_problem_json_data)

Get optimized routing solution for a given problem.

repoll(data)

Poll for a result when get_optimized_routes results in a TimeoutError exception.

get_LP_Solve(cuopt_problem_json_data, tolerances=None, filepath=False, output='')

Get optimized routing solution for a given problem.

Parameters:
cuopt_problem_json_datadict or str

This is either the problem data as a dictionary or the path of a file containing the problem data as JSON. Please refer to the server doc for the structure of this dictionary.

filepath (boolean, optional): Indicates that cuopt_problem_json_data

is the relative path of a cuopt data file under the server’s data directory. The data directory is specified when the server is started (see the server documentation for more detail). Defaults to False.

output (string, optional): Optional name of the result file.

If the server has been configured to write results to files and the size of the result is greater than the configured limit, the server will write the result to a file with this name under the server’s result directory (see the server documentation for more detail). Defaults to a name based on the path if the ‘filepath’ is True, or a uuid if ‘filepath’ is False.

get_optimized_routes(cuopt_problem_json_data, filepath=False, output='')

Get optimized routing solution for a given problem.

Parameters:
cuopt_problem_json_datadict or str

This is either the problem data as a dictionary or the path of a file containing the problem data as JSON. Please refer to the server doc for the structure of this dictionary.

filepath (boolean, optional): Indicates that cuopt_problem_json_data

is the relative path of a cuopt data file under the server’s data directory. The data directory is specified when the server is started (see the server documentation for more detail). Defaults to False.

output (string, optional): Optional name of the result file.

If the server has been configured to write results to files and the size of the result is greater than the configured limit, the server will write the result to a file with this name under the server’s result directory (see the server documentation for more detail). Defaults to a name based on the path if the ‘filepath’ is True, or a uuid if ‘filepath’ is False.

repoll(data)

Poll for a result when get_optimized_routes results in a TimeoutError exception. The request id is returned as JSON in the exception.

Parameters:
datastr

A uuid identifying the original request, returned in a TimeoutError exception. For backward compatibility, data may also be a dictionary containing the key ‘reqId’ where the value is the uuid.

Service CLI

usage: cuopt_sh [-h] [-f] [-t TYPE] [-tol TOLERANCES] [-o OUTPUT]
                [-pt POLL_TIMEOUT] [-i IP] [-p PORT] [-s]
                [-l {critical,error,warning,info,debug}] [-ov]
                data

Solve a cuOpt problem using a self-hosted service client.

positional arguments:
  data                  Filename, or JSON string containing a request id. Data
                        may be a cuopt problem or a request id as displayed in
                        the output from a previous request which timed out. A
                        cuopt problem must be passed in a file, but a request
                        id may be passed in a file or as a JSON string. If the
                        -f option is used, this indicates the path of a file
                        accessible to the server. A cuopt problem file may be
                        a text file containing JSON, optionally zlib-
                        compressed, or a pickle file containing a Python
                        dictionary corresponding to the cuopt JSON format.

options:
  -h, --help            show this help message and exit
  -f, --filepath        Indicates that the DATA argument is the relative path
                        of a cuopt data file under the server's data
                        directory. The data directory is specified when the
                        server is started (see the server documentation for
                        more detail).
  -t TYPE, --type TYPE  The type of problem to solve. Supported options are
                        VRP and LP. If the type is not supplied, problem
                        defaults to VRP
  -tol TOLERANCES, --tolerances TOLERANCES
                        Filename or JSON string containing tolerances for LP
                        problem type
  -o OUTPUT, --output OUTPUT
                        Optional name of the result file. If the server has
                        been configured to write results to files and the size
                        of the result is greater than the configured limit,
                        the server will write the result to a file with this
                        name under the server's result directory (see the
                        server documentation for more detail). By default this
                        name will be based on the DATA argument if the -f
                        option is used, or it will be a uuid if the -f option
                        is not used.
  -pt POLL_TIMEOUT, --poll-timeout POLL_TIMEOUT
                        Number of seconds to poll for a result before timing
                        out and returning a request id to re-query (defaults
                        to 120)
  -i IP, --ip IP        Host address for the cuOpt server (default 0.0.0.0)
  -p PORT, --port PORT  Port for the cuOpt server (default 5000)
  -s, --ssl             Not currently implemented. Use https scheme (default
                        is http)
  -l {critical,error,warning,info,debug}, --log-level {critical,error,warning,info,debug}
                        Log level
  -ov, --only-validation
                        If set, only validates input