Example #1
0
    def test_is_valid_density_mx(self):
        density_mx = np.array([[0.9, 0], [0, 0.1]], 'complex')
        non_density_mx = np.array([[2.0, 1.0], [-1.0, 0]], 'complex')
        self.assertTrue(mt.is_valid_density_mx(density_mx))
        self.assertFalse(mt.is_valid_density_mx(non_density_mx))

        s = mt.mx_to_string(density_mx)
Example #2
0
    def test_is_hermitian(self):
        herm_mx = np.array([[1, 1 + 2j], [1 - 2j, 3]], 'complex')
        non_herm_mx = np.array([[1, 4 + 2j], [1 + 2j, 3]], 'complex')
        self.assertTrue(mt.is_hermitian(herm_mx))
        self.assertFalse(mt.is_hermitian(non_herm_mx))

        s = mt.mx_to_string(non_herm_mx)
Example #3
0
    def __str__(self):
        s = "Tensor product %s vector with length %d\n" % (self._prep_or_effect, self.dim)
        #ar = self.to_dense()
        #s += _mt.mx_to_string(ar, width=4, prec=2)

        # factors are just other States
        s += " x ".join([_mt.mx_to_string(fct.to_dense(on_space='minimal'), width=4, prec=2) for fct in self.factors])
        return s
Example #4
0
 def __str__(self):
     s = "Linearly Parameterized operation with shape %s, num params = %d\n" % \
         (str(self._ptr.shape), self.numParams)
     s += _mt.mx_to_string(self._ptr, width=5, prec=1)
     s += "\nParameterization:"
     for (i, j), terms in self.elementExpressions.items():
         tStr = ' + '.join(['*'.join(["p%d" % p for p in term.paramIndices])
                            for term in terms])
         s += "LinearOperator[%d,%d] = %s\n" % (i, j, tStr)
     return s
Example #5
0
    def __str__(self):
        s = "Tensor product %s vector with length %d\n" % (
            self._prep_or_effect, self.dim)
        #ar = self.to_dense()
        #s += _mt.mx_to_string(ar, width=4, prec=2)

        # factors are POVMs
        s += " x ".join([
            _mt.mx_to_string(
                fct[self.effectLbls[i]].to_dense(on_space='minimal'),
                width=4,
                prec=2) for i, fct in enumerate(self.factors)
        ])
        return s
Example #6
0
    def test_mx_to_string(self):
        mx = np.array([[1, 1 + 2j], [1 - 2j, 3]], 'complex')

        s = mt.mx_to_string(mx)

        ls = s.split('\n')[:-1]  # trim empty last line
        mx2 = np.zeros_like(mx)
        for i, row in enumerate(ls):
            entries = row.split()
            for j in range(len(entries) // 2):
                mx2[i, j] = float(entries[2 * j]) + 1j * float(
                    entries[2 * j + 1][:-1])  # trim 'j'

        self.assertArraysAlmostEqual(mx, mx2)
Example #7
0
 def __str__(self):
     s = "%s with dimension %d\n" % (self.__class__.__name__, self.dim)
     s += _mt.mx_to_string(self.to_dense(on_space='minimal'),
                           width=4,
                           prec=2)
     return s
Example #8
0
 def __str__(self):
     s = "TPInstrument with elements:\n"
     for lbl, element in self.items():
         s += "%s:\n%s\n" % (
             lbl, _mt.mx_to_string(element.to_dense(), width=4, prec=2))
     return s
Example #9
0
 def __str__(self):
     s = "%s with shape %s\n" % (self.__class__.__name__,
                                 str(self._ptr.shape))
     s += _mt.mx_to_string(self._ptr, width=4, prec=2)
     return s