16#include "ns3/q2ns-qgate.h"
17#include "ns3/q2ns-types.h"
20#include "ns3/rng-seed-manager.h"
95 virtual void Print(std::ostream&
os)
const = 0;
170 x += 0x9e3779b97f4a7c15ULL;
171 x = (
x ^ (
x >> 30)) * 0xbf58476d1ce4e5b9ULL;
172 x = (
x ^ (
x >> 27)) * 0x94d049bb133111ebULL;
173 return x ^ (
x >> 31);
197 return std::seed_seq{
a,
b, 0x13579bdu, 0x2468ace0u};
206 NS_ABORT_MSG_IF(seed == 0,
"RngSeedManager::GetSeed() returned 0; Seed must be > 0");
232 std::lock_guard<std::mutex>
lock(
m);
254 template <u
int64_t SALT,
typename ReseedFn>
256 const uint32_t seed = ns3::RngSeedManager::GetSeed();
257 const uint32_t run = ns3::RngSeedManager::GetRun();
290inline std::ostream&
operator<<(std::ostream& os,
const std::shared_ptr<QState>& s) {
294 os <<
"QState{null}";
Lightweight gate descriptor used by QState backends.
Backend-agnostic interface for a quantum state object.
static std::seed_seq MakeSeedSeq(uint64_t s64)
Build a std::seed_seq from a 64-bit seed.
void SetStateId(StateId id)
Set the registry-assigned state id.
virtual std::size_t NumQubits() const =0
Return the number of logical qubits in the state.
virtual int64_t AssignStreams(int64_t stream)
Assign RNG streams for deterministic randomness.
virtual void Print(std::ostream &os) const =0
Print a human-readable representation of the state.
static uint64_t SplitMix64(uint64_t x)
Mix a 64-bit value deterministically.
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.
void PrintHeader(std::ostream &os, const char *backendName) const
Print a standard backend header.
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 void CheckSeedRunNonZero(uint32_t seed, uint32_t run)
Abort if ns-3 seed or run is zero.
StateId stateId_
Registry-assigned state id.
static int64_t AssignStreamsGlobal(int64_t stream, ReseedFn reseed_fn)
Helper for backends that reseed a global RNG source.
static bool ShouldReseed(uint32_t seed, uint32_t run, int64_t stream)
Return whether a backend-global RNG should be reseeded.
virtual MeasureResult Measure(q2ns::Index target, q2ns::Basis basis=q2ns::Basis::Z)=0
Measure one qubit and split the result into new states.
virtual void Apply(const QGate &g, const std::vector< Index > &targets)=0
Apply a gate to the given target indices.
virtual ~QState()
Virtual destructor.
StateId GetStateId() const
Get the registry-assigned state id.
std::uint64_t StateId
Stable identifier for a registered backend state.
Basis
Measurement basis for single-qubit projective measurement.
std::size_t Index
Generic qubit index type within a backend state.
std::ostream & operator<<(std::ostream &os, const QState &s)
Stream insertion for a QState reference.
Result of measuring one qubit and splitting the state.
std::shared_ptr< QState > measured
Measured 1-qubit state.
int outcome
Classical outcome bit.
std::shared_ptr< QState > survivors
Remaining qubits after measurement.