Construct a PauliTerm from the result of str(pauli_term)
774706
def from_compact_str(cls, str_pauli_term):
        
        coef_str, str_pauli_term = str_pauli_term.split('*')
        try:
            coef = int(coef_str)
        except ValueError:
            try:
                coef = float(coef_str)
            except ValueError:
                coef = complex(coef_str)

        op = sI() * coef
        if str_pauli_term == 'I':
            return op
        ma = re.fullmatch(r'(([XYZ])(\d+))+', str_pauli_term)
        if ma is None:
            raise ValueError(f"Could not parse pauli string {str_pauli_term}")
        for ma in re.finditer(r'([XYZ])(\d+)', str_pauli_term):
            op *= cls(ma.group(1), int(ma.group(2)))

        return op
106478
def term_with_coeff(term, coeff):
    
    if not isinstance(coeff, Number):
        raise ValueError("coeff must be a Number")
    new_pauli = term.copy()
    # We cast to a complex number to ensure that internally the coefficients remain compatible.
    new_pauli.coefficient = complex(coeff)
    return new_pauli
8555
def pauli(qubo):
	
	from blueqat.pauli import qubo_bit
	h = 0.0
	assert all(len(q) == len(qubo) for q in qubo)
	for i in range(len(qubo)):
		h += qubo_bit(i) * qubo[i][i]
		for j in range(i + 1, len(qubo)):
			h += qubo_bit(i)*qubo_bit(j) * (qubo[i][j] + qubo[j][i])
	return h
243299
def _str(self, indent=""):
        """"""
        if self.ndim <= 1:
            return "[" + ", ".join(str(x) for x in self) + "]"
        elif self.ndim == 2:
            sep = ",\n" + indent
            return "[" + sep.join(x._str(indent + " ") for x in self) + "]"
        else:
            sep = ",\n\n" + indent
            return "[" + sep.join(x._str(indent + " ") for x in self) + "]"
122089
def from_coordinates(cls, coordinates):
        """"""
        prim = cls()
        for coord in coordinates:
            pm = PseudoMonomer(ampal_parent=prim)
            pa = PseudoAtom(coord, ampal_parent=pm)
            pm.atoms = OrderedDict([('CA', pa)])
            prim.append(pm)
        prim.relabel_all()
        return prim
958075
private ImmutableTerm getNestedConcat(String str) {
        List<ImmutableTerm> terms;
        terms = addToTermsList(str);
        if (terms.size() == 1) {
            return terms.get(0);
        }

        ImmutableFunctionalTerm f = termFactory.getImmutableFunctionalTerm(ExpressionOperation.CONCAT, terms.get(0), terms.get(1));
        for (int j = 2; j < terms.size(); j++) {
            f = termFactory.getImmutableFunctionalTerm(ExpressionOperation.CONCAT, f, terms.get(j));
        }
        return f;
    }
1259182
def _sec_to_str(t):
    
    from functools import reduce
    return "%d:%02d:%02d.%02d" % \
        reduce(lambda ll, b: divmod(ll[0], b) + ll[1:],
               [(t*100,), 100, 60, 60])
718413
def parse_term(s):
    """"""
    size, s = s.split(b':', 1)
    size = int(size)
    return s[:size], s[size:]
1238580
def element_data_str(z, eldata):
    '''
    '''

    sym = lut.element_sym_from_Z(z, True)

    cs = contraction_string(eldata)
    if cs == '':
        cs = '(no electron shells)'
    s = '\nElement: {} : {}\n'.format(sym, cs)

    if 'electron_shells' in eldata:
        for shellidx, shell in enumerate(eldata['electron_shells']):
            s += electron_shell_str(shell, shellidx) + '\n'

    if 'ecp_potentials' in eldata:
        s += 'ECP: Element: {}   Number of electrons: {}\n'.format(sym, eldata['ecp_electrons'])

        for pot in eldata['ecp_potentials']:
            s += ecp_pot_str(pot) + '\n'

    return s
1240255
def _one_q_pauli_prep(label, index, qubit):
    """"""
    if index not in [0, 1]:
        raise ValueError(f'Bad Pauli index: {index}')

    if label == 'X':
        if index == 0:
            return Program(RY(pi / 2, qubit))
        else:
            return Program(RY(-pi / 2, qubit))

    elif label == 'Y':
        if index == 0:
            return Program(RX(-pi / 2, qubit))
        else:
            return Program(RX(pi / 2, qubit))

    elif label == 'Z':
        if index == 0:
            return Program()
        else:
            return Program(RX(pi, qubit))

    raise ValueError(f'Bad Pauli label: {label}')
353488
def fromTerm(cls, term):
        """"""

        if isinstance(term, Term):
            term = term.handle
        elif not isinstance(term, (c_void_p, int)):
            raise ArgumentTypeError((str(Term), str(c_void_p)), str(type(term)))

        a = atom_t()
        if PL_get_atom(term, byref(a)):
            return cls(a.value)
374143
def element_data_from_sym(sym):
    '''
    '''

    sym_lower = sym.lower()
    if sym_lower not in _element_sym_map:
        raise KeyError('No element data for symbol \'{}\''.format(sym))
    return _element_sym_map[sym_lower]
887773
def var_str(name, shape):
    

    size = prod(shape)
    ind = (indices(shape) + 1).reshape(-1, size)
    names = ['[' + ','.join(list(map(str, i))) + ']' for i in zip(*ind)]
    names[0] = '%s %s' % (name, names[0])
    return names
1278486
def format_parameter(element):
    
    if isinstance(element, integer_types) or isinstance(element, np.int_):
        return repr(element)
    elif isinstance(element, float):
        return _check_for_pi(element)
    elif isinstance(element, complex):
        out = ''
        r = element.real
        i = element.imag
        if i == 0:
            return repr(r)

        if r != 0:
            out += repr(r)

        if i == 1:
            assert np.isclose(r, 0, atol=1e-14)
            out = 'i'
        elif i == -1:
            assert np.isclose(r, 0, atol=1e-14)
            out = '-i'
        elif i < 0:
            out += repr(i) + 'i'
        elif r != 0:
            out += '+' + repr(i) + 'i'
        else:
            out += repr(i) + 'i'

        return out
    elif isinstance(element, MemoryReference):
        return str(element)
    elif isinstance(element, Expression):
        return _expression_to_string(element)
    elif isinstance(element, MemoryReference):
        return element.out()
    assert False, "Invalid parameter: %r" % element
121087
def from_string(cls, s):
        """"""
        stream = cStringIO(s)
        stream.seek(0)
        return cls(**yaml.safe_load(stream))
385760
def _csv_str(self, param, stats, quantiles, index=None):
        """"""

        buffer = param
        if not index:
            buffer += ', '
        else:
            buffer += '_' + '_'.join([str(i) for i in index]) + ', '

        for stat in ('mean', 'standard deviation', 'mc error'):
            buffer += str(stats[stat][index]) + ', '

        # Index to interval label
        iindex = [key.split()[-1] for key in stats.keys()].index('interval')
        interval = list(stats.keys())[iindex]
        buffer += ', '.join(stats[interval].T[index].astype(str))

        # Process quantiles
        qvalues = stats['quantiles']
        for q in quantiles:
            buffer += ', ' + str(qvalues[q][index])

        return buffer + '\n'
968080
def from_string(proto_str):
    '''
    
    '''
    _, proto_file = tempfile.mkstemp(suffix='.proto')

    with open(proto_file, 'w+') as proto_f:
        proto_f.write(proto_str)

    return from_file(proto_file)