Managed Service Client API Reference¶
Service Client¶
- class cuopt_thin_client.CuOptServiceClient(client_id: str = '', client_secret: str = None, sak: str = '', function_name: str = '', function_id: str = '', function_version_id: str = '', polling_interval: int = 1, token_expiration_padding: int = 120, request_excess_timeout: int = 120, api_path: str = '', disable_compression=False, disable_version_string=False, only_validate=False, config_path='', exec_timeout=300)¶
The CuOptServiceClient handles requests to the cuOpt service through NVIDIA Cloud Functions (NVCF)
- Parameters:
- client_id (str): NOTE: This is deprecated, use SAK.
The client ID obtained during the registration process. Only one of the two authorization methods (SAK or CLIENT ID-SECRET) should be used.
- client_secret (str): NOTE: This is deprecated, use SAK.
The client secret obtained during the registration process. Only one of the two authorization methods (SAK or CLIENT ID-SECRET) should be used.
- sak (str): The sak obtained through NGC. Only one of the two authorization
methods (SAK or CLIENT ID-SECRET) should be used.
- function_name (str, optional): The name of the function, provided
during registration or discoverable via a function_list API call. This value may be omitted if all available functions have the same name or if function_id is set instead. The client will select the latest available version of the function with this name. Ignored if function_id is set.
- function_id (str, optional): The unique identifier of a function,
provided during registration or discoverable via a function_list API call. Takes precedence over function_name if both are set. The client will select the latest available version of the function with this id.
- function_version_id (str, optional): Selects a particular version of
a function specified by name or id. This should only be used when there are multiple versions available that are not API compatible. If this value is omitted the client will select the latest version of the function.
- polling_interval (int, optional): The duration in seconds between
consecutive polling attempts. Defaults to 1.
- token_expiration_padding (int, optional): The buffer time in
seconds before the token expiration time, during which a new token will be requested. Defaults to 120.
- request_excess_timeout (int, optional): The time in seconds to poll
for completion of a request. If the polling time expires before the request is finished, the client may re-poll the request. If set to None, the client will never timeout and will poll indefinitely. Defaults to 120.
- api_path (str, optional): Deprecated. Set auth/api endpoints for
cuOpt, useful only for NVIDIA testing.
- disable_compression (boolean, optional): Disable zlib compression
of large files.
- disable_version_string (boolean, optional): Do not send the client
version to the server.
- only_validate (boolean, optional): Only validates input and doesn’t
add to billing
- config_path (boolean, optional): Path of a JSON config file for setting
client defaults in JSON. These values will be used if the corresponding arguments are not passed to __init__. Format is:
- {
- “defaults”: {
“function_name”: “”, “function_id”: “”, “function_version_id”: “”
}
}
Methods
Lists all availble functions for the user in NVCF.
get_optimized_routes
(cuopt_problem_json_data)Get optimized routing solution for a given problem.
repoll
(req_id[, asset_id])Poll for a result when get_optimized_routes results in a TimeoutError exception.
set_function_by_id
(id[, version_id])Set the function to invoke by id and optionally specify a version.
set_function_by_name
(name[, version_id])Set the function to invoke by name and optionally specify a version.
get_func_defaults_from_config
- get_func_defaults_from_config(name, id, vid)¶
- get_functions()¶
Lists all availble functions for the user in NVCF.
- get_optimized_routes(cuopt_problem_json_data)¶
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. The file may be a msgpack file containing a dictionary, or a text file containing a dictionary as JSON, or a zlib-compressed file containing a dictionary as JSON. Please refer to the server doc for the structure of this dictionary.
- repoll(req_id, asset_id=None)¶
Poll for a result when get_optimized_routes results in a TimeoutError exception. The req_id and asset_id are returned in the exception.
- Parameters:
- req_idstr
A uuid identifying the original request, returned in a TimeoutError exception.
- asset_idstr
A uuid identifying the asset used (if any) for the original request, returned in a TimeoutError exception. The client will delete this asset when a result is returned.
- set_function_by_id(id, version_id=None)¶
Set the function to invoke by id and optionally specify a version. The current list of functions can be retrieved with get_functions().
- Parameters:
- idstr
The id of a function to invoke.
- version_id: str
Optional version id of the function to invoke. If there are multiple versions of the function specified by id, version_id can be used to select a particular version. If version_id is not set, the latest version of the specified function will be chosen.
- set_function_by_name(name, version_id=None)¶
Set the function to invoke by name and optionally specify a version. The current list of functions can be retrieved with get_functions().
- Parameters:
- namestr
Name of a function to invoke. If name is the empty string and all available functions have the same name, that name will be used.
- version_id: str
Optional version id of the function to invoke. If there are multiple versions of the named function, version_id can be used to select a particular version. If version_id is not set, the latest version of the named function will be chosen.
Service CLI¶
usage: cuopt_cli [-h] [-t TYPE] [-s SAK] [-c CREDENTIALS] [-cn CONFIG]
[-f FUNC] [-i FVID] [-g]
[-l {critical,error,warning,info,debug}] [-p POLL_TIMEOUT]
[-nc] [-nv] [-ov] [-e EXEC_TIMEOUT] [-v]
[file]
Solve a cuOpt problem using a managed service client.
positional arguments:
file Filename or JSON string, required if -g is not
specified. Data may be a cuopt problem or contain
reqId and assetId (if any) as displayed in the output
from a previous request which timed out.
options:
-h, --help show this help message and exit
-t TYPE, --type TYPE The type of problem to solve. Supported options are
VRP. If the type is not supplied, problem defaults to
VRP
-s SAK, --sak SAK NOTE: This is still under development and not yet
supported. File containing sak value in JSON. If this
file is not supplied, the environment variable
CUOPT_CLIENT_SAK will be used. Only one of the two
authetication methods (SAK or CLIENT ID & SECRET) can
be used.
-c CREDENTIALS, --credentials CREDENTIALS
Note: This is deprecated, use -s option for SAK.File
containing client_id and secret values in JSON. If
this file is not supplied, the environment variables
CUOPT_CLIENT_SAK or pair ofCUOPT_CLIENT_ID and
CUOPT_CLIENT_SECRET will be used.Only one of the two
authetication methods(SAK or CLIENT ID & SECRET) can
be used.In case both are provided, SAK takes
precedence.
-cn CONFIG, --config CONFIG
Config file for setting client defaults in JSON. The
format is {"defaults": {"function_name": "",
"function_id": "", "function_version_id": ""}}. None
are required, and function_id takes precedence over
function_name. If set, function_version_id must be a
valid version of the function identified by name or id
-f FUNC, --func FUNC name or id of the cuOpt cloud function to call. If no
name or id is specified and all available functions
have the same name then that name will be used. The
latest version of the specified function will be
called if the -i option is not set.
-i FVID, --fvid FVID The id of a specific version of the specified function
to call. This should only be used when multiple
versions of the same function are available and a
version other than the latest is desired. By default,
the latest version will be called.
-g, --get-functions Print a list of available cuOpt functions and exit.
Refreshes the version cache.
-l {critical,error,warning,info,debug}, --log-level {critical,error,warning,info,debug}
Log level
-p 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)
-nc, --no-compress Disable zlib compression for uncompressed data files
larger than 250kb. For most cases zlib compression
will improve cuOpt download speed and should be left
enabled.This flag may be used to preserve backward
compatibility with older cuOpt versions that do not
support zlib compression.
-nv, --no-version-string
Do not send the client version to the server. This
flag may be used to preserve backward compatibility
with older cuOpt versions that do not support the
version string.
-ov, --only-validation
If set, only validates input and doesn't add to
billing.
-e EXEC_TIMEOUT, --exec-timeout EXEC_TIMEOUT
http timeout when invoking a function. The server may
wait up to 5 minutes before returning a pending-
evalution result on long jobs. Most likely this does
not need to be modified (defaults to 300)
-v, --version Print client version and exit.