qndk.batchscheduler¶
Runs many quantum jobs against one shared topology. Where the rest of the pipeline asks what does this circuit cost on this network, this asks how well does this network serve a queue.
The model¶
A job is a dict with three keys:
| Key | Type | Meaning |
|---|---|---|
id |
str |
Identifier used in the results |
num_qubits |
int |
How many compute qubits it needs |
transpiled_circuit |
TranspiledCircuit |
The circuit itself |
QuantumBatchScheduler takes a network and a partitioner_fn — a callable
of (circuit, network) -> PartitionResult. That indirection is what lets
you evaluate the same queue under different partitioning strategies.
from qndk.circuit.qiskit_circuits import QiskitCircuit
from qndk.transpile.transpile import TranspiledCircuit
from qndk.quantum_network import build_clos, QPUSpec
from qndk.partition.kl import KernighanLinPartitioner
from qndk.batchscheduler.batch_scheduler import QuantumBatchScheduler
network = build_clos(ports_per_switch=4, qpus_per_rack=2,
qpu_spec=QPUSpec(comp_qubits=4, connectivity="all2all"))
jobs = [{"id": f"job-{i}", "num_qubits": n,
"transpiled_circuit": TranspiledCircuit(
QiskitCircuit("qft", num_qubits=n))}
for i, n in enumerate((4, 6, 5, 8, 4))]
scheduler = QuantumBatchScheduler(
network=network,
partitioner_fn=lambda circuit, net:
KernighanLinPartitioner(circuit, net).partition(),
)
out = scheduler.run_fifo_strict(jobs)
print(f"makespan : {out['total_execution_cost']:.2f}")
print(f"wastage/qubit : {out['wastage_per_qubit']:.2f}")
print(f"jobs finished : {len(out['job_results'])}")
The two algorithms¶
| Method | Behaviour |
|---|---|
run_fifo_strict(jobs) |
Strict first-in-first-out. The baseline. |
run_batch_optimized(jobs, heuristic=...) |
Reorders to pack the topology better |
Three heuristics for the optimized form:
heuristic |
Strategy |
|---|---|
"hybrid" |
Default. Balances large and small jobs. |
"min_qubits" |
Smallest jobs first — maximizes concurrency |
"max_qubits" |
Largest jobs first — clears big jobs early |
from qndk.circuit.qiskit_circuits import QiskitCircuit
from qndk.transpile.transpile import TranspiledCircuit
from qndk.quantum_network import build_clos, QPUSpec
from qndk.partition.kl import KernighanLinPartitioner
from qndk.batchscheduler.batch_scheduler import QuantumBatchScheduler
network = build_clos(ports_per_switch=4, qpus_per_rack=2,
qpu_spec=QPUSpec(comp_qubits=4, connectivity="all2all"))
jobs = [{"id": f"job-{i}", "num_qubits": n,
"transpiled_circuit": TranspiledCircuit(
QiskitCircuit("qft", num_qubits=n))}
for i, n in enumerate((4, 8, 5, 6, 4, 7))]
scheduler = QuantumBatchScheduler(
network=network,
partitioner_fn=lambda c, n: KernighanLinPartitioner(c, n).partition(),
)
print(f"{'algorithm':12s} {'makespan':>10s} {'wastage/qubit':>14s}")
runs = {"fifo": scheduler.run_fifo_strict(jobs)}
for heuristic in ("hybrid", "min_qubits", "max_qubits"):
runs[heuristic] = scheduler.run_batch_optimized(jobs,
heuristic=heuristic)
for name, out in runs.items():
print(f"{name:12s} {out['total_execution_cost']:10.2f} "
f"{out['wastage_per_qubit']:14.2f}")
The two metrics¶
Makespan — total_execution_cost. Total time to drain the queue. Lower
is better, and it is the number a user of the machine cares about.
Wastage — wastage_per_qubit. Average idle time per qubit, in the same
units as the makespan. Not a fraction. It counts time a qubit was held
but doing nothing, which is the number an operator of the machine cares
about.
The two trade off. A schedule that packs jobs tightly has low wastage but may delay a large job; one that clears large jobs first may leave qubits idle. Which matters depends on whether you are billing for the hardware or waiting on a result.
What comes back¶
from qndk.circuit.qiskit_circuits import QiskitCircuit
from qndk.transpile.transpile import TranspiledCircuit
from qndk.quantum_network import build_clos, QPUSpec
from qndk.partition.kl import KernighanLinPartitioner
from qndk.batchscheduler.batch_scheduler import QuantumBatchScheduler
network = build_clos(ports_per_switch=4, qpus_per_rack=2,
qpu_spec=QPUSpec(comp_qubits=4, connectivity="all2all"))
jobs = [{"id": f"job-{i}", "num_qubits": n,
"transpiled_circuit": TranspiledCircuit(
QiskitCircuit("qft", num_qubits=n))}
for i, n in enumerate((4, 6))]
scheduler = QuantumBatchScheduler(
network=network,
partitioner_fn=lambda c, n: KernighanLinPartitioner(c, n).partition())
out = scheduler.run_fifo_strict(jobs)
print("keys:", sorted(out))
for row in out["job_results"]:
print(f" {row['id']}: start={row['start_time']:.2f} "
f"finish={row['finish_time']:.2f} cost={row['execution_cost']:.2f}")
print(f"levels recorded : {len(out['levels'])}")
print(f"qubits tracked : {len(out['qubit_timeline'])}")
| Key | Contents |
|---|---|
total_execution_cost |
Makespan |
wastage_per_qubit |
Average idle time per qubit |
job_results |
Per-job start, finish and cost |
levels |
Time intervals with which jobs ran concurrently |
qubit_timeline |
Per-qubit list of (start, end, job_id) |
qubit_timeline is the raw material for utilization plots — see
analysis.
Real network metrics¶
By default the scheduler estimates job cost with a non_local_multiplier
applied to cross-QPU gates. To use real simulated network metrics instead,
pass job_schedule_fn — the adapter runs StaticScheduler per job and
returns its measurements:
from qndk.circuit.qiskit_circuits import QiskitCircuit
from qndk.transpile.transpile import TranspiledCircuit
from qndk.quantum_network import build_clos, QPUSpec
from qndk.partition.kl import KernighanLinPartitioner
from qndk.batchscheduler.batch_scheduler import QuantumBatchScheduler
from qndk.batchscheduler.job_schedule_adapter import job_schedule_adapter
network = build_clos(ports_per_switch=4, qpus_per_rack=2,
qpu_spec=QPUSpec(comp_qubits=4, connectivity="all2all"))
jobs = [{"id": f"job-{i}", "num_qubits": n,
"transpiled_circuit": TranspiledCircuit(
QiskitCircuit("qft", num_qubits=n))}
for i, n in enumerate((4, 6))]
scheduler = QuantumBatchScheduler(
network=network,
partitioner_fn=lambda c, n: KernighanLinPartitioner(c, n).partition(),
job_schedule_fn=job_schedule_adapter,
)
out = scheduler.run_fifo_strict(jobs)
print(f"with real network metrics: makespan="
f"{out['total_execution_cost']:.2f}")
The trade is accuracy for time: every job now runs a full simulation, so a long queue takes correspondingly longer to evaluate.
non_local_multiplier (default 10.0) is the knob on the cheap estimate —
how much more a cross-QPU gate costs than a local one.
Next¶
Feed the results to analysis, which turns a set of runs into dataframes and comparison plots.