Tutorial 4 — Built-in Topology Generators
Objective: Generate and inspect three pre-built topology templates to understand qnet-core's ready-made network configurations.
qnet-core ships with generate_topology() — a factory function that creates realistic network topologies programmatically. This saves you from manually defining every node and link.
Generate All Three Topologies
from qnet_core import QNetEngine, generate_topology
for name in ("telecom_backbone", "repeater_chain", "hybrid_satellite_fiber"):
print(f"\n=== {name} ===")
payload = generate_topology(name)
print(f" Nodes ({len(payload.nodes)}): {[n.id for n in payload.nodes]}")
print(f" Links ({len(payload.links)}):")
for link in payload.links:
link_type = getattr(link.link_type, "_name", "Fiber") or "Fiber"
extra = ""
if hasattr(link, "satellite_conditions") and link.satellite_conditions:
cond = link.satellite_conditions
extra = f" [satellite vis={cond.visibility:.1f} weather={cond.weather_factor:.1f}]"
print(f" {link.from_node} → {link.to}: {link.distance_km:.0f} km, "
f"fidelity={link.base_fidelity:.2f}, rate={link.generation_rate_hz:.0f} Hz{extra}")
Topology Reference
| Name | Type | Description |
|---|---|---|
telecom_backbone | Mesh fiber network | Urban telecom-style mesh with intermediate repeaters, mimicking real fiber backbone layouts |
repeater_chain | Linear chain (4 hops) | Point-to-point repeater chain — ideal for testing purification across multiple segments |
hybrid_satellite_fiber | Satellite + fiber mix | Hybrid network with a satellite uplink and fiber ground segments |
Use a Generated Topology in Simulation
engine = QNetEngine()
payload = generate_topology("telecom_backbone")
engine.define_network(payload.nodes, payload.links)
nodes_ids = [n.id for n in payload.nodes]
if len(nodes_ids) >= 2:
stats = engine.simulate(
from_node=nodes_ids[0],
to=nodes_ids[-1],
fidelity_target=0.85,
max_latency_ms=10_000.0,
runs=100,
seed=42,
)
print(f"Success rate: {stats.empirical_success_rate:.1%}")
print(f"Mean latency: {stats.mean_latency_ms:.1f} ms")
print(f"Mean fidelity: {stats.mean_fidelity:.4f}")
What's next
- Satellite-Fiber Links — explore satellite conditions in detail
- Basic Entanglement Request — manual topology definition