!16987 add run_check moudle

From: @fenglovebei
Reviewed-by: @kingxian,@guoqi1024
Signed-off-by: @kingxian
This commit is contained in:
mindspore-ci-bot 2021-06-03 14:38:25 +08:00 committed by Gitee
commit c1f931e5f4
6 changed files with 97 additions and 6 deletions

View File

@ -326,6 +326,7 @@ install(
${CMAKE_SOURCE_DIR}/mindspore/profiler
${CMAKE_SOURCE_DIR}/mindspore/explainer
${CMAKE_SOURCE_DIR}/mindspore/compression
${CMAKE_SOURCE_DIR}/mindspore/run_check
DESTINATION ${INSTALL_PY_DIR}
COMPONENT mindspore
)

View File

@ -14,7 +14,7 @@
# ============================================================================
""".. MindSpore package."""
from ._check_version import check_version_and_env_config
from .run_check import run_check
from . import common, train, log
from .common import *
from .ops import _op_impl
@ -22,8 +22,10 @@ from .train import *
from .log import *
from .version import __version__
all = ["run_check"]
__all__ = []
__all__.extend(__version__)
__all__.extend(run_check.__all__)
__all__.extend(common.__all__)
__all__.extend(train.__all__)
__all__.extend(log.__all__)

View File

@ -0,0 +1,20 @@
# Copyright 2021 Huawei Technologies Co., Ltd
#
# 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.
# ============================================================================
""".. run_check package."""
from .run_check import run_check
from ._check_version import check_version_and_env_config
__all__ = ['run_check']

View File

@ -20,9 +20,9 @@ from pathlib import Path
from abc import abstractmethod, ABCMeta
import numpy as np
from packaging import version
from . import log as logger
from .version import __version__
from .default_config import __package_name__
from mindspore import log as logger
from ..version import __version__
from ..default_config import __package_name__
class EnvChecker(metaclass=ABCMeta):
@ -282,7 +282,8 @@ class AscendEnvChecker(EnvChecker):
input_args = ["--mindspore_version=" + __version__]
for v in self.version:
input_args.append("--supported_version=" + v)
deps_version_checker = os.path.join(os.path.split(os.path.realpath(__file__))[0], "_check_deps_version.py")
deps_version_checker = os.path.join(os.path.split(os.path.realpath(__file__))[0],
"_check_deps_version.py")
call_cmd = [sys.executable, deps_version_checker] + input_args
try:
process = subprocess.run(call_cmd, timeout=3, text=True, capture_output=True, check=False)
@ -390,7 +391,7 @@ def check_version_and_env_config():
try:
# check version of ascend site or cuda
env_checker.check_version()
from . import _c_expression
from .. import _c_expression
env_checker.set_env()
except ImportError as e:
env_checker.check_env(e)

View File

@ -0,0 +1,67 @@
# Copyright 2021 Huawei Technologies Co., Ltd
#
# 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.
# ============================================================================
"""
mindspore.run_check
The goal is to provide a convenient API to check if the installation is successful or failed.
"""
import numpy as np
from importlib import import_module
try:
ms = import_module("mindspore")
except ModuleNotFoundError:
ms = None
def _check_mul():
"""
Define the mul method.
"""
input_x = ms.Tensor(np.array([1.0, 2.0, 3.0]), ms.float32)
input_y = ms.Tensor(np.array([4.0, 5.0, 6.0]), ms.float32)
mul = ms.ops.Mul()
mul(input_x, input_y)
print(f"The result of multiplication calculation is correct, MindSpore has been installed successfully!")
def _check_install():
"""
Define the check install method.
Print MindSpore version.
"""
print(f"MindSpore version:", ms.__version__)
def run_check():
"""
Provide a convenient API to check if the installation is successful or failed.
Examples:
>>> import mindspore
>>> mindspore.run_check()
MindSpore version: xxx
The result of multiplication calculation is correct, MindSpore has been installed successfully!
"""
try:
_check_install()
_check_mul()
# pylint: disable=broad-except
except Exception as e:
print("MindSpore installation failed!")
print("CheckFailed: ", str(e))