|
numerics
|
Typedefs | |
| using | Statevector = num::CVector |
| Dense statevector: complex vector of length 2^n_qubits, backed by num::CVector. | |
| using | 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 | Gate2Q = std::array< cplx, 16 > |
| 4x4 two-qubit gate stored row-major (16 entries) | |
| using | cplx = std::complex< real > |
Functions | |
| Statevector | zero_state (int n_qubits) |
| Returns |0...0> computational basis state for n_qubits qubits. | |
| Statevector | basis_state (int n_qubits, int k) |
| Returns the computational basis state |k> for an n_qubits system. | |
| Gate | gate_x () |
| Pauli-X (NOT) | |
| Gate | gate_y () |
| Pauli-Y. | |
| Gate | gate_z () |
| Pauli-Z. | |
| Gate | gate_h () |
| Hadamard. | |
| Gate | gate_s () |
| Phase gate S = diag(1, i) | |
| Gate | gate_sdg () |
| S† = diag(1, -i) | |
| Gate | gate_t () |
| T gate = diag(1, e^{ipi/4}) | |
| Gate | gate_tdg () |
| T† gate. | |
| Gate | gate_rx (real theta) |
| Rotation about X: R_x(theta) = exp(-ithetaX/2) | |
| Gate | gate_ry (real theta) |
| Rotation about Y: R_y(theta) = exp(-ithetaY/2) | |
| Gate | gate_rz (real theta) |
| Rotation about Z: R_z(theta) = exp(-ithetaZ/2) | |
| Gate | gate_p (real lambda) |
| Phase gate: diag(1, e^{ilambda}) | |
| Gate | gate_u (real theta, real phi, real lambda) |
| General SU(2) gate. | |
| Gate2Q | gate2q_cnot () |
| CNOT (qubit 0 = control, qubit 1 = target in subspace) | |
| Gate2Q | gate2q_cz () |
| Controlled-Z. | |
| Gate2Q | gate2q_swap () |
| SWAP. | |
| void | apply_1q (Statevector &sv, int n_qubits, const Gate &G, int target) |
| Apply a 2x2 gate to a single qubit in-place. | |
| void | 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 | apply_cnot (Statevector &sv, int n_qubits, int control, int target) |
| CNOT with explicit control and target qubits. | |
| void | apply_cz (Statevector &sv, int n_qubits, int control, int target) |
| Controlled-Z. | |
| void | apply_swap (Statevector &sv, int n_qubits, int q0, int q1) |
| SWAP two qubits. | |
| void | apply_toffoli (Statevector &sv, int n_qubits, int c0, int c1, int target) |
| Toffoli (CCX) gate. | |
| void | apply_cy (Statevector &sv, int n_qubits, int control, int target) |
| Controlled-Y. | |
| void | 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 | apply_cswap (Statevector &sv, int n_qubits, int ctrl, int q0, int q1) |
| Fredkin (CSWAP): swaps q0 and q1 when ctrl=1. | |
| real | norm (const Statevector &sv) |
| L2 norm of the statevector (should be 1 for a valid quantum state) | |
| void | normalize (Statevector &sv) |
| Normalize statevector in-place. | |
| std::vector< real > | probabilities (const Statevector &sv) |
| Measurement probability for each basis state: p_i = |a_i|^2. | |
| real | 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 | expectation_z (const Statevector &sv, int qubit) |
| <Z_q> = P(q=0) - P(q=1) for qubit q | |
| real | expectation_x (const Statevector &sv, int n_qubits, int qubit) |
| <X_q> for qubit q | |
| real | expectation_y (const Statevector &sv, int n_qubits, int qubit) |
| <Y_q> for qubit q | |
| std::array< std::complex< real >, 4 > | reduced_density_matrix (const Statevector &sv, int n_qubits, int qubit) |
| Reduced density matrix for a single qubit (2x2, returned row-major) | |
| real | entanglement_entropy (const Statevector &sv, int n_qubits, int qubit) |
| Von Neumann entropy of a single qubit's reduced density matrix. | |
| using num::quantum::cplx = typedef std::complex<real> |
Definition at line 7 of file statevector.cpp.
| using num::quantum::Gate = typedef std::array<cplx, 4> |
2x2 single-qubit gate stored row-major: { G[0,0], G[0,1], G[1,0], G[1,1] }
Definition at line 31 of file statevector.hpp.
| using num::quantum::Gate2Q = typedef std::array<cplx, 16> |
4x4 two-qubit gate stored row-major (16 entries)
Definition at line 34 of file statevector.hpp.
Dense statevector: complex vector of length 2^n_qubits, backed by num::CVector.
Definition at line 28 of file statevector.hpp.
Apply a 2x2 gate to a single qubit in-place.
| sv | Statevector of length 2^n_qubits (modified in-place) |
| n_qubits | Total number of qubits |
| G | 2x2 gate (row-major) |
| target | Target qubit index (0 = LSB) |
Definition at line 107 of file statevector.cpp.
References num::ipow().
Referenced by expectation_x(), and expectation_y().
Apply a general 4x4 two-qubit gate to qubits q0, q1.
| sv | Statevector |
| n_qubits | Total number of qubits |
| G | 4x4 gate acting on (q0, q1) in little-endian order |
| q0 | First qubit (LSB of the 2-qubit subspace) |
| q1 | Second qubit (MSB of the 2-qubit subspace) |
Definition at line 122 of file statevector.cpp.
References num::ipow().
| void num::quantum::apply_cnot | ( | Statevector & | sv, |
| int | n_qubits, | ||
| int | control, | ||
| int | target | ||
| ) |
CNOT with explicit control and target qubits.
Definition at line 139 of file statevector.cpp.
References num::ipow().
| 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.
Definition at line 277 of file statevector.cpp.
References num::ipow().
Fredkin (CSWAP): swaps q0 and q1 when ctrl=1.
Definition at line 288 of file statevector.cpp.
References num::ipow().
| void num::quantum::apply_cy | ( | Statevector & | sv, |
| int | n_qubits, | ||
| int | control, | ||
| int | target | ||
| ) |
| void num::quantum::apply_cz | ( | Statevector & | sv, |
| int | n_qubits, | ||
| int | control, | ||
| int | target | ||
| ) |
| void num::quantum::apply_swap | ( | Statevector & | sv, |
| int | n_qubits, | ||
| int | q0, | ||
| int | q1 | ||
| ) |
| Statevector num::quantum::basis_state | ( | int | n_qubits, |
| int | k | ||
| ) |
Returns the computational basis state |k> for an n_qubits system.
Definition at line 18 of file statevector.cpp.
References num::ipow().
| real num::quantum::entanglement_entropy | ( | const Statevector & | sv, |
| int | n_qubits, | ||
| int | qubit | ||
| ) |
Von Neumann entropy of a single qubit's reduced density matrix.
Definition at line 248 of file statevector.cpp.
References num::e, num::ipow(), and reduced_density_matrix().
Referenced by main().
| 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.
Definition at line 192 of file statevector.cpp.
References num::ipow(), and num::BasicVector< T >::size().
| real num::quantum::expectation_x | ( | const Statevector & | sv, |
| int | n_qubits, | ||
| int | qubit | ||
| ) |
<X_q> for qubit q
Definition at line 211 of file statevector.cpp.
References apply_1q(), gate_x(), num::ipow(), and num::BasicVector< T >::size().
| real num::quantum::expectation_y | ( | const Statevector & | sv, |
| int | n_qubits, | ||
| int | qubit | ||
| ) |
<Y_q> for qubit q
Definition at line 220 of file statevector.cpp.
References apply_1q(), gate_y(), num::ipow(), and num::BasicVector< T >::size().
| real num::quantum::expectation_z | ( | const Statevector & | sv, |
| int | qubit | ||
| ) |
<Z_q> = P(q=0) - P(q=1) for qubit q
Definition at line 201 of file statevector.cpp.
References num::ipow(), and num::BasicVector< T >::size().
| Gate2Q num::quantum::gate2q_cnot | ( | ) |
CNOT (qubit 0 = control, qubit 1 = target in subspace)
Definition at line 78 of file statevector.cpp.
| Gate2Q num::quantum::gate2q_cz | ( | ) |
Controlled-Z.
Definition at line 87 of file statevector.cpp.
| Gate2Q num::quantum::gate2q_swap | ( | ) |
SWAP.
Definition at line 96 of file statevector.cpp.
| Gate num::quantum::gate_h | ( | ) |
Hadamard.
Definition at line 30 of file statevector.cpp.
Phase gate: diag(1, e^{ilambda})
Definition at line 60 of file statevector.cpp.
Rotation about X: R_x(theta) = exp(-ithetaX/2)
Definition at line 47 of file statevector.cpp.
Rotation about Y: R_y(theta) = exp(-ithetaY/2)
Definition at line 51 of file statevector.cpp.
Rotation about Z: R_z(theta) = exp(-ithetaZ/2)
Definition at line 55 of file statevector.cpp.
| Gate num::quantum::gate_s | ( | ) |
Phase gate S = diag(1, i)
Definition at line 35 of file statevector.cpp.
| Gate num::quantum::gate_sdg | ( | ) |
S† = diag(1, -i)
Definition at line 36 of file statevector.cpp.
| Gate num::quantum::gate_t | ( | ) |
| Gate num::quantum::gate_tdg | ( | ) |
General SU(2) gate.
Definition at line 65 of file statevector.cpp.
References num::ipow(), and num::phi.
| Gate num::quantum::gate_x | ( | ) |
| Gate num::quantum::gate_y | ( | ) |
| Gate num::quantum::gate_z | ( | ) |
Pauli-Z.
Definition at line 28 of file statevector.cpp.
| real num::quantum::norm | ( | const Statevector & | sv | ) |
L2 norm of the statevector (should be 1 for a valid quantum state)
Definition at line 177 of file statevector.cpp.
References num::norm().
Referenced by main().
| void num::quantum::normalize | ( | Statevector & | sv | ) |
Normalize statevector in-place.
Definition at line 181 of file statevector.cpp.
References num::ipow(), and num::norm().
| std::vector< real > num::quantum::probabilities | ( | const Statevector & | sv | ) |
Measurement probability for each basis state: p_i = |a_i|^2.
Definition at line 186 of file statevector.cpp.
References num::ipow(), and num::BasicVector< T >::size().
Referenced by main(), and num::Circuit::run().
| std::array< cplx, 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)
Definition at line 228 of file statevector.cpp.
References num::ipow().
Referenced by entanglement_entropy().
| Statevector num::quantum::zero_state | ( | int | n_qubits | ) |
Returns |0...0> computational basis state for n_qubits qubits.
Definition at line 12 of file statevector.cpp.
Referenced by num::Circuit::statevector_at().