Example #1
0
def test_script():
    logging.basicConfig(level=logging.INFO)
    logging.getLogger().setLevel(logging.INFO)
    # initialize the graph edges (initial and final state)
    initial_state = [("D0", [0])]
    final_state = [("K_S0", [0]), ("K+", [0]), ("K-", [0])]

    tbd_manager = StateTransitionManager(initial_state, final_state,
                                         ["a0", "phi", "a2(1320)-"])
    tbd_manager.number_of_threads = 2

    graph_interaction_settings_groups = tbd_manager.prepare_graphs()
    (solutions, violated_rules
     ) = tbd_manager.find_solutions(graph_interaction_settings_groups)

    print("found " + str(len(solutions)) + " solutions!")
    assert len(solutions) == 5

    # print intermediate state particle names
    for g in solutions:
        print(g.edge_props[1]["@Name"])

    xml_generator = HelicityAmplitudeGeneratorXML()
    xml_generator.generate(solutions)
    xml_generator.write_to_file("D0ToKs0KpKm.xml")
Example #2
0
def test_external_edge_identical_particle_combinatorics(initial_state,
                                                        final_state,
                                                        final_state_groupings,
                                                        result_graph_count):
    tbd_manager = StateTransitionManager(initial_state, final_state, [],
                                         formalism_type='helicity')

    tbd_manager.set_allowed_interaction_types([InteractionTypes.Strong])
    for x in final_state_groupings:
        tbd_manager.add_final_state_grouping(x)
    tbd_manager.number_of_threads = 1

    topology_graphs = tbd_manager.build_topologies()

    init_graphs = tbd_manager.create_seed_graphs(topology_graphs)
    match_external_edges(init_graphs)

    comb_graphs = []
    for x in init_graphs:
        comb_graphs.extend(
            perform_external_edge_identical_particle_combinatorics(x))
    assert len(comb_graphs) == result_graph_count

    ref_mapping_fs = create_edge_id_particle_mapping(comb_graphs[0],
                                                     get_final_state_edges)
    ref_mapping_is = create_edge_id_particle_mapping(comb_graphs[0],
                                                     get_initial_state_edges)

    for x in comb_graphs[1:]:
        assert ref_mapping_fs == create_edge_id_particle_mapping(
            x, get_final_state_edges)
        assert ref_mapping_is == create_edge_id_particle_mapping(
            x, get_initial_state_edges)
Example #3
0
def test_edge_swap(initial_state, final_state):
    tbd_manager = StateTransitionManager(initial_state,
                                         final_state, [],
                                         formalism_type="helicity")

    tbd_manager.set_allowed_interaction_types([InteractionTypes.Strong])
    tbd_manager.number_of_threads = 1

    topology_graphs = tbd_manager.build_topologies()
    init_graphs = tbd_manager.create_seed_graphs(topology_graphs)

    for x in init_graphs:
        ref_mapping = create_edge_id_particle_mapping(x, get_final_state_edges)
        edge_keys = list(ref_mapping.keys())
        edge1 = edge_keys[0]
        edge1_val = x.edges[edge1]
        edge1_props = x.edge_props[edge1]
        edge2 = edge_keys[1]
        edge2_val = x.edges[edge2]
        edge2_props = x.edge_props[edge2]
        x.swap_edges(edge1, edge2)
        assert x.edges[edge1] == edge2_val
        assert x.edges[edge2] == edge1_val
        assert x.edge_props[edge1] == edge2_props
        assert x.edge_props[edge2] == edge1_props
Example #4
0
def test_external_edge_identical_particle_combinatorics(
        initial_state, final_state, final_state_groupings, result_graph_count):
    tbd_manager = StateTransitionManager(initial_state,
                                         final_state, [],
                                         formalism_type="helicity")

    tbd_manager.set_allowed_interaction_types([InteractionTypes.Strong])
    for x in final_state_groupings:
        tbd_manager.add_final_state_grouping(x)
    tbd_manager.number_of_threads = 1

    topology_graphs = tbd_manager.build_topologies()

    init_graphs = tbd_manager.create_seed_graphs(topology_graphs)
    match_external_edges(init_graphs)

    comb_graphs = []
    for x in init_graphs:
        comb_graphs.extend(
            perform_external_edge_identical_particle_combinatorics(x))
    assert len(comb_graphs) == result_graph_count

    ref_mapping_fs = create_edge_id_particle_mapping(comb_graphs[0],
                                                     get_final_state_edges)
    ref_mapping_is = create_edge_id_particle_mapping(comb_graphs[0],
                                                     get_initial_state_edges)

    for x in comb_graphs[1:]:
        assert ref_mapping_fs == create_edge_id_particle_mapping(
            x, get_final_state_edges)
        assert ref_mapping_is == create_edge_id_particle_mapping(
            x, get_initial_state_edges)
