|
1 | | -# rqm-api API Guide |
| 1 | +# RQM Optimization API — Reference |
2 | 2 |
|
3 | | -`rqm-api` is the user-facing API layer for the RQM ecosystem. It coordinates circuit intake, compilation, optional optimization, and backend dispatch in a single unified interface. This page provides an overview of its primary functions and usage patterns. |
| 3 | +`rqm-api` is the HTTP service for geometry-aware quantum circuit optimization. The primary endpoint is `POST /v1/circuits/optimize`. |
4 | 4 |
|
5 | | ---- |
| 5 | +**Base URL:** `https://rqm-api.onrender.com` |
6 | 6 |
|
7 | | -## Role of `rqm-api` |
| 7 | +[:material-book-open-variant: Swagger UI](https://rqm-api.onrender.com/docs){ .md-button .md-button--primary } |
| 8 | +[:material-lightning-bolt: API Quickstart](quickstart.md){ .md-button } |
8 | 9 |
|
9 | | -`rqm-api` is the top of the stack. It is the primary entry point for users who want to run circuits without managing individual layers: |
| 10 | +--- |
10 | 11 |
|
11 | | -``` |
12 | | -rqm-circuits (circuit object) |
13 | | - → rqm-api |
14 | | - ├── rqm-compiler (gate resolution → u1q IR) |
15 | | - ├── [optional] rqm-optimize (gate fusion, compression) |
16 | | - └── backend dispatch |
17 | | - ├── rqm-qiskit |
18 | | - ├── rqm-braket |
19 | | - └── rqm-pennylane |
20 | | - → result |
21 | | -``` |
| 12 | +## Primary Endpoint: `/v1/circuits/optimize` |
22 | 13 |
|
23 | | -Its responsibilities: |
| 14 | +**`POST /v1/circuits/optimize`** |
24 | 15 |
|
25 | | -1. **Backend dispatch** — route execution to the correct backend based on the `backend` argument |
26 | | -2. **Pipeline coordination** — invoke the compiler and optionally the optimizer before execution |
27 | | -3. **Result normalization** — return a consistent result object regardless of backend |
| 16 | +Upload a quantum circuit. Get back a measurably better one. |
28 | 17 |
|
29 | | ---- |
| 18 | +What you get back: |
30 | 19 |
|
31 | | -## Modules |
| 20 | +- **Optimized circuit** — fewer gates, lower depth |
| 21 | +- **Gate count reduction** — before and after |
| 22 | +- **Depth reduction** — before and after |
| 23 | +- **Canonical structure** — SU(2)-normalized gate representation |
| 24 | +- **Optimization report** — structured summary of all transformations applied |
32 | 25 |
|
33 | | -| Module | Responsibility | |
34 | | -|---|---| |
35 | | -| `rqm_api.run` | Top-level `run()` function for circuit execution | |
36 | | -| `rqm_api.result` | `Result` type returned by `run()` | |
37 | | -| `rqm_api.backends` | Backend registry and backend selection helpers | |
| 26 | +```bash |
| 27 | +curl -X POST https://rqm-api.onrender.com/v1/circuits/optimize \ |
| 28 | + -H "Content-Type: application/json" \ |
| 29 | + -d @example.json |
| 30 | +``` |
38 | 31 |
|
39 | | ---- |
| 32 | +Use `GET /v1/circuits/example` to get a valid `example.json` payload. |
40 | 33 |
|
41 | | -## `rqm_api.run` |
| 34 | +--- |
42 | 35 |
|
43 | | -### `run` |
| 36 | +## Support Endpoints |
44 | 37 |
|
45 | | -Compiles and executes a circuit on the specified backend. |
| 38 | +### `GET /v1/circuits/example` |
46 | 39 |
|
47 | | -```python |
48 | | -from rqm_api import run |
| 40 | +Returns a ready-to-use example circuit payload. Use this to test `/optimize` without constructing a circuit manually. |
49 | 41 |
|
50 | | -result = run(qc, backend="qiskit") |
51 | | -print(result.counts) |
52 | | -# {"00": 512, "11": 512} |
| 42 | +```bash |
| 43 | +curl https://rqm-api.onrender.com/v1/circuits/example |
53 | 44 | ``` |
54 | 45 |
|
55 | | -**Parameters**: |
56 | | -- `circuit` — a `rqm_circuits.Circuit` object (or compatible gate list). |
57 | | -- `backend` — string backend name (`"qiskit"`, `"braket"`, `"pennylane"`) or a backend instance. |
58 | | -- `shots` — optional number of measurement shots (default: `1024`). |
59 | | -- `optimize` — optional boolean; if `True`, runs `rqm-optimize` before execution (default: `False`). |
60 | | -- `device` — optional device identifier for hardware execution (default: local simulator). |
| 46 | +### `POST /v1/circuits/validate` |
61 | 47 |
|
62 | | -**Returns**: `rqm_api.result.Result` object. |
| 48 | +Checks whether a circuit payload is well-formed. Use this before submitting to `/optimize` if you are constructing circuits programmatically. |
63 | 49 |
|
64 | | ---- |
| 50 | +```bash |
| 51 | +curl -X POST https://rqm-api.onrender.com/v1/circuits/validate \ |
| 52 | + -H "Content-Type: application/json" \ |
| 53 | + -d @example.json |
| 54 | +``` |
65 | 55 |
|
66 | | -## `rqm_api.result` |
| 56 | +### `POST /v1/circuits/analyze` |
67 | 57 |
|
68 | | -### `Result` |
| 58 | +Returns a structural analysis of the circuit (gate count, depth, gate types) without optimizing it. |
69 | 59 |
|
70 | | -The normalized result object returned by `run()`. |
| 60 | +```bash |
| 61 | +curl -X POST https://rqm-api.onrender.com/v1/circuits/analyze \ |
| 62 | + -H "Content-Type: application/json" \ |
| 63 | + -d @example.json |
| 64 | +``` |
71 | 65 |
|
72 | | -```python |
73 | | -from rqm_api import run |
| 66 | +--- |
| 67 | + |
| 68 | +## Role of `rqm-api` |
74 | 69 |
|
75 | | -result = run(qc, backend="braket") |
| 70 | +`rqm-api` is the top of the stack. It coordinates circuit intake, compilation, optimization, and result delivery: |
76 | 71 |
|
77 | | -print(result.counts) # {"00": 512, "11": 512} |
78 | | -print(result.backend) # "braket" |
79 | | -print(result.shots) # 1024 |
| 72 | +``` |
| 73 | +circuit input (JSON) |
| 74 | + → rqm-api |
| 75 | + ├── rqm-compiler (gate resolution → u1q IR) |
| 76 | + ├── rqm-optimize (gate fusion, compression) |
| 77 | + └── result: optimized circuit + report |
80 | 78 | ``` |
81 | 79 |
|
82 | | -**Key attributes**: |
| 80 | +Its responsibilities: |
83 | 81 |
|
84 | | -| Attribute | Description | |
85 | | -|---|---| |
86 | | -| `counts` | Dict mapping bitstring to observation count | |
87 | | -| `backend` | Backend name used for execution | |
88 | | -| `shots` | Number of measurement shots | |
89 | | -| `metadata` | Dict with additional backend-specific metadata | |
| 82 | +1. **Circuit intake** — accept and validate circuit payloads |
| 83 | +2. **Pipeline coordination** — invoke the compiler and optimizer |
| 84 | +3. **Result delivery** — return a structured response with optimized circuit and report |
90 | 85 |
|
91 | 86 | --- |
92 | 87 |
|
93 | | -## Usage Examples |
| 88 | +## Python SDK |
94 | 89 |
|
95 | | -### Bell state on Qiskit |
| 90 | +The API is also accessible via the Python SDK. See [SDK Quickstart](../quickstart.md) for setup. |
96 | 91 |
|
97 | 92 | ```python |
98 | | -from rqm_circuits import Circuit, Gate |
99 | 93 | from rqm_api import run |
100 | 94 |
|
101 | | -qc = Circuit(num_qubits=2) |
102 | | -qc.add(Gate("H", target=0)) |
103 | | -qc.add(Gate("CNOT", control=0, target=1)) |
104 | | - |
105 | | -result = run(qc, backend="qiskit", shots=1024) |
| 95 | +result = run(qc, backend="qiskit", optimize=True) |
106 | 96 | print(result.counts) |
107 | 97 | ``` |
108 | 98 |
|
109 | | -### Same circuit on Braket |
| 99 | +**Parameters**: |
| 100 | +- `circuit` — a `rqm_circuits.Circuit` object (or compatible gate list). |
| 101 | +- `backend` — string backend name (`"qiskit"`, `"braket"`, `"pennylane"`) or a backend instance. |
| 102 | +- `shots` — optional number of measurement shots (default: `1024`). |
| 103 | +- `optimize` — optional boolean; if `True`, runs `rqm-optimize` before execution (default: `False`). |
| 104 | +- `device` — optional device identifier for hardware execution (default: local simulator). |
| 105 | + |
| 106 | +**Returns**: `rqm_api.result.Result` object. |
110 | 107 |
|
111 | | -```python |
112 | | -result = run(qc, backend="braket", shots=1024) |
113 | | -print(result.counts) |
114 | | -``` |
| 108 | +--- |
115 | 109 |
|
116 | | -### Same circuit on PennyLane |
| 110 | +## Troubleshooting |
117 | 111 |
|
118 | | -```python |
119 | | -result = run(qc, backend="pennylane", shots=1024) |
120 | | -print(result.counts) |
121 | | -``` |
| 112 | +**Error: `"instructions": ["string"]`** |
122 | 113 |
|
123 | | -### With optimization |
| 114 | +This is the default Swagger placeholder. The `instructions` field must contain structured gate objects, not plain strings. |
124 | 115 |
|
125 | | -```python |
126 | | -result = run(qc, backend="qiskit", shots=1024, optimize=True) |
127 | | -print(result.counts) |
128 | | -``` |
| 116 | +**Fix:** Use `GET /v1/circuits/example` to get a valid payload, then send that to `POST /v1/circuits/optimize`. |
129 | 117 |
|
130 | 118 | --- |
131 | 119 |
|
132 | | -!!! note "Full API Reference" |
133 | | - Auto-generated API documentation with full signatures, type annotations, and docstrings is planned for a future release. In the meantime, refer to the source code in the [`rqm-api` repository](https://github.com/RQM-Technologies-dev/rqm-api). |
| 120 | +!!! note "Full schema" |
| 121 | + For request/response schemas and field-level documentation, use the [Swagger UI](https://rqm-api.onrender.com/docs). Auto-generated Python API docs are planned for a future release. In the meantime, refer to the source code in the [`rqm-api` repository](https://github.com/RQM-Technologies-dev/rqm-api). |
0 commit comments