|
numerics
|
Statevector-based quantum circuit simulator. More...
#include "core/types.hpp"#include "core/vector.hpp"#include <array>#include <functional>#include <vector>Go to the source code of this file.
Namespaces | |
| namespace | num |
| namespace | num::quantum |
Typedefs | |
| using | num::quantum::Statevector = num::CVector |
| Dense statevector: complex vector of length 2^n_qubits, backed by num::CVector. | |
| using | num::quantum::Gate = std::array< cplx, 4 > |
| 2x2 single-qubit gate stored row-major: { G[0,0], G[0,1], G[1,0], G[1,1] } | |
| using | num::quantum::Gate2Q = std::array< cplx, 16 > |
| 4x4 two-qubit gate stored row-major (16 entries) | |
Functions | |
| Statevector | num::quantum::zero_state (int n_qubits) |
| Returns |0...0> computational basis state for n_qubits qubits. | |
| Statevector | num::quantum::basis_state (int n_qubits, int k) |
| Returns the computational basis state |k> for an n_qubits system. | |
| Gate | num::quantum::gate_x () |
| Pauli-X (NOT) | |
| Gate | num::quantum::gate_y () |
| Pauli-Y. | |
| Gate | num::quantum::gate_z () |
| Pauli-Z. | |
| Gate | num::quantum::gate_h () |
| Hadamard. | |
| Gate | num::quantum::gate_s () |
| Phase gate S = diag(1, i) | |
| Gate | num::quantum::gate_sdg () |
| S† = diag(1, -i) | |
| Gate | num::quantum::gate_t () |
| T gate = diag(1, e^{ipi/4}) | |
| Gate | num::quantum::gate_tdg () |
| T† gate. | |
| Gate | num::quantum::gate_rx (real theta) |
| Rotation about X: R_x(theta) = exp(-ithetaX/2) | |
| Gate | num::quantum::gate_ry (real theta) |
| Rotation about Y: R_y(theta) = exp(-ithetaY/2) | |
| Gate | num::quantum::gate_rz (real theta) |
| Rotation about Z: R_z(theta) = exp(-ithetaZ/2) | |
| Gate | num::quantum::gate_p (real lambda) |
| Phase gate: diag(1, e^{ilambda}) | |
| Gate | num::quantum::gate_u (real theta, real phi, real lambda) |
| General SU(2) gate. | |
| Gate2Q | num::quantum::gate2q_cnot () |
| CNOT (qubit 0 = control, qubit 1 = target in subspace) | |
| Gate2Q | num::quantum::gate2q_cz () |
| Controlled-Z. | |
| Gate2Q | num::quantum::gate2q_swap () |
| SWAP. | |
| void | num::quantum::apply_1q (Statevector &sv, int n_qubits, const Gate &G, int target) |
| Apply a 2x2 gate to a single qubit in-place. | |
| void | num::quantum::apply_2q (Statevector &sv, int n_qubits, const Gate2Q &G, int q0, int q1) |
| Apply a general 4x4 two-qubit gate to qubits q0, q1. | |
| void | num::quantum::apply_cnot (Statevector &sv, int n_qubits, int control, int target) |
| CNOT with explicit control and target qubits. | |
| void | num::quantum::apply_cz (Statevector &sv, int n_qubits, int control, int target) |
| Controlled-Z. | |
| void | num::quantum::apply_swap (Statevector &sv, int n_qubits, int q0, int q1) |
| SWAP two qubits. | |
| void | num::quantum::apply_toffoli (Statevector &sv, int n_qubits, int c0, int c1, int target) |
| Toffoli (CCX) gate. | |
| void | num::quantum::apply_cy (Statevector &sv, int n_qubits, int control, int target) |
| Controlled-Y. | |
| void | num::quantum::apply_cp (Statevector &sv, int n_qubits, real lambda, int control, int target) |
| Controlled phase: applies phase e^{ilambda} when both control=1 and target=1. | |
| void | num::quantum::apply_cswap (Statevector &sv, int n_qubits, int ctrl, int q0, int q1) |
| Fredkin (CSWAP): swaps q0 and q1 when ctrl=1. | |
| real | num::quantum::norm (const Statevector &sv) |
| L2 norm of the statevector (should be 1 for a valid quantum state) | |
| void | num::quantum::normalize (Statevector &sv) |
| Normalize statevector in-place. | |
| std::vector< real > | num::quantum::probabilities (const Statevector &sv) |
| Measurement probability for each basis state: p_i = |a_i|^2. | |
| real | num::quantum::expectation (const Statevector &sv, std::function< void(const Statevector &, Statevector &)> op) |
| Expectation value <psi|O|psi> for a Hermitian operator given as matrix-free matvec. | |
| real | num::quantum::expectation_z (const Statevector &sv, int qubit) |
| <Z_q> = P(q=0) - P(q=1) for qubit q | |
| real | num::quantum::expectation_x (const Statevector &sv, int n_qubits, int qubit) |
| <X_q> for qubit q | |
| real | num::quantum::expectation_y (const Statevector &sv, int n_qubits, int qubit) |
| <Y_q> for qubit q | |
| std::array< std::complex< real >, 4 > | num::quantum::reduced_density_matrix (const Statevector &sv, int n_qubits, int qubit) |
| Reduced density matrix for a single qubit (2x2, returned row-major) | |
| real | num::quantum::entanglement_entropy (const Statevector &sv, int n_qubits, int qubit) |
| Von Neumann entropy of a single qubit's reduced density matrix. | |
Statevector-based quantum circuit simulator.
Simulates an n-qubit system as a dense complex statevector of length 2^n. Qubit indexing is little-endian: qubit 0 is the least-significant bit of the basis-state index.
Definition in file statevector.hpp.