Browse Source

Add version check with MindSpore.

pull/429/head
ZhidanLiu 2 years ago
parent
commit
818a39e42f
7 changed files with 117 additions and 1 deletions
  1. +1
    -1
      .jenkins/test/config/dependent_packages.yaml
  2. +11
    -0
      README.md
  3. +11
    -0
      README_CN.md
  4. +14
    -0
      RELEASE.md
  5. +14
    -0
      RELEASE_CN.md
  6. +51
    -0
      mindarmour/__init__.py
  7. +15
    -0
      mindarmour/version.py

+ 1
- 1
.jenkins/test/config/dependent_packages.yaml View File

@@ -1,3 +1,3 @@
mindspore:
'mindspore/mindspore/version/202209/20220917/r1.9_20220917123349_90b3153080efc701223898e8498b719aa0b0e317/'
'mindspore/mindspore/version/202209/20220923/r1.9_20220923224458_c16390f59ab8dace3bb7e5a6ab4ae4d3bfe74bea/'


+ 11
- 0
README.md View File

@@ -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.


+ 11
- 0
README_CN.md View File

@@ -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下载源码。


+ 14
- 0
RELEASE.md View File

@@ -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


+ 14
- 0
RELEASE_CN.md View File

@@ -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


+ 51
- 0
mindarmour/__init__.py View File

@@ -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()

+ 15
- 0
mindarmour/version.py View File

@@ -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'

Loading…
Cancel
Save