Q2NS dev
ns-3 module
Loading...
Searching...
No Matches
q2ns::QStateStab Class Referencefinal

Stabilizer concrete QState backend using stab::AffineState. More...

#include <q2ns-qstate-stab.h>

Inheritance diagram for q2ns::QStateStab:
Collaboration diagram for q2ns::QStateStab:

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< QStateMergeDisjoint (const QState &other) const override
 Return the disjoint merge of this state and another stabilizer backend.
 
std::shared_ptr< QStateClone () 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< QStateStabSynth1QEigenstate_ (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.
 

Detailed Description

Stabilizer concrete QState backend using stab::AffineState.

QStateStab supports Clifford-state simulation using a vendored stab::AffineState implementation.

Supported operations include:

  • 1-qubit Clifford gates I, H, S, SDG, X, Y, Z
  • 2-qubit Clifford gates CNOT, CZ, SWAP
  • single-qubit projective measurement in X, Y, and Z bases
  • disjoint merge by tensor product

This backend does not support arbitrary custom unitary gates.

See also
QState
QGateKind

Definition at line 48 of file q2ns-qstate-stab.h.

Constructor & Destructor Documentation

◆ QStateStab()

q2ns::QStateStab::QStateStab ( std::size_t  numQubits)
explicit

Construct the |0...0> stabilizer state on numQubits qubits.

Parameters
numQubitsNumber of qubits.

Definition at line 23 of file q2ns-qstate-stab.cc.

Member Function Documentation

◆ Apply()

void q2ns::QStateStab::Apply ( const QGate g,
const std::vector< Index > &  t 
)
overridevirtual

Apply a supported Clifford gate to the given target qubits.

Parameters
gGate descriptor.
tTarget 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.

Here is the call graph for this function:

◆ AssignStreams()

int64_t q2ns::QStateStab::AssignStreams ( int64_t  stream)
overridevirtual

Assign RNG streams for deterministic randomness.

This seeds the underlying stab random source used by measurement and other stochastic backend operations.

Parameters
streamStarting stream index.
Returns
Number of streams consumed.

Reimplemented from q2ns::QState.

Definition at line 28 of file q2ns-qstate-stab.cc.

References q2ns::QState::AssignStreamsGlobal().

Here is the call graph for this function:

◆ Clone()

std::shared_ptr< QState > q2ns::QStateStab::Clone ( ) const
inline

Return a clone of this stabilizer state.

Returns
Newly allocated copy of this state.

Definition at line 113 of file q2ns-qstate-stab.h.

◆ GetAffineState()

const stab::AffineState & q2ns::QStateStab::GetAffineState ( ) const
inline

Return the underlying AffineState.

Returns
Reference to the backend stabilizer state.

Definition at line 121 of file q2ns-qstate-stab.h.

References psi_.

◆ Measure()

QState::MeasureResult q2ns::QStateStab::Measure ( Index  target,
Basis  basis = Basis::Z 
)
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.

Parameters
targetIndex of the qubit to measure.
basisMeasurement basis. Defaults to Z.
Returns
Measurement result containing outcome, measured state, and survivor state.

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_().

Here is the call graph for this function:

◆ MergeDisjoint()

std::shared_ptr< QState > q2ns::QStateStab::MergeDisjoint ( const QState other) const
overridevirtual

Return the disjoint merge of this state and another stabilizer backend.

The merged qubit order is [this-qubits..., other-qubits...].

Parameters
otherOther state to merge with.
Returns
Newly allocated merged state.

Implements q2ns::QState.

Definition at line 205 of file q2ns-qstate-stab.cc.

References q2ns::QState::AssignStreamsGlobal(), numQubits_, and psi_.

Here is the call graph for this function:

◆ NumQubits()

std::size_t q2ns::QStateStab::NumQubits ( ) const
overridevirtual

Return the number of logical qubits in the state.

Returns
Number of logical qubits.

Implements q2ns::QState.

Definition at line 36 of file q2ns-qstate-stab.cc.

References numQubits_.

◆ Print()

void q2ns::QStateStab::Print ( std::ostream &  os) const
overridevirtual

Print a human-readable representation of the state.

Parameters
osOutput stream.

Implements q2ns::QState.

Definition at line 42 of file q2ns-qstate-stab.cc.

References q2ns::QState::AssignStreamsGlobal(), q2ns::QState::PrintHeader(), and psi_.

Here is the call graph for this function:

◆ RemoveQubit_()

void q2ns::QStateStab::RemoveQubit_ ( Index  target)
private

Remove one qubit while preserving survivor order.

The target is swapped to the end and then dropped from the underlying AffineState.

Parameters
targetQubit to remove.

Definition at line 158 of file q2ns-qstate-stab.cc.

References q2ns::QState::AssignStreamsGlobal(), numQubits_, and psi_.

Here is the call graph for this function:

◆ RotateIntoZBasis_()

void q2ns::QStateStab::RotateIntoZBasis_ ( Index  q,
Basis  basis 
)
private

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.

Parameters
qTarget qubit.
basisRequested 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().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ Synth1QEigenstate_()

std::shared_ptr< QStateStab > q2ns::QStateStab::Synth1QEigenstate_ ( Basis  basis,
int  bit 
)
staticprivate

Build a 1-qubit basis eigenstate for a measurement outcome.

Parameters
basisMeasurement basis.
bitOutcome bit.
Returns
Newly allocated 1-qubit stabilizer state.

Definition at line 126 of file q2ns-qstate-stab.cc.

References q2ns::QState::AssignStreamsGlobal(), q2ns::X, q2ns::Y, and q2ns::Z.

Referenced by Measure().

Here is the call graph for this function:
Here is the caller graph for this function:

Member Data Documentation

◆ numQubits_

std::size_t q2ns::QStateStab::numQubits_ {0}
private

Number of logical qubits.

Definition at line 155 of file q2ns-qstate-stab.h.

Referenced by Measure(), MergeDisjoint(), NumQubits(), and RemoveQubit_().

◆ psi_

stab::AffineState q2ns::QStateStab::psi_
private

Underlying stabilizer state.

Definition at line 156 of file q2ns-qstate-stab.h.

Referenced by Apply(), GetAffineState(), Measure(), MergeDisjoint(), Print(), RemoveQubit_(), and RotateIntoZBasis_().


The documentation for this class was generated from the following files: