![]() |
Q2NS dev
ns-3 module
|
Ket-based concrete QState backend using qpp. More...
#include <q2ns-qstate-ket.h>
Public Member Functions | |
| QStateKet (std::size_t numQubits) | |
| Construct the |0...0> state on numQubits qubits. | |
| QStateKet (qpp::ket state) | |
| Construct from an existing ket. | |
| int64_t | AssignStreams (int64_t stream) override |
| Assign RNG streams for deterministic randomness. | |
| std::size_t | NumQubits () const override |
| Return the number of logical qubits in the state. | |
| void | Print (std::ostream &os) const override |
| Print a human-readable representation of the state. | |
| void | Apply (const QGate &g, const std::vector< q2ns::Index > &targets) override |
| Apply a gate to the given target qubits. | |
| std::shared_ptr< QState > | MergeDisjoint (const QState &other) const override |
| Return the disjoint merge of this state and another ket backend. | |
| MeasureResult | Measure (q2ns::Index target, q2ns::Basis basis=q2ns::Basis::Z) override |
| Measure one qubit in the requested basis and split the result. | |
| const qpp::ket & | GetKet () const |
| Return the underlying ket. | |
| void | SetKet (const qpp::ket &k) |
| Replace the underlying ket. | |
| qpp::cmat | GetDensityMatrix () const |
| Return the density matrix |psi><psi| of the current ket. | |
Public Member Functions inherited from q2ns::QState | |
| virtual | ~QState () |
| Virtual destructor. | |
| StateId | GetStateId () const |
| Get the registry-assigned state id. | |
| void | SetStateId (StateId id) |
| Set the registry-assigned state id. | |
| virtual void | Apply (const QGate &g, const std::vector< Index > &targets)=0 |
| Apply a gate to the given target indices. | |
Static Private Member Functions | |
| static void | ValidateKet (const qpp::ket &k) |
| Validate basic ket properties. | |
Private Attributes | |
| qpp::ket | state_ |
| Pure state ket. | |
Additional Inherited Members | |
Protected Member Functions inherited from q2ns::QState | |
| void | PrintHeader (std::ostream &os, const char *backendName) const |
| Print a standard backend header. | |
Static Protected Member Functions inherited from q2ns::QState | |
| 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. | |
Ket-based concrete QState backend using qpp.
QStateKet stores an N-qubit pure state as a qpp::ket and implements the common QState interface.
This is the default backend and supports:
It also exposes backend-specific helpers for direct ket access and conversion to a density matrix.
Constructors validate basic ket structure such as power-of-two dimension and norm close to one.
Definition at line 46 of file q2ns-qstate-ket.h.
|
explicit |
Construct the |0...0> state on numQubits qubits.
| numQubits | Number of qubits. |
Definition at line 51 of file q2ns-qstate-ket.cc.
References q2ns::QState::AssignStreamsGlobal(), and state_.
|
explicit |
Construct from an existing ket.
| state | Pure state ket. |
| std::invalid_argument | if the ket is empty, not a column vector, not of dimension 2^N, or not normalized. |
Definition at line 58 of file q2ns-qstate-ket.cc.
References state_, and ValidateKet().
|
override |
Apply a gate to the given target qubits.
| g | Gate descriptor. |
| targets | Target qubit indices. |
Definition at line 88 of file q2ns-qstate-ket.cc.
References q2ns::QState::AssignStreamsGlobal(), q2ns::Custom, q2ns::MatrixOf(), and state_.
Assign RNG streams for deterministic randomness.
This seeds qpp's random source for measurement and other stochastic qpp operations used by this backend.
| stream | Starting stream index. |
Reimplemented from q2ns::QState.
Definition at line 64 of file q2ns-qstate-ket.cc.
References q2ns::QState::AssignStreamsGlobal(), and q2ns::QState::MakeSeedSeq().
| qpp::cmat q2ns::QStateKet::GetDensityMatrix | ( | ) | const |
Return the density matrix |psi><psi| of the current ket.
Definition at line 179 of file q2ns-qstate-ket.cc.
References state_.
| const qpp::ket & q2ns::QStateKet::GetKet | ( | ) | const |
Return the underlying ket.
Definition at line 166 of file q2ns-qstate-ket.cc.
References state_.
|
overridevirtual |
Measure one qubit in the requested basis and split the result.
The returned measured state is a 1-qubit collapsed state expressed in the requested measurement basis. The survivors state contains the remaining qubits in their original relative order.
| target | Index of the qubit to measure. |
| basis | Measurement basis. Defaults to Z. |
Implements q2ns::QState.
Definition at line 124 of file q2ns-qstate-ket.cc.
References q2ns::QState::AssignStreamsGlobal(), q2ns::H, NumQubits(), q2ns::S, state_, q2ns::X, q2ns::Y, and q2ns::Z.
|
overridevirtual |
Return the disjoint merge of this state and another ket backend.
The merged qubit order is [this-qubits..., other-qubits...].
| other | Other state to merge with. |
Implements q2ns::QState.
Definition at line 112 of file q2ns-qstate-ket.cc.
References q2ns::QState::AssignStreamsGlobal(), and state_.
|
overridevirtual |
Return the number of logical qubits in the state.
Implements q2ns::QState.
Definition at line 75 of file q2ns-qstate-ket.cc.
References state_.
Referenced by Measure().
|
overridevirtual |
Print a human-readable representation of the state.
| os | Output stream. |
Implements q2ns::QState.
Definition at line 81 of file q2ns-qstate-ket.cc.
References q2ns::QState::AssignStreamsGlobal(), q2ns::QState::PrintHeader(), and state_.
Replace the underlying ket.
| k | New backend ket. |
| std::invalid_argument | if the ket is empty, not a column vector, not of dimension 2^N, or not normalized. |
Definition at line 172 of file q2ns-qstate-ket.cc.
References q2ns::QState::AssignStreamsGlobal(), state_, and ValidateKet().
Validate basic ket properties.
| k | Ket to validate. |
Definition at line 26 of file q2ns-qstate-ket.cc.
References q2ns::QState::AssignStreamsGlobal().
Referenced by QStateKet(), and SetKet().
|
private |
Pure state ket.
Definition at line 149 of file q2ns-qstate-ket.h.
Referenced by Apply(), GetDensityMatrix(), GetKet(), Measure(), MergeDisjoint(), NumQubits(), Print(), QStateKet(), QStateKet(), and SetKet().