|
Sequential Quantum Gate Decomposer
v1.9.6
Powerful decomposition of general unitarias into one- and two-qubit gates gates
|
Quantum density matrix Ï for mixed-state representation. More...
#include <density_matrix.h>

Public Member Functions | |
| void | apply_local_unitary (const matrix_base< QGD_Complex16 > &u_kernel, const std::vector< int > &target_qbits) |
| Apply k-qubit unitary using local kernel (general case) More... | |
| void | apply_single_qubit_unitary (const matrix_base< QGD_Complex16 > &u_2x2, int target_qbit) |
| Apply single-qubit unitary using local kernel (optimized) More... | |
| void | apply_two_qubit_unitary (const matrix_base< QGD_Complex16 > &u_2x2, int target_qbit, int control_qbit) |
| Apply two-qubit controlled unitary using local kernel (optimized) More... | |
| void | apply_unitary (const matrix_base< QGD_Complex16 > &U) |
| Apply unitary transformation: Ï â UÏUâ More... | |
| DensityMatrix | clone () const |
| Create deep copy. More... | |
| void | conjugate () |
| Call to conjugate (or un-conjugate) the matrix for CBLAS functions. More... | |
| matrix_base< QGD_Complex16 > | copy () const |
| Call to create a copy of the matrix. More... | |
| void | copy_to (matrix_base< QGD_Complex16 > &target) const |
| Copy the current matrix storage into a reusable target matrix. More... | |
| DensityMatrix (int qbit_num) | |
| Create density matrix for n qubits. More... | |
| DensityMatrix (const matrix_base< QGD_Complex16 > &state_vector) | |
| Create from state vector: Ï = |Ïâ©â¨Ï|. More... | |
| DensityMatrix (QGD_Complex16 *data, int dim) | |
| Wrap existing data (non-owning wrapper) More... | |
| DensityMatrix (const DensityMatrix &other) | |
| Copy constructor. More... | |
| DensityMatrix (DensityMatrix &&other) noexcept | |
| Move constructor. More... | |
| std::vector< double > | eigenvalues () const |
| Get eigenvalues (sorted descending) More... | |
| void | ensure_aligned () |
| double | entropy () const |
| von Neumann entropy: S(Ï) = -Tr(Ï logâ Ï) More... | |
| QGD_Complex16 * | get_data () const |
| Call to get the pointer to the stored data. More... | |
| int | get_dim () const |
| Get matrix dimension (2^qbit_num) More... | |
| int | get_qbit_num () const |
| Get number of qubits. More... | |
| bool | is_conjugated () const |
| Call to get whether the matrix should be conjugated in CBLAS functions or not. More... | |
| bool | is_transposed () const |
| Call to get whether the matrix should be conjugated in CBLAS functions or not. More... | |
| bool | is_valid (double tol=1e-10) const |
| Check if valid density matrix. More... | |
| QGD_Complex16 & | operator() (int i, int j) |
| Element access: Ï(i,j) More... | |
| const QGD_Complex16 & | operator() (int i, int j) const |
| bool | operator< (const matrix_base< QGD_Complex16 > &other) const |
| DensityMatrix & | operator= (const DensityMatrix &other) |
| DensityMatrix & | operator= (DensityMatrix &&other) noexcept |
| QGD_Complex16 & | operator[] (int idx) const |
| Operator [] to access elements in array style (does not check the boundaries of the stored array) More... | |
| DensityMatrix | partial_trace (const std::vector< int > &trace_out) const |
| Compute partial trace over specified qubits. More... | |
| void | print () const |
| Print matrix with properties. More... | |
| void | print_matrix () const |
| Call to prints the stored matrix on the standard output. More... | |
| double | purity () const |
| Calculate purity: Tr(ϲ) More... | |
| void | release_data () |
| Call to release the data stored by the matrix. More... | |
| void | replace_data (QGD_Complex16 *data_in, bool owner_in) |
| Call to replace the stored data by an another data array. More... | |
| void | set_owner (bool owner_in) |
| Call to set the current class instance to be (or not to be) the owner of the stored data array. More... | |
| int | size () const |
| Call to get the number of the allocated elements. More... | |
| QGD_Complex16 | trace () const |
| Calculate trace: Tr(Ï) More... | |
| void | transpose () |
| Call to transpose (or un-transpose) the matrix for CBLAS functions. More... | |
| ~DensityMatrix ()=default | |
| Destructor (uses base class default) More... | |
Static Public Member Functions | |
| static DensityMatrix | maximally_mixed (int qbit_num) |
| Create maximally mixed state: Ï = I/2^n. More... | |
Public Attributes | |
| int | cols |
| The number of columns. More... | |
| QGD_Complex16 * | data |
| pointer to the stored data More... | |
| int | rows |
| The number of rows. More... | |
| int | stride |
| The column stride of the array. (The array elements in one row are a_0, a_1, ... a_{cols-1}, 0, 0, 0, 0. The number of zeros is stride-cols) More... | |
Protected Attributes | |
| bool | conjugated |
| logical variable indicating whether the matrix needs to be conjugated in CBLAS operations More... | |
| bool | owner |
| logical value indicating whether the class instance is the owner of the stored data or not. (If true, the data array is released in the destructor) More... | |
| std::atomic< int64_t > * | references |
| the number of the current references of the present object More... | |
| bool | transposed |
| logical variable indicating whether the matrix needs to be transposed in CBLAS operations More... | |
Private Member Functions | |
| bool | is_hermitian (double tol) const |
| void | validate_dimensions () const |
Private Attributes | |
| int | qbit_num_ |
| Number of qubits. More... | |
Quantum density matrix Ï for mixed-state representation.
Inherits from matrix_base<QGD_Complex16> to reuse:
Adds density matrix specific:
Mathematical properties:
Example:
Definition at line 53 of file density_matrix.h.
|
explicit |
Create density matrix for n qubits.
| qbit_num | Number of qubits (must be >= 1) |
| std::invalid_argument | if qbit_num < 1 |
Initializes to pure ground state: Ï = |0...0â©â¨0...0| Matrix dimension is 2^qbit_num à 2^qbit_num
Definition at line 56 of file density_matrix.cpp.
|
explicit |
Create from state vector: Ï = |Ïâ©â¨Ï|.
| state_vector | Pure state (column vector, inherits from matrix_base) |
| std::invalid_argument | if state_vector is not column vector or dim not power of 2 |
Computes outer product to create density matrix. Resulting matrix represents a pure state with Tr(ϲ) = 1.
Definition at line 73 of file density_matrix.cpp.
| squander::density::DensityMatrix::DensityMatrix | ( | QGD_Complex16 * | data, |
| int | dim | ||
| ) |
Wrap existing data (non-owning wrapper)
| data | Pointer to matrix data (row-major, size dim à dim) |
| dim | Matrix dimension (must be power of 2) |
| std::invalid_argument | if dim is not power of 2 |
Creates non-owning view of existing memory. Caller is responsible for lifetime management of data.
Definition at line 97 of file density_matrix.cpp.
| squander::density::DensityMatrix::DensityMatrix | ( | const DensityMatrix & | other | ) |
Copy constructor.
| other | Density matrix to copy |
Uses matrix_base reference counting - shares memory until modified.
Definition at line 112 of file density_matrix.cpp.
|
noexcept |
Move constructor.
| other | Density matrix to move from |
Takes ownership of other's data, leaving other in valid but empty state.
Definition at line 115 of file density_matrix.cpp.
|
default |
Destructor (uses base class default)
| void squander::density::DensityMatrix::apply_local_unitary | ( | const matrix_base< QGD_Complex16 > & | u_kernel, |
| const std::vector< int > & | target_qbits | ||
| ) |
Apply k-qubit unitary using local kernel (general case)
| u_kernel | The 2^k à 2^k unitary kernel |
| target_qbits | Vector of target qubit indices (size k) |
General optimized local application for arbitrary k-qubit gates. Complexity: O(2^{2N+k}) instead of O(2^{3N})
For k << N, this is much faster than full matrix multiplication.
Definition at line 553 of file density_matrix.cpp.


