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, self_signed_cert='', 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): Use HTTPS to communicate
with server in secured way.
- self_signed_cert (str, optional): A complete path to
self signed certificate. If it’s a standard certificate, then no need to provide anything.
- 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. If set to None, the client will never timeout and will poll indefinitely. Defaults to 600.
- only_validate (boolean, optional): Only validates input.
Defaults to False.
Methods
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_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 ‘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] [-o OUTPUT] [-pt POLL_TIMEOUT] [-i IP]
[-p PORT] [-s] [-c SELF_SIGNED_CERT]
[-l {critical,error,warning,info,debug}] [-ov] [-v]
[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 in a file, but a request id may
be passed in a file or as a JSON string.
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.
-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). A default name
will be used if this is not specified.
-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)
-c SELF_SIGNED_CERT, --self-signed-cert SELF_SIGNED_CERT
Path to self signed certificates only, skip for
standard certificates
-l {critical,error,warning,info,debug}, --log-level {critical,error,warning,info,debug}
Log level
-ov, --only-validation
If set, only validates input
-v, --version Print client version and exit.