From 818a39e42f786500df4dd8c9db46680e250dda95 Mon Sep 17 00:00:00 2001 From: ZhidanLiu Date: Wed, 19 Oct 2022 11:24:34 +0800 Subject: [PATCH] Add version check with MindSpore. --- .jenkins/test/config/dependent_packages.yaml | 2 +- README.md | 11 ++++++ README_CN.md | 11 ++++++ RELEASE.md | 14 ++++++++ RELEASE_CN.md | 14 ++++++++ mindarmour/__init__.py | 51 ++++++++++++++++++++++++++++ mindarmour/version.py | 15 ++++++++ 7 files changed, 117 insertions(+), 1 deletion(-) create mode 100644 mindarmour/version.py diff --git a/.jenkins/test/config/dependent_packages.yaml b/.jenkins/test/config/dependent_packages.yaml index d9a494d..661c30e 100644 --- a/.jenkins/test/config/dependent_packages.yaml +++ b/.jenkins/test/config/dependent_packages.yaml @@ -1,3 +1,3 @@ mindspore: - 'mindspore/mindspore/version/202209/20220917/r1.9_20220917123349_90b3153080efc701223898e8498b719aa0b0e317/' + 'mindspore/mindspore/version/202209/20220923/r1.9_20220923224458_c16390f59ab8dace3bb7e5a6ab4ae4d3bfe74bea/' diff --git a/README.md b/README.md index 415750a..5e7c0d5 100644 --- a/README.md +++ b/README.md @@ -79,6 +79,17 @@ The architecture is shown as follow: ### Installation +### Version dependency + +Due the dependency between MindArmour and MindSpore, please follow the table below and install the corresponding MindSpore verision from [MindSpore download page](https://www.mindspore.cn/versions/en). + +| MindArmour Version | Branch | MindSpore Version | +| ------------------ | --------------------------------------------------------- | ----------------- | +| 2.0.0 | [r2.0](https://gitee.com/mindspore/mindarmour/tree/r2.0/) | 1.7.0 - | +| 1.9.0 | [r1.9](https://gitee.com/mindspore/mindarmour/tree/r1.9/) | 1.7.0 - | +| 1.8.0 | [r1.8](https://gitee.com/mindspore/mindarmour/tree/r1.8/) | 1.7.0 - | +| 1.7.0 | [r1.7](https://gitee.com/mindspore/mindarmour/tree/r1.7/) | r1.7 | + #### Installation by Source Code 1. Download source code from Gitee. diff --git a/README_CN.md b/README_CN.md index 0c53995..9bb9852 100644 --- a/README_CN.md +++ b/README_CN.md @@ -76,6 +76,17 @@ Fuzz Testing模块的架构图如下: ### 安装 +#### MindSpore版本依赖关系 + +由于MindArmour与MindSpore有依赖关系,请按照下表所示的对应关系,在[MindSpore下载页面](https://www.mindspore.cn/versions)下载并安装对应的whl包。 + +| MindArmour | 分支 | MindSpore | +| ---------- | --------------------------------------------------------- | --------- | +| 2.0.0 | [r2.0](https://gitee.com/mindspore/mindarmour/tree/r2.0/) | 1.7.0 - | +| 1.9.0 | [r1.9](https://gitee.com/mindspore/mindarmour/tree/r1.9/) | 1.7.0 - | +| 1.8.0 | [r1.8](https://gitee.com/mindspore/mindarmour/tree/r1.8/) | 1.7.0 - | +| 1.7.0 | [r1.7](https://gitee.com/mindspore/mindarmour/tree/r1.7/) | r1.7 | + #### 源码安装 1. 从Gitee下载源码。 diff --git a/RELEASE.md b/RELEASE.md index 7566ca5..a1bfd70 100644 --- a/RELEASE.md +++ b/RELEASE.md @@ -1,5 +1,19 @@ # MindArmour Release Notes +## MindArmour 2.0.0 Release Notes + +### API Change + +* Add version check with MindSpore. + +### Contributors + +Thanks goes to these wonderful people: + +Liu Zhidan, Zhang Shukun, Liu Liu, Tang Cong. + +Contributions of any kind are welcome! + ## MindArmour 1.9.0 Release Notes ### API Change diff --git a/RELEASE_CN.md b/RELEASE_CN.md index 1e7145a..90ae98f 100644 --- a/RELEASE_CN.md +++ b/RELEASE_CN.md @@ -2,6 +2,20 @@ [View English](./RELEASE.md) +## MindArmour 2.0.0 Release Notes + +### API Change + +* 增加与MindSpore的版本校验关系。 + +### 贡献 + +感谢以下人员做出的贡献: + +Liu Zhidan, Zhang Shukun, Liu Liu, Tang Cong. + +欢迎以任何形式对项目提供贡献! + ## MindArmour 1.9.0 Release Notes ### API Change diff --git a/mindarmour/__init__.py b/mindarmour/__init__.py index ec295cd..0918b1c 100644 --- a/mindarmour/__init__.py +++ b/mindarmour/__init__.py @@ -27,6 +27,7 @@ from .privacy.sup_privacy.train.model import SuppressModel from .privacy.sup_privacy.mask_monitor.masker import SuppressMasker from .privacy.evaluation.inversion_attack import ImageInversionAttack from .reliability.concept_drift.concept_drift_check_time_series import ConceptDriftCheckTimeSeries +from .utils import logger __all__ = ['Attack', 'BlackModel', @@ -40,3 +41,53 @@ __all__ = ['Attack', 'SuppressMasker', 'ImageInversionAttack', 'ConceptDriftCheckTimeSeries'] + + +def _mindspore_version_check(): + """ + Do the MindSpore version check for MindArmour. If the + MindSpore can not be imported, it will raise ImportError. If its + version is not compatibale with current MindArmour verision, + it will print a warning. + + Raise: + ImportError: If the MindSpore can not be imported. + """ + try: + from mindarmour.version import __version__ + ma_version = __version__[:3] + except ModuleNotFoundError: + logger.warning(f"Get MindArmour version failed") + return + + try: + import mindspore as ms + except (ImportError, ModuleNotFoundError): + print("Can not find MindSpore in current environment. Please install " + "MindSpore before using MindSpore Reinforcement, by following " + "the instruction at https://www.mindspore.cn/install") + raise + + ms_ma_version_match = {'1.7': ['1.7'], + '1.8': ['1.7', '1.8', '1.9', '2.0'], + '1.9': ['1.7', '1.8', '1.9', '2.0'], + '2.0': ['1.7', '1.8', '1.9', '2.0']} + + ms_version = ms.__version__[:3] + required_mindspore_verision = ms_ma_version_match.get(ma_version[:3]) + + if ms_version not in required_mindspore_verision: + logger.warning("Current version of MindSpore is not compatible with MindArmour. " + "Some functions might not work or even raise error. Please install MindSpore " + "version in {}. For more details about dependency setting, please check " + "the instructions at MindSpore official website https://www.mindspore.cn/install " + "or check the README.md at https://gitee.com/mindspore/mindarmour".format( + required_mindspore_verision)) + warning_countdown = 3 + for i in range(warning_countdown, 0, -1): + logger.warning( + f"Please pay attention to the above warning, countdown: {i}") + time.sleep(1) + + +_mindspore_version_check() diff --git a/mindarmour/version.py b/mindarmour/version.py new file mode 100644 index 0000000..c0190a0 --- /dev/null +++ b/mindarmour/version.py @@ -0,0 +1,15 @@ +# Copyright 2020 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. +"""Version of MindArmour""" +__version__ = '2.0.0'