| void squander::density::DensityMatrix::apply_single_qubit_unitary | ( | const matrix_base< QGD_Complex16 > & | u_2x2, |
| int | target_qbit | ||
| ) |
Apply single-qubit unitary using local kernel (optimized)
| u_2x2 | The 2Ã2 unitary kernel |
| target_qbit | Target qubit index |
Optimized local application that avoids constructing full 2^N Ã 2^N matrix. Complexity: O(2^{2N}) instead of O(2^{3N})
This is the critical optimization for density matrix simulation. Speedup: ~2^N times faster than apply_unitary() for single-qubit gates.
Definition at line 314 of file density_matrix.cpp.

| void squander::density::DensityMatrix::apply_two_qubit_unitary | ( | const matrix_base< QGD_Complex16 > & | u_2x2, |
| int | target_qbit, | ||
| int | control_qbit | ||
| ) |
Apply two-qubit controlled unitary using local kernel (optimized)
| u_2x2 | The 2Ã2 unitary kernel to apply when control is |1â© |
| target_qbit | Target qubit index |
| control_qbit | Control qubit index |
Optimized local application for controlled gates (CNOT, CZ, CRX, etc.) Complexity: O(2^{2N}) instead of O(2^{3N})
Speedup: ~2^N times faster than apply_unitary() for two-qubit gates.
Definition at line 441 of file density_matrix.cpp.