def test_external_edge_initialization(initial_state, final_state,
                                      final_state_groupings,
                                      result_graph_count):
    tbd_manager = StateTransitionManager(initial_state, final_state, [],
                                         formalism_type='helicity')

    tbd_manager.set_allowed_interaction_types([InteractionTypes.Strong])
    for x in final_state_groupings:
        tbd_manager.add_final_state_grouping(x)
    tbd_manager.number_of_threads = 1

    topology_graphs = tbd_manager.build_topologies()

    init_graphs = tbd_manager.create_seed_graphs(topology_graphs)
    assert len(init_graphs) == result_graph_count
Example #6
0
def test_external_edge_initialization(initial_state, final_state,
                                      final_state_groupings,
                                      result_graph_count):
    tbd_manager = StateTransitionManager(initial_state, final_state, [],
                                         formalism_type='helicity')

    tbd_manager.set_allowed_interaction_types([InteractionTypes.Strong])
    for x in final_state_groupings:
        tbd_manager.add_final_state_grouping(x)
    tbd_manager.number_of_threads = 1

    topology_graphs = tbd_manager.build_topologies()

    init_graphs = tbd_manager.create_seed_graphs(topology_graphs)
    assert len(init_graphs) == result_graph_count
Example #7
0
def test_canonical_clebsch_gordan_ls_coupling(initial_state, final_state, L, S,
                                              solution_count):
    # because the amount of solutions is too big we change the default domains
    formalism_type = "canonical-helicity"
    int_settings = create_default_interaction_settings(formalism_type)

    remove_conservation_law(int_settings[InteractionTypes.Strong],
                            ParityConservationHelicity())

    tbd_manager = StateTransitionManager(
        initial_state,
        final_state,
        [],
        interaction_type_settings=int_settings,
        formalism_type=formalism_type,
    )

    tbd_manager.set_allowed_interaction_types([InteractionTypes.Strong])
    tbd_manager.number_of_threads = 2
    tbd_manager.filter_remove_qns = []

    l_label = InteractionQuantumNumberNames.L
    s_label = InteractionQuantumNumberNames.S
    qn_label = XMLLabelConstants.QuantumNumber

    spin_converter = SpinQNConverter()
    node_props = {
        0: {
            qn_label.name: [
                spin_converter.convert_to_dict(l_label, L),
                spin_converter.convert_to_dict(s_label, S),
            ]
        }
    }
    graph_node_setting_pairs = tbd_manager.prepare_graphs()
    for v in graph_node_setting_pairs.values():
        for e in v:
            e[0].node_props = node_props

    solutions = tbd_manager.find_solutions(graph_node_setting_pairs)[0]

    assert len(solutions) == solution_count
Example #8
0
def generate_model_xml():
    from pycompwa.expertsystem.amplitude.helicitydecay import (
        HelicityDecayAmplitudeGeneratorXML,
    )
    from pycompwa.expertsystem.state.particle import (
        XMLLabelConstants,
        get_xml_label,
    )
    from pycompwa.expertsystem.ui.system_control import (
        InteractionTypes,
        StateTransitionManager,
    )

    # initialize the graph edges (initial and final state)
    initial_state = [("D1(2420)0", [-1, 1])]
    final_state = [("D0", [0]), ("pi-", [0]), ("pi+", [0])]

    tbd_manager = StateTransitionManager(initial_state, final_state, ["D*"])
    tbd_manager.number_of_threads = 1
    tbd_manager.set_allowed_interaction_types([InteractionTypes.Strong])
    graph_interaction_settings_groups = tbd_manager.prepare_graphs()

    (solutions, violated_rules) = tbd_manager.find_solutions(
        graph_interaction_settings_groups
    )

    print("found " + str(len(solutions)) + " solutions!")

    print("intermediate states:")
    decinfo_label = get_xml_label(XMLLabelConstants.DecayInfo)
    for g in solutions:
        print(g.edge_props[1]["@Name"])
        for edge_props in g.edge_props.values():
            if decinfo_label in edge_props:
                del edge_props[decinfo_label]
                edge_props[decinfo_label] = {
                    get_xml_label(XMLLabelConstants.Type): "nonResonant"
                }

    xml_generator = HelicityDecayAmplitudeGeneratorXML()
    xml_generator.generate(solutions)
    xml_generator.write_to_file("model.xml")
