![]() |
Q2NS dev
ns-3 module
|
Stabilizer concrete QState backend using stab::AffineState. More...
#include <q2ns-qstate-stab.h>
Public Member Functions | |
| QStateStab (std::size_t numQubits) | |
| Construct the |0...0> stabilizer state on numQubits qubits. | |
| 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. | |
| void | Apply (const QGate &g, const std::vector< Index > &t) override |
| Apply a supported Clifford gate to the given target qubits. | |
| std::size_t | NumQubits () const override |
| Return the number of logical qubits in the state. | |
| MeasureResult | Measure (Index target, Basis basis=Basis::Z) override |
| Measure one qubit in the requested basis and split the result. | |
| std::shared_ptr< QState > | MergeDisjoint (const QState &other) const override |
| Return the disjoint merge of this state and another stabilizer backend. | |
| std::shared_ptr< QState > | Clone () const |
| Return a clone of this stabilizer state. | |
| const stab::AffineState & | GetAffineState () const |
| Return the underlying AffineState. | |
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. | |
Private Member Functions | |
| void | RotateIntoZBasis_ (Index q, Basis basis) |
| Rotate a local basis so that measuring Z implements the requested basis. | |
| void | RemoveQubit_ (Index target) |
| Remove one qubit while preserving survivor order. | |
Static Private Member Functions | |
| static std::shared_ptr< QStateStab > | Synth1QEigenstate_ (Basis basis, int bit) |
| Build a 1-qubit basis eigenstate for a measurement outcome. | |
Private Attributes | |
| std::size_t | numQubits_ {0} |
| Number of logical qubits. | |
| stab::AffineState | psi_ |
| Underlying stabilizer state. | |
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. | |
Stabilizer concrete QState backend using stab::AffineState.
QStateStab supports Clifford-state simulation using a vendored stab::AffineState implementation.
Supported operations include:
This backend does not support arbitrary custom unitary gates.
Definition at line 48 of file q2ns-qstate-stab.h.
|
explicit |
Construct the |0...0> stabilizer state on numQubits qubits.
| numQubits | Number of qubits. |
Definition at line 23 of file q2ns-qstate-stab.cc.
Apply a supported Clifford gate to the given target qubits.
| g | Gate descriptor. |
| t | Target qubit indices. |
Implements q2ns::QState.
Definition at line 49 of file q2ns-qstate-stab.cc.
References q2ns::QState::AssignStreamsGlobal(), q2ns::CNOT, q2ns::Custom, q2ns::CZ, q2ns::H, q2ns::I, psi_, q2ns::S, q2ns::SDG, q2ns::SWAP, q2ns::X, q2ns::Y, and q2ns::Z.
Assign RNG streams for deterministic randomness.
This seeds the underlying stab random source used by measurement and other stochastic backend operations.
| stream | Starting stream index. |
Reimplemented from q2ns::QState.
Definition at line 28 of file q2ns-qstate-stab.cc.
References q2ns::QState::AssignStreamsGlobal().
|
inline |
Return a clone of this stabilizer state.
Definition at line 113 of file q2ns-qstate-stab.h.
|
inline |
Return the underlying AffineState.
Definition at line 121 of file q2ns-qstate-stab.h.
References psi_.
|
overridevirtual |
Measure one qubit in the requested basis and split the result.
The returned measured state is a 1-qubit stabilizer eigenstate in the requested 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 178 of file q2ns-qstate-stab.cc.
References q2ns::QState::AssignStreamsGlobal(), numQubits_, q2ns::QState::MeasureResult::outcome, psi_, RotateIntoZBasis_(), and Synth1QEigenstate_().
|
overridevirtual |
Return the disjoint merge of this state and another stabilizer backend.
The merged qubit order is [this-qubits..., other-qubits...].
| other | Other state to merge with. |
Implements q2ns::QState.
Definition at line 205 of file q2ns-qstate-stab.cc.
References q2ns::QState::AssignStreamsGlobal(), numQubits_, and psi_.
|
overridevirtual |
Return the number of logical qubits in the state.
Implements q2ns::QState.
Definition at line 36 of file q2ns-qstate-stab.cc.
References numQubits_.
|
overridevirtual |
Print a human-readable representation of the state.
| os | Output stream. |
Implements q2ns::QState.
Definition at line 42 of file q2ns-qstate-stab.cc.
References q2ns::QState::AssignStreamsGlobal(), q2ns::QState::PrintHeader(), and psi_.
Remove one qubit while preserving survivor order.
The target is swapped to the end and then dropped from the underlying AffineState.
| target | Qubit to remove. |
Definition at line 158 of file q2ns-qstate-stab.cc.
References q2ns::QState::AssignStreamsGlobal(), numQubits_, and psi_.
Rotate a local basis so that measuring Z implements the requested basis.
X measurement is implemented as H then Z. Y measurement is implemented as SDG then H then Z.
| q | Target qubit. |
| basis | Requested measurement basis. |
Definition at line 107 of file q2ns-qstate-stab.cc.
References q2ns::QState::AssignStreamsGlobal(), psi_, q2ns::X, q2ns::Y, and q2ns::Z.
Referenced by Measure().
|
staticprivate |
Build a 1-qubit basis eigenstate for a measurement outcome.
| basis | Measurement basis. |
| bit | Outcome bit. |
Definition at line 126 of file q2ns-qstate-stab.cc.
References q2ns::QState::AssignStreamsGlobal(), q2ns::X, q2ns::Y, and q2ns::Z.
Referenced by Measure().
|
private |
Number of logical qubits.
Definition at line 155 of file q2ns-qstate-stab.h.
Referenced by Measure(), MergeDisjoint(), NumQubits(), and RemoveQubit_().
|
private |
Underlying stabilizer state.
Definition at line 156 of file q2ns-qstate-stab.h.
Referenced by Apply(), GetAffineState(), Measure(), MergeDisjoint(), Print(), RemoveQubit_(), and RotateIntoZBasis_().