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

Lightweight handle for one qubit inside a registry-managed state. More...

#include <q2ns-qubit.h>

Inheritance diagram for q2ns::Qubit:
Collaboration diagram for q2ns::Qubit:

Public Member Functions

 Qubit (QStateRegistry &registry, StateId stateId, unsigned int index, std::string label="")
 Construct a qubit handle bound to a registry, state id, and index.
 
QubitId GetQubitId () const
 Get the stable qubit id.
 
StateId GetStateId () const
 Get the current backend state id.
 
unsigned int GetIndexInState () const
 Get the current index within the backend state.
 
const std::string & GetLabel () const
 Get the application-level label.
 
void SetLabel (std::string label)
 Set the application-level label.
 
Location GetLocation () const
 Return the registry-tracked current location of this qubit.
 

Private Member Functions

void SetQubitId (QubitId id)
 Assign the stable qubit id.
 
void SetStateId (StateId stateId)
 Update the current backend state id.
 
void SetIndexInState (unsigned int index)
 Update the current index within the backend state.
 
void Rebind (StateId newStateId, std::size_t newIndex)
 Rebind this handle to a different state id and index.
 
void SetLocationNode (uint32_t nodeId)
 Mark this qubit as local to a node.
 
void SetLocationChannel (uint32_t channelId)
 Mark this qubit as in transit on a channel.
 
void SetLocationLost ()
 Mark this qubit as lost.
 

Private Attributes

QStateRegistryregistry_
 Backing state registry.
 
QubitId qubitId_ {0}
 Stable qubit id assigned by the registry.
 
StateId stateId_ {0}
 Current backend state id.
 
unsigned int indexInState_ {}
 Current zero-based index within the state.
 
std::string label_
 Optional human-readable label.
 

Friends

class QStateRegistry
 
class QProcessor
 
class QNetworker
 
class QMap
 

Detailed Description

Lightweight handle for one qubit inside a registry-managed state.

Qubit does not own the underlying QState. Instead, it stores:

  • a stable qubit id assigned by QStateRegistry
  • a state id identifying the current backend state
  • a zero-based index within that state
  • an optional human-readable label

Resolution of the underlying backend state and tracked location is performed through QStateRegistry.

Qubit is intentionally a lightweight handle object. Most user-facing operations are performed through QNode rather than directly through Qubit.

See also
QNode
QStateRegistry

Definition at line 48 of file q2ns-qubit.h.

Constructor & Destructor Documentation

◆ Qubit()

q2ns::Qubit::Qubit ( QStateRegistry registry,
StateId  stateId,
unsigned int  index,
std::string  label = "" 
)

Construct a qubit handle bound to a registry, state id, and index.

The stable qubit id is assigned later by QStateRegistry::Register().

Parameters
registryBacking state registry.
stateIdCurrent backend state id.
indexIndex within that backend state.
labelOptional human-readable qubit label.
See also
QStateRegistry::Register

Definition at line 29 of file q2ns-qubit.cc.

Member Function Documentation

◆ GetIndexInState()

unsigned int q2ns::Qubit::GetIndexInState ( ) const

Get the current index within the backend state.

Returns
Zero-based in-state index.

Definition at line 60 of file q2ns-qubit.cc.

References indexInState_.

◆ GetLabel()

const std::string & q2ns::Qubit::GetLabel ( ) const

Get the application-level label.

Returns
Label string, possibly empty.

Definition at line 72 of file q2ns-qubit.cc.

References label_.

◆ GetLocation()

Location q2ns::Qubit::GetLocation ( ) const

Return the registry-tracked current location of this qubit.

Returns
Current tracked location, or Unset if unknown.
See also
QStateRegistry::GetLocation

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

References q2ns::QStateRegistry::GetLocation(), qubitId_, and registry_.

Here is the call graph for this function:

◆ GetQubitId()

QubitId q2ns::Qubit::GetQubitId ( ) const

Get the stable qubit id.

Returns
Stable qubit id, or 0 if not yet registered.
See also
QStateRegistry::Register

Definition at line 36 of file q2ns-qubit.cc.

References qubitId_.

◆ GetStateId()

StateId q2ns::Qubit::GetStateId ( ) const

Get the current backend state id.