def test_script():
    logging.basicConfig(level=logging.INFO)
    # initialize the graph edges (initial and final state)
    initial_state = [("J/psi", [-1, 1])]
    final_state = [("gamma", [-1, 1]), ("pi0", [0]), ("pi0", [0])]

    tbd_manager = StateTransitionManager(initial_state, final_state,
                                         ['f0', 'f2', 'omega'])
    tbd_manager.number_of_threads = 2
    tbd_manager.set_allowed_interaction_types(
        [InteractionTypes.Strong, InteractionTypes.EM])
    graph_interaction_settings_groups = tbd_manager.prepare_graphs()

    (solutions, violated_rules) = tbd_manager.find_solutions(
        graph_interaction_settings_groups)

    print("found " + str(len(solutions)) + " solutions!")
    assert len(solutions) == 48

    ref_mapping_fs = create_edge_id_particle_mapping(solutions[0],
                                                     get_final_state_edges)
    ref_mapping_is = create_edge_id_particle_mapping(solutions[0],
                                                     get_initial_state_edges)
    for x in solutions[1:]:
        assert ref_mapping_fs == create_edge_id_particle_mapping(
            x, get_final_state_edges)
        assert ref_mapping_is == create_edge_id_particle_mapping(
            x, get_initial_state_edges)

    print("intermediate states:")
    intermediate_states = set()
    for g in solutions:
        int_edge_id = get_intermediate_state_edges(g)[0]
        intermediate_states.add(g.edge_props[int_edge_id]['@Name'])
    print(intermediate_states)

    xml_generator = HelicityAmplitudeGeneratorXML()
    xml_generator.generate(solutions)
    xml_generator.write_to_file('JPsiToGammaPi0Pi0.xml')
def test_match_external_edges(initial_state, final_state):
    tbd_manager = StateTransitionManager(initial_state, final_state, [],
                                         formalism_type='helicity')

    tbd_manager.set_allowed_interaction_types([InteractionTypes.Strong])
    tbd_manager.number_of_threads = 1

    topology_graphs = tbd_manager.build_topologies()
    init_graphs = tbd_manager.create_seed_graphs(topology_graphs)

    match_external_edges(init_graphs)

    ref_mapping_fs = create_edge_id_particle_mapping(init_graphs[0],
                                                     get_final_state_edges)
    ref_mapping_is = create_edge_id_particle_mapping(init_graphs[0],
                                                     get_initial_state_edges)

    for x in init_graphs[1:]:
        assert ref_mapping_fs == create_edge_id_particle_mapping(
            x, get_final_state_edges)
        assert ref_mapping_is == create_edge_id_particle_mapping(
            x, get_initial_state_edges)
Example #11
0
def test_script():
    logging.basicConfig(level=logging.INFO)
    # initialize the graph edges (initial and final state)
    initial_state = [("J/psi", [-1, 1])]
    final_state = [("gamma", [-1, 1]), ("pi0", [0]), ("pi0", [0])]

    tbd_manager = StateTransitionManager(initial_state, final_state,
                                         ['f0', 'f2', 'omega'])
    tbd_manager.number_of_threads = 2
    tbd_manager.set_allowed_interaction_types(
        [InteractionTypes.Strong, InteractionTypes.EM])
    graph_interaction_settings_groups = tbd_manager.prepare_graphs()

    (solutions, violated_rules) = tbd_manager.find_solutions(
        graph_interaction_settings_groups)

    print("found " + str(len(solutions)) + " solutions!")
    assert len(solutions) == 48

    ref_mapping_fs = create_edge_id_particle_mapping(solutions[0],
                                                     get_final_state_edges)
    ref_mapping_is = create_edge_id_particle_mapping(solutions[0],
                                                     get_initial_state_edges)
    for x in solutions[1:]:
        assert ref_mapping_fs == create_edge_id_particle_mapping(
            x, get_final_state_edges)
        assert ref_mapping_is == create_edge_id_particle_mapping(
            x, get_initial_state_edges)

    print("intermediate states:")
    intermediate_states = set()
    for g in solutions:
        int_edge_id = get_intermediate_state_edges(g)[0]
        intermediate_states.add(g.edge_props[int_edge_id]['@Name'])
    print(intermediate_states)

    xml_generator = HelicityAmplitudeGeneratorXML()
    xml_generator.generate(solutions)
    xml_generator.write_to_file('JPsiToGammaPi0Pi0.xml')
