![]() |
Q2NS dev
ns-3 module
|
Backend-agnostic interface for a quantum state object. More...
#include <q2ns-qstate.h>
Classes | |
| struct | MeasureResult |
| Result of measuring one qubit and splitting the state. More... | |
Public Member Functions | |
| virtual | ~QState () |
| Virtual destructor. | |
| virtual int64_t | AssignStreams (int64_t stream) |
| Assign RNG streams for deterministic randomness. | |
| StateId | GetStateId () const |
| Get the registry-assigned state id. | |
| void | SetStateId (StateId id) |
| Set the registry-assigned state id. | |
| virtual void | Print (std::ostream &os) const =0 |
| Print a human-readable representation of the state. | |
| virtual std::size_t | NumQubits () const =0 |
| Return the number of logical qubits in the state. | |
| virtual void | Apply (const QGate &g, const std::vector< Index > &targets)=0 |
| Apply a gate to the given target indices. | |
| virtual std::shared_ptr< QState > | MergeDisjoint (const QState &other) const =0 |
| Return a new state that is the disjoint merge of this state and another. | |
| virtual MeasureResult | Measure (q2ns::Index target, q2ns::Basis basis=q2ns::Basis::Z)=0 |
| Measure one qubit and split the result into new states. | |
Protected Member Functions | |
| void | PrintHeader (std::ostream &os, const char *backendName) const |
| Print a standard backend header. | |
Static Protected Member Functions | |
| static uint64_t | SplitMix64 (uint64_t x) |
| Mix a 64-bit value deterministically. | |
| static uint64_t | DeriveSeed64 (uint32_t seed, uint32_t run, int64_t stream, uint64_t salt) |
| Derive a deterministic 64-bit seed from ns-3 seed/run and a stream. | |
| static std::seed_seq | MakeSeedSeq (uint64_t s64) |
| Build a std::seed_seq from a 64-bit seed. | |
| static void | CheckSeedRunNonZero (uint32_t seed, uint32_t run) |
| Abort if ns-3 seed or run is zero. | |
| template<uint64_t SALT> | |
| static bool | ShouldReseed (uint32_t seed, uint32_t run, int64_t stream) |
| Return whether a backend-global RNG should be reseeded. | |
| template<uint64_t SALT, typename ReseedFn > | |
| static int64_t | AssignStreamsGlobal (int64_t stream, ReseedFn reseed_fn) |
| Helper for backends that reseed a global RNG source. | |
Private Attributes | |
| StateId | stateId_ {0} |
| Registry-assigned state id. | |
Backend-agnostic interface for a quantum state object.
QState defines the minimal common interface implemented by concrete backend state classes such as ket, density-matrix, and stabilizer backends.
Design goals:
Concrete implementations may expose backend-specific views on their own concrete classes, but QState provides the common operational interface used by QProcessor and QStateRegistry.
Definition at line 51 of file q2ns-qstate.h.
|
virtualdefault |
Virtual destructor.
|
pure virtual |
Apply a gate to the given target indices.
Concrete backends may support different gate subsets. For example, matrix-based backends may accept arbitrary custom unitaries while other backends may reject non-native operations.
| g | Gate descriptor. |
| targets | Target qubit indices. |
Implemented in q2ns::QStateStab.
Assign RNG streams for deterministic randomness.
Backends that use random sampling should deterministically seed or bind their random sources here using the provided stream index together with the current ns-3 seed and run values.
Backends that consume no random streams may keep the default behavior.
| stream | Starting stream index. |
Reimplemented in q2ns::QStateDM, q2ns::QStateKet, and q2ns::QStateStab.
Definition at line 70 of file q2ns-qstate.h.
References AssignStreamsGlobal().
Referenced by q2ns::NetController::NetController().
|
inlinestaticprotected |
Helper for backends that reseed a global RNG source.
This helper reads ns-3 seed and run values, checks they are valid, skips redundant reseeding when the configuration is unchanged, derives a 64-bit seed, and invokes the provided reseed callback.
| SALT | Backend-specific salt. |
| ReseedFn | Callback type used to perform backend reseeding. |
| stream | Stream index. |
| reseed_fn | Callback that accepts the derived 64-bit seed. |
Definition at line 255 of file q2ns-qstate.h.
References AssignStreamsGlobal(), CheckSeedRunNonZero(), and DeriveSeed64().
Referenced by q2ns::QStateStab::Apply(), q2ns::QStateDM::Apply(), q2ns::QStateKet::Apply(), AssignStreams(), q2ns::QStateDM::AssignStreams(), q2ns::QStateKet::AssignStreams(), q2ns::QStateStab::AssignStreams(), AssignStreamsGlobal(), CheckSeedRunNonZero(), DeriveSeed64(), MakeSeedSeq(), q2ns::QStateStab::Measure(), q2ns::QStateDM::Measure(), q2ns::QStateKet::Measure(), q2ns::QStateDM::MergeDisjoint(), q2ns::QStateKet::MergeDisjoint(), q2ns::QStateStab::MergeDisjoint(), q2ns::QStateDM::NumQubits(), q2ns::QStateDM::PartialTrace(), q2ns::QStateDM::Print(), q2ns::QStateKet::Print(), q2ns::QStateStab::Print(), PrintHeader(), q2ns::QStateKet::QStateKet(), q2ns::QStateStab::RemoveQubit_(), q2ns::QStateStab::RotateIntoZBasis_(), q2ns::QStateKet::SetKet(), q2ns::QStateDM::SetRho(), ShouldReseed(), SplitMix64(), q2ns::QStateStab::Synth1QEigenstate_(), and q2ns::QStateKet::ValidateKet().
Abort if ns-3 seed or run is zero.
| seed | ns-3 global seed. |
| run | ns-3 global run. |
Definition at line 205 of file q2ns-qstate.h.
References AssignStreamsGlobal().
Referenced by AssignStreamsGlobal().
|
inlinestaticprotected |
Derive a deterministic 64-bit seed from ns-3 seed/run and a stream.
| seed | ns-3 global seed. |
| run | ns-3 global run. |
| stream | Stream index. |
| salt | Backend-specific salt. |
Definition at line 184 of file q2ns-qstate.h.
References AssignStreamsGlobal(), and SplitMix64().
Referenced by AssignStreamsGlobal().
|
inline |
Get the registry-assigned state id.
Definition at line 79 of file q2ns-qstate.h.
References stateId_.
Referenced by PrintHeader().
Build a std::seed_seq from a 64-bit seed.
| s64 | Derived 64-bit seed. |
Definition at line 194 of file q2ns-qstate.h.
References AssignStreamsGlobal().
Referenced by q2ns::QStateDM::AssignStreams(), and q2ns::QStateKet::AssignStreams().
|
pure virtual |
Measure one qubit and split the result into new states.
Survivors preserve their original relative order. Any original indices greater than the measured target shift down by one in the survivors state.
| target | Index of the qubit to measure. |
| basis | Measurement basis. Defaults to Z. |
Implemented in q2ns::QStateStab, q2ns::QStateDM, and q2ns::QStateKet.
|
pure virtual |
Return a new state that is the disjoint merge of this state and another.
Index-order invariant:
| other | Other state to merge with. |
Implemented in q2ns::QStateDM, q2ns::QStateKet, and q2ns::QStateStab.
|
pure virtual |
Return the number of logical qubits in the state.
Implemented in q2ns::QStateDM, q2ns::QStateKet, and q2ns::QStateStab.
Referenced by q2ns::analysis::Fidelity(), PrintHeader(), q2ns::analysis::Purity(), q2ns::analysis::TraceDistance(), and q2ns::analysis::VonNeumannEntropy().
Print a human-readable representation of the state.
| os | Output stream. |
Implemented in q2ns::QStateDM, q2ns::QStateKet, and q2ns::QStateStab.
Referenced by q2ns::operator<<().
|
inlineprotected |
Print a standard backend header.
| os | Output stream. |
| backendName | Human-readable backend name. |
Definition at line 159 of file q2ns-qstate.h.
References AssignStreamsGlobal(), GetStateId(), and NumQubits().
Referenced by q2ns::QStateDM::Print(), q2ns::QStateKet::Print(), and q2ns::QStateStab::Print().
Set the registry-assigned state id.
| id | New state id. |
Definition at line 87 of file q2ns-qstate.h.
References stateId_.
|
inlinestaticprotected |
Return whether a backend-global RNG should be reseeded.
This caches the most recent seed, run, and stream tuple for a given SALT.
| SALT | Backend-specific salt. |
| seed | ns-3 global seed. |
| run | ns-3 global run. |
| stream | Stream index. |
Definition at line 221 of file q2ns-qstate.h.
References AssignStreamsGlobal().
Mix a 64-bit value deterministically.
| x | Input value. |
Definition at line 169 of file q2ns-qstate.h.
References AssignStreamsGlobal().
Referenced by DeriveSeed64().
|
private |
Registry-assigned state id.
Definition at line 270 of file q2ns-qstate.h.
Referenced by GetStateId(), and SetStateId().