![]() |
Q2NS dev
ns-3 module
|
Density-matrix concrete QState backend using qpp::cmat. More...
#include <q2ns-qstate-dm.h>
Public Member Functions | |
| QStateDM (std::size_t numQubits) | |
| Construct the |0...0><0...0| state on numQubits qubits. | |
| QStateDM (qpp::cmat rho) | |
| Construct from an existing density matrix. | |
| int64_t | AssignStreams (int64_t stream) override |
| Assign RNG streams for deterministic randomness. | |
| void | Print (std::ostream &os) const override |
| Print a human-readable representation of the state. | |
| std::size_t | NumQubits () const override |
| Return the number of logical qubits in 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 density-matrix 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::cmat & | GetRho () const |
| Return the underlying density matrix. | |
| void | SetRho (const qpp::cmat &rho) |
| Replace the underlying density matrix after validation. | |
| std::shared_ptr< QState > | PartialTrace (const std::vector< q2ns::Index > &subsystemA) |
| Extract a subsystem by partial trace. | |
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 | ValidateDensityMatrix (const qpp::cmat &rho) |
| Validate basic density-matrix structure. | |
Private Attributes | |
| qpp::cmat | rho_ |
| Backend density matrix. | |
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. | |
Density-matrix concrete QState backend using qpp::cmat.
QStateDM stores an N-qubit state as a 2^N by 2^N density matrix and implements the common QState interface.
Supported behavior includes:
Constructors validate basic density-matrix structure such as square shape, power-of-two dimension, and trace close to one.
Definition at line 45 of file q2ns-qstate-dm.h.
|
explicit |
Construct the |0...0><0...0| state on numQubits qubits.
| numQubits | Number of qubits. |
Definition at line 80 of file q2ns-qstate-dm.cc.
References rho_, and ValidateDensityMatrix().
|
explicit |
Construct from an existing density matrix.
| rho | Density matrix. |
| std::invalid_argument | if the matrix is not square, not Hermitian, not positive semidefinite, not of dimension 2^N, or does not have trace one. |
Definition at line 89 of file q2ns-qstate-dm.cc.
References rho_, and ValidateDensityMatrix().
|
override |
Apply a gate to the given target qubits.
| g | Gate descriptor. |
| targets | Target qubit indices. |
Definition at line 120 of file q2ns-qstate-dm.cc.
References q2ns::QState::AssignStreamsGlobal(), q2ns::Custom, q2ns::MatrixOf(), and rho_.
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 95 of file q2ns-qstate-dm.cc.
References q2ns::QState::AssignStreamsGlobal(), and q2ns::QState::MakeSeedSeq().
|
inline |
Return the underlying density matrix.
Definition at line 120 of file q2ns-qstate-dm.h.
References rho_.
|
overridevirtual |
Measure one qubit in the requested basis and split the result.
The returned measured state is a 1-qubit density matrix 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 156 of file q2ns-qstate-dm.cc.
References q2ns::QState::AssignStreamsGlobal(), q2ns::H, NumQubits(), rho_, q2ns::S, q2ns::X, q2ns::Y, and q2ns::Z.
|
overridevirtual |
Return the disjoint merge of this state and another density-matrix backend.
The merged qubit order is [this-qubits..., other-qubits...].
| other | Other state to merge with. |
Implements q2ns::QState.
Definition at line 144 of file q2ns-qstate-dm.cc.
References q2ns::QState::AssignStreamsGlobal(), and rho_.
|
overridevirtual |
Return the number of logical qubits in the state.
Implements q2ns::QState.
Definition at line 106 of file q2ns-qstate-dm.cc.
References q2ns::QState::AssignStreamsGlobal(), and rho_.
Referenced by Measure(), and PartialTrace().
| std::shared_ptr< QState > q2ns::QStateDM::PartialTrace | ( | const std::vector< q2ns::Index > & | subsystemA | ) |
Extract a subsystem by partial trace.
The qubits listed in subsystemA are kept in the returned state. This object is mutated to become the complementary subsystem.
| subsystemA | Indices of the subsystem to keep in the returned state. |
Definition at line 204 of file q2ns-qstate-dm.cc.
References q2ns::QState::AssignStreamsGlobal(), NumQubits(), rho_, and ValidateDensityMatrix().
|
overridevirtual |
Print a human-readable representation of the state.
| os | Output stream. |
Implements q2ns::QState.
Definition at line 113 of file q2ns-qstate-dm.cc.
References q2ns::QState::AssignStreamsGlobal(), q2ns::QState::PrintHeader(), and rho_.
Replace the underlying density matrix after validation.
| rho | New density matrix. |
| std::invalid_argument | if the matrix is not square, not Hermitian, not positive semidefinite, not of dimension 2^N, or does not have trace one. |
Definition at line 252 of file q2ns-qstate-dm.cc.
References q2ns::QState::AssignStreamsGlobal(), rho_, and ValidateDensityMatrix().
Validate basic density-matrix structure.
| rho | Density matrix to validate. |
Definition at line 25 of file q2ns-qstate-dm.cc.
References q2ns::H.
Referenced by PartialTrace(), QStateDM(), QStateDM(), and SetRho().
|
private |
Backend density matrix.
Definition at line 152 of file q2ns-qstate-dm.h.
Referenced by Apply(), GetRho(), Measure(), MergeDisjoint(), NumQubits(), PartialTrace(), Print(), QStateDM(), QStateDM(), and SetRho().