class TestSolutionFilter(object): @pytest.mark.parametrize("LS_pairs,result", [ ([(1, 0), (1, 1)], 2), ([(1, 0), (1, 0)], 1), ]) def test_remove_duplicates(self, LS_pairs, result): graphs = {'test': []} for x in LS_pairs: graphs['test'].append(([make_ls_test_graph(x[0], x[1])], [])) results = remove_duplicate_solutions(graphs) num_solutions = [len(x[0]) for x in results['test']] assert sum(num_solutions) == result for x in LS_pairs: graphs['test'].append(([make_ls_test_graph_scrambled(x[0], x[1])], [])) results = remove_duplicate_solutions(graphs) num_solutions = [len(x[0]) for x in results['test']] assert sum(num_solutions) == result @pytest.mark.parametrize("input_values,filter_parameters,result", [ ([('foo', (1, 0)), ('foo', (1, 1))], ('foo', InteractionQuantumNumberNames.L, create_spin_domain([1], True)), 2), ([('foo', (1, 0)), ('foo', (2, 1))], ('foo', InteractionQuantumNumberNames.L, create_spin_domain([1], True)), 1), ([('foo', (1, 0)), ('foo', (1, 1))], ('foobar', InteractionQuantumNumberNames.L, create_spin_domain([1], True)), 0), ([('foo', (0, 0)), ('foo', (1, 1)), ('foo', (2, 1))], ('foo', InteractionQuantumNumberNames.L, create_spin_domain([1, 2], True)), 2), ([('foo', (1, 0)), ('foo', (1, 1))], ('foo', InteractionQuantumNumberNames.S, create_spin_domain([1], True)), 1), ]) def test_filter_graphs_for_interaction_qns(self, input_values, filter_parameters, result): graphs = [] name_label = get_xml_label(XMLLabelConstants.Name) value_label = get_xml_label(XMLLabelConstants.Value) for x in input_values: tempgraph = make_ls_test_graph(x[1][0], x[1][1]) tempgraph.add_edges([0]) tempgraph.attach_edges_to_node_ingoing([0], 0) tempgraph.edge_props[0] = {name_label: {value_label: x[0]}} graphs.append(tempgraph) myfilter = require_interaction_property(*filter_parameters) filtered_graphs = filter_graphs(graphs, [myfilter]) assert len(filtered_graphs) == result
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))
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()))
def create_default_interaction_settings(formalism_type, use_mass_conservation=True): ''' Create a container, which holds the settings for the various interactions (e.g.: strong, em and weak interaction). ''' interaction_type_settings = {} formalism_conservation_laws = [] formalism_qn_domains = {} formalism_type = formalism_type if 'helicity' in formalism_type: formalism_conservation_laws = [ SpinConservation(StateQuantumNumberNames.Spin, False), HelicityConservation()] formalism_qn_domains = { InteractionQuantumNumberNames.L: create_spin_domain( [0, 1, 2], True), InteractionQuantumNumberNames.S: create_spin_domain( [0, 0.5, 1, 1.5, 2], True)} elif formalism_type == 'canonical': formalism_conservation_laws = [ SpinConservation(StateQuantumNumberNames.Spin)] formalism_qn_domains = { InteractionQuantumNumberNames.L: create_spin_domain( [0, 1, 2]), InteractionQuantumNumberNames.S: create_spin_domain( [0, 0.5, 1, 2])} if formalism_type == 'canonical-helicity': formalism_conservation_laws.append( ClebschGordanCheckHelicityToCanonical()) if use_mass_conservation: formalism_conservation_laws.append(MassConservation()) weak_settings = InteractionNodeSettings() weak_settings.conservation_laws = formalism_conservation_laws weak_settings.conservation_laws.extend([ GellMannNishijimaRule(), AdditiveQuantumNumberConservation( StateQuantumNumberNames.Charge), AdditiveQuantumNumberConservation( StateQuantumNumberNames.ElectronLN), AdditiveQuantumNumberConservation( StateQuantumNumberNames.MuonLN), AdditiveQuantumNumberConservation( StateQuantumNumberNames.TauLN), AdditiveQuantumNumberConservation( StateQuantumNumberNames.BaryonNumber), IdenticalParticleSymmetrization() ]) weak_settings.qn_domains = { StateQuantumNumberNames.Charge: [-2, -1, 0, 1, 2], StateQuantumNumberNames.BaryonNumber: [-1, 0, 1], StateQuantumNumberNames.ElectronLN: [-1, 0, 1], StateQuantumNumberNames.MuonLN: [-1, 0, 1], StateQuantumNumberNames.TauLN: [-1, 0, 1], StateQuantumNumberNames.Parity: [-1, 1], StateQuantumNumberNames.Cparity: [-1, 1, None], StateQuantumNumberNames.Gparity: [-1, 1, None], StateQuantumNumberNames.Spin: create_spin_domain( [0, 0.5, 1, 1.5, 2]), StateQuantumNumberNames.IsoSpin: create_spin_domain( [0, 0.5, 1, 1.5]), StateQuantumNumberNames.Charm: [-1, 0, 1], StateQuantumNumberNames.Strangeness: [-1, 0, 1] } weak_settings.qn_domains.update(formalism_qn_domains) weak_settings.interaction_strength = 10**(-4) interaction_type_settings[InteractionTypes.Weak] = weak_settings em_settings = deepcopy(weak_settings) em_settings.conservation_laws.extend( [AdditiveQuantumNumberConservation( StateQuantumNumberNames.Charm), AdditiveQuantumNumberConservation( StateQuantumNumberNames.Strangeness), ParityConservation(), CParityConservation() ] ) if 'helicity' in formalism_type: em_settings.conservation_laws.append( ParityConservationHelicity()) em_settings.qn_domains.update({ InteractionQuantumNumberNames.ParityPrefactor: [-1, 1] }) em_settings.interaction_strength = 1 interaction_type_settings[InteractionTypes.EM] = em_settings strong_settings = deepcopy(em_settings) strong_settings.conservation_laws.extend( [SpinConservation( StateQuantumNumberNames.IsoSpin), GParityConservation()] ) strong_settings.interaction_strength = 60 interaction_type_settings[InteractionTypes.Strong] = strong_settings return interaction_type_settings