Returns
Current state id.

Definition at line 48 of file q2ns-qubit.cc.

References stateId_.

◆ Rebind()

void q2ns::Qubit::Rebind ( StateId  newStateId,
std::size_t  newIndex 
)
private

Rebind this handle to a different state id and index.

This is an internal helper used during state rewrites such as merging or splitting.

Parameters
newStateIdNew backend state id.
newIndexNew zero-based in-state index.

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

References indexInState_, and stateId_.

◆ SetIndexInState()

void q2ns::Qubit::SetIndexInState ( unsigned int  index)
private

Update the current index within the backend state.

Parameters
indexNew zero-based in-state index.

Definition at line 66 of file q2ns-qubit.cc.

References indexInState_.

◆ SetLabel()

void q2ns::Qubit::SetLabel ( std::string  label)

Set the application-level label.

Parameters
labelNew label string.

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

References label_.

◆ SetLocationChannel()

void q2ns::Qubit::SetLocationChannel ( uint32_t  channelId)
private

Mark this qubit as in transit on a channel.

Parameters
channelIdChannel id.

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

References q2ns::Channel, q2ns::QStateRegistry::GetLocation(), q2ns::Lost, qubitId_, registry_, and q2ns::QStateRegistry::SetLocation().

Here is the call graph for this function:

◆ SetLocationLost()

void q2ns::Qubit::SetLocationLost ( )
private

Mark this qubit as lost.

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

References q2ns::Lost, registry_, and q2ns::QStateRegistry::SetLocation().

Referenced by q2ns::QMap::SetLost_().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ SetLocationNode()

void q2ns::Qubit::SetLocationNode ( uint32_t  nodeId)
private

Mark this qubit as local to a node.

Parameters
nodeIdOwning node id.

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

References q2ns::QStateRegistry::GetLocation(), q2ns::Lost, q2ns::Node, qubitId_, registry_, and q2ns::QStateRegistry::SetLocation().

Here is the call graph for this function:

◆ SetQubitId()

void q2ns::Qubit::SetQubitId ( QubitId  id)
private

Assign the stable qubit id.

Parameters
idStable qubit id.
See also
QStateRegistry::Register

Definition at line 42 of file q2ns-qubit.cc.

References qubitId_.

◆ SetStateId()

void q2ns::Qubit::SetStateId ( StateId  stateId)
private

Update the current backend state id.

Parameters
stateIdNew state id.

Definition at line 54 of file q2ns-qubit.cc.

References stateId_.

Friends And Related Symbol Documentation

◆ QMap

friend class QMap
friend

Definition at line 163 of file q2ns-qubit.h.

◆ QNetworker

friend class QNetworker
friend

Definition at line 162 of file q2ns-qubit.h.

◆ QProcessor

friend class QProcessor
friend

Definition at line 161 of file q2ns-qubit.h.

◆ QStateRegistry

friend class QStateRegistry
friend

Definition at line 160 of file q2ns-qubit.h.

Member Data Documentation

◆ indexInState_

unsigned int q2ns::Qubit::indexInState_ {}
private

Current zero-based index within the state.

Definition at line 157 of file q2ns-qubit.h.

Referenced by GetIndexInState(), Rebind(), and SetIndexInState().

◆ label_

std::string q2ns::Qubit::label_
private

Optional human-readable label.

Definition at line 158 of file q2ns-qubit.h.

Referenced by GetLabel(), and SetLabel().

◆ qubitId_

QubitId q2ns::Qubit::qubitId_ {0}
private

Stable qubit id assigned by the registry.

Definition at line 155 of file q2ns-qubit.h.

Referenced by GetLocation(), GetQubitId(), SetLocationChannel(), SetLocationNode(), and SetQubitId().

◆ registry_

QStateRegistry& q2ns::Qubit::registry_
private

Backing state registry.

Definition at line 153 of file q2ns-qubit.h.

Referenced by GetLocation(), SetLocationChannel(), SetLocationLost(), and SetLocationNode().

◆ stateId_

StateId q2ns::Qubit::stateId_ {0}
private

Current backend state id.

Definition at line 156 of file q2ns-qubit.h.

Referenced by GetStateId(), Rebind(), and SetStateId().


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