# SPDX-FileCopyrightText: Copyright (c) 2023 - 2025 NVIDIA CORPORATION & AFFILIATES. # SPDX-FileCopyrightText: All rights reserved. # SPDX-License-Identifier: Apache-2.0 # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. # You may obtain a copy of the License at # # http://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable law or agreed to in writing, software # distributed under the License is distributed on an "AS IS" BASIS, # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. import logging from physicsnemo.datapipes.meta import DatapipeMetaData class Datapipe: """The base class for all datapipes in PhysicsNeMo. Parameters ---------- meta : DatapipeMetaData, optional Meta data class for storing info regarding model, by default None """ def __init__(self, meta: DatapipeMetaData = None): super().__init__() if not meta or not isinstance(meta, DatapipeMetaData): self.meta = DatapipeMetaData() else: self.meta = meta self.logger = logging.getLogger("core.datapipe") handler = logging.StreamHandler() formatter = logging.Formatter( "[%(asctime)s - %(levelname)s] %(message)s", datefmt="%H:%M:%S" ) handler.setFormatter(formatter) self.logger.addHandler(handler) self.logger.setLevel(logging.WARNING) def debug(self): """Turn on debug logging""" self.logger.handlers.clear() handler = logging.StreamHandler() formatter = logging.Formatter( f"[%(asctime)s - %(levelname)s - {self.meta.name}] %(message)s", datefmt="%Y-%m-%d %H:%M:%S", ) handler.setFormatter(formatter) self.logger.addHandler(handler) self.logger.setLevel(logging.DEBUG) # TODO: set up debug log # fh = logging.FileHandler(f'physicsnemo-core-{self.meta.name}.log')