cuopt-thin-client


Namecuopt-thin-client JSON
Version 24.11.0 PyPI version JSON
download
home_pageNone
SummaryA Python client and command-line
upload_time2024-11-09 06:26:49
maintainerNone
docs_urlNone
authorNVIDIA Corporation
requires_python>=3.10
licenseMIT
keywords
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            # 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.
        -s    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 used.
        -c    File containing client_id and secret values in JSON. If this file is not supplied, the environment variables CUOPT_CLIENT_SAK
              or pair of CUOPT_CLIENT_ID and CUOPT_CLIENT_SECRET will be used. SAK takes precedence.
        -cn   Config file for setting client defaults in JSON. The format is {"defaults": {"function_name": "", "function_id": "", "function_version_id": ""}}
              None are required, and function_id takes precedence over function_name. If set, function_version_id must be a valid version of the function identified by name or id.
        -f    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.
              A default function name or id may be set in a config file with the -cn option.
        -i    The id of a specific version of the specified function to call. By default, the latest version will be called.
              A default function version id may be set in a config file with the -cn option.
        -g    Print a list of available cuOpt functions and exit. Refreshes the version cache.
        -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)
        -ov   If set, only validates input and doesn't add to billing.


## Run thin client - python script
### Initialize the CuOptServiceClient with Client SAK provided
```bash
	from cuopt_thin_client import CuOptServiceClient
        cuopt_service_client = CuOptServiceClient(
            sak=sak
        )
```

### Or Initialize the CuOptServiceClient with Client Id and Secret provided (Deprecated)
```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),
            )
```

### Credentials file formats
For client id and secret
```bash
{
    "CUOPT_CLIENT_ID" : "PASTE_YOUR_CLIENT_ID_HERE",
    "CUOPT_CLIENT_SECRET" : "PASTE_YOUR_CLIENT_SECRET_HERE"
}
```

For SAK
```bash
{
    "CUOPT_CLIENT_SAK" : "PASTE_YOUR_CLIENT_SAK_HERE",
}
```

### Config file format
This file can be used to set default values for function name, id, and/or version when multiple functions are available and the client requires clarification of which function to call. This is an alternative to passing these values explicitly to the client.

Function id takes precedence over function name if both are set. If neither are set and functions all have the same name, that name will be used.
If function is chosen by name, the client will select the newest function of that name.
If function version is set, that version must exist in the function identified by id or name. If not set, the newest version of that function will be chosen.


```bash
{
    "defaults": {
        "function_name": "PASTE_FUNCTION_NAME_HERE",
        "function_id": "PASTE_FUNCTION_ID_HERE",
        "function_version_id": "PASTE_VERSION_ID_HERE"
    }
}
```

            

Raw data

            {
    "_id": null,
    "home_page": null,
    "name": "cuopt-thin-client",
    "maintainer": null,
    "docs_url": null,
    "requires_python": ">=3.10",
    "maintainer_email": null,
    "keywords": null,
    "author": "NVIDIA Corporation",
    "author_email": null,
    "download_url": "https://files.pythonhosted.org/packages/5e/fe/1a373b22e3d875ed27c1d34856eca16a062b02e009b1e99d4b558a33e9ed/cuopt_thin_client-24.11.0.tar.gz",
    "platform": null,
    "description": "# cuOpt Service Python Thin Client\ncuOpt Service Python Thin Client is a Python interface to enable access to NVIDIA managed cuOpt service.\n\nInstall `cuopt-thin-client` via pip\n```bash\npip install cuopt-thin-client --extra-index-url=https://pypi.nvidia.com\n```\n\n## Run thin client - CLI\nAfter installation, the command-line utility can be accessed using\n```bash\ncuopt_cli -c credentials.json cuopt_problem_data.json\n```\n\n## Checking the status of a request which timed out\n\nIf a request times out because the problem is taking a long time to solve,\nyou will see a result like this:\n```bash\nRequest timed out.\nRe-check the status with the following command:\ncuopt_cli '{\"reqId\": \"cde52321-693e-444c-aa77-f55a3f6b0105\", \"assetId\": \"3958447c-389d-40ea-bd69-bbf242a9ec80\"}'\n```\n\nThe JSON object displayed can be passed back to *cuopt_cli* to check the status. This may be done multiple\ntimes until a solution is returned. The JSON object may or may not include an *assetId*\n\n```bash\ncuopt_cli '{\"reqId\": \"cde52321-693e-444c-aa77-f55a3f6b0105\", \"assetId\": \"3958447c-389d-40ea-bd69-bbf242a9ec80\"}'\n2023-08-17 15:13:16.120 cuopt_thin_client.cuopt_service_client INFO Using Cached Token\n...\n```\n\n### List of Arguments (abbreviated, check program help for more details):\n        file: Filename or JSON string, required if -g is not specified.\n              Data may be a cuopt problem or contain reqId and assetId (if any)\n              as displayed in the output from a previous request which timed out.\n        -s    File containing sak value in JSON. If this file is not supplied, the environment variable CUOPT_CLIENT_SAK will be used.\n              Only one of the two authetication methods (SAK or CLIENT ID & SECRET) can be used.\n        -c    File containing client_id and secret values in JSON. If this file is not supplied, the environment variables CUOPT_CLIENT_SAK\n              or pair of CUOPT_CLIENT_ID and CUOPT_CLIENT_SECRET will be used. SAK takes precedence.\n        -cn   Config file for setting client defaults in JSON. The format is {\"defaults\": {\"function_name\": \"\", \"function_id\": \"\", \"function_version_id\": \"\"}}\n              None are required, and function_id takes precedence over function_name. If set, function_version_id must be a valid version of the function identified by name or id.\n        -f    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\n              then that name will be used. The latest version of the specified function will be called if the -i option is not set.\n              A default function name or id may be set in a config file with the -cn option.\n        -i    The id of a specific version of the specified function to call. By default, the latest version will be called.\n              A default function version id may be set in a config file with the -cn option.\n        -g    Print a list of available cuOpt functions and exit. Refreshes the version cache.\n        -l    Log level\n        -p    Number of seconds to poll for a result before timing out and returning a request id to re-query (defaults to 120)\n        -ov   If set, only validates input and doesn't add to billing.\n\n\n## Run thin client - python script\n### Initialize the CuOptServiceClient with Client SAK provided\n```bash\n\tfrom cuopt_thin_client import CuOptServiceClient\n        cuopt_service_client = CuOptServiceClient(\n            sak=sak\n        )\n```\n\n### Or Initialize the CuOptServiceClient with Client Id and Secret provided (Deprecated)\n```bash\n\tfrom cuopt_thin_client import CuOptServiceClient\n        cuopt_service_client = CuOptServiceClient(\n            client_id=cuopt_client_id,\n            client_secret=cuopt_client_secret,\n        )\n```\n\n### Load the problem data\n```bash\n        with open(cuopt_problem_data_file_path, \"r\") as f:\n            cuopt_problem_data = json.load(f)\n```\n\n##### The problem data file should contain a json with the following details:\n        cost_waypoint_graph_data: Waypoint graph of Cost matrix \n        travel_time_waypoint_graph_data: Waypoint graph of Travel time matrix\n        cost_matrix_data: Cost matrix\n        travel_time_matrix_data: Travel time matrix\n        fleet_data: Fleet information\n        task_data: Task Waypoint graph of\n        solver_config: Solver settings\n    \n    For more details see https://docs.nvidia.com/cuopt/user-guide/serv_api.html\n    \n### Get optimized routes\n```bash\n        optimized_routes = cuopt_service_client.get_optimized_routes(\n            cuopt_problem_data\n        )\n```\n\n### Check the status of a previous request that timed out\n```bash\n\n        if \"reqId\" in cuopt_problem_data:\n            optimized_routes = cuopt_service_client.repoll(\n                cuopt_problem_data[\"reqId\"],\n                cuopt_problem_data.get(\"assetId\", None),\n            )\n```\n\n### Credentials file formats\nFor client id and secret\n```bash\n{\n    \"CUOPT_CLIENT_ID\" : \"PASTE_YOUR_CLIENT_ID_HERE\",\n    \"CUOPT_CLIENT_SECRET\" : \"PASTE_YOUR_CLIENT_SECRET_HERE\"\n}\n```\n\nFor SAK\n```bash\n{\n    \"CUOPT_CLIENT_SAK\" : \"PASTE_YOUR_CLIENT_SAK_HERE\",\n}\n```\n\n### Config file format\nThis file can be used to set default values for function name, id, and/or version when multiple functions are available and the client requires clarification of which function to call. This is an alternative to passing these values explicitly to the client.\n\nFunction id takes precedence over function name if both are set. If neither are set and functions all have the same name, that name will be used.\nIf function is chosen by name, the client will select the newest function of that name.\nIf function version is set, that version must exist in the function identified by id or name. If not set, the newest version of that function will be chosen.\n\n\n```bash\n{\n    \"defaults\": {\n        \"function_name\": \"PASTE_FUNCTION_NAME_HERE\",\n        \"function_id\": \"PASTE_FUNCTION_ID_HERE\",\n        \"function_version_id\": \"PASTE_VERSION_ID_HERE\"\n    }\n}\n```\n",
    "bugtrack_url": null,
    "license": "MIT",
    "summary": "A Python client and command-line",
    "version": "24.11.0",
    "project_urls": {
        "Homepage": "https://docs.nvidia.com/cuopt/overview.html",
        "Source": "https://github.com/rapidsai/cuopt"
    },
    "split_keywords": [],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "5efe1a373b22e3d875ed27c1d34856eca16a062b02e009b1e99d4b558a33e9ed",
                "md5": "6df177a26da49b5360e0edcc797c208b",
                "sha256": "baac4905e712e12e2791043d2098b1ab8018d244574393a88ebfd01e0e3b3b8b"
            },
            "downloads": -1,
            "filename": "cuopt_thin_client-24.11.0.tar.gz",
            "has_sig": false,
            "md5_digest": "6df177a26da49b5360e0edcc797c208b",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": ">=3.10",
            "size": 2833,
            "upload_time": "2024-11-09T06:26:49",
            "upload_time_iso_8601": "2024-11-09T06:26:49.684249Z",
            "url": "https://files.pythonhosted.org/packages/5e/fe/1a373b22e3d875ed27c1d34856eca16a062b02e009b1e99d4b558a33e9ed/cuopt_thin_client-24.11.0.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2024-11-09 06:26:49",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "github_user": "rapidsai",
    "github_project": "cuopt",
    "github_not_found": true,
    "lcname": "cuopt-thin-client"
}
        
Elapsed time: 0.95259s