def test_equivalence( formalism: str, jpsi_to_gamma_pi_pi_canonical_amplitude_model: AmplitudeModel, jpsi_to_gamma_pi_pi_helicity_amplitude_model: AmplitudeModel, output_dir, ): exported = None if formalism == "helicity": exported = jpsi_to_gamma_pi_pi_helicity_amplitude_model elif formalism == "canonical": exported = jpsi_to_gamma_pi_pi_canonical_amplitude_model else: raise NotImplementedError(formalism) filename = output_dir + f"test_io_cross_check_{formalism}" filename_xml = f"{filename}.xml" filename_yml = f"{filename}.yml" io.write(exported, filename_xml) io.write(exported, filename_yml) imported_xml = io.load_amplitude_model(filename_xml) imported_yml = io.load_amplitude_model(filename_yml) assert imported_xml.particles == imported_yml.particles assert imported_xml.parameters == imported_yml.parameters assert imported_xml.kinematics == imported_yml.kinematics assert imported_xml.dynamics == imported_yml.dynamics assert imported_xml.intensity == imported_yml.intensity assert imported_xml == imported_yml assert imported_xml is not imported_yml
def test_not_implemented_writer( jpsi_to_gamma_pi_pi_canonical_amplitude_model: AmplitudeModel, ): with pytest.raises(NotImplementedError): io.write( instance=jpsi_to_gamma_pi_pi_canonical_amplitude_model, filename="JPsiToGammaPi0Pi0.csv", )
def particle_selection(output_dir, particle_database: ParticleCollection): selection = ParticleCollection() selection += particle_database.filter(lambda p: p.name.startswith("pi")) selection += particle_database.filter(lambda p: p.name.startswith("K")) selection += particle_database.filter(lambda p: p.name.startswith("D")) selection += particle_database.filter(lambda p: p.name.startswith("J/psi")) io.write(selection, output_dir + XML_FILE) io.write(selection, output_dir + YAML_FILE) return selection
def test_write_graph_list(output_dir, jpsi_to_gamma_pi_pi_helicity_solutions: Result): output_file = output_dir + "test_graph_list.gv" io.write( instance=jpsi_to_gamma_pi_pi_helicity_solutions.solutions, filename=output_file, ) with open(output_file, "r") as stream: dot_data = stream.read() assert pydot.graph_from_dot_data(dot_data) is not None
def imported_dict( output_dir, jpsi_to_gamma_pi_pi_canonical_amplitude_model: AmplitudeModel, ): output_filename = output_dir + "JPsiToGammaPi0Pi0_cano_recipe.yml" io.write( instance=jpsi_to_gamma_pi_pi_canonical_amplitude_model, filename=output_filename, ) with open(output_filename, "rb") as input_file: loaded_dict = yaml.load(input_file, Loader=yaml.FullLoader) return loaded_dict
def test_write_particle_graphs( output_dir, jpsi_to_gamma_pi_pi_helicity_solutions: Result, ): result = jpsi_to_gamma_pi_pi_helicity_solutions particle_graphs = result.get_particle_graphs() output_file = output_dir + "test_particle_graphs.gv" io.write( instance=particle_graphs, filename=output_file, ) with open(output_file, "r") as stream: dot_data = stream.read() assert pydot.graph_from_dot_data(dot_data) is not None
def test_write_topology(output_dir): output_file = output_dir + "two_body_decay_topology.gv" topology = Topology( nodes={0}, edges={ 0: Edge(0, None), 1: Edge(None, 0), 2: Edge(None, 0) }, ) io.write( instance=topology, filename=output_file, ) with open(output_file, "r") as stream: dot_data = stream.read() assert pydot.graph_from_dot_data(dot_data) is not None
def test_write_load( file_extension: str, formalism: str, jpsi_to_gamma_pi_pi_canonical_amplitude_model: AmplitudeModel, jpsi_to_gamma_pi_pi_helicity_amplitude_model: AmplitudeModel, output_dir, ): filename = output_dir + f"test_write_read_{formalism}.{file_extension}" exported = None if formalism == "helicity": exported = jpsi_to_gamma_pi_pi_helicity_amplitude_model elif formalism == "canonical": exported = jpsi_to_gamma_pi_pi_canonical_amplitude_model else: raise NotImplementedError(formalism) io.write(exported, filename) imported = io.load_amplitude_model(filename) assert exported.particles == imported.particles assert exported.parameters == imported.parameters assert exported.kinematics == imported.kinematics assert exported.dynamics == imported.dynamics assert exported.intensity == imported.intensity assert exported == imported assert exported is not imported
def test_not_implemented_errors(output_dir, particle_selection: ParticleCollection): with pytest.raises(NotImplementedError): io.load_particle_collection(output_dir + __file__) with pytest.raises(NotImplementedError): io.write(particle_selection, output_dir + __file__) with pytest.raises(Exception): io.write(particle_selection, output_dir + "no_file_extension") with pytest.raises(NotImplementedError): io.write(666, output_dir + "wont_work_anyway.xml")
def test_exception(output_dir): with pytest.raises(NotImplementedError): io.write( instance="nope, can't write a str", filename=output_dir + "dummy_file.gv", )