Example #12
0
def test_match_external_edges(initial_state, final_state):
    tbd_manager = StateTransitionManager(initial_state, final_state, [],
                                         formalism_type='helicity')

    tbd_manager.set_allowed_interaction_types([InteractionTypes.Strong])
    tbd_manager.number_of_threads = 1

    topology_graphs = tbd_manager.build_topologies()
    init_graphs = tbd_manager.create_seed_graphs(topology_graphs)

    match_external_edges(init_graphs)

    ref_mapping_fs = create_edge_id_particle_mapping(init_graphs[0],
                                                     get_final_state_edges)
    ref_mapping_is = create_edge_id_particle_mapping(init_graphs[0],
                                                     get_initial_state_edges)

    for x in init_graphs[1:]:
        assert ref_mapping_fs == create_edge_id_particle_mapping(
            x, get_final_state_edges)
        assert ref_mapping_is == create_edge_id_particle_mapping(
            x, get_initial_state_edges)
def generate_model_xml():
    from pycompwa.expertsystem.ui.system_control import (
        StateTransitionManager, InteractionTypes)

    from pycompwa.expertsystem.amplitude.helicitydecay import (
        HelicityDecayAmplitudeGeneratorXML)

    from pycompwa.expertsystem.state.particle import (
        get_xml_label, XMLLabelConstants)
    # initialize the graph edges (initial and final state)
    initial_state = [("D1(2420)0", [-1, 1])]
    final_state = [("D0", [0]), ("pi-", [0]), ("pi+", [0])]

    tbd_manager = StateTransitionManager(initial_state, final_state,
                                         ['D*'])
    tbd_manager.number_of_threads = 1
    tbd_manager.set_allowed_interaction_types(
        [InteractionTypes.Strong])
    graph_interaction_settings_groups = tbd_manager.prepare_graphs()

    (solutions, violated_rules) = tbd_manager.find_solutions(
        graph_interaction_settings_groups)

    print("found " + str(len(solutions)) + " solutions!")

    print("intermediate states:")
    decinfo_label = get_xml_label(XMLLabelConstants.DecayInfo)
    for g in solutions:
        print(g.edge_props[1]['@Name'])
        for edge_props in g.edge_props.values():
            if decinfo_label in edge_props:
                del edge_props[decinfo_label]
                edge_props[decinfo_label] = {
                    get_xml_label(XMLLabelConstants.Type): "nonResonant"}

    xml_generator = HelicityDecayAmplitudeGeneratorXML()
    xml_generator.generate(solutions)
    xml_generator.write_to_file('model.xml')
Example #14
0
def test_canonical_clebsch_gordan_ls_couling(initial_state, final_state,
                                             L, S, solution_count):
    # because the amount of solutions is too big we change the default domains
    formalism_type = 'canonical-helicity'
    int_settings = create_default_interaction_settings(formalism_type)

    remove_conservation_law(int_settings[InteractionTypes.Strong],
                            ParityConservationHelicity())

    tbd_manager = StateTransitionManager(
        initial_state, final_state, [],
        interaction_type_settings=int_settings,
        formalism_type=formalism_type)

    tbd_manager.set_allowed_interaction_types([InteractionTypes.Strong])
    tbd_manager.number_of_threads = 2
    tbd_manager.filter_remove_qns = []

    l_label = InteractionQuantumNumberNames.L
    s_label = InteractionQuantumNumberNames.S
    qn_label = XMLLabelConstants.QuantumNumber

    spin_converter = SpinQNConverter()
    node_props = {0: {
        qn_label.name: [spin_converter.convert_to_dict(l_label, L),
                        spin_converter.convert_to_dict(
            s_label, S)
        ]}
    }
    graph_node_setting_pairs = tbd_manager.prepare_graphs()
    for k, v in graph_node_setting_pairs.items():
        for e in v:
            e[0].node_props = node_props

    (solutions, violated_rules) = tbd_manager.find_solutions(
        graph_node_setting_pairs)

    assert len(solutions) == solution_count
