DQCsim
|
Represents a square matrix used for describing N-qubit gates. More...
Public Member Functions | |
Matrix (HandleIndex handle) noexcept | |
Wraps the given matrix handle. More... | |
Matrix (size_t num_qubits, const complex *matrix) | |
Constructs a matrix from a row-major flattened array of 4**num_qubits complex s. More... | |
Matrix (size_t num_qubits, const double *matrix) | |
Constructs a matrix from a row-major flattened array of 2 * 4**num_qubits complex s. More... | |
Matrix (PredefinedGate gate) | |
Constructs a non-parameterized predefined matrix. More... | |
Matrix (PredefinedGate gate, ArbData &¶meters) | |
Constructs a predefined matrix, using ArbData to represent the parameters for parameterized gates. More... | |
Matrix (PredefinedGate gate, const ArbData ¶meters) | |
Constructs a predefined matrix, using ArbData to represent the parameters for parameterized gates. More... | |
Matrix (PauliBasis basis) | |
Constructs a Pauli basis matrix. More... | |
Matrix (const Matrix &src) | |
Copy-constructs a matrix. More... | |
void | operator= (const Matrix &src) |
Copy assignment operator for matrices. More... | |
Matrix (Matrix &&)=default | |
Default move constructor. | |
Matrix & | operator= (Matrix &&)=default |
Default move assignment. | |
size_t | size () const |
Returns the number of elements in the matrix. More... | |
size_t | dimension () const |
Returns the number of rows/columns in the matrix. More... | |
size_t | num_qubits () const |
Returns the number of qubits associated with the matrix. More... | |
std::vector< complex > | get () const |
Returns the data contained by the matrix in row-major form as complex numbers. More... | |
std::vector< double > | get_as_doubles () const |
Returns the data contained by the matrix in row-major form as pairs of real/imag doubles. More... | |
bool | approx_eq (const Matrix &other, double epsilon=0.000001, bool ignore_global_phase=true) const |
Approximate equality operator for two matrices. More... | |
bool | basis_approx_eq (const Matrix &other, double epsilon=0.000001) const |
Approximate equality operator for two basis matrices. More... | |
bool | approx_unitary (double epsilon=0.000001) const |
Approximate unitary check. More... | |
bool | is_predefined (PredefinedGate gate, double epsilon=0.000001, bool ignore_global_phase=true, ArbData *parameters=nullptr) const |
Detects whether this matrix is approximately equal to (some parameterization of) the given predefined gate. More... | |
Matrix | add_controls (size_t number_of_controls) const |
Constructs a controlled matrix from the given matrix. More... | |
std::pair< std::vector< size_t >, Matrix > | strip_control (double epsilon, bool ignore_global_phase) const |
Splits a controlled matrix into its non-controlled submatrix and the indices of the control qubits. More... | |
Public Member Functions inherited from dqcsim::wrap::Handle | |
Handle () noexcept | |
Constructs an empty wrapper. More... | |
Handle (HandleIndex handle) noexcept | |
Wraps the given raw handle. More... | |
virtual | ~Handle () noexcept |
Delete the handle and its wrapper. | |
void | free () |
Explicitly delete the handle, allowing errors to be caught. More... | |
bool | is_valid () const noexcept |
Returns whether this wrapper (still) contains a valid handle. More... | |
HandleIndex | get_handle () const noexcept |
Returns the raw handle without relinquishing ownership. More... | |
HandleIndex | take_handle () noexcept |
Returns the raw handle and relinquishes ownership. More... | |
Handle (const Handle &)=delete | |
void | operator= (const Handle &)=delete |
Handle (Handle &&src) | |
Move constructor; simply moves ownership of the handle from the source object to the constructed object. More... | |
Handle & | operator= (Handle &&src) |
Move constructor; simply moves ownership of the handle from the source object to the assignment target. More... | |
std::string | dump () const |
Returns a string containing a debug dump of the handle. More... | |
HandleType | type () const |
Returns the type of this handle. More... | |
Additional Inherited Members | |
Protected Attributes inherited from dqcsim::wrap::Handle | |
HandleIndex | handle |
The wrapped handle. | |
Represents a square matrix used for describing N-qubit gates.
|
inlinenoexcept |
|
inline |
Constructs a matrix from a row-major flattened array of 4**num_qubits
complex
s.
num_qubits | The number of qubits that the matrix is intended for. Must be 1 or more. |
matrix | Pointer to an array of complex numbers representing the desired matrix in row-major form. The matrix has 4**num_qubits complex entries. |
std::runtime_error | When constructing the matrix failed. |
|
inline |
Constructs a matrix from a row-major flattened array of 2 * 4**num_qubits
complex
s.
num_qubits | The number of qubits that the matrix is intended for. Must be 1 or more. |
matrix | Pointer to an array of complex numbers representing the desired matrix in row-major form using (real, imag) pairs. The matrix contains 2*4**num_qubits doubles. |
std::runtime_error | When constructing the matrix failed. |
|
inline |
Constructs a non-parameterized predefined matrix.
gate | The gate to construct the matrix for. |
std::runtime_error | When the matrix for a parameterized gate type is requested, or constructing the matrix failed. |
|
inline |
Constructs a predefined matrix, using ArbData
to represent the parameters for parameterized gates.
The ArbData
needed for the rotation gates can be trivially constructed in-line. Here's the relevant code:
gate | The gate to construct the matrix for. |
parameters | The parameters for the gate; refer to the docs for PredefinedGate for more information. |
std::runtime_error | When constructing the matrix failed. |
|
inline |
Constructs a predefined matrix, using ArbData
to represent the parameters for parameterized gates.
gate | The gate to construct the matrix for. |
parameters | The parameters for the gate; refer to the docs for PredefinedGate for more information. |
std::runtime_error | When constructing the matrix failed. |
|
inline |
|
inline |
|
inline |
Copy assignment operator for matrices.
src | The object to copy from. |
std::runtime_error | When the source handle is invalid, any previously wrapped handle in the destination object could not be freed, or construction of the new handle failed for some reason. |
|
inline |
|
inline |
|
inline |
|
inline |
|
inline |
|
inline |
Approximate equality operator for two matrices.
If ignore_gphase is set, this checks that the following holds for some x:
\[ This \cdot e^{ix} \approx Other \]
other | The matrix to compare to. |
epsilon | The maximum tolerated RMS variation of the elements. |
ignore_global_phase | Whether global phase differences should be ignored in the comparison. |
std::runtime_error | When either handle is invalid. |
|
inline |
Approximate equality operator for two basis matrices.
This checks that the following holds for some x and y:
\[ This \cdot \begin{bmatrix} e^{ix} & 0 \\ 0 & e^{iy} \end{bmatrix} \approx Other \]
other | The matrix to compare to. |
epsilon | The maximum tolerated RMS variation of the elements. |
std::runtime_error | When either handle is invalid. |
|
inline |
Approximate unitary check.
This internally computes the product of this matrix and its Hermetian, and then does an approximate compare against the identity matrix.
epsilon | The maximum tolerated RMS variation between the identity matrix and the computed product. |
std::runtime_error | When the handle is invalid. |
|
inline |
Detects whether this matrix is approximately equal to (some parameterization of) the given predefined gate.
The detected parameters are optionally returned as an ArbData
if the matrix matches. If you want to compare to a specific parameterization of a predefined gate (for instance, an X rotation of 45 degrees), construct its matrix first, and then compare with approx_eq()
.
gate | The predefined gate matrix to detect. |
epsilon | The maximum tolerated RMS variation of the elements. |
ignore_global_phase | Whether global phase differences should be ignored in the comparison. |
parameters | If non-null, the detected parameters (if any) are written into the referenced ArbData . Any previous contents are discarded. |
std::runtime_error | When the current handle is invalid, detection fails, or parameters could not be updated. |
|
inline |
|
inline |
Splits a controlled matrix into its non-controlled submatrix and the indices of the control qubits.
epsilon | The maximum magitude of the difference between the column vectors of the input matrix and the identity matrix (after dephasing if ignore_phase is set) for the column vector to be considered to not affect the respective entry in the quantum state vector. Note that if this is greater than zero, the resulting gate may not be exactly equivalent. |
ignore_global_phase | If this is set, any global phase in the matrix is ignored, but note that if control qubits are stripped the "global" phase of the resulting submatrix is always significant. |
std::runtime_error | When the handle is invalid or construction of the new matrix failed. |