示例#1
0
 def _represent_base(self, basis, **options):
     j = options.get('j', Rational(1, 2))
     size, mvals = m_values(j)
     result = zeros((size, size))
     for p in range(size):
         for q in range(size):
             me = self.matrix_element(j, mvals[p], j, mvals[q])
             result[p, q] = me
     return result
示例#2
0
 def _represent_coupled_base(self, **options):
     evect = self.uncoupled_class()
     result = zeros(self.hilbert_space.dimension, 1)
     if self.j == int(self.j):
         start = self.j**2
     else:
         start = (2*self.j-1)*(1+2*self.j)/4
     result[start:start+2*self.j+1,0] = evect(self.j, self.m)._represent_base(**options)
     return result
示例#3
0
文件: spin.py 项目: hitej/meta-core
 def _represent_base(self, basis, **options):
     j = options.get("j", Rational(1, 2))
     size, mvals = m_values(j)
     result = zeros((size, size))
     for p in range(size):
         for q in range(size):
             me = self.matrix_element(j, mvals[p], j, mvals[q])
             result[p, q] = me
     return result
示例#4
0
文件: spin.py 项目: tomtwohats/sympy
 def _represent_coupled_base(self, **options):
     evect = self.uncoupled_class()
     result = zeros(self.hilbert_space.dimension, 1)
     if self.j == int(self.j):
         start = self.j**2
     else:
         start = (2*self.j-1)*(1+2*self.j)/4
     result[start:start+2*self.j+1,0] = evect(self.j, self.m)._represent_base(**options)
     return result
示例#5
0
文件: spin.py 项目: hitej/meta-core
 def _represent_base(self, **options):
     j = self.j
     alpha = options.get("alpha", 0)
     beta = options.get("beta", 0)
     gamma = options.get("gamma", 0)
     size, mvals = m_values(j)
     result = zeros((size, 1))
     for p in range(size):
         result[p, 0] = Rotation.D(self.j, mvals[p], self.m, alpha, beta, gamma).doit()
     return result
示例#6
0
 def _represent_base(self, **options):
     j = self.j
     alpha = options.get('alpha', 0)
     beta = options.get('beta', 0)
     gamma = options.get('gamma', 0)
     size, mvals = m_values(j)
     result = zeros((size,1))
     for p in range(size):
         result[p,0] = Rotation.D(self.j, mvals[p], self.m, alpha, beta, gamma).doit()
     return result
示例#7
0
def matrix_to_zero(e):
    """Convert a zero matrix to the scalar zero."""
    if isinstance(e, Matrix):
        if matrices.zeros(*e.shape) == e:
            e = Integer(0)
    elif isinstance(e, numpy_ndarray):
        e = _numpy_matrix_to_zero(e)
    elif isinstance(e, scipy_sparse_matrix):
        e = _scipy_sparse_matrix_to_zero(e)
    return e
示例#8
0
def matrix_to_zero(e):
    """Convert a zero matrix to the scalar zero."""
    if isinstance(e, Matrix):
        if matrices.zeros(e.shape) == e:
            e = Integer(0)
    elif isinstance(e, numpy_ndarray):
        e = _numpy_matrix_to_zero(e)
    elif isinstance(e, scipy_sparse_matrix):
        e = _scipy_sparse_matrix_to_zero(e)
    return e
示例#9
0
 def _represent_base(self, **options):
     j = sympify(self.j)
     m = sympify(self.m)
     alpha = sympify(options.get('alpha', 0))
     beta = sympify(options.get('beta', 0))
     gamma = sympify(options.get('gamma', 0))
     if self.j.is_number:
         size, mvals = m_values(j)
         result = zeros(size, 1)
         for p in range(size):
             if m.is_number and alpha.is_number and beta.is_number and gamma.is_number:
                 result[p,0] = Rotation.D(self.j, mvals[p], self.m, alpha, beta, gamma).doit()
             else:
                 result[p,0] = Rotation.D(self.j, mvals[p], self.m, alpha, beta, gamma)
         return result
     else:
         mi = symbols("mi")
         result = zeros(1, 1)
         result[0] = (Rotation.D(self.j, mi, self.m, alpha, beta, gamma), mi)
         return result
