Q2NS dev
ns-3 module
Loading...
Searching...
No Matches
q2ns::QNode Class Reference

Main user-facing per-node API for quantum operations and transmission. More...

#include <q2ns-qnode.h>

Inheritance diagram for q2ns::QNode:
Collaboration diagram for q2ns::QNode:

Public Member Functions

 QNode (QStateRegistry &registry)
 Construct a node bound to a shared state registry.
 
 ~QNode () override
 Destructor.
 
std::shared_ptr< QubitGetQubit (const std::string &label) const
 Lookup a local qubit by application label.
 
std::shared_ptr< QubitGetQubit (QubitId id) const
 Lookup a local qubit by unique identifier.
 
std::vector< std::shared_ptr< Qubit > > GetLocalQubits () const
 Return the qubits currently located at this node.
 
void AddDevice (ns3::Ptr< ns3::NetDevice > device)
 Register a device with this node.
 
void AddRoute (uint32_t dstNodeId, uint32_t oif)
 Add or replace a simple host route for quantum transmission.
 
bool Send (std::shared_ptr< Qubit > q, uint32_t dstNodeId)
 Send a qubit toward a destination node.
 
void SetRecvCallback (RecvCallback cb)
 Set the application-level receive callback.
 
std::shared_ptr< QubitCreateQubit (const std::string &label="")
 Create a new local qubit initialized in the |0> state.
 
std::shared_ptr< QubitCreateQubit (const std::shared_ptr< QState > &state, const std::string &label="")
 Create a new local qubit from an existing single-qubit backend state.
 
std::pair< std::shared_ptr< Qubit >, std::shared_ptr< Qubit > > CreateBellPair ()
 Create a local Bell pair in the |Phi+> state.
 
std::shared_ptr< QStateGetState (const std::shared_ptr< Qubit > &q)
 Get the current backend state of a qubit.
 
bool Apply (const QGate &gate, const std::vector< std::shared_ptr< Qubit > > &qs)
 Apply a gate to one or more local qubits.
 
bool Apply (const q2ns::Matrix &gate, const std::vector< std::shared_ptr< Qubit > > &qs)
 Apply a custom matrix gate to one or more local qubits.
 
int Measure (const std::shared_ptr< Qubit > &q, q2ns::Basis basis=q2ns::Basis::Z)
 Measure a local qubit in the given basis.
 
std::pair< int, int > MeasureBell (const std::shared_ptr< Qubit > &a, const std::shared_ptr< Qubit > &b)
 Perform a Bell-state measurement on two local qubits.
 

Static Public Member Functions

static ns3::TypeId GetTypeId (void)
 Get the ns-3 TypeId.
 

Private Member Functions

void AdoptQubit (const std::shared_ptr< Qubit > &q)
 Mark a qubit as local to this node.
 

Private Attributes

QStateRegistryregistry_
 Shared state registry.
 
std::unique_ptr< QProcessorprocessor_
 Internal local quantum processor.
 
std::unique_ptr< QNetworkernetworker_
 Internal networking component.
 

Friends

class NetController
 
class QNetworker
 

Detailed Description

Main user-facing per-node API for quantum operations and transmission.

QNode is the primary interface through which users create qubits, apply local operations, perform measurements, and send qubits to other nodes.

Internally, QNode delegates local quantum state manipulation to QProcessor and network-facing transmission and reception to QNetworker. These internal components operate against a shared QStateRegistry.

Responsibilities:

  • Provide user-facing helpers for qubit creation, lookup, measurement, entanglement, and gate application.
  • Own an internal QProcessor for local quantum operations.
  • Own an internal QNetworker for transmission and reception.
  • Integrate quantum devices with the underlying ns-3 Node device model.
See also
QProcessor
QNetworker

Definition at line 63 of file q2ns-qnode.h.

Constructor & Destructor Documentation

◆ QNode()

q2ns::QNode::QNode ( QStateRegistry registry)
explicit

Construct a node bound to a shared state registry.

Parameters
registryRegistry used for state and location tracking.

Definition at line 34 of file q2ns-qnode.cc.

◆ ~QNode()

q2ns::QNode::~QNode ( )
overridedefault

Destructor.

Member Function Documentation

◆ AddDevice()

void q2ns::QNode::AddDevice ( ns3::Ptr< ns3::NetDevice >  device)