| void squander::density::DensityMatrix::apply_unitary | ( | const matrix_base< QGD_Complex16 > & | U | ) |
Apply unitary transformation: Ï â UÏUâ
| U | Unitary matrix (must be matrix_base<QGD_Complex16>) |
| std::runtime_error | if dimension mismatch |
Modifies density matrix in-place. Uses BLAS for efficient matrix multiplication:
Computational complexity: O(2^(3n))
Definition at line 282 of file density_matrix.cpp.


| DensityMatrix squander::density::DensityMatrix::clone | ( | ) | const |
Create deep copy.
Unlike copy constructor (which shares memory), this creates independent copy.
Definition at line 742 of file density_matrix.cpp.


|
inlineinherited |
Call to conjugate (or un-conjugate) the matrix for CBLAS functions.
Definition at line 252 of file matrix_base.hpp.
|
inlineinherited |
Call to create a copy of the matrix.
Definition at line 410 of file matrix_base.hpp.
|
inlineinherited |
Copy the current matrix storage into a reusable target matrix.
The target is reallocated when dimensions or stride differ; otherwise its existing allocation is reused.
| target | The matrix receiving a deep copy of the current storage. |
Definition at line 433 of file matrix_base.hpp.
| std::vector< double > squander::density::DensityMatrix::eigenvalues | ( | ) | const |
Get eigenvalues (sorted descending)
Uses LAPACK zheev for Hermitian eigenvalue decomposition. Computational complexity: O(2^(3n))
Definition at line 246 of file density_matrix.cpp.


|
inlineinherited |
Definition at line 448 of file matrix_base.hpp.
| double squander::density::DensityMatrix::entropy | ( | ) | const |
von Neumann entropy: S(Ï) = -Tr(Ï logâ Ï)
Computational complexity: O(2^(3n)) via eigenvalue decomposition
Definition at line 189 of file density_matrix.cpp.


|
inlineinherited |
Call to get the pointer to the stored data.
Definition at line 285 of file matrix_base.hpp.
|
inline |
Get matrix dimension (2^qbit_num)
Definition at line 143 of file density_matrix.h.


|
inline |
Get number of qubits.
Definition at line 137 of file density_matrix.h.

|
inlineinherited |
Call to get whether the matrix should be conjugated in CBLAS functions or not.
Definition at line 245 of file matrix_base.hpp.
|
private |
|
inlineinherited |
Call to get whether the matrix should be conjugated in CBLAS functions or not.
Definition at line 263 of file matrix_base.hpp.
| bool squander::density::DensityMatrix::is_valid | ( | double | tol = 1e-10 | ) | const |
Check if valid density matrix.
| tol | Numerical tolerance (default: 1e-10) |
Performs three checks:
Definition at line 202 of file density_matrix.cpp.


|
static |
Create maximally mixed state: Ï = I/2^n.
| qbit_num | Number of qubits |
Properties:
Definition at line 752 of file density_matrix.cpp.

