14#include "ns3/q2ns-qstate-stab.h"
24 : numQubits_(numQubits), psi_(static_cast<int>(numQubits)) {}
50 const auto arity =
t.size();
53 throw std::runtime_error(
"QStateStab does not support custom gates");
57 const int q =
static_cast<int>(
t[0]);
82 throw std::runtime_error(
"QStateStab supports only 1-qubit Clifford gates");
86 const int a =
static_cast<int>(
t[0]);
87 const int b =
static_cast<int>(
t[1]);
101 throw std::runtime_error(
"QStateStab supports only 2-qubit Clifford gates");
104 throw std::runtime_error(
"QStateStab supports only 1-qubit and 2-qubit gates");
108 const int j =
static_cast<int>(
q);
123 throw std::runtime_error(
"QStateStab: unsupported measurement basis");
127 auto st = std::make_shared<QStateStab>(1);
153 throw std::runtime_error(
"QStateStab: unsupported basis in Synth1QEigenstate_");
160 throw std::runtime_error(
"QStateStab::RemoveQubit_: empty state");
163 throw std::runtime_error(
"QStateStab::RemoveQubit_: target out of range");
169 psi_.SWAP(
static_cast<int>(
q),
static_cast<int>(
q + 1));
172 psi_.DropLastQubit();
180 throw std::runtime_error(
"QStateStab::Measure: target out of range");
191 auto survivors = std::make_shared<QStateStab>(*
this);
192 survivors->RemoveQubit_(
target);
198 r.measured = std::move(measured);
199 r.survivors = std::move(survivors);
208 throw std::runtime_error(
"QStateStab::MergeDisjoint: incompatible backend");
211 stab::AffineState
mergedPsi = stab::AffineState::TensorProduct(this->
psi_,
rhs->psi_);
213 auto out = std::make_shared<QStateStab>(0);
Lightweight gate descriptor used by QState backends.
Stabilizer concrete QState backend using stab::AffineState.
MeasureResult Measure(Index target, Basis basis=Basis::Z) override
Measure one qubit in the requested basis and split the result.
void RemoveQubit_(Index target)
Remove one qubit while preserving survivor order.
std::size_t numQubits_
Number of logical qubits.
QStateStab(std::size_t numQubits)
Construct the |0...0> stabilizer state on numQubits qubits.
void RotateIntoZBasis_(Index q, Basis basis)
Rotate a local basis so that measuring Z implements the requested basis.
std::shared_ptr< QState > MergeDisjoint(const QState &other) const override
Return the disjoint merge of this state and another stabilizer backend.
std::size_t NumQubits() const override
Return the number of logical qubits in the state.
static std::shared_ptr< QStateStab > Synth1QEigenstate_(Basis basis, int bit)
Build a 1-qubit basis eigenstate for a measurement outcome.
stab::AffineState psi_
Underlying stabilizer state.
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.
int64_t AssignStreams(int64_t stream) override
Assign RNG streams for deterministic randomness.
Backend-agnostic interface for a quantum state object.
void PrintHeader(std::ostream &os, const char *backendName) const
Print a standard backend header.
static int64_t AssignStreamsGlobal(int64_t stream, ReseedFn reseed_fn)
Helper for backends that reseed a global RNG source.
Basis
Measurement basis for single-qubit projective measurement.
std::size_t Index
Generic qubit index type within a backend state.
@ Custom
Caller-supplied matrix.
Result of measuring one qubit and splitting the state.
int outcome
Classical outcome bit.