cuOpt Thin Client API Example

 1import os
 2from cuopt_thin_client import CuOptServiceClient
 3
 4data = {"cost_matrix_data": {"data": {"0": [[0,1],[1,0]]}},
 5        "task_data": {"task_locations": [0,1]},
 6        "fleet_data": {"vehicle_locations": [[0,0],[0,0]]}}
 7
 8# Load the credential "NVIDIA Identity Federation API Key" from the environment or some other way
 9
10sak = os.environ["NVIDIA_IDENTITY_FEDERATION_API_KEY"]
11
12cuopt_service_client = CuOptServiceClient(
13    sak=sak,
14    function_id=<FUNCTION_ID_OBTAINED_FROM_NGC>
15)
16
17optimized_routes = cuopt_service_client.get_optimized_routes(data)
18print(optimized_routes)

The function_id can be found in NGC -> Cloud Functions -> Shared Functions. For more details, please check Quick Start Guide.

The data argument to get_optimized_routes may be a dictionary of the format show in Get Routes Open-API spec. It may also be the path of a file containing such a dictionary as JSON or written using the Python pickle module. A JSON file may optionally be compressed with zlib.

cuOpt Thin Client CLI Example

Put your NVIDIA Identity Federation API Key in a credentials.json file as below:

{
    "CUOPT_CLIENT_SAK" : "PASTE_YOUR_NVIDIA_IDENTITY_FEDERATION_API_KEY"
}

Create a data.json file containing this sample data:

{"cost_matrix_data": {"data": {"0": [[0, 1], [1, 0]]}},
 "task_data": {"task_locations": [0, 1]},
 "fleet_data": {"vehicle_locations": [[0, 0], [0, 0]]}}

Invoke the CLI

cuopt_cli data.json -f <FUNCTION_ID> -s credentials.json

As mentioned above function_id can be found in NGC -> Cloud Functions -> Shared Functions. For more details, please check Quick Start Guide.

Alternatively, you may set NVIDIA Identity Federation API Key as CUOPT_CLIENT_SAK in your environment and omit the -s argument to cuopt_cli.