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

Internal helper owned by a QNode to handle local quantum operations. More...

#include <q2ns-qprocessor.h>

Collaboration diagram for q2ns::QProcessor:

Public Member Functions

 QProcessor (QStateRegistry &registry, QNode &owner)
 Construct a processor bound to a registry and owning node.
 
const QNodeGetOwnerNode () const
 Get owning node.
 
std::shared_ptr< QubitCreateQubit (const std::string &label="")
 Create a new local qubit in |0>.
 
std::shared_ptr< QubitCreateQubit (const std::shared_ptr< QState > &state, const std::string &label="")
 Create a new local qubit handle in the given state.
 
std::pair< std::shared_ptr< Qubit >, std::shared_ptr< Qubit > > CreateBellPair ()
 Create a local Bell pair in |Phi+>
 
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 the owning node.
 
void AdoptQubit (const std::shared_ptr< Qubit > &q)
 Adopt a qubit into this processor's owning node.
 
std::shared_ptr< QStateGetState (const std::shared_ptr< Qubit > &q) const
 Get the current state of the qubit.
 
bool Apply (const QGate &gate, const std::vector< std::shared_ptr< Qubit > > &qs)
 Apply a gate to one or more local qubits.
 
int Measure (const std::shared_ptr< Qubit > &qubit, q2ns::Basis basis=q2ns::Basis::Z)
 Measure a single, local qubit in the given basis (default Z).
 
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.
 

Private Attributes

QStateRegistryregistry_
 Quantum state registry.
 
QNodeowner_
 Owning QNode.
 

Detailed Description

Internal helper owned by a QNode to handle local quantum operations.

QProcessor is not intended to be the main user-facing API. Instead, users should use QNode, which will internally delegate to QProcessor where necessary.

Responsibilities:

  • Create and adopt qubit handles associated with the owning node (via registry location).
  • Enforce locality checks for operations intended to be local to the owning node.
  • Delegate gates, measurement, and state merging/splitting to QStateRegistry and QState.

QProcessor does not own a persistent local-qubit container; locality is tracked centrally and only by QStateRegistry.

Definition at line 49 of file q2ns-qprocessor.h.

Constructor & Destructor Documentation

◆ QProcessor()

q2ns::QProcessor::QProcessor ( QStateRegistry registry,
QNode owner 
)

Construct a processor bound to a registry and owning node.

Parameters
registryReference to the global quantum state registry.
ownerReference to the owning node.

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

Member Function Documentation

◆ AdoptQubit()

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

Adopt a qubit into this processor's owning node.

Adoption updates the qubit's registry-authoritative location to the owning node.

Parameters
qQubit handle.

Definition at line 143 of file q2ns-qprocessor.cc.

References q2ns::Lost, and owner_.

◆ Apply()

bool q2ns::QProcessor::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. All must be local and not lost.
Returns
True if the application was successful, false otherwise.

Definition at line 170 of file q2ns-qprocessor.cc.

References q2ns::QStateRegistry::GetLocation(), q2ns::QStateRegistry::MergeStates(), q2ns::Node, owner_, and registry_.

Referenced by CreateBellPair(), and MeasureBell().

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

◆ CreateBellPair()

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

Create a local Bell pair in |Phi+>

Returns
Pair of local qubits {q0, q1}.

Definition at line 83 of file q2ns-qprocessor.cc.

References Apply(), q2ns::gates::CNOT(), q2ns::QStateRegistry::CreateState(), q2ns::gates::H(), owner_, q2ns::QStateRegistry::Register(), and registry_.

Here is the call graph for this function:

◆ CreateQubit() [1/2]

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

Create a new local qubit handle in the given state.

Parameters
stateState to prepare the qubit in.
labelOptional human-readable qubit label.
Returns
Shared pointer to the new qubit, or nullptr if state is null.

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

References q2ns::QStateRegistry::CreateStateFromExisting(), GetQubit(), owner_, q2ns::QStateRegistry::Register(), and registry_.

Here is the call graph for this function:

◆ CreateQubit() [2/2]

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

Create a new local qubit in |0>.

Parameters
labelOptional human-readable qubit label.
Returns
Shared pointer to the new qubit.

Definition at line 40 of file q2ns-qprocessor.cc.

References q2ns::QStateRegistry::CreateState(), GetQubit(), owner_, q2ns::QStateRegistry::Register(), and registry_.

Here is the call graph for this function:

◆ GetLocalQubits()

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

Return the qubits currently located at the owning 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 the owning node.

Definition at line 137 of file q2ns-qprocessor.cc.

References q2ns::QStateRegistry::GetLocalQubits(), owner_, and registry_.

Here is the call graph for this function:

◆ GetOwnerNode()

const QNode & q2ns::QProcessor::GetOwnerNode ( ) const

Get owning node.

Returns
Reference to the owning node.

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

References owner_.

◆ GetQubit() [1/2]

std::shared_ptr< Qubit > q2ns::QProcessor::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 101 of file q2ns-qprocessor.cc.

References q2ns::QStateRegistry::GetLocalQubits(), owner_, and registry_.

Referenced by CreateQubit(), and CreateQubit().

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

◆ GetQubit() [2/2]

std::shared_ptr< Qubit > q2ns::QProcessor::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 119 of file q2ns-qprocessor.cc.

References q2ns::QStateRegistry::GetLocation(), q2ns::QStateRegistry::GetQubitHandle(), q2ns::Node, owner_, and registry_.

Here is the call graph for this function:

◆ GetState()

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

Get the current state of the qubit.

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

Definition at line 160 of file q2ns-qprocessor.cc.

References q2ns::QStateRegistry::GetState(), and registry_.

Here is the call graph for this function:

◆ Measure()

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

Measure a single, local qubit in the given basis (default Z).

The measured qubit is rebound to a new one-qubit state. Any surviving qubits from the original backend state are rebound to a new survivor state.

Parameters
[in]qubitTarget qubit.
[in]basisMeasurement basis.
Returns
Classical outcome bit (0 or 1), or -1 if the measurement is rejected.

Definition at line 209 of file q2ns-qprocessor.cc.

References q2ns::QStateRegistry::CreateStateFromExisting(), q2ns::QStateRegistry::GetLocation(), q2ns::QStateRegistry::GetState(), q2ns::Node, owner_, q2ns::QStateRegistry::QubitsOf(), q2ns::QStateRegistry::Register(), registry_, q2ns::QStateRegistry::RemoveState(), q2ns::QStateRegistry::SetLocation(), and q2ns::QStateRegistry::UnregisterEverywhere().

Referenced by MeasureBell().

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

◆ MeasureBell()

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

Perform a Bell-state measurement on two local qubits.

This implementation performs a Bell-basis rotation using CNOT(a,b) followed by H(a), then measures both qubits in the computational basis.

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

Definition at line 289 of file q2ns-qprocessor.cc.

References Apply(), q2ns::gates::CNOT(), q2ns::QStateRegistry::GetLocation(), q2ns::gates::H(), q2ns::Lost, Measure(), q2ns::Node, owner_, and registry_.

Here is the call graph for this function:

Member Data Documentation

◆ owner_

QNode& q2ns::QProcessor::owner_
private

◆ registry_

QStateRegistry& q2ns::QProcessor::registry_
private

Quantum state registry.

Definition at line 174 of file q2ns-qprocessor.h.

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


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