SDK · CLI · REST API

Geliştirici, SDK ve REST API dokümantasyonuDeveloper, SDK and REST API documentation

Aynı API JavaScript (Node.js ve tarayıcı) ve saf Python'da bulunur. Zorunlu bağımlılık yoktur; NumPy, Mitiq, Cirq, Qiskit, dimod ve PennyLane yalnızca kullanıldığında yüklenir. Bütün örnekler kopyalanabilir ve tohumlu olduğu için tekrarlanabilir.The same API exists in JavaScript (Node.js and browser) and pure Python. There are no mandatory dependencies; NumPy, Mitiq, Cirq, Qiskit, dimod and PennyLane are imported only when used. Every example can be copied and is seeded, so it is reproducible.

Node.js≥ 18
Python≥ 3.9
Zorunlu bağımlılıkMandatory dependencies0
JSON API ucuJSON API endpoints10

KurulumInstallation

Paket adı her iki dilde quboforge. Depoyu doğrudan kullanıyorsanız kurulum gerekmez: src/index.mjs ve python/quboforge olduğu gibi içe aktarılır.The package is called quboforge in both languages. Working from the repository needs no install step: src/index.mjs and python/quboforge can be imported as they are.

npm i quboforge

JavaScript ESM

Çekirdek, Node.js 18+ ve modern tarayıcılarda değişmeden çalışan ES modüllerinden oluşur. solve() her çözücü için tek kapıdır ve hem QUBO hem Ising enerjisini (ikisi aynıdır) döndürür.The core is a set of ES modules that run unchanged in Node.js 18+ and modern browsers. solve() is the single front door for every solver and returns the energy, identical in the QUBO and Ising picture.

solve.mjs
import * as qf from 'quboforge';            // or './src/index.mjs' from the repository

// Max-Cut on a seeded 3-regular graph with discrete simulated bifurcation
const ising = qf.maxCutToIsing(qf.randomRegularGraph(12, 3, 2026));
const best = qf.solve(ising, { solver: 'dsb', seed: 1, steps: 600, nTrajectories: 32 });
console.log(best.energy, best.x);             // x: 0/1 bits, spins: -1/+1

// Your own QUBO as a dictionary {"i,j": weight}
const qubo = qf.quboFromDict({ '0,0': -1, '0,1': 2, '1,1': -1 }, 2);
console.log(qf.solve(qubo, { solver: 'bruteforce' }).energy);

// Industrial compilers return baseline, optimized and validation
const cut = qf.cuttingStock.solveCuttingStock(qf.cuttingStock.CUTTING_PRESETS.glass_facade);
console.log(cut.baseline.sheetCount, cut.optimized.sheetCount, cut.validation.optimized.ok);

const roster = qf.shiftRostering.solveRoster(qf.shiftRostering.ROSTER_PRESETS.factory_3shift);
console.log(roster.optimized.assignmentCount, roster.optimized.hardViolations);

Çözücüler: dsb, bsb, sa, tabu, greedy, bruteforce, qaoa. Derleyiciler: cuttingStock, cvrp, shiftRostering, binPacking3d, energyArbitrage; gürültü ve ZNE için noise.Solvers: dsb, bsb, sa, tabu, greedy, bruteforce, qaoa. Compilers: cuttingStock, cvrp, shiftRostering, binPacking3d, energyArbitrage; noise and ZNE live in noise.

Tarayıcı: klasik bundle ve file://Browser: classic bundle and file://

Tarayıcılar diskten açılan sayfalarda ES modülü içe aktarımlarını reddeder. Bu yüzden scripts/build-bundle.mjs aynı kaynakları tek bir klasik betiğe paketler: quboforge.bundle.js. Betik, kütüphaneyi window.QuboForge olarak sunar ve hem http:// hem file:// altında çalışır. Canlı Stüdyo bu yolu kullanır.Browsers refuse ES module imports on pages opened from disk. scripts/build-bundle.mjs therefore packs the same sources into one classic script, quboforge.bundle.js. It exposes the library as window.QuboForge and works under http:// and file:// alike. The Live Studio uses exactly this path.

index.html
<script defer src="./quboforge.bundle.js"></script>
<script defer src="./my-app.js"></script>

// my-app.js
const Q = window.QuboForge;
const res = Q.solve(Q.maxCutToIsing(Q.randomRegularGraph(16, 3, 7)), { solver: 'dsb', seed: 1 });
document.title = 'energy ' + res.energy;
paketi yeniden üretrebuild the bundle
npm run build          # writes web/quboforge.bundle.js
npm run build:check    # exit code 1 if the bundle is stale

Python + NumPy

