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 = 60,
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=None,
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 60, 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 timing out. The default is None which causes the client to poll until a result is received and never time out.

  • timeout_exception (boolean) – If True, the client returns # noqa a TimeoutError exception if polling_timeout seconds passes before a solution is returned. If False, the client will simply return None. 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.

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