| QGD_Complex16 & squander::density::DensityMatrix::operator() | ( | int | i, |
| int | j | ||
| ) |
Element access: Ï(i,j)
| i | Row index (0 to dim-1) |
| j | Column index (0 to dim-1) |
| std::out_of_range | if indices invalid |
Definition at line 141 of file density_matrix.cpp.
| const QGD_Complex16 & squander::density::DensityMatrix::operator() | ( | int | i, |
| int | j | ||
| ) | const |
Definition at line 148 of file density_matrix.cpp.
|
inlineinherited |
Definition at line 394 of file matrix_base.hpp.
| DensityMatrix & squander::density::DensityMatrix::operator= | ( | const DensityMatrix & | other | ) |
|
noexcept |
|
inlineinherited |
Operator [] to access elements in array style (does not check the boundaries of the stored array)
| idx | the index of the element |
Definition at line 382 of file matrix_base.hpp.
| DensityMatrix squander::density::DensityMatrix::partial_trace | ( | const std::vector< int > & | trace_out | ) | const |
Compute partial trace over specified qubits.
| trace_out | List of qubit indices to trace out |
Example: For 3 qubits, trace_out={2} gives 2-qubit reduced density matrix. Ï_A = Tr_B(Ï_AB) where B are the traced-out qubits.
Computational complexity: O(2^(2n))
Definition at line 651 of file density_matrix.cpp.


| void squander::density::DensityMatrix::print | ( | ) | const |
Print matrix with properties.
Displays:
Definition at line 772 of file density_matrix.cpp.


|
inlineinherited |
Call to prints the stored matrix on the standard output.
Definition at line 471 of file matrix_base.hpp.
| double squander::density::DensityMatrix::purity | ( | ) | const |
Calculate purity: Tr(ϲ)
Computational complexity: O(2^(3n)) via matrix multiplication
Definition at line 173 of file density_matrix.cpp.


|
inlineinherited |
Call to release the data stored by the matrix.
(If the class instance was not the owner of the data, then the data pointer is simply set to NULL pointer.)
Definition at line 311 of file matrix_base.hpp.
|
inlineinherited |
Call to replace the stored data by an another data array.
If the class was the owner of the original data array, then it is released.
| data_in | The data array to be set as a new storage. |
| owner_in | Set true to set the current class instance to be the owner of the data array, or false otherwise. |
Definition at line 297 of file matrix_base.hpp.
|
inlineinherited |
Call to set the current class instance to be (or not to be) the owner of the stored data array.
| owner_in | Set true to set the current class instance to be the owner of the data array, or false otherwise. |
Definition at line 337 of file matrix_base.hpp.
|
inlineinherited |
Call to get the number of the allocated elements.
Definition at line 461 of file matrix_base.hpp.
| QGD_Complex16 squander::density::DensityMatrix::trace | ( | ) | const |
Calculate trace: Tr(Ï)
For valid density matrix: Tr(Ï) = 1 Computational complexity: O(2^n)
Definition at line 159 of file density_matrix.cpp.

|
inlineinherited |
Call to transpose (or un-transpose) the matrix for CBLAS functions.
Definition at line 273 of file matrix_base.hpp.
|
private |
Definition at line 804 of file density_matrix.cpp.
|
inherited |
The number of columns.
Definition at line 44 of file matrix_base.hpp.
|
protectedinherited |
logical variable indicating whether the matrix needs to be conjugated in CBLAS operations
Definition at line 53 of file matrix_base.hpp.
|
inherited |
pointer to the stored data
Definition at line 48 of file matrix_base.hpp.
|
protectedinherited |
logical value indicating whether the class instance is the owner of the stored data or not. (If true, the data array is released in the destructor)
Definition at line 57 of file matrix_base.hpp.
|
private |
Number of qubits.
Definition at line 313 of file density_matrix.h.
|
protectedinherited |
the number of the current references of the present object
Definition at line 59 of file matrix_base.hpp.
|
inherited |
The number of rows.
Definition at line 42 of file matrix_base.hpp.
|
inherited |
The column stride of the array. (The array elements in one row are a_0, a_1, ... a_{cols-1}, 0, 0, 0, 0. The number of zeros is stride-cols)
Definition at line 46 of file matrix_base.hpp.
|
protectedinherited |
logical variable indicating whether the matrix needs to be transposed in CBLAS operations
Definition at line 55 of file matrix_base.hpp.
1.8.13