Getting Started¶
Two complete runs from an empty file. The first is the NISQ path — split a circuit across QPUs and see what the network cost. The second is the fault-tolerant path — do the same thing to error-corrected logical qubits and get a logical error rate out.
1. A first distributed run¶
Four steps: load a circuit, build a network, split the circuit across it, simulate.
from qndk.circuit.qiskit_circuits import QiskitCircuit
from qndk.quantum_network import build_clos, QPUSpec
from qndk.partition.kl import KernighanLinPartitioner
from qndk.simulator.dqc import DQCScheduler
# 1. a circuit -- 8-qubit QFT from the built-in library
circuit = QiskitCircuit("qft", num_qubits=8)
# 2. a network small enough that the circuit cannot fit on one QPU.
# 4 comp qubits per QPU x 4 QPUs = 16 qubits for an 8-qubit circuit,
# so the partitioner has to spread it and the gates that cross a QPU
# boundary become network operations.
network = build_clos(
ports_per_switch=4,
qpus_per_rack=1,
qpu_spec=QPUSpec(comp_qubits=4, connectivity="all2all"),
)
# 3. decide which circuit qubit lives on which QPU
partition = KernighanLinPartitioner(circuit, network).partition()
# 4. step it through the network
result = DQCScheduler(partition).run_simulation()
counts = result.gate_counts()
print(f"qpus : {len(network.qpu_ids())}")
print(f"local gates : {counts['num_local']}")
print(f"remote gates : {counts['num_remote']}")
print(f"epr cost : {result.epr_cost()}")
print(f"finish time : {result.final_timestep:.4f} ms")
The four numbers at the end are the whole point:
- local gates ran inside one QPU and cost only gate time.
- remote gates crossed a QPU boundary. Each one needed an entangled pair delivered over the network first.
- epr cost is how many entangled pairs the run consumed. This is the headline resource number, and it is a direct consequence of the partitioning decision.
- finish time is the makespan in milliseconds, including every stall where a gate waited for entanglement or for a busy switch.
Change one thing¶
Give each QPU enough room for the whole circuit and the network work disappears:
from qndk.circuit.qiskit_circuits import QiskitCircuit
from qndk.quantum_network import build_clos, QPUSpec
from qndk.partition.kl import KernighanLinPartitioner
from qndk.simulator.dqc import DQCScheduler
circuit = QiskitCircuit("qft", num_qubits=8)
for comp_qubits in (4, 8):
network = build_clos(
ports_per_switch=4, qpus_per_rack=1,
qpu_spec=QPUSpec(comp_qubits=comp_qubits, connectivity="all2all"),
)
partition = KernighanLinPartitioner(circuit, network).partition()
result = DQCScheduler(partition).run_simulation()
counts = result.gate_counts()
print(f"{comp_qubits} comp qubits/qpu -> "
f"{counts['num_remote']:3d} remote gates, "
f"epr {result.epr_cost():3d}, "
f"{result.final_timestep:.4f} ms")
That comparison — same circuit, one hardware parameter changed — is the basic experimental loop the SDK is built around.
2. Seeing what happened¶
A SimulationResult carries the full event log, not just totals.
from qndk.circuit.qiskit_circuits import QiskitCircuit
from qndk.quantum_network import build_clos, QPUSpec
from qndk.partition.kl import KernighanLinPartitioner
from qndk.simulator.dqc import DQCScheduler
circuit = QiskitCircuit("qft", num_qubits=8)
network = build_clos(ports_per_switch=4, qpus_per_rack=1,
qpu_spec=QPUSpec(comp_qubits=4, connectivity="all2all"))
partition = KernighanLinPartitioner(circuit, network).partition()
result = DQCScheduler(partition).run_simulation()
# a text summary of every event type, counts and durations
print(result.execution_log_summary_table())
# how many Bell-state measurements each switch spent, per timestep
for row in result.bsm_usage_per_step()[:5]:
print(row)
Plots come off the objects that own the data rather than from loose matplotlib code:
# fragment: opens windows; needs Graphviz
result.plot() # timeline overview
result.plot_gantt() # per-device Gantt chart
result.plot_bsms_used_per_timestep() # switch contention over time
network.plot(partition_result=partition) # the split, drawn on the topology
3. The fault-tolerant path¶
Same shape, different entry point. Instead of a partitioner, call
fault_tolerant_encode(): it rewrites T gates into magic-state
consumptions, lays each logical qubit out as a surface-code patch, and
hands back a PartitionResult the simulator accepts as normal.
from qndk.circuit.qiskit_circuits import QiskitCircuit
from qndk.quantum_network import build_clos, QPUSpec
from qndk.simulator.dqc import DQCScheduler
from qndk.quantum_error_correction import (
fault_tolerant_encode, tler, SurfaceCode, FixedIdleEpr)
circuit = QiskitCircuit("tfim", num_qubits=10,
num_trotter_steps=1).circuit
circuit.t(4) # one T gate -> one magic state to consume
# num_magic_factories is required for the fault-tolerant path: T gates are
# implemented by consuming a magic state, and a magic state has to come
# from a factory QPU that actually exists on the network.
network = build_clos(
ports_per_switch=4,
qpus_per_rack=1,
qpu_spec=QPUSpec(comp_qubits=4, connectivity="all2all"),
num_magic_factories=1,
)
code = SurfaceCode(d=15)
partition = fault_tolerant_encode(circuit, network, code=code,
num_ancilla=1)
result = DQCScheduler(partition).run_simulation()
# the same `code` object goes to the encode stage and the pricing stage,
# so both describe the same physics
budget = tler(result, code=code, epr=FixedIdleEpr(k_idle=4))
print(f"total {budget.total[0]:.3e}")
print(f" local {budget.local[0]:.3e}")
print(f" remote {budget.remote[0]:.3e}")
print(f" mem {budget.mem[0]:.3e}")
print(f" magic {budget.magic[0]:.3e}")
print(budget.validity()["summary"])
tler() returns a Total Logical Error Rate: the probability the
computation's answer is wrong, broken into the four places error comes
from. budget.total is an array over a sweep of physical error rates, so
[0] is the value at the lowest one. See
quantum_error_correction for
what each term means and why the split matters.
d is not free
SurfaceCode(d=15) means every logical qubit is a 15×15 patch. The
layout stage does not multiply your qubit count by 225 — one network
compute qubit represents one logical qubit regardless of d — but the
error budget prices the real cost. Raising d past the point where
magic states dominate buys nothing at all; the
QEC page shows where
that point is.
4. Choosing the pieces¶
Each stage has interchangeable implementations. The defaults are reasonable; these are the axes to vary.
| Decision | Options | Default |
|---|---|---|
| Topology | build_clos, build_fattree, build_bcube, build_qfly |
none — pick one |
| QPU internal wiring | QPUSpec(connectivity="grid4") or "all2all" |
"grid4" |
| Switch model | SwitchSpec(model="generic") or "cisco" |
"generic" |
| Partitioner | KernighanLinPartitioner, MetisPartitioner, WindowBasedCircuitPartitioner |
— |
| Simulator | StaticScheduler, DynamicScheduler, DQCScheduler |
— |
| EPR delivery model | FixedIdleEpr, PoissonEpr |
FixedIdleEpr(k_idle=4) |
grid4 is the realistic choice — real hardware is overwhelmingly
nearest-neighbour constrained, and grid4 makes the simulator account for
the SWAPs needed to route around that. all2all is the optimistic baseline,
useful when you want to isolate network effects from internal routing.
Next: Concepts for the vocabulary, or Examples to skip ahead to worked problems.