Managed Service Client API Reference#

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 = 10,
token_expiration_padding: int = 120,
request_excess_timeout: int = -1,
api_path: str = '',
disable_compression=False,
disable_version_string=False,
only_validate=False,
config_path='',
exec_timeout=300,
polling_timeout=120,
timeout_exception=True,
)#

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) – 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) – 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) – 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) – The duration in seconds of each polling attempt. Defaults to 10, minimum is 5.

  • token_expiration_padding (int) – 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) – Deprecated. Please use polling_timeout instead.

  • api_path (str) – Note: Deprecated. Set auth/api endpoints for cuOpt, useful only for NVIDIA testing.

  • disable_compression (boolean) – Disable zlib compression of large files.

  • disable_version_string (boolean) – Do not send the client version to the server.

  • only_validate (boolean) – Only validates input and doesn’t add to billing

  • config_path (boolean) – 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”: “” } }

  • exec_timeout (int) – Http request timeout used when sending and receiving data to the managed service. This should not need to be changed. Defaults to 300 seconds.

  • polling_timeout (int) – The time in seconds that the client will poll for a result before exiting and returning a request id. The request id may be polled again in a call to repoll(). If set to None, the client will never timeout and will poll indefinitely. Defaults to 120.

  • timeout_exception (boolean) – If True, the client returns # noqa a TimeoutError exception if polling_timeout seconds passes before a solution is returned. The value of the exception contains JSON giving the request id and asset id (if any) so that repoll() may be called to poll again for a result. If False, the client returns a dictionary containing the repoll information with no exception. Defaults to True.

get_LP_solve(
cuopt_data_models,
solver_config=<solver_settings.solver_settings.SolverSettings object>,
response_type='obj',
)#

Get linear programming solution for a given problem.

Parameters:
  • cuopt_data_models

    Note - Batch mode is only available for LP and not for MILP.

    File path to mps or json/dict/DataModel returned by cuopt_mps_parser/list[mps file paths]/list[dict]/list[DataModel].

    For single problem, input should be either a path to mps/json file, /DataModel returned by cuopt_mps_parser/ path to json file/ dictionary.

    For batch problem, input should be either a list of paths to mps files/ a list of DataModel returned by cuopt_mps_parser/ a list of dictionaries.

  • solver_config ((SolverSettings object or Dict, optional) Contains) – solver settings including tolerance values. See the LP documentation for details on solver settings.

  • response_type (str) – Choose “dict” if response should be returned as a dictionary or “obj” for Solution object. Defaults to “obj”

  • Returns (dict or Solution object.)

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_data (dict 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 or 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, response_type='obj')#

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_id (str) – A uuid identifying the original request, returned in a TimeoutError exception.

  • asset_id (str) – 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.

  • response_type (str) – For LP problem choose “dict” if response should be returned as a dictionary or “obj” for Solution object. Defaults to “obj”. For VRP problem, response_type is ignored and always returns a dict.

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:
  • id (str) – 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:
  • name (str) – 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.

LP Supporting Classes#

Please refer to thin client supporting classes.

Service CLI#

 1usage: cuopt_cli [-h] [-t TYPE] [-ss SOLVER_SETTINGS] [-s SAK]
 2                 [-c CREDENTIALS] [-cn CONFIG] [-f FUNC] [-i FVID] [-g]
 3                 [-l {critical,error,warning,info,debug}] [-p POLL_TIMEOUT]
 4                 [-pi POLL_INTERVAL] [-nc] [-nv] [-ov] [-e EXEC_TIMEOUT] [-v]
 5                 [file ...]
 6
 7Solve a cuOpt problem using a managed service client.
 8
 9positional arguments:
10  file                  Filename or JSON string, required if -g is not
11                        specified. Data may be a cuopt problem or contain
12                        reqId and assetId (if any) as displayed in the output
13                        from a previous request which timed out.For VRP and
14                        MILP a single problem file is expected. For LP
15                        multiple problem input files can be passed for batch
16                        mode.
17
18options:
19  -h, --help            show this help message and exit
20  -t TYPE, --type TYPE  The type of problem to solve. Supported options are
21                        VRP and LP. If the type is not supplied, problem
22                        defaults to VRP
23  -ss SOLVER_SETTINGS, --solver-settings SOLVER_SETTINGS
24                        Filename or JSON string containing solver settings for
25                        LP problem type
26  -s SAK, --sak SAK     File containing sak value in JSON. If this file is not
27                        supplied, the environment variable CUOPT_CLIENT_SAK
28                        will be used. Only one of the two authetication
29                        methods (SAK or CLIENT ID & SECRET) can be used.
30  -c CREDENTIALS, --credentials CREDENTIALS
31                        Note: This is deprecated, use -s option for SAK.File
32                        containing client_id and secret values in JSON. If
33                        this file is not supplied, the environment variables
34                        CUOPT_CLIENT_SAK or pair ofCUOPT_CLIENT_ID and
35                        CUOPT_CLIENT_SECRET will be used.Only one of the two
36                        authetication methods(SAK or CLIENT ID & SECRET) can
37                        be used.In case both are provided, SAK takes
38                        precedence.
39  -cn CONFIG, --config CONFIG
40                        Config file for setting client defaults in JSON. The
41                        format is {"defaults": {"function_name": "",
42                        "function_id": "", "function_version_id": ""}}. None
43                        are required, and function_id takes precedence over
44                        function_name. If set, function_version_id must be a
45                        valid version of the function identified by name or id
46  -f FUNC, --func FUNC  name or id of the cuOpt cloud function to call. If no
47                        name or id is specified and all available functions
48                        have the same name then that name will be used. The
49                        latest version of the specified function will be
50                        called if the -i option is not set.
51  -i FVID, --fvid FVID  The id of a specific version of the specified function
52                        to call. This should only be used when multiple
53                        versions of the same function are available and a
54                        version other than the latest is desired. By default,
55                        the latest version will be called.
56  -g, --get-functions   Print a list of available cuOpt functions and exit.
57                        Refreshes the version cache.
58  -l {critical,error,warning,info,debug}, --log-level {critical,error,warning,info,debug}
59                        Log level
60  -p POLL_TIMEOUT, --poll-timeout POLL_TIMEOUT
61                        Number of seconds to poll for a result before timing
62                        out and returning a request id to re-query (defaults
63                        to 120)
64  -pi POLL_INTERVAL, --poll-interval POLL_INTERVAL
65                        The duration in seconds of each polling attempt.
66                        Mininum is 5. Default is 10.
67  -nc, --no-compress    Disable zlib compression for uncompressed data files
68                        larger than 250kb. For most cases zlib compression
69                        will improve cuOpt download speed and should be left
70                        enabled.This flag may be used to preserve backward
71                        compatibility with older cuOpt versions that do not
72                        support zlib compression.
73  -nv, --no-version-string
74                        Do not send the client version to the server. This
75                        flag may be used to preserve backward compatibility
76                        with older cuOpt versions that do not support the
77                        version string.
78  -ov, --only-validation
79                        If set, only validates input and doesn't add to
80                        billing.
81  -e EXEC_TIMEOUT, --exec-timeout EXEC_TIMEOUT
82                        http timeout when invoking a function. The server may
83                        wait up to 5 minutes before returning a pending-
84                        evalution result on long jobs. Most likely this does
85                        not need to be modified (defaults to 300)
86  -v, --version         Print client version and exit.