Saf Python paketi aynı modülleri yansıtır. NumPy kuruluysa backend="auto" bütün yörüngeleri tek bir (M, N) matrisi olarak işler; her adımda tek çarpım F = sgn(X) Jᵀ + h hesaplanır. Başlangıç koşulları saf arka uçla aynı tohumlu üreteçten gelir.The pure-Python package mirrors the same modules. With NumPy installed, backend="auto" treats all trajectories as one (M, N) matrix and computes a single product F = sgn(X) Jᵀ + h per step. Initial conditions come from the same seeded generator as the pure backend.

solve.py
import quboforge as qf                     # or sys.path.insert(0, "python") in the repository

ising = qf.max_cut_to_ising(qf.random_regular_graph(12, 3, seed=2026))
fast = qf.dsb(ising, seed=1, steps=600, n_trajectories=32, backend="auto")
print(fast["energy"], fast["params"]["backend"])   # "numpy" when NumPy is installed

from quboforge.compilers import shift_rostering as ro
plan = ro.solve_roster(ro.ROSTER_PRESETS["factory_3shift"], seed=1)
print(plan["optimized"]["assignment_count"], plan["optimized"]["hard_violations"])

CLI & IBM Quantum Heron r2

Kuru çalıştırma (--dry-run) devreyi {rz, sx, x, cz} yerel kapı kümesine yeniden yazar ve varsayılan Heron sınıfı hata oranlarıyla yerelde örnekler. Bu oranlar herhangi bir cihazın kalibrasyon verisi değildir. Gerçek donanım için IBM_QUANTUM_TOKEN ortam değişkenini ayarlayın; heavy-hex yerleşimi ve yönlendirme Qiskit transpiler tarafından yapılır.The dry run (--dry-run) rewrites the circuit to the native {rz, sx, x, cz} gate set and samples locally under assumed Heron-class error rates. These rates are not calibration data of any device. For real hardware set IBM_QUANTUM_TOKEN; heavy-hex layout and routing are done by the Qiskit transpiler.

shell
# local rehearsal, no account needed
python -m quboforge.ibm_runtime --dry-run --nodes 6 --p 1 --shots 4000

# real Heron r2 processor (ibm_fez, ibm_marrakesh, ibm_kingston)
export IBM_QUANTUM_TOKEN=<your API key>
python -m quboforge.ibm_runtime --backend ibm_fez --nodes 10 --p 1 --shots 4000

Hesabınıza açık işlemcileri IBM Quantum Platform üzerinden kontrol edin. IBM_QUANTUM_CHANNEL ve IBM_QUANTUM_INSTANCE servis kanalını ve örneği değiştirir. Anahtarınızı depoya veya istemlere yazmayın.Check which processors your account can use on the IBM Quantum Platform. IBM_QUANTUM_CHANNEL and IBM_QUANTUM_INSTANCE override the service channel and instance. Never commit your key or paste it into prompts.

OpenQASM 3.0 & Mitiq ZNE

QAOA devresi OpenQASM 3.0 metni olarak üretilir: her ZZ terimi cx; rz(2γw); cx, karıştırıcı rx(2β). Bağımsız bir kapı seviyesi simülatörü üretilen metni yeniden yürütür. Gürültü modülü devreyi kesin yoğunluk matrisi üzerinde depolarizan kanallarla çalıştırır, kapıları 1, 3, 5 ölçeğinde katlar ve Richardson ile sıfır gürültüye ekstrapole eder.The QAOA circuit is emitted as OpenQASM 3.0 text: each ZZ term as cx; rz(2γw); cx, mixer rx(2β). An independent gate-level simulator re-executes the emitted text. The noise module runs the circuit on an exact density matrix with depolarizing channels, folds gates at scales 1, 3, 5 and extrapolates to zero noise with Richardson.

import * as qf from 'quboforge';

const model = qf.maxCutToIsing(qf.randomRegularGraph(6, 3, 3));
const q = qf.optimizeQaoa(model, { p: 2, seed: 1 });
console.log(q.approxRatio, q.qasm.split('\n')[0]);       // OPENQASM 3.0;
console.log(qf.validateQasm3(q.qasm).ok);

const zne = qf.noise.zneQaoa(model, { p: 1, p1: 0.001, p2: 0.01, scales: [1, 3, 5] });
console.log(zne.ideal, zne.zne.richardson, zne.errors.unmitigated / zne.errors.richardson);

console.log(qf.toQiskit(model).python);                   // SparsePauliOp.from_list([...])
console.log(qf.toPennyLane(model).python);                // qml.Hamiltonian(...)

REST API · server.mjs

server.mjs sıfır bağımlılıklı bir Node.js HTTP sunucusudur: siteyi, Canlı Stüdyo'yu ve aşağıdaki JSON uçlarını sunar. Varsayılan olarak yalnızca 127.0.0.1 adresini dinler. Bütün POST gövdeleri JSON'dur; seçenekler sunucu tarafından beyaz listeyle süzülür ve sınırlanır.server.mjs is a zero-dependency Node.js HTTP server: it serves the site, the Live Studio and the JSON endpoints below. By default it listens on 127.0.0.1 only. Every POST body is JSON; options are whitelisted and clamped by the server.

