From e5fc67abbee04f481ae94e75e4e746c7e8cd806b Mon Sep 17 00:00:00 2001 From: Manoel Marques Date: Sun, 5 Apr 2020 19:13:14 -0400 Subject: [PATCH 1/3] Show combined deprecation warnings on travis --- .travis.yml | 151 ++++++++++++++++++++++++++++------- requirements-dev.txt | 2 +- tools/extract_deprecation.py | 103 ++++++++++++++++++++++++ 3 files changed, 225 insertions(+), 31 deletions(-) create mode 100644 tools/extract_deprecation.py diff --git a/.travis.yml b/.travis.yml index 7828e1601e..746aeb2c0d 100644 --- a/.travis.yml +++ b/.travis.yml @@ -130,37 +130,61 @@ jobs: if: tag IS blank workspaces: create: - name: aqua1 - paths: aqua1.dat + name: aqua137 + paths: + - aqua1.dat + - aqua137.dep before_script: - pip install cvxopt - export PYTHON="coverage3 run --source qiskit/aqua,qiskit/chemistry,qiskit/finance,qiskit/ml,qiskit/optimization --omit */gauopen/* --parallel-mode" - script: stestr --test-path test/aqua run --blacklist-file selection.txt && coverage3 combine && mv .coverage aqua1.dat + script: + - stestr --test-path test/aqua run --blacklist-file selection.txt 2>&1 | tee out.txt + - coverage3 combine + - mv .coverage aqua1.dat + - python tools/extract_deprecation.py -file out.txt -output aqua137.dep - name: "Test Aqua 1 Python 3.8" <<: *stage_test_aqua if: tag IS blank + workspaces: + create: + name: aqua138 + paths: aqua138.dep python: 3.8 before_script: - pip install cvxopt - script: stestr --test-path test/aqua run --blacklist-file selection.txt + script: + - stestr --test-path test/aqua run --blacklist-file selection.txt 2>&1 | tee out.txt + - python tools/extract_deprecation.py -file out.txt -output aqua138.dep - name: "Test Aqua 2 Python 3.7" <<: *stage_test_aqua if: tag IS blank workspaces: create: - name: aqua2 - paths: aqua2.dat + name: aqua237 + paths: + - aqua2.dat + - aqua237.dep before_script: - pip install cvxopt - export PYTHON="coverage3 run --source qiskit/aqua,qiskit/chemistry,qiskit/finance,qiskit/ml,qiskit/optimization --omit */gauopen/* --parallel-mode" - script: stestr --test-path test/aqua run --whitelist-file selection.txt && coverage3 combine && mv .coverage aqua2.dat + script: + - stestr --test-path test/aqua run --whitelist-file selection.txt 2>&1 | tee out.txt + - coverage3 combine + - mv .coverage aqua2.dat + - python tools/extract_deprecation.py -file out.txt -output aqua237.dep - name: "Test Aqua 2 Python 3.8" <<: *stage_test_aqua if: tag IS blank + workspaces: + create: + name: aqua238 + paths: aqua238.dep python: 3.8 before_script: - pip install cvxopt - script: stestr --test-path test/aqua run --whitelist-file selection.txt + script: + - stestr --test-path test/aqua run --whitelist-file selection.txt 2>&1 | tee out.txt + - python tools/extract_deprecation.py -file out.txt -output aqua238.dep - name: "Test Chemistry Python 3.7" <<: *stage_dependencies if: tag IS blank @@ -169,8 +193,10 @@ jobs: - OPENBLAS_NUM_THREADS=1 workspaces: create: - name: chemistry - paths: chemistry.dat + name: chemistry37 + paths: + - chemistry.dat + - chemistry37.dep install: # install gaussian dependency libgfortran 5 - sudo apt-get -y update @@ -179,10 +205,18 @@ jobs: - pip install https://github.com/rpmuller/pyquante2/archive/master.zip --progress-bar off before_script: - export PYTHON="coverage3 run --source qiskit/aqua,qiskit/chemistry,qiskit/finance,qiskit/ml,qiskit/optimization --omit */gauopen/* --parallel-mode" - script: stestr --test-path test/chemistry run && coverage3 combine && mv .coverage chemistry.dat + script: + - stestr --test-path test/chemistry run 2>&1 | tee out.txt + - coverage3 combine + - mv .coverage chemistry.dat + - python tools/extract_deprecation.py -file out.txt -output chemistry37.dep - name: "Test Chemistry Python 3.8" <<: *stage_dependencies if: tag IS blank + workspaces: + create: + name: chemistry38 + paths: chemistry38.dep python: 3.8 env: OPENBLAS_NUM_THREADS=1 install: @@ -191,52 +225,90 @@ jobs: - sudo apt-get -y install libgfortran5 # Installing pyquante2 master branch... - pip install https://github.com/rpmuller/pyquante2/archive/master.zip --progress-bar off - script: stestr --test-path test/chemistry run + script: + - stestr --test-path test/chemistry run 2>&1 | tee out.txt + - python tools/extract_deprecation.py -file out.txt -output chemistry38.dep - name: "Test Finance Python 3.7" <<: *stage_dependencies if: tag IS blank workspaces: create: - name: finance - paths: finance.dat + name: finance37 + paths: + - finance.dat + - finance37.dep before_script: - export PYTHON="coverage3 run --source qiskit/aqua,qiskit/chemistry,qiskit/finance,qiskit/ml,qiskit/optimization --omit */gauopen/* --parallel-mode" - script: stestr --test-path test/finance run && coverage3 combine && mv .coverage finance.dat + script: + - stestr --test-path test/finance run 2>&1 | tee out.txt + - coverage3 combine + - mv .coverage finance.dat + - python tools/extract_deprecation.py -file out.txt -output finance37.dep - name: "Test Finance Python 3.8" <<: *stage_dependencies if: tag IS blank + workspaces: + create: + name: finance38 + paths: finance38.dep python: 3.8 - script: stestr --test-path test/finance run + script: + - stestr --test-path test/finance run 2>&1 | tee out.txt + - python tools/extract_deprecation.py -file out.txt -output finance38.dep - name: "Test Machine Learning Python 3.7" <<: *stage_dependencies if: tag IS blank workspaces: create: - name: ml - paths: ml.dat + name: ml37 + paths: + - ml.dat + - ml37.dep before_script: - export PYTHON="coverage3 run --source qiskit/aqua,qiskit/chemistry,qiskit/finance,qiskit/ml,qiskit/optimization --omit */gauopen/* --parallel-mode" - script: stestr --test-path test/ml run && coverage3 combine && mv .coverage ml.dat + script: + - stestr --test-path test/ml run 2>&1 | tee out.txt + - coverage3 combine + - mv .coverage ml.dat + - python tools/extract_deprecation.py -file out.txt -output ml37.dep - name: "Test Machine Learning Python 3.8" <<: *stage_dependencies if: tag IS blank + workspaces: + create: + name: ml38 + paths: ml38.dep python: 3.8 - script: stestr --test-path test/ml run + script: + - stestr --test-path test/ml run 2>&1 | tee out.txt + - python tools/extract_deprecation.py -file out.txt -output ml38.dep - name: "Test Optimization Python 3.7" <<: *stage_dependencies if: tag IS blank workspaces: create: - name: optimization - paths: optimization.dat + name: optimization37 + paths: + - optimization.dat + - optimization37.dep before_script: - export PYTHON="coverage3 run --source qiskit/aqua,qiskit/chemistry,qiskit/finance,qiskit/ml,qiskit/optimization --omit */gauopen/* --parallel-mode" - script: stestr --test-path test/optimization run && coverage3 combine && mv .coverage optimization.dat + script: + - stestr --test-path test/optimization run 2>&1 | tee out.txt + - coverage3 combine + - mv .coverage optimization.dat + - python tools/extract_deprecation.py -file out.txt -output optimization37.dep - name: "Test Optimization Python 3.8" <<: *stage_dependencies if: tag IS blank + workspaces: + create: + name: optimization38 + paths: optimization38.dep python: 3.8 - script: stestr --test-path test/optimization run + script: + - stestr --test-path test/optimization run 2>&1 | tee out.txt + - python tools/extract_deprecation.py -file out.txt -output optimization38.dep - name: "Run pip check" <<: *stage_dependencies if: tag IS blank @@ -244,17 +316,36 @@ jobs: - pip install cvxopt - pip install https://github.com/rpmuller/pyquante2/archive/master.zip --progress-bar off - pip check + - stage: Deprecation Messages + name: "Print deprecation messages" + if: tag IS blank + workspaces: + use: + - aqua137 + - aqua138 + - aqua237 + - aqua238 + - chemistry37 + - chemistry38 + - finance37 + - finance38 + - ml37 + - ml38 + - optimization37 + - optimization38 + script: + - sort -f -u aqua137.dep aqua138.dep aqua237.dep aqua238.dep chemistry37.dep chemistry38.dep finance37.dep finance38.dep ml37.dep ml38.dep optimization37.dep optimization38.dep || true - stage: Coverage name: "Combine all coverages and upload to Coveralls" if: tag IS blank workspaces: use: - - aqua1 - - aqua2 - - chemistry - - finance - - ml - - optimization + - aqua137 + - aqua237 + - chemistry37 + - finance37 + - ml37 + - optimization37 install: - pip install -U coverage coveralls diff-cover script: diff --git a/requirements-dev.txt b/requirements-dev.txt index 4d883d7951..540475dde8 100644 --- a/requirements-dev.txt +++ b/requirements-dev.txt @@ -4,7 +4,7 @@ ddt>=1.2.0 pycodestyle pylint>=2.4.3 pylintfileheader>=0.0.2 -Sphinx>=1.8.3 +Sphinx>=1.8.3,<3.0 sphinx-rtd-theme>=0.4.0 sphinx-tabs>=1.1.11 sphinx-autodoc-typehints diff --git a/tools/extract_deprecation.py b/tools/extract_deprecation.py new file mode 100644 index 0000000000..05db0fd35b --- /dev/null +++ b/tools/extract_deprecation.py @@ -0,0 +1,103 @@ +# -*- coding: utf-8 -*- + +# This code is part of Qiskit. +# +# (C) Copyright IBM 2020. +# +# This code is licensed under the Apache License, Version 2.0. You may +# obtain a copy of this license in the LICENSE.txt file in the root directory +# of this source tree or at http://www.apache.org/licenses/LICENSE-2.0. +# +# Any modifications or derivative works of this code must retain this +# copyright notice, and modified files need to carry a notice indicating +# that they have been altered from the originals. + +""" Extract deprecation messages from input """ + +import sys +import os +import argparse + + +class DeprecationExtractor: + """ Extract deprecation messages """ + + def __init__(self, in_file: str, out_file: str) -> None: + self._input_filename = in_file + self._output_filename = out_file + self._messages = None + + def extract_messages(self) -> bool: + """ + extract deprecation + Returns: + bool: if messages were found + """ + + self._messages = None + messages = set() + with open(self._input_filename, 'rt', encoding="utf8", errors='ignore') as file: + for line in file: + if line.find('DeprecationWarning:') > 0: + messages.add(line.strip()) + + if messages: + self._messages = sorted(messages) + return True + + return False + + def save_to_output(self, force_create: bool) -> bool: + """ + save messages to file if they exist + Args: + force_create: create file even if it is empty + Returns: + bool: if messages were saved + """ + if self._output_filename: + # create file even if it is empty + if self._messages or force_create: + with open(self._output_filename, 'w') as file: + if self._messages: + file.write('\n'.join(self._messages)) + return True + + return False + + def print_messages(self) -> None: + """ print messages """ + if self._messages: + print('---------------------') + print('Deprecation Messages:') + print('---------------------') + for line in self._messages: + print(line) + + +def _check_file(path) -> str: + if not os.path.isfile(path): + raise argparse.ArgumentTypeError("file: '{}' doesn't exist.".format(path)) + + return path + + +if __name__ == '__main__': + PARSER = argparse.ArgumentParser(description='Qiskit Extract Deprecation Messages Tool') + PARSER.add_argument('-file', + type=_check_file, + required=True, + metavar='file', + help='Input file.') + PARSER.add_argument('-output', + metavar='output', + help='Output file.') + + ARGS = PARSER.parse_args() + + OBJ = DeprecationExtractor(ARGS.file, ARGS.output) + OBJ.extract_messages() + OBJ.save_to_output(True) + OBJ.print_messages() + + sys.exit(os.EX_OK) From 2f5e5949f688241e42538e08723becfa42518668 Mon Sep 17 00:00:00 2001 From: Manoel Marques Date: Mon, 6 Apr 2020 10:47:53 -0400 Subject: [PATCH 2/3] fix docstring identation --- qiskit/aqua/algorithms/eigen_solvers/numpy_eigen_solver.py | 2 +- requirements-dev.txt | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/qiskit/aqua/algorithms/eigen_solvers/numpy_eigen_solver.py b/qiskit/aqua/algorithms/eigen_solvers/numpy_eigen_solver.py index bf69ae07e2..9184a487be 100644 --- a/qiskit/aqua/algorithms/eigen_solvers/numpy_eigen_solver.py +++ b/qiskit/aqua/algorithms/eigen_solvers/numpy_eigen_solver.py @@ -189,7 +189,7 @@ def _run(self): Returns: dict: Dictionary of results Raises: - AquaError: if no operator has been provided + AquaError: if no operator has been provided """ if self._operator is None: raise AquaError("Operator was never provided") diff --git a/requirements-dev.txt b/requirements-dev.txt index 540475dde8..4d883d7951 100644 --- a/requirements-dev.txt +++ b/requirements-dev.txt @@ -4,7 +4,7 @@ ddt>=1.2.0 pycodestyle pylint>=2.4.3 pylintfileheader>=0.0.2 -Sphinx>=1.8.3,<3.0 +Sphinx>=1.8.3 sphinx-rtd-theme>=0.4.0 sphinx-tabs>=1.1.11 sphinx-autodoc-typehints From 4b159229669172f4def07cfd10bff90eb8b28a04 Mon Sep 17 00:00:00 2001 From: Manoel Marques Date: Mon, 6 Apr 2020 11:11:11 -0400 Subject: [PATCH 3/3] restrict Sphinx version to < 3.0 --- requirements-dev.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/requirements-dev.txt b/requirements-dev.txt index 4d883d7951..540475dde8 100644 --- a/requirements-dev.txt +++ b/requirements-dev.txt @@ -4,7 +4,7 @@ ddt>=1.2.0 pycodestyle pylint>=2.4.3 pylintfileheader>=0.0.2 -Sphinx>=1.8.3 +Sphinx>=1.8.3,<3.0 sphinx-rtd-theme>=0.4.0 sphinx-tabs>=1.1.11 sphinx-autodoc-typehints