Example #15
0
def test_script():
    logging.basicConfig(level=logging.INFO)
    # initialize the graph edges (intial and final state)
    initial_state = [("D0", [0])]
    final_state = [("K_S0", [0]), ("K+", [0]), ("K-", [0])]

    tbd_manager = StateTransitionManager(initial_state, final_state,
                                         ['a0', 'phi', 'a2(1320)-'])
    tbd_manager.number_of_threads = 2

    graph_interaction_settings_groups = tbd_manager.prepare_graphs()
    (solutions, violated_rules) = tbd_manager.find_solutions(
        graph_interaction_settings_groups)

    print("found " + str(len(solutions)) + " solutions!")
    assert len(solutions) == 5

    # print intermediate state particle names
    for g in solutions:
        print(g.edge_props[1]['@Name'])

    xml_generator = HelicityAmplitudeGeneratorXML()
    xml_generator.generate(solutions)
    xml_generator.write_to_file('D0ToKs0KpKm.xml')
Example #16
0
def test_edge_swap(initial_state, final_state):
    tbd_manager = StateTransitionManager(initial_state, final_state, [],
                                         formalism_type='helicity')

    tbd_manager.set_allowed_interaction_types([InteractionTypes.Strong])
    tbd_manager.number_of_threads = 1

    topology_graphs = tbd_manager.build_topologies()
    init_graphs = tbd_manager.create_seed_graphs(topology_graphs)

    for x in init_graphs:
        ref_mapping = create_edge_id_particle_mapping(x, get_final_state_edges)
        edge_keys = list(ref_mapping.keys())
        edge1 = edge_keys[0]
        edge1_val = x.edges[edge1]
        edge1_props = x.edge_props[edge1]
        edge2 = edge_keys[1]
        edge2_val = x.edges[edge2]
        edge2_props = x.edge_props[edge2]
        x.swap_edges(edge1, edge2)
        assert x.edges[edge1] == edge2_val
        assert x.edges[edge2] == edge1_val
        assert x.edge_props[edge1] == edge2_props
        assert x.edge_props[edge2] == edge1_props
Example #17
0
def test_script_full():
    # initialize the graph edges (intial and final state)
    initial_state = [("Y", [-1, 1])]
    final_state = ["D0", "D0bar", "pi0", "pi0"]

    # because the amount of solutions is too big we change the default domains
    formalism_type = 'canonical-helicity'
    int_settings = create_default_interaction_settings(formalism_type)
    change_qn_domain(int_settings[InteractionTypes.Strong],
                     InteractionQuantumNumberNames.L,
                     create_spin_domain([0, 1, 2, 3], True))
    change_qn_domain(int_settings[InteractionTypes.Strong],
                     InteractionQuantumNumberNames.S,
                     create_spin_domain([0, 1, 2], True))

    tbd_manager = StateTransitionManager(
        initial_state,
        final_state, ['D*'],
        interaction_type_settings=int_settings,
        formalism_type=formalism_type)

    tbd_manager.set_allowed_interaction_types([InteractionTypes.Strong])
    tbd_manager.add_final_state_grouping([['D0', 'pi0'], ['D0bar', 'pi0']])
    tbd_manager.number_of_threads = 2

    graph_node_setting_pairs = tbd_manager.prepare_graphs()

    (solutions,
     violated_rules) = tbd_manager.find_solutions(graph_node_setting_pairs)

    print("found " + str(len(solutions)) + " solutions!")

    canonical_xml_generator = CanonicalDecayAmplitudeGeneratorXML()
    canonical_xml_generator.generate(solutions)

    # because the amount of solutions is too big we change the default domains
    formalism_type = 'helicity'
    int_settings = create_default_interaction_settings(formalism_type)
    change_qn_domain(int_settings[InteractionTypes.Strong],
                     InteractionQuantumNumberNames.L,
                     create_spin_domain([0, 1, 2, 3], True))
    change_qn_domain(int_settings[InteractionTypes.Strong],
                     InteractionQuantumNumberNames.S,
                     create_spin_domain([0, 1, 2], True))

    tbd_manager = StateTransitionManager(
        initial_state,
        final_state, ['D*'],
        interaction_type_settings=int_settings,
        formalism_type=formalism_type)

    tbd_manager.set_allowed_interaction_types([InteractionTypes.Strong])
    tbd_manager.add_final_state_grouping([['D0', 'pi0'], ['D0bar', 'pi0']])
    tbd_manager.number_of_threads = 2

    graph_node_setting_pairs = tbd_manager.prepare_graphs()
    (solutions,
     violated_rules) = tbd_manager.find_solutions(graph_node_setting_pairs)
    print("found " + str(len(solutions)) + " solutions!")

    helicity_xml_generator = HelicityDecayAmplitudeGeneratorXML()
    helicity_xml_generator.generate(solutions)

    #print(helicity_xml_generator.fit_parameters,
    #      canonical_xml_generator.fit_parameters)
    assert (len(helicity_xml_generator.fit_parameters) == len(
        canonical_xml_generator.fit_parameters))
