Пример #1
0
def initialize_graphs_with_particles(graphs, allowed_particle_list=[]):
    initialized_graphs = []
    mod_allowed_particle_list = initialize_allowed_particle_list(
        allowed_particle_list)

    for graph in graphs:
        logging.debug("initializing graph...")
        intermediate_edges = get_intermediate_state_edges(graph)
        current_new_graphs = [graph]
        for int_edge_id in intermediate_edges:
            particle_edges = get_particle_candidates_for_state(
                graph.edge_props[int_edge_id], mod_allowed_particle_list)
            if len(particle_edges) == 0:
                logging.debug("Did not find any particle candidates for")
                logging.debug("edge id: " + str(int_edge_id))
                logging.debug("edge properties:")
                logging.debug(graph.edge_props[int_edge_id])
            new_graphs_temp = []
            for curr_new_graph in current_new_graphs:
                for particle_edge in particle_edges:
                    temp_graph = deepcopy(curr_new_graph)
                    temp_graph.edge_props[int_edge_id] = particle_edge
                    new_graphs_temp.append(temp_graph)
            current_new_graphs = new_graphs_temp

        initialized_graphs.extend(current_new_graphs)
    return initialized_graphs
Пример #2
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')
Пример #3
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')
Пример #4
0
    def apply_solutions_to_graph(self, solutions):
        """
        Apply the CSP solutions to the graph instance.
        In other words attach the solution quantum numbers as properties to
        the edges. Also the solutions are filtered using the allowed
        intermediate particle list, to avoid large memory consumption.

        Args:
          solutions: list of solutions of the csp solver
        
        Returns:
          solution graphs ([:class:`.StateTransitionGraph`])
        """
        solution_graphs = []
        initial_edges = get_initial_state_edges(self.graph)
        final_edges = get_final_state_edges(self.graph)

        full_allowed_particle_list = initialize_allowed_particle_list(
            self.allowed_intermediate_particles)

        # logging.info("attempting to filter " + str(len(solutions)) +
        #             " solutions for allowed intermediate particles and"
        #             " create a copy graph")
        #bar = IncrementalBar('Filtering solutions', max=len(solutions))

        found_JPs = set()

        for solution in solutions:
            graph_copy = deepcopy(self.graph)
            for var_name, value in solution.items():
                var_info = decode_variable_name(
                    var_name, self.particle_variable_delimiter)
                ele_id = var_info.element_id

                if var_info.graph_element_type is graph_element_types.edge:
                    if ele_id in initial_edges or ele_id in final_edges:
                        # skip if its an initial or final state edge
                        continue

                add_qn_to_graph_element(graph_copy, var_info, value)

            solution_valid = True
            if self.allowed_intermediate_particles:
                for int_edge_id in get_intermediate_state_edges(graph_copy):
                    # for documentation in case of failure
                    spin = get_particle_property(
                        graph_copy.edge_props[int_edge_id],
                        StateQuantumNumberNames.Spin)
                    parity = get_particle_property(
                        graph_copy.edge_props[int_edge_id],
                        StateQuantumNumberNames.Parity)
                    found_JPs.add(
                        str(spin.magnitude()) +
                        ("-" if parity == -1 or parity == -1.0 else "+"))
                    # now do actual candidate finding
                    candidates = get_particle_candidates_for_state(
                        graph_copy.edge_props[int_edge_id],
                        full_allowed_particle_list)
                    if not candidates:
                        solution_valid = False
                        break
            if solution_valid:
                solution_graphs.append(graph_copy)
            # bar.next()
        # bar.finish()
        if solutions and not solution_graphs:
            logging.warning(
                "No intermediate state particles match the found " +
                str(len(solutions)) + " solutions!")
            logging.warning("solution inter. state J^P: " + str(found_JPs))
        return solution_graphs