def single_axis_transverse_component(num_qubits, transverse_axis='z'):

    individual_transverse_terms = []

    for i in range(1, 1 + num_qubits):
        single_term = ''
        t_str = 'T'
        for q in range(1, 1 + num_qubits):
            if i == q:
                single_term += transverse_axis
            else:
                single_term += 'i'

            if q != num_qubits:
                single_term += t_str
                t_str += 'T'

        individual_transverse_terms.append(single_term)

    running_mtx = construct_models.compute(individual_transverse_terms[0])

    for term in individual_transverse_terms[1:]:
        running_mtx += construct_models.compute(term)

    return running_mtx
def single_axis_nearest_neighbour_interaction_chain(num_qubits,
                                                    interaction_axis='x'):
    individual_interaction_terms = []

    for i in range(1, num_qubits):
        single_term = ''
        t_str = 'T'
        for q in range(1, num_qubits + 1):
            if i == q or i + 1 == q:

                single_term += interaction_axis
            else:
                single_term += 'i'

            if q != num_qubits:
                single_term += t_str
                t_str += 'T'

        individual_interaction_terms.append(single_term)

    running_mtx = construct_models.compute(individual_interaction_terms[0])

    for term in individual_interaction_terms[1:]:
        running_mtx += construct_models.compute(term)

    return running_mtx
def process_multipauli_term(term):
    # term of form pauliSet_aJb_iJk_dN
    # where a is operator on site i
    # b is operator on site k
    # N is total number of sites
    # e.g. pauliSet_xJy_1J3_d4

    components = term.split('_')
    components.remove('pauliSet')
    core_operators = list(sorted(construct_models.core_operator_dict.keys()))
    for l in components:
        if l[0] == 'd':
            dim = int(l.replace('d', ''))
        elif l[0] in core_operators:
            operators = l.split('J')
        else:
            sites = l.split('J')
    # get strings when splitting the list elements
    sites = [int(s) for s in sites]
    # want tuples of (site, operator) for dict logic
    all_terms = list(zip(sites, operators))

    term_dict = {'dim': dim, 'terms': [all_terms]}

    full_mod_str = full_model_string(term_dict)
    return construct_models.compute(full_mod_str)
def process_n_qubit_NV_centre_spin(term):
    components = term.split('_')
    for l in components:
        if l[0] == 'd':
            dim = int(l.replace('d', ''))
        elif l == 'spin':
            term_type = 'spin'
        elif l == 'interaction':
            term_type = 'interaction'
        elif l in ['x', 'y', 'z']:
            pauli = l

    if term_type == 'spin':
        t_str = 'T'
        op_name = str(pauli)

        for d in range(dim - 1):
            op_name += str(t_str + 'i')
            t_str += 'T'
    elif term_type == 'interaction':
        p_str = 'P' * dim
        op_name = ''
        for d in range(dim - 1):
            t_str = 'T'
            single_term_name = str(pauli)
            for j in range(dim - 1):
                single_term_name += str(t_str)
                if d == j:
                    single_term_name += pauli
                else:
                    single_term_name += 'i'
                t_str += 'T'
            op_name += single_term_name
            if d < (dim - 2):
                op_name += p_str

    # print("Type {} ; name {}".format(term_type, op_name))
    return construct_models.compute(op_name)