Metadata-Version: 2.1
Name: cuopt-thin-client
Version: 24.3.0
Summary: A Python client and command-line
Author: NVIDIA Corporation
License: MIT
Project-URL: Homepage, https://docs.nvidia.com/cuopt/overview.html
Project-URL: Source, https://github.com/rapidsai/cuopt
Classifier: Development Status :: 4 - Beta
Classifier: Programming Language :: Python :: 3.9
Classifier: Programming Language :: Python :: 3.10
Classifier: License :: OSI Approved :: MIT License
Classifier: Operating System :: OS Independent
Requires-Python: >=3.9
Description-Content-Type: text/markdown
License-File: License.txt
Requires-Dist: requests
Provides-Extra: test
Requires-Dist: pytest ; extra == 'test'

# cuOpt Service Python Thin Client
cuOpt Service Python Thin Client is a Python interface to enable access to NVIDIA managed cuOpt service.

Install `cuopt-thin-client` via pip
```bash
pip install cuopt-thin-client --extra-index-url=https://pypi.nvidia.com
```

## Run thin client - CLI
After installation, the command-line utility can be accessed using
```bash
cuopt_cli -c credentials.json cuopt_problem_data.json
```

## Checking the status of a request which timed out

If a request times out because the problem is taking a long time to solve,
you will see a result like this:
```bash
Request timed out.
Re-check the status with the following command:
cuopt_cli '{"reqId": "cde52321-693e-444c-aa77-f55a3f6b0105", "assetId": "3958447c-389d-40ea-bd69-bbf242a9ec80"}'
```

The JSON object displayed can be passed back to *cuopt_cli* to check the status. This may be done multiple
times until a solution is returned. The JSON object may or may not include an *assetId*

```bash
cuopt_cli '{"reqId": "cde52321-693e-444c-aa77-f55a3f6b0105", "assetId": "3958447c-389d-40ea-bd69-bbf242a9ec80"}'
2023-08-17 15:13:16.120 cuopt_thin_client.cuopt_service_client INFO Using Cached Token
...
```

### List of Arguments (abbreviated, check program help for more details):
        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.
        -c:   credentials 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
        -a:   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.
        -f:   cuOpt cloud function to call (defaults to "optimized_routes_sync_elite")
        -i:   Function version id is specified by name. This should only be used when multiple versions are available with incompatible APIs.
        -g:   get available functions. Prints list of available cuOpt functions and exits. Refreshes the version cache.
        -t:   directory to write temporary files for handling large results (defaults to "./")
        -l:   Log level
        -p:   Number of seconds to poll for a result before timing out and returning a request id to re-query (defaults to 120)


## Run thin client - python script
### Initialize the CuOptServiceClient with Client Id and Secret provided
```bash
	from cuopt_thin_client import CuOptServiceClient
        cuopt_service_client = CuOptServiceClient(
            client_id=cuopt_client_id,
            client_secret=cuopt_client_secret,
        )
```

### Load the problem data
```bash
        with open(cuopt_problem_data_file_path, "r") as f:
            cuopt_problem_data = json.load(f)
```

##### The problem data file should contain a json with the following details:
        cost_waypoint_graph_data: Waypoint graph of Cost matrix 
        travel_time_waypoint_graph_data: Waypoint graph of Travel time matrix
        cost_matrix_data: Cost matrix
        travel_time_matrix_data: Travel time matrix
        fleet_data: Fleet information
        task_data: Task Waypoint graph of
        solver_config: Solver settings
    
    For more details see https://docs.nvidia.com/cuopt/user-guide/serv_api.html
    
### Get optimized routes
```bash
        optimized_routes = cuopt_service_client.get_optimized_routes(
            cuopt_problem_data
        )
```

### Check the status of a previous request that timed out
```bash

        if "reqId" in cuopt_problem_data:
            optimized_routes = cuopt_service_client.repoll(
                cuopt_problem_data["reqId"],
                cuopt_problem_data.get("assetId", None),
            )
```
