diff --git a/pysemtools/datatypes/field.py b/pysemtools/datatypes/field.py index 2f04ece..fe7209c 100644 --- a/pysemtools/datatypes/field.py +++ b/pysemtools/datatypes/field.py @@ -115,7 +115,7 @@ def __init__(self, comm, data=None): if not isinstance(data, NoneType): self.log.tic() - self.log.write("info", "Initializing Field object from HexaData") + self.log.write("debug", "Initializing Field object from HexaData") vars_ = data.var self.vel_fields = vars_[1] @@ -142,10 +142,10 @@ def __init__(self, comm, data=None): self.t = data.time - self.log.write("info", "Field object initialized") - self.log.toc() + self.log.write("debug", "Field object initialized") + self.log.toc(message="Field object initialized from HexaData") else: - self.log.write("info", "Initializing empty Field object") + self.log.write("debug", "Initializing empty Field object") def update_vars(self): """ @@ -340,6 +340,9 @@ def update_vars(self): self.registry[f"s{i}"] = self.fields["scal"][i] self.registry_pos[f"s{i}"] = f"scal_{i}" + if self.registry.keys().__len__() > 0: + self.log.write("info", f"Field registry updated with: {list(self.registry.keys())} - dtype: {self.registry[list(self.registry.keys())[0]].dtype}") + def clear(self): """ Clear the registry and the fields. diff --git a/pysemtools/datatypes/msh.py b/pysemtools/datatypes/msh.py index 106fb42..591718a 100644 --- a/pysemtools/datatypes/msh.py +++ b/pysemtools/datatypes/msh.py @@ -85,10 +85,10 @@ class Mesh: """ def __init__( - self, comm, data=None, x=None, y=None, z=None, elmap=None, create_connectivity=False, bckend="numpy" + self, comm, data=None, x=None, y=None, z=None, elmap=None, create_connectivity=False, bckend="numpy", log_level=None ): - self.log = Logger(comm=comm, module_name="Mesh") + self.log = Logger(comm=comm, module_name="Mesh", level=log_level) self.create_connectivity_bool = create_connectivity self.bckend = bckend @@ -107,7 +107,7 @@ def __init__( self.init_from_coords(comm, x, y, z, elmap=elmap) else: - self.log.write("info", "Initializing empty Mesh object.") + self.log.write("debug", "Initializing empty Mesh object.") def init_from_data(self, comm, data): """ @@ -165,7 +165,7 @@ def init_from_coords(self, comm, x, y, z, elmap=None): """ self.log.tic() - self.log.write("info", "Initializing Mesh object from x,y,z ndarrays.") + self.log.write("debug", "Initializing Mesh object from x,y,z ndarrays.") self.x = x self.y = y @@ -174,9 +174,9 @@ def init_from_coords(self, comm, x, y, z, elmap=None): self.init_common(comm) - self.log.write("info", "Mesh object initialized.") - self.log.write("info", f"Mesh data is of type: {self.x.dtype}") - self.log.toc() + self.log.write("debug", "Mesh object initialized.") + self.log.write("debug", f"Mesh data is of type: {self.x.dtype}") + self.log.toc(message=f"Mesh object initialized from coordinates with type: {self.x.dtype}") def init_common(self, comm): """ @@ -195,7 +195,7 @@ def init_common(self, comm): Nothing is returned, the attributes are set in the object. """ - self.log.write("info", "Initializing common attributes.") + self.log.write("debug", "Initializing common attributes.") self.lx = np.int64( self.x.shape[3] @@ -279,7 +279,7 @@ def get_vertices(self): we store 3 coordinates for each vertex. ''' - self.log.write("info", "Getting vertices") + self.log.write("debug", "Getting vertices") if self.gdim == 2: self.vertices = np.zeros((self.nelv, 4, 3), dtype=self.x.dtype) # 4 vertices, 3 coords (z = 0) @@ -310,7 +310,7 @@ def get_edge_centers(self): we store 3 coordinates for each edge. ''' - self.log.write("info", "Getting edge centers") + self.log.write("debug", "Getting edge centers") if self.gdim == 2: self.edge_centers = np.zeros((self.nelv, 4, 3), dtype=self.x.dtype) # 4 vertices, 3 coords (z = 0) @@ -348,10 +348,10 @@ def get_facet_centers(self): ''' if self.gdim == 2: - self.log.write("info", "Facet centers not available for 2D") + self.log.write("debug", "Facet centers not available for 2D") elif self.gdim == 3: - self.log.write("info", "Getting facet centers") + self.log.write("debug", "Getting facet centers") self.facet_centers = np.zeros((self.nelv, 6, 3), dtype=self.x.dtype) # 6 facets, 3 coordinates diff --git a/pysemtools/datatypes/msh_partitioning.py b/pysemtools/datatypes/msh_partitioning.py index 5573876..58dad66 100644 --- a/pysemtools/datatypes/msh_partitioning.py +++ b/pysemtools/datatypes/msh_partitioning.py @@ -56,7 +56,7 @@ def __init__( y_ = msh.y[self.compliant_elements] z_ = msh.z[self.compliant_elements] - sub_mesh = Mesh(comm, x=x_, y=y_, z=z_, create_connectivity=False) + sub_mesh = Mesh(comm, x=x_, y=y_, z=z_, create_connectivity=False, log_level="hide") self.partition_nelv = sub_mesh.nelv self.partition_glb_nelv = sub_mesh.glb_nelv @@ -87,16 +87,16 @@ def create_partitioned_mesh( """ self.log.write( - "info", + "debug", f"Partitioning the mesh coordinates with {partitioning_algorithm} algorithm", ) x_ = self.redistribute_field_elements(msh.x, partitioning_algorithm) y_ = self.redistribute_field_elements(msh.y, partitioning_algorithm) z_ = self.redistribute_field_elements(msh.z, partitioning_algorithm) - self.log.write("info", "Creating mesh object") + self.log.write("debug", "Creating mesh object") partitioned_mesh = Mesh( - self.rt.comm, x=x_, y=y_, z=z_, create_connectivity=create_conectivity + self.rt.comm, x=x_, y=y_, z=z_, create_connectivity=create_conectivity, log_level="hide" ) return partitioned_mesh @@ -124,7 +124,7 @@ def create_partitioned_field( """ self.log.write( - "info", + "debug", f"Partitioning the field object with {partitioning_algorithm} algorithm", ) diff --git a/pysemtools/interpolation/interpolator.py b/pysemtools/interpolation/interpolator.py index ba1d9cd..75bfbdd 100644 --- a/pysemtools/interpolation/interpolator.py +++ b/pysemtools/interpolation/interpolator.py @@ -279,8 +279,8 @@ def __init__( local_data_structure="kdtree", ): self.log = Logger(comm=comm, module_name="Interpolator") - self.log.write("info", "Initializing Interpolator object") - self.log.tic() + self.log.write("debug", "Initializing Interpolator object") + #self.log.tic() # Instance communication object self.rt = Router(comm) @@ -306,7 +306,7 @@ def __init__( # Determine which point interpolator to use self.log.write( - "info", + "debug", "Initializing point interpolator: {}".format(point_interpolator_type), ) self.ei = get_point_interpolator( @@ -318,7 +318,7 @@ def __init__( ) # Determine which buffer to use - self.log.write("info", "Allocating buffers in point interpolator") + self.log.write("debug", "Allocating buffers in point interpolator") self.r = self.ei.alloc_result_buffer(dtype="double") self.s = self.ei.alloc_result_buffer(dtype="double") self.t = self.ei.alloc_result_buffer(dtype="double") @@ -331,7 +331,7 @@ def __init__( except AttributeError: dev = "cpu" - self.log.write("info", f"Using device: {dev}") + self.log.write("debug", f"Using device: {dev}") self.progress_bar = progress_bar @@ -378,8 +378,8 @@ def __init__( self.search_radious = None self.bin_to_rank_map = None - self.log.write("info", "Interpolator initialized") - self.log.toc() + self.log.write("debug", "Interpolator initialized") + #self.log.toc("Interpolator initialized") def set_up_global_tree( self, @@ -391,12 +391,12 @@ def set_up_global_tree( if find_points_comm_pattern == "broadcast": self.log.write( - "info", "Communication pattern selected does not need global tree" + "debug", "Communication pattern selected does not need global tree" ) elif (find_points_comm_pattern == "point_to_point") or (find_points_comm_pattern == "collective") or (find_points_comm_pattern == "rma"): self.global_tree_type = global_tree_type - self.log.write("info", f"Using global_tree of type: {global_tree_type}") + self.log.write("debug", f"Using global_tree of type: {global_tree_type}") if global_tree_type == "rank_bbox": self.set_up_global_tree_rank_bbox_( comm, global_tree_nbins=global_tree_nbins @@ -408,12 +408,12 @@ def set_up_global_tree( def set_up_global_tree_rank_bbox_(self, comm, global_tree_nbins=None): - self.log.tic() + #self.log.tic() size = comm.Get_size() # Find the bounding box of the rank to create a global but "sparse" kdtree - self.log.write("info", "Finding bounding boxes for each rank") + self.log.write("debug", "Finding bounding boxes for each rank") rank_bbox = np.zeros((1, 6), dtype=INTERPOLATION_DTYPE) rank_bbox[0, 0] = np.min(self.x) rank_bbox[0, 1] = np.max(self.x) @@ -449,11 +449,11 @@ def set_up_global_tree_rank_bbox_(self, comm, global_tree_nbins=None): bbox_centroid[:, 2] = self.global_bbox[:, 4] + bbox_dist[:, 2] / 2 # Create a tree with the rank centroids - self.log.write("info", "Creating global KD tree with rank centroids") + self.log.write("debug", "Creating global KD tree with rank centroids") self.global_tree = KDTree(bbox_centroid) self.search_radious = bbox_max_dist - self.log.toc() + #self.log.toc() def binning_hash(self, x, y, z): """ @@ -488,7 +488,7 @@ def set_up_global_tree_domain_binning_(self, comm, global_tree_nbins=None): if isinstance(global_tree_nbins, NoneType): global_tree_nbins = comm.Get_size() self.log.write( - "info", f"nbins not provided, using {global_tree_nbins} as default" + "debug", f"nbins not provided, using {global_tree_nbins} as default" ) bin_size = global_tree_nbins @@ -498,15 +498,15 @@ def set_up_global_tree_domain_binning_(self, comm, global_tree_nbins=None): bins_per_rank = int(np.ceil(bin_size / comm.Get_size())) self.log.write( - "info", f"Using {bin_size} as actual bin size" + "debug", f"Using {bin_size} as actual bin size" ) self.log.write( - "info", f"Storing {bins_per_rank} in each rank" + "debug", f"Storing {bins_per_rank} in each rank" ) # Find the values that delimit a cubic boundin box # for the whole domain - self.log.write("info", "Finding bounding box tha delimits the whole domain") + self.log.write("debug", "Finding bounding box tha delimits the whole domain") rank_bbox = np.zeros((1, 6), dtype=INTERPOLATION_DTYPE) rank_bbox[0, 0] = np.min(self.x) rank_bbox[0, 1] = np.max(self.x) @@ -560,7 +560,7 @@ def scatter_probes_from_io_rank(self, io_rank, comm): rank = comm.Get_rank() size = comm.Get_size() - self.log.write("info", "Scattering probes") + self.log.write("debug", "Scattering probes") self.log.tic() # Check how many probes should be in each rank with a load balanced linear distribution @@ -645,7 +645,7 @@ def scatter_probes_from_io_rank(self, io_rank, comm): self.test_pattern, probe_partition_sendcount, io_rank, INTERPOLATION_DTYPE ) - self.log.write("info", "done") + self.log.write("debug", "done") self.log.toc() return @@ -653,8 +653,8 @@ def scatter_probes_from_io_rank(self, io_rank, comm): def assign_local_probe_partitions(self): """If each rank has recieved a partition of the probes, assign them to the local variables""" - self.log.write("info", "Assigning local probe partitions") - self.log.tic() + self.log.write("debug", "Assigning local probe partitions") + #self.log.tic() # Set the necesary arrays for identification of point number_of_points = self.probes.shape[0] @@ -678,15 +678,15 @@ def assign_local_probe_partitions(self): self.err_code_partition = self.err_code self.test_pattern_partition = self.test_pattern - self.log.write("info", "done") - self.log.toc() + self.log.write("debug", "done") + #self.log.toc() return def gather_probes_to_io_rank(self, io_rank, comm): """Gather the probes to the rank that is used to read them - rank0 by default""" - self.log.write("info", "Gathering probes") + self.log.write("debug", "Gathering probes") self.log.tic() root = io_rank @@ -719,7 +719,7 @@ def gather_probes_to_io_rank(self, io_rank, comm): if not isinstance(recvbuf, NoneType): self.test_pattern[:] = recvbuf[:] - self.log.write("info", "done") + self.log.write("debug", "done") self.log.toc() return @@ -738,7 +738,7 @@ def find_points( ): """Public method to dins points across ranks and elements""" self.log.write( - "info", + "debug", "using communication pattern: {}".format(find_points_comm_pattern), ) # Check that the inputs are in the correct format @@ -819,7 +819,7 @@ def find_points_broadcast( elif local_data_structure == "bounding_boxes": # First each rank finds their bounding box - self.log.write("info", "Finding bounding box of sem mesh") + self.log.write("debug", "Finding bounding box of sem mesh") self.my_bbox = get_bbox_from_coordinates(self.x, self.y, self.z) elif local_data_structure == "rtree": @@ -1262,7 +1262,7 @@ def find_points_( self.rank = rank self.log.write("info", "Finding points - start") - self.log.tic() + if DEBUG: self.log.tic() start_time = MPI.Wtime() kwargs = { @@ -1276,7 +1276,7 @@ def find_points_( elif local_data_structure == "bounding_boxes": # First each rank finds their bounding box - self.log.write("info", "Finding bounding box of sem mesh") + self.log.write("debug", "Finding bounding box of sem mesh") self.my_bbox = get_bbox_from_coordinates(self.x, self.y, self.z) elif local_data_structure == "rtree": @@ -1290,7 +1290,7 @@ def find_points_( # Get candidate ranks from a global kd tree # These are the destination ranks - self.log.write("info", "Obtaining candidate ranks and sources") + self.log.write("debug", "Obtaining candidate ranks and sources") my_dest, _ = get_candidate_ranks(self, comm) # Create temporary arrays that store the points that have not been found @@ -1305,7 +1305,7 @@ def find_points_( test_pattern_not_found = self.test_pattern_partition[not_found] # Send data to my candidates and recieve from ranks where I am candidate - self.log.write("info", "Send data to candidates and recieve from sources") + self.log.write("debug", "Send data to candidates and recieve from sources") # Pack and send/recv the probe data p_probes = pack_data(array_list=[probe_not_found, probe_rst_not_found]) @@ -1327,7 +1327,7 @@ def find_points_( buff_el_owner, buff_glb_el_owner, buff_rank_owner, buff_err_code = unpack_source_data(packed_source_data=buff_p_info, number_of_arrays=4, equal_length=True) # Set the information for the coordinate search in this rank - self.log.write("info", "Find rst coordinates for the points") + self.log.write("debug", "Find rst coordinates for the points") mesh_info = {} mesh_info["x"] = self.x mesh_info["y"] = self.y @@ -1355,10 +1355,13 @@ def find_points_( buffers["test_interp"] = self.test_interp # Now find the rst coordinates for the points stored in each of the buffers + self.log.write( + "info", f"Processing data in multiple ranks. Reporting progress only for rank 0" + ) for source_index in range(0, len(my_source)): self.log.write( - "debug", f"Processing batch: {source_index} out of {len(my_source)}" + "info", f"Processing batch: {source_index+1} out of {len(my_source)}" ) probes_info = {} @@ -1383,7 +1386,7 @@ def find_points_( ] = self.ei.find_rst(probes_info, mesh_info, settings, buffers=buffers) # Set the request to Recieve back the data that I have sent to my candidates - self.log.write("info", "Send data to sources and recieve from candidates") + self.log.write("debug", "Send data to sources and recieve from candidates") # Pack and send/recv the probe data p_buff_probes = pack_destination_data(destination_data=[buff_probes, buff_probes_rst]) @@ -1418,7 +1421,7 @@ def find_points_( # Now loop through all the points in the buffers that # have been sent back and determine which point was found self.log.write( - "info", "Determine which points were found and find best candidate" + "debug", "Determine which points were found and find best candidate" ) for point in range(0, n_not_found): @@ -1475,8 +1478,8 @@ def find_points_( self.err_code_partition[j] = 0 comm.Barrier() - self.log.write("info", "Finding points - finished") - self.log.toc() + self.log.write("debug", "Finding points - finished") + if DEBUG: self.log.toc() return @@ -1496,8 +1499,8 @@ def find_points_iterative( rank = comm.Get_rank() self.rank = rank - self.log.write("info", "Finding points - start") - self.log.tic() + self.log.write("debug", "Finding points - start") + if DEBUG: self.log.tic() start_time = MPI.Wtime() kwargs = { @@ -1511,7 +1514,7 @@ def find_points_iterative( elif local_data_structure == "bounding_boxes": # First each rank finds their bounding box - self.log.write("info", "Finding bounding box of sem mesh") + self.log.write("debug", "Finding bounding box of sem mesh") self.my_bbox = get_bbox_from_coordinates(self.x, self.y, self.z) elif local_data_structure == "rtree": @@ -1525,10 +1528,10 @@ def find_points_iterative( # Get candidate ranks from a global kd tree # These are the destination ranks - self.log.write("info", "Obtaining candidate ranks and sources") + self.log.write("debug", "Obtaining candidate ranks and sources") my_dest, candidate_ranks_list = get_candidate_ranks(self, comm) - self.log.write("info", "Determining maximun number of candidates") + self.log.write("debug", "Determining maximun number of candidates") max_candidates = np.ones((1), dtype=np.int32) * len(my_dest) max_candidates = comm.allreduce(max_candidates, op=MPI.MAX) if batch_size > max_candidates[0]: batch_size = max_candidates[0] @@ -1588,7 +1591,7 @@ def find_points_iterative( test_pattern_not_found = self.test_pattern_partition[not_found] # Send data to my candidates and recieve from ranks where I am candidate - self.log.write("info", "Send data to candidates and recieve from sources") + self.log.write("debug", "Send data to candidates and recieve from sources") # Pack and send/recv the probe data p_probes = pack_data(array_list=[probe_not_found, probe_rst_not_found]) @@ -1610,7 +1613,7 @@ def find_points_iterative( buff_el_owner, buff_glb_el_owner, buff_rank_owner, buff_err_code = unpack_source_data(packed_source_data=buff_p_info, number_of_arrays=4, equal_length=True) # Set the information for the coordinate search in this rank - self.log.write("info", "Find rst coordinates for the points") + self.log.write("debug", "Find rst coordinates for the points") mesh_info = {} mesh_info["x"] = self.x mesh_info["y"] = self.y @@ -1666,7 +1669,7 @@ def find_points_iterative( ] = self.ei.find_rst(probes_info, mesh_info, settings, buffers=buffers) # Set the request to Recieve back the data that I have sent to my candidates - self.log.write("info", "Send data to sources and recieve from candidates") + self.log.write("debug", "Send data to sources and recieve from candidates") # Pack and send/recv the probe data p_buff_probes = pack_destination_data(destination_data=[buff_probes, buff_probes_rst]) @@ -1710,7 +1713,7 @@ def find_points_iterative( # Now loop through all the points in the buffers that # have been sent back and determine which point was found self.log.write( - "info", "Determine which points were found and find best candidate" + "debug", "Determine which points were found and find best candidate" ) for relative_point, absolute_point in enumerate(not_found): @@ -1768,8 +1771,8 @@ def find_points_iterative( self.err_code_partition[j] = 0 comm.Barrier() - self.log.write("info", "Finding points - finished") - self.log.toc() + self.log.write("debug", "Finding points - finished") + if DEBUG: self.log.toc() return @@ -1787,8 +1790,8 @@ def find_points_iterative_rma( rank = comm.Get_rank() self.rank = rank - self.log.write("info", "Finding points - start") - self.log.tic() + self.log.write("debug", "Finding points - start") + if DEBUG: self.log.tic() start_time = MPI.Wtime() self.log.write("warning", "RMA mode is known to miss some points that can be found otherwise. If you encounter some not found points, consider changing communication pattern") @@ -1810,7 +1813,7 @@ def find_points_iterative_rma( elif local_data_structure == "bounding_boxes": # First each rank finds their bounding box - self.log.write("info", "Finding bounding box of sem mesh") + self.log.write("debug", "Finding bounding box of sem mesh") self.my_bbox = get_bbox_from_coordinates(self.x, self.y, self.z) elif local_data_structure == "rtree": @@ -1825,7 +1828,7 @@ def find_points_iterative_rma( # Get candidate ranks from a global data structure # These are the destination ranks - self.log.write("info", "Obtaining candidate ranks and sources") + self.log.write("debug", "Obtaining candidate ranks and sources") my_dest, candidate_ranks_list = get_candidate_ranks(self, comm) # Put my own rank first if it is in the list if comm.Get_rank() in my_dest: @@ -1838,7 +1841,7 @@ def find_points_iterative_rma( max_candidates = np.ones((1), dtype=np.int32) * len(my_dest) max_candidates = comm.allreduce(max_candidates, op=MPI.MAX) if batch_size > max_candidates[0]: batch_size = max_candidates[0] - self.log.write("info", f"Max candidates in a rank was: {max_candidates}") + self.log.write("debug", f"Max candidates in a rank was: {max_candidates}") # Obtain the number of columns corresponding to the maximum number of candidates among all points # Then create a numpy array padding for points that have less candidates @@ -2140,7 +2143,7 @@ def find_points_iterative_rma( if int(keep_searching) == int(self.rt.comm.Get_size()): - self.log.write("info", "All ranks are done searching, exiting") + self.log.write("debug", "All ranks are done searching, exiting") search_flag = False continue @@ -2156,8 +2159,8 @@ def find_points_iterative_rma( self.err_code_partition[j] = 0 comm.Barrier() - self.log.write("info", "Finding points - finished") - self.log.toc() + self.log.write("debug", "Finding points - finished") + if DEBUG: self.log.toc() return @@ -2166,7 +2169,7 @@ def redistribute_probes_to_owners_from_io_rank(self, io_rank, comm): """Redistribute the probes to the ranks that have been determined in the search""" - self.log.write("info", "Scattering probes") + self.log.write("debug", "Scattering probes") self.log.tic() rank = comm.Get_rank() @@ -2255,7 +2258,7 @@ def redistribute_probes_to_owners_from_io_rank(self, io_rank, comm): recvbuf = self.rt.scatter_from_root(sendbuf, sendcounts, root, np.int32) my_rank_owner = recvbuf - self.log.write("info", "Assigning my data") + self.log.write("debug", "Assigning my data") self.my_probes = my_probes self.my_probes_rst = my_probes_rst self.my_err_code = my_err_code @@ -2264,8 +2267,8 @@ def redistribute_probes_to_owners_from_io_rank(self, io_rank, comm): self.sendcounts = sendcounts self.sort_by_rank = sort_by_rank - self.log.write("info", "done") - self.log.toc() + self.log.write("debug", "done") + #self.log.toc() return @@ -2273,8 +2276,8 @@ def redistribute_probes_to_owners(self): """Redistribute the probes to the ranks that have been determined in the search""" - self.log.write("info", "Redistributing probes to owners") - self.log.tic() + self.log.write("debug", "Redistributing probes to owners") + if DEBUG: self.log.tic() # Assing the partitions self.probes[:, :] = self.probe_partition[:, :] @@ -2356,16 +2359,16 @@ def redistribute_probes_to_owners(self): local_probe_index_sent_to_destination ) - self.log.write("info", "done") - self.log.toc() + self.log.write("debug", "done") + if DEBUG: self.log.toc() return def interpolate_field_from_rst(self, sampled_field): """Interpolate the field from the rst coordinates found""" - self.log.write("info", "Interpolating field from rst coordinates") - self.log.tic() + self.log.write("debug", "Interpolating field from rst coordinates") + if DEBUG: self.log.tic() if isinstance(self.my_probes_rst, list): # The inputs were distributed @@ -2415,7 +2418,7 @@ def interpolate_field_from_rst(self, sampled_field): settings=settings, ) - self.log.toc() + if DEBUG: self.log.toc() return sampled_field_at_probe @@ -2953,13 +2956,13 @@ def __init__(self, logger, x: np.ndarray, y: np.ndarray, z: np.ndarray, **kwargs ei = kwargs.get("point_interpolator", None) # First each rank finds their bounding box - self.log.write("info", "Finding bounding box of sem mesh") + self.log.write("debug", "Finding bounding box of sem mesh") self.my_bbox = get_bbox_from_coordinates(x, y, z) # Get the oriented bbox data if self.use_obb: if hasattr(ei, "get_obb"): - self.log.write("info", "Finding oriented bounding box of sem mesh") + self.log.write("debug", "Finding oriented bounding box of sem mesh") self.obb_c, self.obb_jinv = ei.get_obb(x, y, z, max_pts=self.max_pts) else: self.log.write("error", "You are trying to use the OBB feature, but the ei object does not have the get_obb method. Please check your code.") @@ -2990,7 +2993,7 @@ def __init__(self, logger, x: np.ndarray, y: np.ndarray, z: np.ndarray, **kwargs ) # Build a KDtree with my information - self.log.write("info", "Creating KD tree with local bbox centroids") + self.log.write("debug", "Creating KD tree with local bbox centroids") self.my_tree = KDTree(self.my_bbox_centroids) def search(self, probes: np.ndarray, progress_bar = False, **kwargs): @@ -3028,7 +3031,7 @@ def search(self, probes: np.ndarray, progress_bar = False, **kwargs): element_candidates.extend(element_candidates_) if self.use_obb: - self.log.write("info", "obb was used to refine search") + self.log.write("debug", "obb was used to refine search") return element_candidates @@ -3051,19 +3054,19 @@ def __init__(self, logger, x: np.ndarray, y: np.ndarray, z: np.ndarray, **kwargs "Rtree is not installed, please install it with pip install rtree to use this feature" ) - self.log.write("info", "Finding bounding box of sem mesh") + self.log.write("debug", "Finding bounding box of sem mesh") self.my_bbox = get_bbox_from_coordinates_rtree(x, y, z, rel_tol=self.elem_percent_expansion) # Get the oriented bbox data if self.use_obb: if hasattr(ei, "get_obb"): - self.log.write("info", "Finding oriented bounding box of sem mesh") + self.log.write("debug", "Finding oriented bounding box of sem mesh") self.obb_c, self.obb_jinv = ei.get_obb(x, y, z, max_pts=self.max_pts) else: self.log.write("error", "You are trying to use the OBB feature, but the ei object does not have the get_obb method. Please check your code.") raise ValueError("The ei object does not have the get_obb method. Please check your code.") - self.log.write("info", "Creating Rtree with local bbox centroids") + self.log.write("debug", "Creating Rtree with local bbox centroids") self.my_tree = create_rtee(self.my_bbox) def search(self, probes: np.ndarray, **kwargs): @@ -3080,7 +3083,7 @@ def search(self, probes: np.ndarray, **kwargs): element_candidates_ = refine_candidates_obb(probes, element_candidates, self.obb_c, self.obb_jinv) element_candidates = element_candidates_ - self.log.write("info", "obb was used to refine search") + self.log.write("debug", "obb was used to refine search") return element_candidates @@ -3099,20 +3102,20 @@ def __init__(self, logger, x: np.ndarray, y: np.ndarray, z: np.ndarray, **kwargs ei = kwargs.get("point_interpolator", None) # First each rank finds their bounding box - self.log.write("info", "Finding bounding box of sem mesh") + self.log.write("debug", "Finding bounding box of sem mesh") self.my_bbox = get_bbox_from_coordinates(x, y, z) # Get the oriented bbox data if self.use_obb: if hasattr(ei, "get_obb"): - self.log.write("info", "Finding oriented bounding box of sem mesh") + self.log.write("debug", "Finding oriented bounding box of sem mesh") self.obb_c, self.obb_jinv = ei.get_obb(x, y, z, max_pts=self.max_pts) else: self.log.write("error", "You are trying to use the OBB feature, but the ei object does not have the get_obb method. Please check your code.") raise ValueError("The ei object does not have the get_obb method. Please check your code.") # Make the mesh fill the space of its bounding box - self.log.write("info", "Filling bbox space for correct hashtable finding") + self.log.write("debug", "Filling bbox space for correct hashtable finding") x_r, y_r, z_r, _ = linearize_elements(x, y, z, factor=2, rel_tol=self.elem_percent_expansion) bin_size = x.shape[0] @@ -3121,7 +3124,7 @@ def __init__(self, logger, x: np.ndarray, y: np.ndarray, z: np.ndarray, **kwargs # Find the values that delimit a cubic boundin box # for the whole domain - self.log.write("info", "Finding bounding box tha delimits the ranks") + self.log.write("debug", "Finding bounding box tha delimits the ranks") self.domain_min_x = np.min(x) self.domain_min_y = np.min(y) @@ -3132,7 +3135,7 @@ def __init__(self, logger, x: np.ndarray, y: np.ndarray, z: np.ndarray, **kwargs self.bin_size_1d = bin_size_1d # See wich element has points in which bin - self.log.write("info", "Creating bin mesh for the rank") + self.log.write("debug", "Creating bin mesh for the rank") bins_of_points = self.binning_hash(x_r, y_r, z_r) # Create the empty bin to rank map @@ -3209,7 +3212,7 @@ def search(self, probes: np.ndarray, **kwargs): element_candidates_ = refine_candidates_obb(probes, element_candidates, self.obb_c, self.obb_jinv) element_candidates = element_candidates_ - self.log.write("info", "obb was used to refine search") + self.log.write("debug", "obb was used to refine search") return element_candidates diff --git a/pysemtools/interpolation/probes.py b/pysemtools/interpolation/probes.py index 7693758..2b09a24 100644 --- a/pysemtools/interpolation/probes.py +++ b/pysemtools/interpolation/probes.py @@ -155,24 +155,24 @@ def __init__( self.log = Logger(comm=comm, module_name="Probes") self.log.tic() - self.log.write("info", "Initializing Probes object:") - self.log.write("info", f" ======= Settings =======") - self.log.write("info", f"output_fname: {output_fname}") - self.log.write("info", f"write_coords: {write_coords}") - self.log.write("info", f"progress_bar: {progress_bar}") - self.log.write("info", f"point_interpolator_type: {point_interpolator_type}") - self.log.write("info", f"max_pts: {max_pts}") - self.log.write("info", f"find_points_iterative: {find_points_iterative}") - self.log.write("info", f"find_points_comm_pattern: {find_points_comm_pattern}") - self.log.write("info", f"elem_percent_expansion: {elem_percent_expansion}") - self.log.write("info", f"global_tree_type: {global_tree_type}") - self.log.write("info", f"global_tree_nbins: {global_tree_nbins}") - self.log.write("info", f"use_autograd: {use_autograd}") - self.log.write("info", f"find_points_tol: {find_points_tol}") - self.log.write("info", f"find_points_max_iter: {find_points_max_iter}") - self.log.write("info", f"local_data_structure: {local_data_structure}") - self.log.write("info", f"use_oriented_bbox: {use_oriented_bbox}") - self.log.write("info", f" ========================") + self.log.write("info", "Initializing Probes object") + self.log.write("debug", f" ======= Settings =======") + self.log.write("debug", f"output_fname: {output_fname}") + self.log.write("debug", f"write_coords: {write_coords}") + self.log.write("debug", f"progress_bar: {progress_bar}") + self.log.write("debug", f"point_interpolator_type: {point_interpolator_type}") + self.log.write("debug", f"max_pts: {max_pts}") + self.log.write("debug", f"find_points_iterative: {find_points_iterative}") + self.log.write("debug", f"find_points_comm_pattern: {find_points_comm_pattern}") + self.log.write("debug", f"elem_percent_expansion: {elem_percent_expansion}") + self.log.write("debug", f"global_tree_type: {global_tree_type}") + self.log.write("debug", f"global_tree_nbins: {global_tree_nbins}") + self.log.write("debug", f"use_autograd: {use_autograd}") + self.log.write("debug", f"find_points_tol: {find_points_tol}") + self.log.write("debug", f"find_points_max_iter: {find_points_max_iter}") + self.log.write("debug", f"local_data_structure: {local_data_structure}") + self.log.write("debug", f"use_oriented_bbox: {use_oriented_bbox}") + self.log.write("debug", f" ========================") # Check for errors if clean_search_traces and point_interpolator_type != "multiple_point_legendre_numpy": @@ -182,17 +182,17 @@ def __init__( self.log.sync_tic() self.data_read_from_structured_mesh = False if isinstance(probes, np.ndarray) or isinstance(probes, NoneType): - self.log.write("info", "Probes provided as keyword argument") + self.log.write("debug", "Probes provided as keyword argument") self.probes = probes elif isinstance(probes, str): - self.log.write("info", f"Reading probes from {probes}") + self.log.write("debug", f"Reading probes from {probes}") self.probes = read_probes(self, comm, probes) else: print( "ERROR: Probes must be provided as a string, numpy array or None if the probes are not distributed" ) comm.Abort(1) - self.log.sync_toc(message="Query points (probes) read") + self.log.sync_toc(message="Query points (probes) read/assigned") # Check if the probes are distributed self.distributed_probes = False @@ -209,7 +209,7 @@ def __init__( self.distributed_probes = True self.log.write( - "info", + "debug", f"Input probes are distributed: {self.distributed_probes}", ) if self.distributed_probes: @@ -228,7 +228,7 @@ def __init__( # Assign mesh data if isinstance(msh, Mesh): - self.log.write("info", "Mesh provided as keyword argument") + self.log.write("debug", "Mesh provided as keyword argument") if msh.bckend != 'numpy': raise ValueError("Only supported Mesh backend at the moment is numpy") self.x = msh.x @@ -254,7 +254,7 @@ def __init__( self.n_probes = 0 # Initialize the interpolator - self.log.write("info", "Initializing interpolator") + self.log.write("debug", "Initializing interpolator") self.log.sync_tic() self.itp = Interpolator( self.x, @@ -270,7 +270,7 @@ def __init__( ) # Set up the global tree - self.log.write("info", "Setting up global tree") + self.log.write("debug", "Setting up global tree") self.itp.set_up_global_tree( comm, find_points_comm_pattern=find_points_comm_pattern, @@ -281,14 +281,14 @@ def __init__( # Scatter the probes to all ranks if self.distributed_probes: - self.log.write("info", "Assigning input probes to be a probe partition") + self.log.write("debug", "Assigning input probes to be a probe partition") self.itp.assign_local_probe_partitions() else: - self.log.write("info", "Scattering probes to all ranks") + self.log.write("debug", "Scattering probes to all ranks") self.itp.scatter_probes_from_io_rank(0, comm) # Find where the point in each rank should be - self.log.write("info", "Finding points") + self.log.write("debug", "Finding points") self.log.sync_tic() self.itp.find_points( comm, @@ -304,15 +304,15 @@ def __init__( # Send points to the owners if self.distributed_probes: - self.log.write("info", "Redistributing probes to found owners") + self.log.write("debug", "Redistributing probes to found owners") self.itp.redistribute_probes_to_owners() else: # Gather probes to rank 0 again - self.log.write("info", "Gathering probes to rank 0 after search") + self.log.write("debug", "Gathering probes to rank 0 after search") self.itp.gather_probes_to_io_rank(0, comm) # Redistribute the points - self.log.write("info", "Redistributing probes to found owners") + self.log.write("debug", "Redistributing probes to found owners") self.itp.redistribute_probes_to_owners_from_io_rank(0, comm) self.output_fname = output_fname @@ -362,8 +362,8 @@ def __init__( if clean_search_traces: self.clean_search_traces() - self.log.write("info", "Probes object initialized") - self.log.toc() + self.log.write("debug", "Probes object initialized") + self.log.toc(message="Probes object initialized in all ranks") def interpolate_from_field_list( self, t, field_list, comm, write_data=True, field_names: list[str] = None @@ -431,7 +431,7 @@ def interpolate_from_field_list( field = field_list[i] - self.log.write("info", f"Interpolating field {i}") + self.log.write("debug", f"Interpolating field {i}") interpolated_fields_from_sources = self.itp.interpolate_field_from_rst( field @@ -443,7 +443,7 @@ def interpolate_from_field_list( interpolated_fields_from_sources[j] ) - self.log.sync_toc(message="Interpolation: point evaluation done") + self.log.sync_toc(message="Interpolation: point evaluation done", level="debug") self.log.sync_tic(id=1) # Send the data back to the ranks that sent me the probes @@ -464,7 +464,7 @@ def interpolate_from_field_list( self.itp.local_probe_index_sent_to_destination[i] ] = interpolated_data[list(sources).index(self.itp.destinations[i])][:] - self.log.sync_toc(id = 1, message="Interpolation: point redistribution done") + self.log.sync_toc(id = 1, message="Interpolation: point redistribution done", level="debug") self.log.sync_toc(message="Finished interpolation and redistribution in all ranks", time_message="Aggregated time: ") # If the probes were given in rank 0, then each rank interpolates the points that it owns physically @@ -489,14 +489,14 @@ def interpolate_from_field_list( i = 0 for field in field_list: - self.log.write("info", f"Interpolating field {i}") + self.log.write("debug", f"Interpolating field {i}") self.my_interpolated_fields[:, i + 1] = ( self.itp.interpolate_field_from_rst(field)[:] ) i += 1 - self.log.sync_toc(message="Interpolation: point evaluation done") + self.log.sync_toc(message="Interpolation: point evaluation done", level="debug") self.log.sync_tic(id=1) # Gather in rank zero for processing @@ -520,7 +520,7 @@ def interpolate_from_field_list( # You sort to make sure that the data from each rank is grouped. self.interpolated_fields[self.itp.sort_by_rank] = tmp - self.log.sync_toc(id = 1, message="Interpolation: point redistribution done") + self.log.sync_toc(id = 1, message="Interpolation: point redistribution done", level="debug") self.log.sync_toc(message="Finished interpolation and redistribution in all ranks", time_message="Aggregated time: ") # Write the data diff --git a/pysemtools/io/ppymech/neksuite.py b/pysemtools/io/ppymech/neksuite.py index 49a5749..cf76c7f 100644 --- a/pysemtools/io/ppymech/neksuite.py +++ b/pysemtools/io/ppymech/neksuite.py @@ -614,7 +614,7 @@ def pynekread(filename, comm, data_dtype=np.double, msh=None, fld=None, overwrit mpi_offset += ioh.glb_nelv * ioh.gdim * ioh.lxyz * ioh.fld_data_size if not isinstance(fld, type(None)): - log.write("info", "Reading field data") + log.write("debug", "Reading field data") if overwrite_fld: log.write("info", "Overwriting fld object") fld.clear() @@ -693,8 +693,8 @@ def pynekread(filename, comm, data_dtype=np.double, msh=None, fld=None, overwrit fh.Close() - log.write("info", "File read") - log.toc() + log.write("debug", "File read") + log.toc(message="File successfully read") del log return @@ -1420,7 +1420,7 @@ def pynekwrite(filename, comm, msh=None, fld=None, wdsz=4, istep=0, write_mesh=T fh.Close() log.write("debug", "File written") - log.toc() + log.toc(message="File written") del log diff --git a/pysemtools/monitoring/logger.py b/pysemtools/monitoring/logger.py index e12a331..6183f76 100644 --- a/pysemtools/monitoring/logger.py +++ b/pysemtools/monitoring/logger.py @@ -22,7 +22,9 @@ class CustomFormatter(logging.Formatter): # formatt = ( # "%(asctime)s - %(name)s - %(levelname)s - %(message)s (%(filename)s:%(lineno)d)" # ) - formatt = "%(asctime)s - %(name)s - %(levelname)s - %(message)s" + #formatt = "%(asctime)s - %(name)s - %(levelname)s - %(message)s" + formatt = "%(asctime)s %(name)-20s %(levelname)-8s %(message)s" + FORMATS_colored = { logging.DEBUG: grey + formatt + reset, @@ -96,6 +98,18 @@ def __init__(self, level=None, comm=None, module_name=None): if isinstance(level, type(None)): level = logging.INFO + elif level == "debug": + level = logging.DEBUG + elif level == "info": + level = logging.INFO + elif level == "warning": + level = logging.WARNING + elif level == "error": + level = logging.ERROR + elif level == "critical": + level = logging.CRITICAL + elif level == "hide": + level = logging.CRITICAL if DEBUG: level = logging.DEBUG if HIDE: @@ -154,13 +168,16 @@ def sync_tic(self, id = 0): self.comm.Barrier() self.sync_time[id] = time() - def toc(self, level="info"): + def toc(self, message=None, time_message="Elapsed time: ", level="info"): """ Write elapsed time since the last call to tic. """ - self.write(level, f"Elapsed time: {time() - self.time}s") + if message is None: + self.write(level, f"{time_message}{time() - self.time}s") + else: + self.write(level, f"{message} - {time_message}{time() - self.time}s") def sync_toc(self, id = 0, message=None, time_message="Elapsed time: ", level="info"): """ @@ -204,9 +221,9 @@ def write(self, level, message): self.log.info(message) if level == "info_all": - self.log.info(f"Rank {comm.Get_rank()}: {message}") comm.Barrier() - + self.log.info(f"Rank {comm.Get_rank()}: {message}") + if level == "warning": if rank == 0: self.log.warning(message)