Metadata-Version: 2.4
Name: qubecore-client
Version: 1.0.12
Summary: QubeCore Client SDK
License: MIT License
        
        Copyright (c) 2026 QubeCore Project
        
        Permission is hereby granted, free of charge, to any person obtaining a copy
        of this software and associated documentation files (the "Software"), to deal
        in the Software without restriction, including without limitation the rights
        to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
        copies of the Software, and to permit persons to whom the Software is
        furnished to do so, subject to the following conditions:
        
        The above copyright notice and this permission notice shall be included in all
        copies or substantial portions of the Software.
        
        THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
        IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
        FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
        AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
        LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
        OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
        SOFTWARE.
License-File: LICENSE
Requires-Python: >=3.11
Requires-Dist: grpcio>=1.60.0
Requires-Dist: protobuf>=4.0.0
Provides-Extra: dev
Requires-Dist: grpcio-tools>=1.60.0; extra == 'dev'
Requires-Dist: mypy>=1.8.0; extra == 'dev'
Requires-Dist: ruff>=0.1.0; extra == 'dev'
Description-Content-Type: text/markdown

# QubeCore-Client

Python client SDK for QubeCore — Quantum Computing Operating System.

## Overview

QubeCore Client provides a Python-friendly interface for communicating
with QubeCore Server over gRPC. QubeCli, QubeLab, and QubeGate all
depend on this package.

## Requirements

- Python 3.11+
- QubeCore Server

## Installation

```bash
pip install qubecore-client
```

## Quick Start

All APIs follow the same pattern: **submit → poll → result**.

```python
import json
import time
from qubecore_client import QubeClient

client = QubeClient(address="localhost:50051")


def wait(client, job_id):
    while True:
        status = client.get_job_status(job_id)["status"]
        if status in ("COMPLETED", "FAILED", "CANCELLED"):
            return status
        time.sleep(0.5)


# Gate job
job_id = client.submit_gate_job(
    backend_name="backend1",
    gate_circuits=[
        "OPENQASM 2.0;\ninclude \"qelib1.inc\";\nqreg q[2];\ncreg c[2];\nh q[0];\ncx q[0],q[1];\nmeasure q -> c;"
    ],
    shots=1000,
)
wait(client, job_id)
print(client.get_job_result(job_id))

# Pulse job
job_id = client.submit_pulse_job(
    backend_name="kreo.sc-20",
    pulse_circuits=[json.dumps([{"name": "X90", "qubit": ["qubit_0"]}, {"name": "read", "qubit": "qubit_0"}])],
    shots=1000,
)
wait(client, job_id)
print(client.get_job_result(job_id))

# Reset job
job_id = client.submit_reset_job(
    backend_name="kreo.sc-20",
    qubits=["qubit_0", "qubit_1"],
    shots=100,
)
wait(client, job_id)
print(client.get_job_result(job_id))

# Calibration job
job_id = client.submit_calibration_job(
    backend_name="kreo.sc-20",
    calibration_type="widescan",
    params={"qubit": "qubit_0", "span": 100_000_000, "n_points": 200, "num_shots": 100},
)
wait(client, job_id)
print(client.get_job_result(job_id)["calibration_result"])

# Cancel a pending job
job_id = client.submit_gate_job(backend_name="backend1", gate_circuits=["..."], shots=100)
client.cancel_job(job_id)
```

## API

| Method | Description |
|--------|-------------|
| `submit_gate_job()` | Submits a gate-circuit execution job and returns a `job_id` |
| `submit_pulse_job()` | Submits a pulse-program execution job and returns a `job_id` |
| `submit_reset_job()` | Submits a qubit active-reset job and returns a `job_id` |
| `submit_calibration_job()` | Submits a calibration job and returns a `job_id` |
| `get_job_status()` | Retrieves the current job status |
| `get_job_result()` | Retrieves the job result |
| `cancel_job()` | Cancels a job (only possible while status is PENDING) |

## Method Parameters

### `submit_gate_job`

| Parameter | Type | Required | Description |
|-----------|------|:--------:|-------------|
| `backend_name` | `str` | Yes | Backend name (`backend1`, `backend2`, `kreo.sc-20`) |
| `gate_circuits` | `list[str]` | Yes | List of circuit strings (QASM2/QASM3/JSON) |
| `shots` | `int` | Yes | Number of execution shots |
| `priority` | `int` | No | Priority 1–4 (default: 3 = NORMAL) |
| `optimization_level` | `int` | No | Transpile optimization level 0–3 |

> **Priority levels**: 1 = CRITICAL, 2 = HIGH, 3 = NORMAL (default), 4 = LOW

```python
import time
from qubecore_client import QubeClient

client = QubeClient(address="localhost:50051")

job_id = client.submit_gate_job(
    backend_name="backend1",
    gate_circuits=[
        "OPENQASM 2.0;\ninclude \"qelib1.inc\";\nqreg q[2];\ncreg c[2];\nh q[0];\ncx q[0],q[1];\nmeasure q -> c;"
    ],
    shots=1000,
    optimization_level=1,
)

while True:
    status = client.get_job_status(job_id)["status"]
    if status in ("COMPLETED", "FAILED", "CANCELLED"):
        break
    time.sleep(0.5)

result = client.get_job_result(job_id)
print(result)
# {"job_id": "...", "status": "COMPLETED", "results": [{"counts": {"00": 512, "11": 488}, "s11": {}, "qubit_mapping": {...}}]}
```

### `submit_pulse_job`

