# -------------------------------------------------------------------------
#  This file is part of the MindStudio project.
# Copyright (c) 2025 Huawei Technologies Co.,Ltd.
#
# MindStudio is licensed under Mulan PSL v2.
# You can use this software according to the terms and conditions of the Mulan PSL v2.
# You may obtain a copy of Mulan PSL v2 at:
#
#          http://license.coscl.org.cn/MulanPSL2
#
# THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND,
# EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT,
# MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE.
# See the Mulan PSL v2 for more details.
# -------------------------------------------------------------------------

# 全局常量

from .i18n import ZH_CN


class GraphState:
    # 模块级全局变量
    _state = {
        'logdir': '',
        'current_tag': '',
        'current_run': '',
        'current_file_data': {},
        'current_hierarchy': {},
        'config_data': {
            "run": "",
            "npuUnMatchNodes": [],
            "benchUnMatchNodes": [],
            "npuMatchNodes": {},
            "benchMatchNodes": {},
            "manualMatchNodes": {},
            
        },
        'config_info': {},  # 全局的配置信息
        'first_run_tags': {},
        'runs': {},
        'update_precision_cache': {},  # {node_name{precision，...}}，方便查询精度，提高性能
        'all_node_info_cache': {},  # {rank_step_micro_step:{node_name:node_info,...}}，方便查询节点信息，提高性能
        'lang': ZH_CN,
    }

    @staticmethod
    def init_defaults():
        """
        初始化全局变量的默认值
        """
        GraphState._state = {
            'logdir': '',
            'current_tag': '',
            'current_run': '',
            'current_file_data': {},
            'current_hierarchy': {},
            'config_data': {
                "run": "",
                "npuUnMatchNodes": [],
                "benchUnMatchNodes": [],
                "npuMatchNodes": {},
                "benchMatchNodes": {},
                "manualMatchNodes": {},
                
            },
            'config_info': {},  # 全局的配置信息
            'first_run_tags': {},
            'runs': {},
            'update_precision_cache': {},
            'all_node_info_cache': {},
            'lang': ZH_CN,
        }

    @staticmethod
    def set_global_value(key, value):
        """
        设置全局变量的值
        """
        GraphState._state[key] = value

    @staticmethod
    def get_global_value(key, default=None):
        """
        获取全局变量的值
        """
        return GraphState._state.get(key, default)

    @staticmethod
    def reset_global_state():
        """
        重置所有全局变量为默认值
        """
        GraphState.init_defaults()