示例#10
0
文件: spin.py 项目: tomtwohats/sympy
 def _represent_base(self, **options):
     j = sympify(self.j)
     m = sympify(self.m)
     alpha = sympify(options.get('alpha', 0))
     beta = sympify(options.get('beta', 0))
     gamma = sympify(options.get('gamma', 0))
     if self.j.is_number:
         size, mvals = m_values(j)
         result = zeros(size, 1)
         for p in range(size):
             if m.is_number and alpha.is_number and beta.is_number and gamma.is_number:
                 result[p,0] = Rotation.D(self.j, mvals[p], self.m, alpha, beta, gamma).doit()
             else:
                 result[p,0] = Rotation.D(self.j, mvals[p], self.m, alpha, beta, gamma)
         return result
     else:
         mi = symbols("mi")
         result = zeros(1, 1)
         result[0] = (Rotation.D(self.j, mi, self.m, alpha, beta, gamma), mi)
         return result
示例#11
0
文件: qubit.py 项目: ENuge/sympy
def _get_possible_outcomes(m, bits):
    """Get the possible states that can be produced in a measurement.

    Parameters
    ----------
    m : Matrix
        The matrix representing the state of the system.
    bits : tuple, list
        Which bits will be measured.

    Returns
    -------
    result : list
        The list of possible states which can occur given this measurement.
        These are un-normalized so we can derive the probability of finding
        this state by taking the inner product with itself
    """

    # This is filled with loads of dirty binary tricks...You have been warned

    size = max(m.shape) # Max of shape to account for bra or ket
    nqubits = int(math.log(size,2)+.1) # Number of qubits possible

    # Make the output states and put in output_matrices, nothing in them now.
    # Each state will represent a possible outcome of the measurement
    # Thus, output_matrices[0] is the matrix which we get when all measured
    # bits return 0. and output_matrices[1] is the matrix for only the 0th
    # bit being true
    output_matrices = []
    for i in range(1<<len(bits)):
        output_matrices.append(zeros(2**nqubits, 1))

    # Bitmasks will help sort how to determine possible outcomes.
    # When the bit mask is and-ed with a matrix-index,
    # it will determine which state that index belongs to
    bit_masks = []
    for bit in bits:
        bit_masks.append(1<<bit)

    # Make possible outcome states
    for i in range(2**nqubits):
        trueness = 0 # This tells us to which output_matrix this value belongs
        # Find trueness
        for j in range(len(bit_masks)):
            if i&bit_masks[j]:
                trueness += j+1
        # Put the value in the correct output matrix
        output_matrices[trueness][i] = m[i]
    return output_matrices
示例#12
0
def _get_possible_outcomes(m, bits):
    """Get the possible states that can be produced in a measurement.

    Parameters
    ----------
    m : Matrix
        The matrix representing the state of the system.
    bits : tuple, list
        Which bits will be measured.

    Returns
    -------
    result : list
        The list of possible states which can occur given this measurement.
        These are un-normalized so we can derive the probability of finding
        this state by taking the inner product with itself
    """

    # This is filled with loads of dirty binary tricks...You have been warned

    size = max(m.shape)  # Max of shape to account for bra or ket
    nqubits = int(math.log(size, 2) + .1)  # Number of qubits possible

    # Make the output states and put in output_matrices, nothing in them now.
    # Each state will represent a possible outcome of the measurement
    # Thus, output_matrices[0] is the matrix which we get when all measured
    # bits return 0. and output_matrices[1] is the matrix for only the 0th
    # bit being true
    output_matrices = []
    for i in range(1 << len(bits)):
        output_matrices.append(zeros(2**nqubits, 1))

    # Bitmasks will help sort how to determine possible outcomes.
    # When the bit mask is and-ed with a matrix-index,
    # it will determine which state that index belongs to
    bit_masks = []
    for bit in bits:
        bit_masks.append(1 << bit)

    # Make possible outcome states
    for i in range(2**nqubits):
        trueness = 0  # This tells us to which output_matrix this value belongs
        # Find trueness
        for j in range(len(bit_masks)):
            if i & bit_masks[j]:
                trueness += j + 1
        # Put the value in the correct output matrix
        output_matrices[trueness][i] = m[i]
    return output_matrices