You can not select more than 25 topics Topics must start with a chinese character,a letter or number, can include dashes ('-') and can be up to 35 characters long.

run_check.py 2.0 kB

4 years ago
4 years ago
4 years ago
4 years ago
12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. # Copyright 2021 Huawei Technologies Co., Ltd
  2. #
  3. # Licensed under the Apache License, Version 2.0 (the "License");
  4. # you may not use this file except in compliance with the License.
  5. # You may obtain a copy of the License at
  6. #
  7. # http://www.apache.org/licenses/LICENSE-2.0
  8. #
  9. # Unless required by applicable law or agreed to in writing, software
  10. # distributed under the License is distributed on an "AS IS" BASIS,
  11. # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  12. # See the License for the specific language governing permissions and
  13. # limitations under the License.
  14. # ============================================================================
  15. """
  16. mindspore.run_check
  17. The goal is to provide a convenient API to check if the installation is successful or failed.
  18. """
  19. def _check_mul():
  20. """
  21. Define the mul method.
  22. """
  23. from importlib import import_module
  24. import numpy as np
  25. try:
  26. ms = import_module("mindspore")
  27. except ModuleNotFoundError:
  28. ms = None
  29. finally:
  30. pass
  31. print(f"MindSpore version: ", ms.__version__)
  32. input_x = ms.Tensor(np.array([1.0, 2.0, 3.0]), ms.float32)
  33. input_y = ms.Tensor(np.array([4.0, 5.0, 6.0]), ms.float32)
  34. mul = ms.ops.Mul()
  35. mul(input_x, input_y)
  36. print(f"The result of multiplication calculation is correct, MindSpore has been installed successfully!")
  37. def run_check():
  38. """
  39. Provide a convenient API to check if the installation is successful or failed.
  40. If there is no return value, the verification status will be displayed directly.
  41. Examples:
  42. >>> import mindspore
  43. >>> mindspore.run_check()
  44. MindSpore version: xxx
  45. The result of multiplication calculation is correct, MindSpore has been installed successfully!
  46. """
  47. try:
  48. _check_mul()
  49. # pylint: disable=broad-except
  50. except Exception as e:
  51. print("MindSpore running check failed.")
  52. print(str(e))
  53. finally:
  54. pass