Skip to content

Run a job through the API#

Login to the API#

First thing you need to do is to authenticate in the API and obtain an access token.

Run job using a previously uploaded dataset#

The endpoint to run a job for a given use case is as follows:

curl -X POST https://api.sandbox.qcentroid.com/problem/problem-urn
-H 'Authorization: Bearer {access_token}'
-H 'Content-Type: application/json'
-d '{"data_file_identifier": "070737d79192e816db1581409256bdefa0a834fb"}'
response = requests.post(
                url="https://api.sandbox.qcentroid.com/problem/maxcut",
                json={"data_file_identifier": "070737d79192e816db1581409256bdefa0a834fb"},
                headers={"Authorization": "Bearer " + access_token})

In the request’s body, you have to include the dataset id, which is a file already uploaded to the platform and that contains the input data for this execution.

After a successful job is launched, the API returns the Job Id to be used later to check its status and get the output.

Job execution response
{
    "detail": "Authorized. Processing file",
    "job": "W4P3Q4YTSDU1"
}

Run job using providing inline data#

If your input data for the execution is not too large (less than 4 MB), you can provide it directly in the request in JSON format.

In this example, we are providing input data for the Max Cut use case:

curl -X POST https://api.sandbox.qcentroid.com/problem/maxcut
-H 'Authorization: Bearer {access_token}'
-H 'Content-Type: application/json'
-d '{ "num_nodes": 6,
    "adj_matrix": [[0, 9, 5, 2, 4, 1],
                    [9, 0, 3, 8, 7, 6],
                    [5, 3, 0, 2, 8, 4],
                    [2, 8, 2, 0, 9, 3],
                    [4, 7, 8, 9, 0, 2],
                    [1, 6, 4, 3, 2, 0]] }'
response = requests.post(
                url="https://api.sandbox.qcentroid.com/problem/maxcut",
                json={  "num_nodes": 6,
                        "adj_matrix": [[0, 9, 5, 2, 4, 1],
                                        [9, 0, 3, 8, 7, 6],
                                        [5, 3, 0, 2, 8, 4],
                                        [2, 8, 2, 0, 9, 3],
                                        [4, 7, 8, 9, 0, 2],
                                        [1, 6, 4, 3, 2, 0]] },
                headers={"Authorization": "Bearer " + access_token})

Tip

Visit the use case’s details page in the web dashboard to check the input data format.

After a successful job is launched, the API returns the Job Id to be used later to check its status and get the output.

Job execution response
{
    "detail": "Authorized. Processing file",
    "job": "W4P3Q4YTSDU1"
}

Check job status#

To check the status of a job, use the following API GET request, providing the Job Id obtained at job execution:

curl -X GET https://api.sandbox.qcentroid.com/job/W4P3Q4YTSDU1
-H 'Authorization: Bearer {access_token}'
response = requests.get(
                url="https://api.sandbox.qcentroid.com/job/W4P3Q4YTSDU1",
                headers={"Authorization": "Bearer " + access_token})

This endpoint returns a JSON object like this one, with all the job details:

Job status response
{
    "job": {
        "W4P3Q4YTSDU1": {
            "status": "PENDING",
            "started_at": "08/15/2024, 10:52:45",
            "end_at": "",
            "executions": {

                ...

            }
        }
    }
}

Job and execution statuses#

A job runs one or more executions (one per solver and shot). Each execution goes through these statuses in order, and never goes back to a previous one:

Status What is happening
PENDING The execution is registered. The platform has not started sending it yet.
PREPARING The platform prepares the execution: it uploads the input data, resolves the credentials of the provider and the SDK, builds the environment and sends the task to the compute backend.
PROVISIONING The compute backend accepted the task and is allocating resources: queue, scheduling and image download. Your solver code is not running yet.
STARTING The solver runtime is up and is loading its context, the input data, the SDK and the provider. Your solver code is not running yet.
RUNNING Your solver is running.

An execution ends in one of these final statuses, and it never changes after that:

Final status Meaning
SUCCESS The solver ended correctly.
ERROR The execution failed.
CANCELLED The execution was stopped before your solver started running (PENDING, PREPARING, PROVISIONING or STARTING). It has no cost: its cost is set to 0 and the credits charged when the job was launched are returned to you.
TERMINATED The execution was stopped after your solver started running, and it did not fail: you stopped it, it exceeded the maximum execution time, or the platform stopped it. You are charged for the time it ran.

The status of the job summarizes its executions: it is PENDING until the platform starts working on it, PREPARING while some execution is being provisioned and none is running yet, and RUNNING as soon as one execution is running.

Where did the time go?

The time before RUNNING (PREPARING, PROVISIONING and STARTING) is platform and infrastructure time: it does not depend on your solver code and it is not part of the execution time of your solver, which is measured from RUNNING.

What’s next#

See the job results in the web dashboard

Visit the API documentation site