Example #18
0
def test_script_full():
    # initialize the graph edges (intial and final state)
    initial_state = [("Y", [-1, 1])]
    final_state = ["D0", "D0bar", "pi0", "pi0"]

    # because the amount of solutions is too big we change the default domains
    formalism_type = 'canonical-helicity'
    int_settings = create_default_interaction_settings(formalism_type)
    change_qn_domain(int_settings[InteractionTypes.Strong],
                     InteractionQuantumNumberNames.L,
                     create_spin_domain([0, 1, 2, 3], True)
                     )
    change_qn_domain(int_settings[InteractionTypes.Strong],
                     InteractionQuantumNumberNames.S,
                     create_spin_domain([0, 1, 2], True)
                     )

    tbd_manager = StateTransitionManager(initial_state, final_state, ['D*'],
                                         interaction_type_settings=int_settings,
                                         formalism_type=formalism_type)

    tbd_manager.set_allowed_interaction_types([InteractionTypes.Strong])
    tbd_manager.add_final_state_grouping([['D0', 'pi0'], ['D0bar', 'pi0']])
    tbd_manager.number_of_threads = 2

    graph_node_setting_pairs = tbd_manager.prepare_graphs()

    (solutions, violated_rules) = tbd_manager.find_solutions(
        graph_node_setting_pairs)

    print("found " + str(len(solutions)) + " solutions!")

    canonical_xml_generator = CanonicalAmplitudeGeneratorXML()
    canonical_xml_generator.generate(solutions)

    # because the amount of solutions is too big we change the default domains
    formalism_type = 'helicity'
    int_settings = create_default_interaction_settings(formalism_type)
    change_qn_domain(int_settings[InteractionTypes.Strong],
                     InteractionQuantumNumberNames.L,
                     create_spin_domain([0, 1, 2, 3], True)
                     )
    change_qn_domain(int_settings[InteractionTypes.Strong],
                     InteractionQuantumNumberNames.S,
                     create_spin_domain([0, 1, 2], True)
                     )

    tbd_manager = StateTransitionManager(initial_state, final_state, ['D*'],
                                         interaction_type_settings=int_settings,
                                         formalism_type=formalism_type)

    tbd_manager.set_allowed_interaction_types([InteractionTypes.Strong])
    tbd_manager.add_final_state_grouping([['D0', 'pi0'], ['D0bar', 'pi0']])
    tbd_manager.number_of_threads = 2

    graph_node_setting_pairs = tbd_manager.prepare_graphs()
    (solutions, violated_rules) = tbd_manager.find_solutions(
        graph_node_setting_pairs)
    print("found " + str(len(solutions)) + " solutions!")

    helicity_xml_generator = HelicityAmplitudeGeneratorXML()
    helicity_xml_generator.generate(solutions)

    assert (len(helicity_xml_generator.get_fit_parameters()) ==
            len(canonical_xml_generator.get_fit_parameters()))