[][src]Struct dqcsim::common::types::Matrix

pub struct Matrix { /* fields omitted */ }

Matrix wrapper for Gate matrices.

Implementations

impl Matrix[src]

pub fn new(elements: impl IntoIterator<Item = Complex64>) -> Result<Self>[src]

Returns a new Matrix with provided elements.

pub fn new_identity(dimension: usize) -> Self[src]

Returns a new identity Matrix with given dimension.

pub fn approx_eq(
    &self,
    other: &Matrix,
    epsilon: f64,
    ignore_global_phase: bool
) -> bool
[src]

Approximately compares this Matrix with another Matrix. epsilon specifies the maximum element-wise root-mean-square error between the matrices that results in a positive match. ignore_phase specifies whether the aforementioned check should ignore global phase.

pub fn basis_approx_eq(&self, other: &Matrix, epsilon: f64) -> bool[src]

Approximately compares two matrices representing bases with each other.

The basis representation works as follows:

  • (apply hermetian of matrix as gate if measurement)
  • measure/prep Z
  • apply matrix as gate

Any rotation around the Z axis is don't care before and after the prep/measurement, because that information is thrown away when the prep/measurement occurs. Global phase is also don't care as usual. That means the following must hold for the bases to be equal:

              / e^ix   0  \  ~
    basis_a * |           |  =  basis_b
              \  0   e^iy /

    / a_a e^ix   a_b e^iy \  ~  / b_a   b_b \
    |                     |  =  |           |
    \ a_c e^ix   a_d e^iy /     \ b_c   b_d /

with x and y being free variables.

pub fn approx_unitary(&self, epsilon: f64) -> bool[src]

Checks whether this Matrix is approximately unitary by multiplying itself with its hermetian, and measuring the RMS difference of the result and the identity matrix. If this difference is more than epsilon the matrix is not (sufficiently) unitary and this function returns false, otherwise it returns true.

pub fn add_controls(&self, number_of_controls: usize) -> Self[src]

Returns new Matrix with number_of_control qubits added.

pub fn strip_control(
    &self,
    epsilon: f64,
    ignore_global_phase: bool
) -> (HashSet<usize>, Matrix)
[src]

Returns new Matrix with control behavior removed from the Matrix, and the control indices corresponding to the target qubits acting as control in the original Matrix.

epsilon specifies 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. If ignore_global_phase 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.

This function assumes that the incoming matrix is unitary (within epsilon) without verifying that this is the case. The results may thus be invalid if it was not.

The identity matrix special case is handled by interpreting all qubits as non-control (any set of qubits would satisfy the controlled matrix criterium).

pub fn len(&self) -> usize[src]

Returns the number of elements in the Matrix.

pub fn is_empty(&self) -> bool[src]

Returns true if the Matrix is empty.

pub fn dimension(&self) -> usize[src]

Returns the dimension of the Matrix. The dimension equals the square root of the number of elements.

pub fn num_qubits(&self) -> Option<usize>[src]

Returns the number of qubits for this Matrix.

pub fn get(&self, row: usize, column: usize) -> Option<&Complex64>[src]

Returns the element at given row and colum index. Returns None for out of bound indices.

Trait Implementations

impl Clone for Matrix[src]

impl Debug for Matrix[src]

impl<'de> Deserialize<'de> for Matrix[src]

impl Display for Matrix[src]

impl Eq for Matrix[src]

impl From<Basis> for Matrix[src]

impl<'_, '_> From<BoundUnitaryGate<'_, '_>> for Matrix[src]

impl From<Matrix> for FixedMatrixConverter[src]

impl<'_> From<UnboundUnitaryGate<'_>> for Matrix[src]

impl FromArb for Matrix[src]

impl Hash for Matrix[src]

impl Index<(usize, usize)> for Matrix[src]

type Output = Complex64

The returned type after indexing.

impl Index<usize> for Matrix[src]

type Output = Complex64

The returned type after indexing.

impl IndexMut<(usize, usize)> for Matrix[src]

impl IndexMut<usize> for Matrix[src]

impl IntoIterator for Matrix[src]

type Item = Complex64

The type of the elements being iterated over.

type IntoIter = IntoIter<Self::Item>

Which kind of iterator are we turning this into?

impl PartialEq<Matrix> for Matrix[src]

impl Serialize for Matrix[src]

impl ToArb for Matrix[src]

impl TryFrom<UnitaryGateType> for Matrix[src]

type Error = &'static str

The type returned in the event of a conversion error.

impl TryFrom<Vec<Complex<f64>>> for Matrix[src]

type Error = Error

The type returned in the event of a conversion error.

Auto Trait Implementations

impl RefUnwindSafe for Matrix

impl Send for Matrix

impl Sync for Matrix

impl Unpin for Matrix

impl UnwindSafe for Matrix

Blanket Implementations

impl<T> Any for T where
    T: 'static + ?Sized
[src]

impl<T> Borrow<T> for T where
    T: ?Sized
[src]

impl<T> BorrowMut<T> for T where
    T: ?Sized
[src]

impl<T> DeserializeOwned for T where
    T: for<'de> Deserialize<'de>, 
[src]

impl<T> From<T> for T[src]

impl<T, U> Into<U> for T where
    U: From<T>, 
[src]

impl<I> IntoIterator for I where
    I: Iterator
[src]

type Item = <I as Iterator>::Item

The type of the elements being iterated over.

type IntoIter = I

Which kind of iterator are we turning this into?

impl<T> ToOwned for T where
    T: Clone
[src]

type Owned = T

The resulting type after obtaining ownership.

impl<T> ToString for T where
    T: Display + ?Sized
[src]

impl<T, U> TryFrom<U> for T where
    U: Into<T>, 
[src]

type Error = Infallible

The type returned in the event of a conversion error.

impl<T, U> TryInto<U> for T where
    U: TryFrom<T>, 
[src]

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.

impl<V, T> VZip<V> for T where
    V: MultiLane<T>,