| Parameter | Type | Required | Description |
|-----------|------|:--------:|-------------|
| `backend_name` | `str` | Yes | Backend name |
| `pulse_circuits` | `list[str]` | Yes | List of pulse program strings (backend-specific JSON) |
| `shots` | `int` | Yes | Number of execution shots |
| `priority` | `int` | No | Priority 1–4 (default: 3 = NORMAL) |

```python
import json
import time
from qubecore_client import QubeClient

client = QubeClient(address="localhost:50051")

pulse_program = json.dumps([
    {"name": "delay", "t": 0.0005},
    {"name": "X90", "qubit": ["qubit_0"]},
    {"name": "read", "qubit": "qubit_0"},
])

job_id = client.submit_pulse_job(
    backend_name="kreo.sc-20",
    pulse_circuits=[pulse_program],
    shots=1000,
)

while True:
    status = client.get_job_status(job_id)["status"]
    if status in ("COMPLETED", "FAILED", "CANCELLED"):
        break
    time.sleep(0.5)

result = client.get_job_result(job_id)
print(result)
# {"job_id": "...", "status": "COMPLETED", "results": [{"counts": {"0": 850, "1": 150}, "s11": {...}, "qubit_mapping": {}}]}
```

### `submit_reset_job`

| Parameter | Type | Required | Description |
|-----------|------|:--------:|-------------|
| `backend_name` | `str` | Yes | Backend name |
| `qubits` | `list[str]` | Yes | Qubit names to reset (e.g. `["qubit_0", "qubit_1"]`) |
| `shots` | `int` | Yes | Number of verification shots after reset |
| `priority` | `int` | No | Priority 1–4 (default: 3 = NORMAL) |

```python
import time
from qubecore_client import QubeClient

client = QubeClient(address="localhost:50051")

job_id = client.submit_reset_job(
    backend_name="kreo.sc-20",
    qubits=["qubit_0", "qubit_1"],
    shots=100,
)

while True:
    status = client.get_job_status(job_id)["status"]
    if status in ("COMPLETED", "FAILED", "CANCELLED"):
        break
    time.sleep(0.5)

result = client.get_job_result(job_id)
print(result)
# {"job_id": "...", "status": "COMPLETED", "results": [{"counts": {"00": 98, "01": 1, "10": 1}, "s11": {}, "qubit_mapping": {}}]}
```

### `submit_calibration_job`

| Parameter | Type | Required | Description |
|-----------|------|:--------:|-------------|
| `backend_name` | `str` | Yes | Backend name |
| `calibration_type` | `str` | Yes | Calibration type: `"widescan"` or `"punchout"` |
| `params` | `dict` | Yes | Calibration parameters (see server spec) |
| `priority` | `int` | No | Priority 1–4 (default: 3 = NORMAL) |

```python
import time
from qubecore_client import QubeClient

client = QubeClient(address="localhost:50051")

# widescan
job_id = client.submit_calibration_job(
    backend_name="kreo.sc-20",
    calibration_type="widescan",
    params={"qubit": "qubit_0", "span": 100_000_000, "n_points": 200, "num_shots": 100},
)

while True:
    status = client.get_job_status(job_id)["status"]
    if status in ("COMPLETED", "FAILED", "CANCELLED"):
        break
    time.sleep(0.5)

result = client.get_job_result(job_id)
print(result["calibration_result"])
# {"qubit": "qubit_0", "resonator_freq": 6450000000.0, "freqs": [...], "magnitude": [...], "phase": [...]}

# punchout
job_id = client.submit_calibration_job(
    backend_name="kreo.sc-20",
    calibration_type="punchout",
    params={
        "qubit": "qubit_0",
        "res_freq": 6_450_000_000.0,
        "span": 20_000_000,
        "n_freqs": 20,
        "amps": [0.01, 0.02, 0.05, 0.1, 0.2, 0.5],
        "num_shots": 100,
    },
)

while True:
    status = client.get_job_status(job_id)["status"]
    if status in ("COMPLETED", "FAILED", "CANCELLED"):
        break
    time.sleep(0.5)

result = client.get_job_result(job_id)
print(result["calibration_result"])
# {"qubit": "qubit_0", "resonator_freq": 6450000000.0, "freqs": [...], "amps": [...], "magnitude": [[...]], "phase": [[...]]}
```

### `cancel_job`

Cancels a job that is still in `PENDING` status.

```python
from qubecore_client import QubeClient

client = QubeClient(address="localhost:50051")

job_id = client.submit_gate_job(
    backend_name="backend1",
    gate_circuits=[
        "OPENQASM 2.0;\ninclude \"qelib1.inc\";\nqreg q[1];\ncreg c[1];\nh q[0];\nmeasure q -> c;"
    ],
    shots=1000,
)

message = client.cancel_job(job_id)
print(message)  # "Job has been cancelled"
```

## Job Result

`get_job_result()` returns a dict. The shape differs by job type:

**gate / pulse / reset jobs**
```python
{
    "job_id": "...",
    "status": "COMPLETED",
    "results": [
        {
            "counts":        {"00": 512, "11": 488},
            "s11":           {"qubit_0.rdlo": {"real": [[...]], "imag": [[...]]}},
            "qubit_mapping": {"q[0]": "qubit_5", "q[1]": "qubit_6"}
        }
    ]
}
```

**calibration jobs**
```python
{
    "job_id": "...",
    "status": "COMPLETED",
    "calibration_result": {
        "qubit": "qubit_0",
        "resonator_freq": 6450000000.0,
        ...
    }
}
```

## CLI

Command line interface is provided separately via [qubecli](https://pypi.org/project/qubecli/).

```bash
pip install qubecli
```

## Compatibility

| qubecore-client | qubecore |
|----------------|----------|
| 1.x | 1.x |

## License

MIT
