![]() |
Q2NS dev
ns-3 module
|
Main user-facing facade for creating and configuring a quantum network. More...
#include <q2ns-netcontroller.h>
Public Member Functions | |
| NetController () | |
| Default constructor. | |
| QStateRegistry & | GetRegistry () |
| Access the shared state registry. | |
| void | SetQStateBackend (QStateBackend b) |
| Set the default backend used for newly created quantum states. | |
| void | SetQStateBackend (std::string_view name) |
| Set the default backend by name. | |
| QStateBackend | GetQStateBackend () |
| Get the current default backend. | |
| int64_t | AssignStreams (int64_t stream) |
| Assign RNG streams to q2ns-owned random sources. | |
| ns3::Ptr< QNode > | CreateNode (const std::string &label="") |
| Create a QNode with an optional human-readable label. | |
| ns3::Ptr< QNode > | GetNode (uint32_t nodeId) |
| Return the QNode associated with a node id. | |
| ns3::Ptr< QChannel > | InstallQuantumLink (ns3::Ptr< QNode > a, ns3::Ptr< QNode > b) |
| Install a duplex quantum link between two nodes. | |
| std::vector< ns3::Ptr< QChannel > > | InstallQuantumChain (const std::vector< ns3::Ptr< QNode > > &nodes) |
| Connect a sequence of nodes as a linear chain. | |
| std::vector< ns3::Ptr< QChannel > > | InstallQuantumAllToAll (const std::vector< ns3::Ptr< QNode > > &nodes) |
| Connect a set of nodes with all-to-all quantum links. | |
| ns3::Ptr< QChannel > | GetChannel (ns3::Ptr< QNode > a, ns3::Ptr< QNode > b) |
| Return the QChannel connecting two nodes. | |
| std::shared_ptr< QState > | GetState (const std::shared_ptr< Qubit > &q) const |
| Convenience helper to get a qubit's current backend state. | |
Private Member Functions | |
| void | EnsureStreamsAssigned_ () |
| Ensure RNG streams have been assigned before simulation activity begins. | |
Private Attributes | |
| bool | streamsAssigned_ = false |
| True once AssignStreams has been called. | |
| int64_t | nextStream_ = 0 |
| Next stream index to assign. | |
| QStateRegistry | registry_ |
| Shared state registry. | |
| std::unordered_map< uint32_t, ns3::Ptr< QNode > > | nodes_ |
| Node id to QNode map. | |
| std::map< std::pair< uint32_t, uint32_t >, ns3::Ptr< QChannel > > | channels_ |
| Undirected link map keyed by sorted endpoint ids. | |
Main user-facing facade for creating and configuring a quantum network.
NetController owns the shared QStateRegistry used by the q2ns network and provides convenience helpers to create QNodes, install QChannels, and query network objects by node or link.
Qubit creation and manipulation are normally performed through QNode. In contrast, NetController is primarily responsible for topology construction, shared configuration, and deterministic RNG stream assignment.
Responsibilities:
Definition at line 65 of file q2ns-netcontroller.h.
| q2ns::NetController::NetController | ( | ) |
Default constructor.
Definition at line 38 of file q2ns-netcontroller.cc.
References q2ns::QState::AssignStreams(), EnsureStreamsAssigned_(), nextStream_, registry_, q2ns::QStateRegistry::SetStreamAssigner(), and streamsAssigned_.
| int64_t q2ns::NetController::AssignStreams | ( | int64_t | stream | ) |
Assign RNG streams to q2ns-owned random sources.
This method should normally be called after the topology has been built and before the simulation is run. Streams are assigned deterministically from the provided starting index.
| stream | Starting stream index. |
Definition at line 54 of file q2ns-netcontroller.cc.
References channels_, q2ns::QStateRegistry::GetStatesSortedById(), nextStream_, registry_, and streamsAssigned_.
Referenced by EnsureStreamsAssigned_().
| ns3::Ptr< QNode > q2ns::NetController::CreateNode | ( | const std::string & | label = "" | ) |
Create a QNode with an optional human-readable label.
The node is registered internally and bound to this controller's shared QStateRegistry.
| label | Optional human-readable label. |
Definition at line 109 of file q2ns-netcontroller.cc.
References nodes_, and registry_.
Referenced by q2ns::TeleportationHelper::BuildNodes(), main(), main(), main(), main(), anonymous_namespace{q2ns-5-noisy-teleportation-advanced-example.cc}::RunOnce(), anonymous_namespace{q2ns-5-noisy-teleportation-example.cc}::RunOnce(), and anonymous_namespace{q2ns-4-multipartite-scaling-example.cc}::RunOnce().
|
private |
Ensure RNG streams have been assigned before simulation activity begins.
This is used as an internal safety net so q2ns behaves deterministically even if the user calls ns3::Simulator::Run() directly instead of going through a controller-owned wrapper.
Definition at line 85 of file q2ns-netcontroller.cc.
References AssignStreams(), and streamsAssigned_.
Referenced by NetController().
Return the QChannel connecting two nodes.
| a | One endpoint node. |
| b | The other endpoint node. |
Definition at line 242 of file q2ns-netcontroller.cc.
References channels_.
| ns3::Ptr< QNode > q2ns::NetController::GetNode | ( | uint32_t | nodeId | ) |
Return the QNode associated with a node id.
| nodeId | Desired node identifier. |
Definition at line 122 of file q2ns-netcontroller.cc.
References nodes_.
| QStateBackend q2ns::NetController::GetQStateBackend | ( | ) |
Get the current default backend.
Definition at line 105 of file q2ns-netcontroller.cc.
References q2ns::QStateRegistry::GetDefaultBackend(), and registry_.
| QStateRegistry & q2ns::NetController::GetRegistry | ( | ) |
Access the shared state registry.
Definition at line 93 of file q2ns-netcontroller.cc.
References registry_.
Convenience helper to get a qubit's current backend state.
| q | Target qubit. |
Definition at line 261 of file q2ns-netcontroller.cc.
References q2ns::QStateRegistry::GetState(), and registry_.
Referenced by main(), main(), anonymous_namespace{q2ns-5-noisy-teleportation-example.cc}::TryCorrections(), and anonymous_namespace{q2ns-5-noisy-teleportation-advanced-example.cc}::TryCorrections().
| std::vector< ns3::Ptr< QChannel > > q2ns::NetController::InstallQuantumAllToAll | ( | const std::vector< ns3::Ptr< QNode > > & | nodes | ) |
Connect a set of nodes with all-to-all quantum links.
For N nodes, this installs one link for every unordered node pair. Existing links are left unchanged and their existing channel pointers are returned in the corresponding positions.
| nodes | Node set. |
Definition at line 203 of file q2ns-netcontroller.cc.
References InstallQuantumLink().
| std::vector< ns3::Ptr< QChannel > > q2ns::NetController::InstallQuantumChain | ( | const std::vector< ns3::Ptr< QNode > > & | nodes | ) |
Connect a sequence of nodes as a linear chain.
For a sequence n0, n1, ..., n{k-1}, this installs links (n0,n1), (n1,n2), ..., (n{k-2},n{k-1}).
Existing links are left unchanged and their existing channel pointers are returned in the corresponding positions.
| nodes | Ordered node sequence. |
Definition at line 172 of file q2ns-netcontroller.cc.
References InstallQuantumLink().
| ns3::Ptr< QChannel > q2ns::NetController::InstallQuantumLink | ( | ns3::Ptr< QNode > | a, |
| ns3::Ptr< QNode > | b | ||
| ) |
Install a duplex quantum link between two nodes.
This method creates two QNetDevice instances and one QChannel, attaches one device to each node, and installs per-destination host routes so each node can send to the other over the created link.
| a | First endpoint node. |
| b | Second endpoint node. |
Definition at line 131 of file q2ns-netcontroller.cc.
References channels_, nextStream_, and streamsAssigned_.
Referenced by q2ns::EntanglementSwapHelper::BuildQuantum(), q2ns::TeleportationHelper::BuildQuantum(), InstallQuantumAllToAll(), InstallQuantumChain(), main(), main(), main(), main(), anonymous_namespace{q2ns-5-noisy-teleportation-advanced-example.cc}::RunOnce(), anonymous_namespace{q2ns-5-noisy-teleportation-example.cc}::RunOnce(), and anonymous_namespace{q2ns-4-multipartite-scaling-example.cc}::RunOnce().
| void q2ns::NetController::SetQStateBackend | ( | QStateBackend | b | ) |
Set the default backend used for newly created quantum states.
| b | Backend enum value. |
Definition at line 97 of file q2ns-netcontroller.cc.
References registry_, and q2ns::QStateRegistry::SetDefaultBackend().
Referenced by main(), main(), main(), anonymous_namespace{q2ns-5-noisy-teleportation-advanced-example.cc}::RunOnce(), anonymous_namespace{q2ns-5-noisy-teleportation-example.cc}::RunOnce(), and anonymous_namespace{q2ns-4-multipartite-scaling-example.cc}::RunOnce().
| void q2ns::NetController::SetQStateBackend | ( | std::string_view | name | ) |
Set the default backend by name.
This is a convenience overload intended for CLI or configuration use.
| name | Backend name such as "ket", "dm", or "stab". |
Definition at line 101 of file q2ns-netcontroller.cc.
References q2ns::BackendFromString(), registry_, and q2ns::QStateRegistry::SetDefaultBackend().
|
private |
Undirected link map keyed by sorted endpoint ids.
Definition at line 224 of file q2ns-netcontroller.h.
Referenced by AssignStreams(), GetChannel(), and InstallQuantumLink().
|
private |
Next stream index to assign.
Definition at line 219 of file q2ns-netcontroller.h.
Referenced by AssignStreams(), InstallQuantumLink(), and NetController().
|
private |
Node id to QNode map.
Definition at line 222 of file q2ns-netcontroller.h.
Referenced by CreateNode(), and GetNode().
|
private |
Shared state registry.
Definition at line 221 of file q2ns-netcontroller.h.
Referenced by AssignStreams(), CreateNode(), GetQStateBackend(), GetRegistry(), GetState(), NetController(), SetQStateBackend(), and SetQStateBackend().
|
private |
True once AssignStreams has been called.
Definition at line 218 of file q2ns-netcontroller.h.
Referenced by AssignStreams(), EnsureStreamsAssigned_(), InstallQuantumLink(), and NetController().