140 int n_gates()
const {
return static_cast<int>(ops_.size()); }
143 std::vector<GateView>
views()
const;
148 H, X, Y, Z, S, Sdg, T, Tdg,
150 CX, CY, CZ, CP, SWAP,
154 int q0 = -1, q1 = -1, q2 = -1;
155 real theta = 0, phi = 0, lambda = 0;
162 std::vector<Op> ops_;
167 std::pair<std::vector<int>,
int> compute_layout()
const;
173Circuit
bell_pair(
int q0 = 0,
int q1 = 1);
Dense vector with optional GPU storage, templated over scalar type T.
Chainable quantum circuit builder.
std::vector< GateView > views() const
Gate descriptions with layout columns – for renderers.
std::string diagram() const
ASCII wire diagram (Unicode box-drawing characters)
Circuit & cx(int ctrl, int tgt)
CNOT.
Circuit & swap(int q0, int q1)
SWAP.
Circuit & cp(real lambda, int ctrl, int tgt)
Controlled phase.
Circuit & h(int q)
Hadamard.
Circuit & rz(real theta, int q)
R_z(theta) = e^{-ithetaZ/2}.
Circuit & rx(real theta, int q)
R_x(theta) = e^{-ithetaX/2}.
Circuit & s(int q)
Phase S = sqrtZ.
Circuit & ry(real theta, int q)
R_y(theta) = e^{-ithetaY/2}.
quantum::Statevector statevector() const
Run full circuit -> statevector (no measurement collapse)
Circuit & t(int q)
T = sqrtS.
quantum::Statevector statevector_at(int n) const
Apply first n gates only (0 = bare |0...0>). Useful for stepping through the circuit in a visualiser.
Circuit & z(int q)
Pauli-Z.
Circuit & p(real lambda, int q)
Phase P(lambda)
Circuit & x(int q)
Pauli-X (NOT)
Circuit & u(real theta, real phi, real lambda, int q)
General SU(2)
Circuit & cz(int ctrl, int tgt)
Controlled-Z.
Circuit & ccx(int c0, int c1, int tgt)
Toffoli (CCX)
void print() const
Print diagram to stdout.
Result run(int shots=1024, unsigned seed=42) const
Sample shots measurements from the ideal distribution. Uses pre-computed statevector probabilities – ...
Circuit & cy(int ctrl, int tgt)
Controlled-Y.
Circuit & cswap(int ctrl, int q0, int q1)
Fredkin (CSWAP)
Circuit & y(int q)
Pauli-Y.
Circuit & gate(const quantum::Gate &G, int q, std::string label="U")
std::array< cplx, 16 > Gate2Q
4x4 two-qubit gate stored row-major (16 entries)
std::array< cplx, 4 > Gate
2x2 single-qubit gate stored row-major: { G[0,0], G[0,1], G[1,0], G[1,1] }
num::CVector Statevector
Dense statevector: complex vector of length 2^n_qubits, backed by num::CVector.
constexpr real phi
Golden ratio.
Circuit ghz_state(int n_qubits)
n-qubit GHZ state (|00...0> + |11...1>)/sqrt2
constexpr T ipow(T x) noexcept
Compute x^N at compile time via repeated squaring.
Circuit qft_circuit(int n_qubits)
n-qubit Quantum Fourier Transform circuit Applied to |0...0> unless you prepend state-preparation gat...
void print_state(const quantum::Statevector &sv, int n_qubits, real threshold=1e-6)
Pretty-print a statevector, hiding amplitudes below threshold.
Circuit bell_pair(int q0=0, int q1=1)
Bell state |Phi+> = (|00> + |11>)/sqrt2 on qubits q0, q1.
Statevector-based quantum circuit simulator.
Compact gate description used by visualisation code.
int q1
secondary qubit (-1 if 1Q)
int q2
tertiary qubit (-1 if not 3Q)
std::string label
e.g. "H", "CX", "RY(1.57)", "SWAP"
int q0
primary qubit (target for 1Q; control for 2/3Q)
Measurement outcome from Circuit::run()
void print() const
Print counts sorted by count (descending)
std::string most_likely() const
Basis label with the highest count.
quantum::Statevector sv
pre-measurement statevector
real probability(const std::string &label) const
Empirical probability for a given label (e.g. "11")
std::map< std::string, int > counts
basis label (e.g. "011") -> shot count