shell
node server.mjs                          # http://127.0.0.1:8820
PORT=9000 HOST=0.0.0.0 node server.mjs   # behind a reverse proxy
GET/api/health

Sürüm, çözücü ve derleyici listesi ile site sayfalarını döndürür.Returns the version, solver and compiler lists and the site pages.

curl -s http://127.0.0.1:8820/api/health
GET/api/benchmarks

benchmarks/results.json varsa { available: true, results }, yoksa { available: false, hint } döner.Returns { available: true, results } when benchmarks/results.json exists, otherwise { available: false, hint }.

curl -s http://127.0.0.1:8820/api/benchmarks
POST/api/solve

Gövde: graph: { n, edges } (Max-Cut) veya qubo: { "i,j": w } + isteğe bağlı n, offset; solver (dsb varsayılan) ve options. Yanıt: energy, x, spins, elapsedMs, params.Body: graph: { n, edges } (Max-Cut) or qubo: { "i,j": w } with optional n, offset; solver (default dsb) and options. Response: energy, x, spins, elapsedMs, params.

curl -s -X POST http://127.0.0.1:8820/api/solve \
  -H 'Content-Type: application/json' \
  -d '{"graph":{"n":4,"edges":[[0,1],[1,2],[2,3],[3,0],[0,2]]},"solver":"dsb","options":{"seed":1,"steps":300,"nTrajectories":16}}'

curl -s -X POST http://127.0.0.1:8820/api/solve \
  -H 'Content-Type: application/json' \
  -d '{"qubo":{"0,0":-1,"0,1":2,"1,1":-1},"n":2,"solver":"bruteforce"}'
POST/api/qaoa

QAOA açılarını kesin durum vektörüyle optimize eder (en çok 14 kübit, p 1 ile 3 arası). Yanıt: gammas, betas, expectation, groundEnergy, approxRatio, pOptimal, bestSample, qasm.Optimises QAOA angles on an exact statevector (at most 14 qubits, p from 1 to 3). Response: gammas, betas, expectation, groundEnergy, approxRatio, pOptimal, bestSample, qasm.

curl -s -X POST http://127.0.0.1:8820/api/qaoa \
  -H 'Content-Type: application/json' \
  -d '{"graph":{"n":6,"edges":[[0,1],[1,2],[2,3],[3,4],[4,5],[5,0],[0,3]]},"p":1,"seed":1}'
POST/api/zne

Gürültülü QAOA + sıfır gürültü ekstrapolasyonu (en çok 8 kübit). p1, p2, readout hata oranları; scales en az iki farklı tek sayı (1 ile 9 arası). Yanıt: ideal, noisy[], zne.richardson, zne.linear, errors, qasm.Noisy QAOA + zero-noise extrapolation (at most 8 qubits). p1, p2, readout are error rates; scales needs at least two distinct odd integers between 1 and 9. Response: ideal, noisy[], zne.richardson, zne.linear, errors, qasm.

curl -s -X POST http://127.0.0.1:8820/api/zne \
  -H 'Content-Type: application/json' \
  -d '{"graph":{"n":4,"edges":[[0,1],[1,2],[2,3],[3,0],[0,2]]},"p":1,"p1":0.001,"p2":0.02,"scales":[1,3,5]}'
POST/api/cutting-stock

2B kesim planı. Gövde: sheet: { w, h }, kerf (mm), parts[] (id, w, h, qty, isteğe bağlı rotate), isteğe bağlı cutMode (guillotine veya free). Yanıt: baseline, optimized.sheets[].placements, validation, families.2D cutting plan. Body: sheet: { w, h }, kerf (mm), parts[] (id, w, h, qty, optional rotate), optional cutMode (guillotine or free). Response: baseline, optimized.sheets[].placements, validation, families.

curl -s -X POST http://127.0.0.1:8820/api/cutting-stock \
  -H 'Content-Type: application/json' \
  -d '{"sheet":{"w":2800,"h":2100},"kerf":4,"cutMode":"guillotine","parts":[{"id":"A","w":800,"h":600,"qty":6},{"id":"B","w":1200,"h":400,"qty":4}]}'
POST/api/cvrp

Kapasite kısıtlı araç rotalama. Gövde: depot: { x, y }, customers[] (x, y, demand), vehicles, capacity. Yanıt: baseline, baseline2opt, optimized.routes, improvementPct, validation.Capacitated vehicle routing. Body: depot: { x, y }, customers[] (x, y, demand), vehicles, capacity. Response: baseline, baseline2opt, optimized.routes, improvementPct, validation.

curl -s -X POST http://127.0.0.1:8820/api/cvrp \
  -H 'Content-Type: application/json' \
  -d '{"depot":{"x":30,"y":30},"customers":[{"x":10,"y":12,"demand":8},{"x":48,"y":20,"demand":6},{"x":40,"y":52,"demand":9},{"x":14,"y":44,"demand":7}],"vehicles":2,"capacity":18}'
POST/api/roster

Vardiya çizelgesi. Gövde: demand (gün × vardiya ihtiyaç matrisi), employees[] (id, isteğe bağlı maxShifts, unavailable, avoid), isteğe bağlı shifts, minRestHours (varsayılan 11). Yanıt: baseline ve optimized içinde assignments[], assignmentCount, grid, shortfall, hardViolations.Shift roster. Body: demand (day × shift requirement matrix), employees[] (id, optional maxShifts, unavailable, avoid), optional shifts, minRestHours (default 11). Response: baseline and optimized with assignments[], assignmentCount, grid, shortfall, hardViolations.

curl -s -X POST http://127.0.0.1:8820/api/roster \
  -H 'Content-Type: application/json' \
  -d '{"demand":[[2,1,1],[2,1,1],[1,1,1]],"employees":[{"id":"a"},{"id":"b"},{"id":"c","avoid":["N"]},{"id":"d"},{"id":"e"},{"id":"f"}],"minRestHours":11}'
POST/api/load-3d

3B tır/konteyner yükleme. Gövde: container: { l, w, h, maxWeight }, boxes[] (id, l, w, h, weight, qty, rotate: none, upright veya all), isteğe bağlı minSupport. Yanıt: optimized.containers[].boxes, validation.optimized.intersections.3D truck/container loading. Body: container: { l, w, h, maxWeight }, boxes[] (id, l, w, h, weight, qty, rotate: none, upright or all), optional minSupport. Response: optimized.containers[].boxes, validation.optimized.intersections.

curl -s -X POST http://127.0.0.1:8820/api/load-3d \
  -H 'Content-Type: application/json' \
  -d '{"container":{"l":2400,"w":1200,"h":1200,"maxWeight":2000},"boxes":[{"id":"A","l":600,"w":400,"h":400,"weight":20,"qty":12,"rotate":"all"},{"id":"B","l":800,"w":600,"h":500,"weight":35,"qty":6,"rotate":"upright"}]}'
POST/api/energy

GES + batarya + kaydırılabilir yük planı. Gövde: pv[] ve baseLoad[] (saatlik kW, en çok 96 dilim), isteğe bağlı tariff[], exportPrice, battery (capacity, power, efficiency, initial, min), jobs[] (id, duration, power, earliest, latest). Yanıt: baseline.cost, optimized.cost, optimized.schedule, validation.PV + battery + shiftable load plan. Body: pv[] and baseLoad[] (hourly kW, at most 96 slots), optional tariff[], exportPrice, battery (capacity, power, efficiency, initial, min), jobs[] (id, duration, power, earliest, latest). Response: baseline.cost, optimized.cost, optimized.schedule, validation.

curl -s -X POST http://127.0.0.1:8820/api/energy \
  -H 'Content-Type: application/json' \
  -d '{"pv":[0,50,120,80,0,0],"baseLoad":[40,40,60,60,50,40],"exportPrice":1.5,"battery":{"capacity":100,"power":30,"efficiency":0.9,"initial":20,"min":10},"jobs":[{"id":"x","duration":2,"power":50,"earliest":0,"latest":6}]}'

Sınırlar ve hata kodlarıLimits and error codes

Tanıtım sunucusu tek bir isteğin sunucuyu kilitlememesi için boyutları kontrol eder ve çözücü seçeneklerini sınırlar. Şirket içi kurulumda bu sınırlar ihtiyaca göre ayarlanır.The demo server checks sizes and clamps solver options so that a single request cannot stall it. On-premise deployments tune these limits.

UçEndpointSınırLimit
/api/solveen çok 2000 değişkenat most 2000 variables
/api/qaoaen çok 14 kübit, p ≤ 3at most 14 qubits, p ≤ 3
/api/zneen çok 8 kübit, p ≤ 2, ölçekler 1 ile 9 arası tek sayılarat most 8 qubits, p ≤ 2, scales are odd integers from 1 to 9
/api/cutting-stock100 parça türü, 1000 parça100 part types, 1000 parts
/api/cvrpmüşteri × araç ≤ 1500customers × vehicles ≤ 1500
/api/roster60 çalışan, 31 gün60 employees, 31 days
/api/load-3d30 koli türü, 300 koli30 box types, 300 boxes
/api/energy96 zaman dilimi, 30 parti96 time slots, 30 batches
TümüAllgövde en çok 1 MiB; hatalar { "error": "..." } ile 400, 404, 405 veya 413 dönerbody at most 1 MiB; errors return { "error": "..." } with 400, 404, 405 or 413