[−][src]Struct dqcsim::common::types::Matrix
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]
&self,
other: &Matrix,
epsilon: f64,
ignore_global_phase: bool
) -> bool
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]
&self,
epsilon: f64,
ignore_global_phase: bool
) -> (HashSet<usize>, Matrix)
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]
fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error> where
__D: Deserializer<'de>,
[src]
__D: Deserializer<'de>,
impl Display for Matrix
[src]
impl Eq for Matrix
[src]
impl From<Basis> for Matrix
[src]
impl<'_, '_> From<BoundUnitaryGate<'_, '_>> for Matrix
[src]
fn from(bound_gate: BoundUnitaryGate<'_, '_>) -> Matrix
[src]
impl From<Matrix> for FixedMatrixConverter
[src]
fn from(matrix: Matrix) -> FixedMatrixConverter
[src]
impl<'_> From<UnboundUnitaryGate<'_>> for Matrix
[src]
fn from(unbound_gate: UnboundUnitaryGate<'_>) -> Matrix
[src]
impl FromArb for Matrix
[src]
impl Hash for Matrix
[src]
fn hash<H: Hasher>(&self, state: &mut H)
[src]
fn hash_slice<H>(data: &[Self], state: &mut H) where
H: Hasher,
1.3.0[src]
H: Hasher,
impl Index<(usize, usize)> for Matrix
[src]
type Output = Complex64
The returned type after indexing.
fn index(&self, index: (usize, usize)) -> &Self::Output
[src]
impl Index<usize> for Matrix
[src]
type Output = Complex64
The returned type after indexing.
fn index(&self, index: usize) -> &Self::Output
[src]
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?
fn into_iter(self) -> Self::IntoIter
[src]
impl PartialEq<Matrix> for Matrix
[src]
impl Serialize for Matrix
[src]
fn serialize<__S>(&self, __serializer: __S) -> Result<__S::Ok, __S::Error> where
__S: Serializer,
[src]
__S: Serializer,
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.
fn try_from(gate_type: UnitaryGateType) -> Result<Self, Self::Error>
[src]
impl TryFrom<Vec<Complex<f64>>> for Matrix
[src]
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]
T: 'static + ?Sized,
impl<T> Borrow<T> for T where
T: ?Sized,
[src]
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
[src]
T: ?Sized,
pub fn borrow_mut(&mut self) -> &mut T
[src]
impl<T> DeserializeOwned for T where
T: for<'de> Deserialize<'de>,
[src]
T: for<'de> Deserialize<'de>,
impl<T> From<T> for T
[src]
impl<T, U> Into<U> for T where
U: From<T>,
[src]
U: From<T>,
impl<I> IntoIterator for I where
I: Iterator,
[src]
I: Iterator,
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?
pub fn into_iter(self) -> I
[src]
impl<T> ToOwned for T where
T: Clone,
[src]
T: Clone,
type Owned = T
The resulting type after obtaining ownership.
pub fn to_owned(&self) -> T
[src]
pub fn clone_into(&self, target: &mut T)
[src]
impl<T> ToString for T where
T: Display + ?Sized,
[src]
T: Display + ?Sized,
impl<T, U> TryFrom<U> for T where
U: Into<T>,
[src]
U: Into<T>,
type Error = Infallible
The type returned in the event of a conversion error.
pub fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>
[src]
impl<T, U> TryInto<U> for T where
U: TryFrom<T>,
[src]
U: TryFrom<T>,
type Error = <U as TryFrom<T>>::Error
The type returned in the event of a conversion error.
pub fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>
[src]
impl<V, T> VZip<V> for T where
V: MultiLane<T>,
V: MultiLane<T>,