Register a device with this node.

The device is added to the underlying ns-3 Node. If the device is a QNetDevice, it is also bound to this node's internal QNetworker so that quantum arrivals are forwarded upward correctly.

Parameters
deviceDevice to add.
See also
QNetDevice
AddRoute

Definition at line 50 of file q2ns-qnode.cc.

References networker_.

◆ AddRoute()

void q2ns::QNode::AddRoute ( uint32_t  dstNodeId,
uint32_t  oif 
)

Add or replace a simple host route for quantum transmission.

The route maps a destination node id to an outgoing interface index in the internal QNetworker.

Parameters
dstNodeIdDestination node identifier.
oifOutgoing interface index.
See also
Send

Definition at line 44 of file q2ns-qnode.cc.

References networker_.

◆ AdoptQubit()

void q2ns::QNode::AdoptQubit ( const std::shared_ptr< Qubit > &  q)
private

Mark a qubit as local to this node.

This is an internal helper used by the receive path. Locality is tracked centrally by QStateRegistry through QProcessor.

Parameters
qQubit handle.

Definition at line 145 of file q2ns-qnode.cc.

References processor_.

Referenced by q2ns::QNetworker::ReceiveFromDevice().

Here is the caller graph for this function:

◆ Apply() [1/2]

bool q2ns::QNode::Apply ( const q2ns::Matrix gate,
const std::vector< std::shared_ptr< Qubit > > &  qs 
)

Apply a custom matrix gate to one or more local qubits.

Parameters
gateGate matrix to wrap as a custom gate.
qsTarget qubits.
Returns
True if the gate was applied successfully, false otherwise.
See also
Apply(const QGate&, const std::vector<std::shared_ptr<Qubit>>&)

Definition at line 114 of file q2ns-qnode.cc.

References Apply(), and q2ns::gates::Custom().

Here is the call graph for this function:

◆ Apply() [2/2]

bool q2ns::QNode::Apply ( const QGate gate,
const std::vector< std::shared_ptr< Qubit > > &  qs 
)

Apply a gate to one or more local qubits.

Parameters
gateGate to apply.
qsTarget qubits.
Returns
True if the gate was applied successfully, false otherwise.
See also
Apply(const q2ns::Matrix&, const std::vector<std::shared_ptr<Qubit>>&)

Definition at line 108 of file q2ns-qnode.cc.

References processor_.

Referenced by Apply(), main(), and q2ns::DephasingQMap::Sample().

Here is the caller graph for this function:

◆ CreateBellPair()

std::pair< std::shared_ptr< Qubit >, std::shared_ptr< Qubit > > q2ns::QNode::CreateBellPair ( )

Create a local Bell pair in the |Phi+> state.

Returns
Pair of local qubits {q0, q1}.

Definition at line 96 of file q2ns-qnode.cc.

References processor_.

◆ CreateQubit() [1/2]

std::shared_ptr< Qubit > q2ns::QNode::CreateQubit ( const std::shared_ptr< QState > &  state,
const std::string &  label = "" 
)

Create a new local qubit from an existing single-qubit backend state.

Parameters
stateBackend state to use for the created qubit.
labelOptional application-level qubit label.
Returns
Shared pointer to the new qubit, or nullptr if state is null.
See also
CreateQubit(const std::string&)

Definition at line 71 of file q2ns-qnode.cc.

References processor_.

◆ CreateQubit() [2/2]

std::shared_ptr< Qubit > q2ns::QNode::CreateQubit ( const std::string &  label = "")

Create a new local qubit initialized in the |0> state.

Parameters
labelOptional application-level qubit label.
Returns
Shared pointer to the new qubit.

Definition at line 65 of file q2ns-qnode.cc.

References processor_.

◆ GetLocalQubits()

std::vector< std::shared_ptr< Qubit > > q2ns::QNode::GetLocalQubits ( ) const

Return the qubits currently located at this node.

The returned vector is a snapshot taken at call time. No stable internal container is exposed, and element order is not guaranteed.

Returns
Snapshot of qubit handles currently local to this node.

Definition at line 90 of file q2ns-qnode.cc.

References processor_.

◆ GetQubit() [1/2]

std::shared_ptr< Qubit > q2ns::QNode::GetQubit ( const std::string &  label) const

Lookup a local qubit by application label.

