![]() |
Q2NS dev
ns-3 module
|
Internal helper owned by a QNode to handle local quantum operations. More...
#include <q2ns-qprocessor.h>
Public Member Functions | |
| QProcessor (QStateRegistry ®istry, QNode &owner) | |
| Construct a processor bound to a registry and owning node. | |
| const QNode & | GetOwnerNode () const |
| Get owning node. | |
| std::shared_ptr< Qubit > | CreateQubit (const std::string &label="") |
| Create a new local qubit in |0>. | |
| std::shared_ptr< Qubit > | CreateQubit (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< Qubit > | GetQubit (const std::string &label) const |
| Lookup a local qubit by application label. | |
| std::shared_ptr< Qubit > | GetQubit (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< QState > | GetState (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 | |
| QStateRegistry & | registry_ |
| Quantum state registry. | |
| QNode & | owner_ |
| Owning QNode. | |
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:
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.
| q2ns::QProcessor::QProcessor | ( | QStateRegistry & | registry, |
| QNode & | owner | ||
| ) |
Construct a processor bound to a registry and owning node.
| registry | Reference to the global quantum state registry. |
| owner | Reference to the owning node. |
Definition at line 29 of file q2ns-qprocessor.cc.
| 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.
| q | Qubit handle. |
Definition at line 143 of file q2ns-qprocessor.cc.
References q2ns::Lost, and owner_.
| bool q2ns::QProcessor::Apply | ( | const QGate & | gate, |
| const std::vector< std::shared_ptr< Qubit > > & | qs | ||
| ) |
Apply a gate to one or more local qubits.
| gate | Gate to apply. |
| qs | Target qubits. All must be local and not lost. |
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().
| std::pair< std::shared_ptr< Qubit >, std::shared_ptr< Qubit > > q2ns::QProcessor::CreateBellPair | ( | ) |
Create a local Bell pair in |Phi+>
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_.
| 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.
| state | State to prepare the qubit in. |
| label | Optional human-readable qubit label. |
state is null. Definition at line 60 of file q2ns-qprocessor.cc.
References q2ns::QStateRegistry::CreateStateFromExisting(), GetQubit(), owner_, q2ns::QStateRegistry::Register(), and registry_.
| std::shared_ptr< Qubit > q2ns::QProcessor::CreateQubit | ( | const std::string & | label = "" | ) |
Create a new local qubit in |0>.
| label | Optional human-readable qubit label. |
Definition at line 40 of file q2ns-qprocessor.cc.
References q2ns::QStateRegistry::CreateState(), GetQubit(), owner_, q2ns::QStateRegistry::Register(), and registry_.
| 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.
Definition at line 137 of file q2ns-qprocessor.cc.
References q2ns::QStateRegistry::GetLocalQubits(), owner_, and registry_.
| const QNode & q2ns::QProcessor::GetOwnerNode | ( | ) | const |
Get owning node.
Definition at line 34 of file q2ns-qprocessor.cc.
References owner_.
| 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.
| label | Application-level qubit label. |
Definition at line 101 of file q2ns-qprocessor.cc.
References q2ns::QStateRegistry::GetLocalQubits(), owner_, and registry_.
Referenced by CreateQubit(), and CreateQubit().
Lookup a local qubit by unique identifier.
| id | Qubit identifier. |
Definition at line 119 of file q2ns-qprocessor.cc.
References q2ns::QStateRegistry::GetLocation(), q2ns::QStateRegistry::GetQubitHandle(), q2ns::Node, owner_, and registry_.
Get the current state of the qubit.
| q | Target qubit. |
Definition at line 160 of file q2ns-qprocessor.cc.
References q2ns::QStateRegistry::GetState(), and registry_.
| 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.
| [in] | qubit | Target qubit. |
| [in] | basis | Measurement basis. |
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().
| 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.
| a | First qubit. |
| b | Second qubit. |
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_.
|
private |
Owning QNode.
Definition at line 175 of file q2ns-qprocessor.h.
Referenced by AdoptQubit(), Apply(), CreateBellPair(), CreateQubit(), CreateQubit(), GetLocalQubits(), GetOwnerNode(), GetQubit(), GetQubit(), Measure(), and MeasureBell().
|
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().