Managed Service Client API Reference

Client

Service Client

class cuopt_thin_client.CuOptServiceClient(client_id: str = '', client_secret: str | None = 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)

The CuOptServiceClient handles requests to the cuOpt service through NVIDIA Cloud Functions (NVCF)

Parameters:
client_id (str): 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): 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): Note: This is still under development and not yet supported.

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 (ie, polling time is effectively unlimited using multiple calls). Defaults to 120.

disable_compression (boolean, optional): Disable zlib compression

of large files.

disable_version_string (boolean, optional): Do not send the client

version to the server.

Methods

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.

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_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 pickle 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

 1usage: cuopt_cli [-h] [-s SAK] [-c CREDENTIALS] [-a API] [-f FUNC] [-i FVID] [-g] [-t TEMP] [-l {critical,error,warning,info,debug}] [-p POLL_TIMEOUT] [-n] [file]
 2
 3Solve a cuOpt problem using a managed service client.
 4
 5positional arguments:
 6  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.
 7
 8options:
 9  -h, --help            show this help message and exit
10  -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
11                        used.
12  -c CREDENTIALS, --credentials CREDENTIALS
13                        File containing client_id and secret values in JSON. If this file is not supplied, the environment variables CUOPT_CLIENT_ID and CUOPT_CLIENT_SECRET will be used Only one of the two authetication methods(SAK or CLIENT ID & SECRET) can be used.
14  -a API, --api API     Relevant only for internal NVIDIA testing. File containing api URLS in JSON. If this file is not supplied, the environment variables CUOPT_AUTH_URL and CUOPT_API_URL will be used if set.
15  -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.
16  -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.
17  -g, --get-functions   Print a list of available cuOpt functions and exit. Refreshes the version cache.
18  -t TEMP, --temp TEMP  directory to write temporary files for handling large results (default ./)
19  -l {critical,error,warning,info,debug}, --log-level {critical,error,warning,info,debug}
20                        Log level
21  -p POLL_TIMEOUT, --poll-timeout POLL_TIMEOUT
22                        Number of seconds to poll for a result before timing out and returning a request id to re-query (defaults to 120)
23  -n, --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
24                        support zlib compression.