Labels are optional and need not be unique. Prefer GetQubit(QubitId) when a stable unique identifier is available.

Parameters
labelApplication-level qubit label.
Returns
Matching local qubit, or nullptr if no local match is found.
See also
GetQubit(QubitId)

Definition at line 78 of file q2ns-qnode.cc.

References processor_.

◆ GetQubit() [2/2]

std::shared_ptr< Qubit > q2ns::QNode::GetQubit ( QubitId  id) const

Lookup a local qubit by unique identifier.

Parameters
idQubit identifier.
Returns
Matching local qubit, or nullptr if the qubit is not local or does not exist.
See also
GetQubit(const std::string&)

Definition at line 84 of file q2ns-qnode.cc.

References processor_.

◆ GetState()

std::shared_ptr< QState > q2ns::QNode::GetState ( const std::shared_ptr< Qubit > &  q)

Get the current backend state of a qubit.

Parameters
qTarget qubit.
Returns
Shared pointer to the current backend state, or nullptr if the qubit is null or unknown to the registry.

Definition at line 102 of file q2ns-qnode.cc.

References processor_.

◆ GetTypeId()

ns3::TypeId q2ns::QNode::GetTypeId ( void  )
static

Get the ns-3 TypeId.

Returns
TypeId for q2ns::QNode.

Definition at line 27 of file q2ns-qnode.cc.

◆ Measure()

int q2ns::QNode::Measure ( const std::shared_ptr< Qubit > &  q,
q2ns::Basis  basis = q2ns::Basis::Z 
)

Measure a local qubit in the given basis.

Parameters
qTarget qubit.
basisMeasurement basis. Defaults to q2ns::Basis::Z.
Returns
Classical outcome bit (0 or 1), or -1 if the measurement is rejected.
See also
MeasureBell

Definition at line 120 of file q2ns-qnode.cc.

References processor_.

◆ MeasureBell()

std::pair< int, int > q2ns::QNode::MeasureBell ( const std::shared_ptr< Qubit > &  a,
const std::shared_ptr< Qubit > &  b 
)

Perform a Bell-state measurement on two local qubits.

Parameters
aFirst qubit.
bSecond qubit.
Returns
Pair of classical outcomes {mZZ, mXX}, or {-1, -1} if the operation is rejected.
See also
Measure
QProcessor::MeasureBell

Definition at line 126 of file q2ns-qnode.cc.

References processor_.

◆ Send()

bool q2ns::QNode::Send ( std::shared_ptr< Qubit q,
uint32_t  dstNodeId 
)

Send a qubit toward a destination node.

The qubit must be local to this node and a valid route must exist to the destination node.

Parameters
qQubit to send.
dstNodeIdDestination node identifier.
Returns
True if the send request was accepted, false otherwise.
See also
AddRoute
SetRecvCallback

Definition at line 133 of file q2ns-qnode.cc.

References networker_.

◆ SetRecvCallback()

void q2ns::QNode::SetRecvCallback ( RecvCallback  cb)

Set the application-level receive callback.

The callback is invoked for qubits successfully delivered to this node after destination-side adoption and channel-map processing.

Parameters
cbCallback invoked with the arriving qubit.
See also
Send

Definition at line 139 of file q2ns-qnode.cc.

References networker_.

Friends And Related Symbol Documentation

◆ NetController

friend class NetController
friend

Definition at line 259 of file q2ns-qnode.h.

◆ QNetworker

friend class QNetworker
friend

Definition at line 260 of file q2ns-qnode.h.

Member Data Documentation

◆ networker_

std::unique_ptr<QNetworker> q2ns::QNode::networker_
private

Internal networking component.

Definition at line 257 of file q2ns-qnode.h.

Referenced by AddDevice(), AddRoute(), Send(), and SetRecvCallback().

◆ processor_

std::unique_ptr<QProcessor> q2ns::QNode::processor_
private

Internal local quantum processor.

Definition at line 256 of file q2ns-qnode.h.

Referenced by AdoptQubit(), Apply(), CreateBellPair(), CreateQubit(), CreateQubit(), GetLocalQubits(), GetQubit(), GetQubit(), GetState(), Measure(), and MeasureBell().

◆ registry_

QStateRegistry& q2ns::QNode::registry_
private

Shared state registry.

Definition at line 255 of file q2ns-qnode.h.


The documentation for this class was generated from the following files: