From 013b5429a560196915d16915bf272ea292ecfd8e Mon Sep 17 00:00:00 2001 From: Manoel Marques Date: Fri, 5 Feb 2021 14:27:01 -0500 Subject: [PATCH 01/13] Bump version, add support for python 3.9 --- .github/actions/install-aqua/action.yml | 6 +- .../install-master-dependencies/action.yml | 12 +- .github/workflows/main.yml | 171 ++---------------- qiskit/aqua/VERSION.txt | 2 +- setup.py | 10 +- tox.ini | 30 +-- 6 files changed, 36 insertions(+), 195 deletions(-) diff --git a/.github/actions/install-aqua/action.yml b/.github/actions/install-aqua/action.yml index c2f1964e9e..ae2303e25a 100644 --- a/.github/actions/install-aqua/action.yml +++ b/.github/actions/install-aqua/action.yml @@ -1,6 +1,6 @@ # This code is part of Qiskit. # -# (C) Copyright IBM 2020. +# (C) Copyright IBM 2020, 2021. # # 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 @@ -20,7 +20,9 @@ runs: if [ -f "$HOME/miniconda/etc/profile.d/conda.sh" ]; then source "$HOME/miniconda/etc/profile.d/conda.sh" conda activate + pip install -e .[torch,cplex,cvx,pyscf] + else + pip install -e .[torch,cplex,cvx,pyscf,skquant] fi - pip install -e . pip install -U -c constraints.txt -r requirements-dev.txt shell: bash \ No newline at end of file diff --git a/.github/actions/install-master-dependencies/action.yml b/.github/actions/install-master-dependencies/action.yml index bd910580e2..64dfc7a8e7 100644 --- a/.github/actions/install-master-dependencies/action.yml +++ b/.github/actions/install-master-dependencies/action.yml @@ -1,6 +1,6 @@ # This code is part of Qiskit. # -# (C) Copyright IBM 2020. +# (C) Copyright IBM 2020, 2021. # # 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 @@ -24,11 +24,5 @@ runs: pip install https://github.com/Qiskit/qiskit-terra/archive/master.zip pip install https://github.com/Qiskit/qiskit-ignis/archive/master.zip pip install https://github.com/Qiskit/qiskit-ibmq-provider/archive/master.zip - sudo apt-get -y install g++-7 - sudo apt-get -y install libopenblas-dev - git clone https://github.com/Qiskit/qiskit-aer.git /tmp/qiskit-aer - cd /tmp/qiskit-aer - pip install -U -c /tmp/qiskit-aer/constraints.txt -r /tmp/qiskit-aer/requirements-dev.txt - python /tmp/qiskit-aer/setup.py bdist_wheel -- -DCMAKE_CXX_COMPILER=g++-7 -DAER_THRUST_BACKEND=OMP -- -j4 - pip install /tmp/qiskit-aer/dist/qiskit_aer*whl - shell: bash \ No newline at end of file + pip install https://github.com/Qiskit/qiskit-aer/archive/master.zip + shell: bash diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index f97328ba72..af762705ac 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -1,6 +1,6 @@ # This code is part of Qiskit. # -# (C) Copyright IBM 2020. +# (C) Copyright IBM 2020, 2021. # # 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 @@ -35,15 +35,6 @@ jobs: - uses: actions/setup-python@v2 with: python-version: ${{ matrix.python-version }} - - name: Pip cache - uses: actions/cache@v2 - with: - path: ~/.cache/pip - key: ${{ runner.os }}-pip-checks-${{ hashFiles('setup.py','requirements-dev.txt','constraints.txt') }} - restore-keys: | - ${{ runner.os }}-pip-checks- - ${{ runner.os }}-pip- - ${{ runner.os }}- - uses: ./.github/actions/install-libraries - uses: ./.github/actions/install-master-dependencies if: ${{ !startsWith(github.ref, 'refs/heads/stable') }} @@ -53,14 +44,8 @@ jobs: sudo apt-get -y install python3-enchant sudo apt-get -y install hunspell-en-us pip install pyenchant - pip install cplex - pip install "cvxpy>1.0.0" pip install https://github.com/rpmuller/pyquante2/archive/master.zip shell: bash - - name: Terminate if failure above - run: exit 1 - if: ${{ !success() }} - shell: bash - run: pip check if: ${{ !cancelled() }} shell: bash @@ -109,27 +94,13 @@ jobs: - uses: actions/setup-python@v2 with: python-version: ${{ matrix.python-version }} - - name: Pip cache - uses: actions/cache@v2 - with: - path: ~/.cache/pip - key: ${{ runner.os }}-pip-lint-${{ hashFiles('setup.py','requirements-dev.txt','constraints.txt') }} - restore-keys: | - ${{ runner.os }}-pip-lint- - ${{ runner.os }}-pip- - ${{ runner.os }}- - uses: ./.github/actions/install-libraries - uses: ./.github/actions/install-master-dependencies if: ${{ !startsWith(github.ref, 'refs/heads/stable') }} - uses: ./.github/actions/install-aqua - name: Install Dependencies run: | - pip install "cvxpy>1.0.0" pip install https://github.com/rpmuller/pyquante2/archive/master.zip - - name: Terminate if failure above - run: exit 1 - if: ${{ !success() }} - shell: bash - run: make lint if: ${{ !cancelled() }} shell: bash @@ -149,56 +120,33 @@ jobs: - uses: actions/setup-python@v2 with: python-version: ${{ matrix.python-version }} - - name: Pip cache - uses: actions/cache@v2 - with: - path: ~/.cache/pip - key: ${{ runner.os }}-pip-mypy-${{ hashFiles('setup.py','requirements-dev.txt','constraints.txt') }} - restore-keys: | - ${{ runner.os }}-pip-mypy- - ${{ runner.os }}-pip- - ${{ runner.os }}- - uses: ./.github/actions/install-libraries - uses: ./.github/actions/install-master-dependencies if: ${{ !startsWith(github.ref, 'refs/heads/stable') }} - uses: ./.github/actions/install-aqua - name: Mypy under Python ${{ matrix.python-version }} - run: | - pip install cplex - make mypy + run: make mypy shell: bash Aqua: runs-on: ubuntu-latest strategy: matrix: - python-version: [3.7, 3.8] + python-version: [3.7, 3.8, 3.9] steps: - uses: actions/checkout@v2 - uses: actions/setup-python@v2 with: python-version: ${{ matrix.python-version }} - - name: Pip cache - uses: actions/cache@v2 - with: - path: ~/.cache/pip - key: ${{ runner.os }}-${{ matrix.python-version }}-pip-aqua-${{ hashFiles('setup.py','requirements-dev.txt','constraints.txt') }} - restore-keys: | - ${{ runner.os }}${{ matrix.python-version }}-pip-aqua- - ${{ runner.os }}${{ matrix.python-version }}-pip- - ${{ runner.os }}${{ matrix.python-version }}- - uses: ./.github/actions/install-libraries - uses: ./.github/actions/install-master-dependencies if: ${{ !startsWith(github.ref, 'refs/heads/stable') }} - uses: ./.github/actions/install-aqua - name: Install Dependencies run: | - pip install "cvxpy>1.0.0" - pip install scikit-quant - pip install jax jaxlib - shell: bash - - name: Install cplex - run: pip install cplex - if: ${{ matrix.python-version == 3.7 }} + # pin jax and jaxlib as the latest jaxlib 0.1.60 forces + # numpy 1.19.5 to be installed which causes cvxpy failure to load + # with 'numpy.core.multiarray failed to import.' error. + pip install -U jax==0.2.9 jaxlib==0.1.59 shell: bash - name: Aqua Unit Tests under Python ${{ matrix.python-version }} uses: ./.github/actions/run-tests @@ -224,21 +172,12 @@ jobs: runs-on: ubuntu-latest strategy: matrix: - python-version: [3.7, 3.8] + python-version: [3.7, 3.8, 3.9] steps: - uses: actions/checkout@v2 - uses: actions/setup-python@v2 with: python-version: ${{ matrix.python-version }} - - name: Pip cache - uses: actions/cache@v2 - with: - path: ~/.cache/pip - key: ${{ runner.os }}-${{ matrix.python-version }}-pip-chemistry-${{ hashFiles('setup.py','requirements-dev.txt','constraints.txt') }} - restore-keys: | - ${{ runner.os }}-${{ matrix.python-version }}-pip-chemistry- - ${{ runner.os }}-${{ matrix.python-version }}-pip- - ${{ runner.os }}-${{ matrix.python-version }}- - uses: ./.github/actions/install-psi4 if: ${{ matrix.python-version == 3.7 }} - uses: ./.github/actions/install-libraries @@ -250,25 +189,10 @@ jobs: if [ -f "$HOME/miniconda/etc/profile.d/conda.sh" ]; then source "$HOME/miniconda/etc/profile.d/conda.sh" conda activate - # PSI4 has problems with dataclasses - pip uninstall -y dataclasses + pip install https://github.com/rpmuller/pyquante2/archive/master.zip fi - sudo apt-get -y install libgfortran5 - pip install https://github.com/rpmuller/pyquante2/archive/master.zip - pip install pyscf - shell: bash - - name: Install cplex - run: | - if [ -f "$HOME/miniconda/etc/profile.d/conda.sh" ]; then - source "$HOME/miniconda/etc/profile.d/conda.sh" - conda activate - fi - pip install cplex - if: ${{ matrix.python-version == 3.7 }} shell: bash - name: Chemistry Unit Tests under Python ${{ matrix.python-version }} - env: - OPENBLAS_NUM_THREADS: 1 uses: ./.github/actions/run-tests with: domain: chemistry @@ -296,29 +220,16 @@ jobs: runs-on: ubuntu-latest strategy: matrix: - python-version: [3.7, 3.8] + python-version: [3.7, 3.8, 3.9] steps: - uses: actions/checkout@v2 - uses: actions/setup-python@v2 with: python-version: ${{ matrix.python-version }} - - name: Pip cache - uses: actions/cache@v2 - with: - path: ~/.cache/pip - key: ${{ runner.os }}-${{ matrix.python-version }}-pip-finance-${{ hashFiles('setup.py','requirements-dev.txt','constraints.txt') }} - restore-keys: | - ${{ runner.os }}-${{ matrix.python-version }}-pip-finance- - ${{ runner.os }}-${{ matrix.python-version }}-pip- - ${{ runner.os }}-${{ matrix.python-version }}- - uses: ./.github/actions/install-libraries - uses: ./.github/actions/install-master-dependencies if: ${{ !startsWith(github.ref, 'refs/heads/stable') }} - uses: ./.github/actions/install-aqua - - name: Install cplex - run: pip install cplex - if: ${{ matrix.python-version == 3.7 }} - shell: bash - name: Finance Unit Tests under Python ${{ matrix.python-version }} uses: ./.github/actions/run-tests with: @@ -343,29 +254,16 @@ jobs: runs-on: ubuntu-latest strategy: matrix: - python-version: [3.7, 3.8] + python-version: [3.7, 3.8, 3.9] steps: - uses: actions/checkout@v2 - uses: actions/setup-python@v2 with: python-version: ${{ matrix.python-version }} - - name: Pip cache - uses: actions/cache@v2 - with: - path: ~/.cache/pip - key: ${{ runner.os }}-${{ matrix.python-version }}-pip-machinelearning-${{ hashFiles('setup.py','requirements-dev.txt','constraints.txt') }} - restore-keys: | - ${{ runner.os }}-${{ matrix.python-version }}-pip-machinelearning- - ${{ runner.os }}-${{ matrix.python-version }}-pip- - ${{ runner.os }}-${{ matrix.python-version }}- - uses: ./.github/actions/install-libraries - uses: ./.github/actions/install-master-dependencies if: ${{ !startsWith(github.ref, 'refs/heads/stable') }} - uses: ./.github/actions/install-aqua - - name: Install cplex - run: pip install cplex - if: ${{ matrix.python-version == 3.7 }} - shell: bash - name: Machine Learning Unit Tests under Python ${{ matrix.python-version }} uses: ./.github/actions/run-tests with: @@ -390,29 +288,16 @@ jobs: runs-on: ubuntu-latest strategy: matrix: - python-version: [3.7, 3.8] + python-version: [3.7, 3.8, 3.9] steps: - uses: actions/checkout@v2 - uses: actions/setup-python@v2 with: python-version: ${{ matrix.python-version }} - - name: Pip cache - uses: actions/cache@v2 - with: - path: ~/.cache/pip - key: ${{ runner.os }}-${{ matrix.python-version }}-pip-optimization-${{ hashFiles('setup.py','requirements-dev.txt','constraints.txt') }} - restore-keys: | - ${{ runner.os }}-${{ matrix.python-version }}-pip-optimization- - ${{ runner.os }}-${{ matrix.python-version }}-pip- - ${{ runner.os }}-${{ matrix.python-version }}- - uses: ./.github/actions/install-libraries - uses: ./.github/actions/install-master-dependencies if: ${{ !startsWith(github.ref, 'refs/heads/stable') }} - uses: ./.github/actions/install-aqua - - name: Install cplex - run: pip install cplex - if: ${{ matrix.python-version == 3.7 }} - shell: bash - name: Optimization Unit Tests under Python ${{ matrix.python-version }} uses: ./.github/actions/run-tests with: @@ -443,42 +328,23 @@ jobs: - uses: actions/setup-python@v2 with: python-version: ${{ matrix.python-version }} - - name: Pip cache - uses: actions/cache@v2 - with: - path: ~/.cache/pip - key: ${{ runner.os }}-${{ matrix.python-version }}-pip-tutorials-${{ hashFiles('setup.py','requirements-dev.txt','constraints.txt') }} - restore-keys: | - ${{ runner.os }}-${{ matrix.python-version }}-pip-tutorials- - ${{ runner.os }}-${{ matrix.python-version }}-pip- - ${{ runner.os }}-${{ matrix.python-version }}- - uses: ./.github/actions/install-libraries - uses: ./.github/actions/install-master-dependencies if: ${{ !startsWith(github.ref, 'refs/heads/stable') }} - uses: ./.github/actions/install-aqua - - name: Install cplex - run: pip install cplex - if: ${{ matrix.python-version == 3.6 }} - shell: bash - name: Install Dependencies run: | - sudo apt-get -y install libgfortran5 pip install https://github.com/rpmuller/pyquante2/archive/master.zip - pip install pyscf - pip install "cvxpy>1.0.0" - pip install -U jupyter sphinx nbsphinx sphinx_rtd_theme 'matplotlib<3.3.0' qiskit-terra[visualization] cvxpy + pip install -U jupyter sphinx nbsphinx sphinx_rtd_theme 'matplotlib<3.3.0' qiskit-terra[visualization] sudo apt-get install -y pandoc graphviz shell: bash - name: Run Aqua Tutorials - env: - OPENBLAS_NUM_THREADS: 1 run: | git clone https://github.com/Qiskit/qiskit-tutorials cd qiskit-tutorials rm -r tutorials/circuits/ rm -r tutorials/circuits_advanced/ rm -r tutorials/noise/ - rm -r tutorials/pulse/ rm -r tutorials/simulators/ sphinx-build -b html . _build/html cd _build/html @@ -501,15 +367,6 @@ jobs: - uses: actions/setup-python@v2 with: python-version: ${{ matrix.python-version }} - - name: Pip cache - uses: actions/cache@v2 - with: - path: ~/.cache/pip - key: ${{ runner.os }}-pip-coverage-${{ hashFiles('setup.py','requirements-dev.txt','constraints.txt') }} - restore-keys: | - ${{ runner.os }}-pip-coverage- - ${{ runner.os }}-pip- - ${{ runner.os }}- - uses: actions/download-artifact@v2 with: name: aqua3.7 @@ -563,5 +420,5 @@ jobs: - name: Upload to Coveralls env: GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} - run: coveralls || true + run: coveralls --service=github shell: bash diff --git a/qiskit/aqua/VERSION.txt b/qiskit/aqua/VERSION.txt index 6f4eebdf6f..100435be13 100644 --- a/qiskit/aqua/VERSION.txt +++ b/qiskit/aqua/VERSION.txt @@ -1 +1 @@ -0.8.1 +0.8.2 diff --git a/setup.py b/setup.py index d1bebe2cee..16814d959c 100644 --- a/setup.py +++ b/setup.py @@ -1,6 +1,6 @@ # This code is part of Qiskit. # -# (C) Copyright IBM 2018, 2020. +# (C) Copyright IBM 2018, 2021. # # 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 @@ -40,6 +40,7 @@ "quandl", "yfinance", "retworkx>=0.5.0", + "dataclasses; python_version < '3.7'" ] if not hasattr(setuptools, 'find_namespace_packages') or not inspect.ismethod(setuptools.find_namespace_packages): @@ -73,6 +74,7 @@ "Programming Language :: Python :: 3.6", "Programming Language :: Python :: 3.7", "Programming Language :: Python :: 3.8", + "Programming Language :: Python :: 3.9", "Topic :: Scientific/Engineering" ), keywords='qiskit sdk quantum aqua', @@ -81,9 +83,9 @@ include_package_data=True, python_requires=">=3.6", extras_require={ - 'torch': ["torch; sys_platform == 'linux' or (python_version < '3.8' and sys_platform != 'win32')"], - 'cplex': ["cplex; python_version >= '3.6' and python_version < '3.8'"], - 'cvx': ['cvxpy>1.0.0,!=1.1.0,!=1.1.1,!=1.1.2'], + 'torch': ["torch"], + 'cplex': ["cplex; python_version < '3.9'"], + 'cvx': ['cvxpy>1.0.0,!=1.1.0,!=1.1.1,!=1.1.2,!=1.1.8'], 'pyscf': ["pyscf; sys_platform != 'win32'"], 'skquant': ["scikit-quant"], }, diff --git a/tox.ini b/tox.ini index a8e32e04cc..e00de9c308 100644 --- a/tox.ini +++ b/tox.ini @@ -1,6 +1,6 @@ [tox] minversion = 2.1 -envlist = py36, py37, py38, lint +envlist = py36, py37, py38, py39, lint skipsdist = True [testenv] @@ -11,49 +11,35 @@ setenv = LANGUAGE=en_US LC_ALL=en_US.utf-8 ARGS="-V" -deps = git+https://github.com/Qiskit/qiskit-terra - git+https://github.com/Qiskit/qiskit-ignis - git+https://github.com/Qiskit/qiskit-aer - git+https://github.com/Qiskit/qiskit-ibmq-provider +deps = https://github.com/Qiskit/qiskit-terra/archive/master.zip + https://github.com/Qiskit/qiskit-ignis/archive/master.zip + https://github.com/Qiskit/qiskit-aer/archive/master.zip + https://github.com/Qiskit/qiskit-ibmq-provider/archive/master.zip + -r{toxinidir}/requirements-dev.txt commands = - pip install -c constraints.txt -r{toxinidir}/requirements-dev.txt stestr run {posargs} [testenv:lint] basepython = python3 -deps = git+https://github.com/Qiskit/qiskit-terra - git+https://github.com/Qiskit/qiskit-ignis - git+https://github.com/Qiskit/qiskit-aer - git+https://github.com/Qiskit/qiskit-ibmq-provider commands = - pip install -c constraints.txt -r{toxinidir}/requirements-dev.txt pycodestyle qiskit/aqua qiskit/chemistry qiskit/finance qiskit/ml qiskit/optimization test tools pylint -rn --ignore=gauopen qiskit/aqua qiskit/chemistry qiskit/finance qiskit/ml qiskit/optimization test tools + mypy qiskit test tools python3 {toxinidir}/tools/check_copyright.py -path {toxinidir} [testenv:coverage] basepython = python3 setenv = {[testenv]setenv} - PYTHON=coverage3 run --source qiskit/aqua,qiskit/chemistry,qiskit/finance,qiskit/ml,qiskit/optimization --omit */gauopen/* --parallel-mode -deps = git+https://github.com/Qiskit/qiskit-terra - git+https://github.com/Qiskit/qiskit-ignis - git+https://github.com/Qiskit/qiskit-aer - git+https://github.com/Qiskit/qiskit-ibmq-provider + PYTHON=coverage3 run --source qiskit/aqua,qiskit/chemistry,qiskit/finance,qiskit/ml,qiskit/optimization --omit */gauopen/* --parallel-modes commands = - pip install -c constraints.txt -r{toxinidir}/requirements-dev.txt stestr run {posargs} coverage3 combine coverage3 report [testenv:docs] basepython = python3 -deps = git+https://github.com/Qiskit/qiskit-terra - git+https://github.com/Qiskit/qiskit-ignis - git+https://github.com/Qiskit/qiskit-aer - git+https://github.com/Qiskit/qiskit-ibmq-provider commands = - pip install -c constraints.txt -r{toxinidir}/requirements-dev.txt sphinx-build -b html -W {posargs} docs/ docs/_build/html [pycodestyle] From 228f8a6ab67aa0461fa51ad7d6af900c81b9be42 Mon Sep 17 00:00:00 2001 From: Manoel Marques Date: Fri, 5 Feb 2021 14:37:39 -0500 Subject: [PATCH 02/13] Fix for docplex 2.20 --- qiskit/optimization/problems/quadratic_program.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/qiskit/optimization/problems/quadratic_program.py b/qiskit/optimization/problems/quadratic_program.py index d756487016..b1749b35ef 100644 --- a/qiskit/optimization/problems/quadratic_program.py +++ b/qiskit/optimization/problems/quadratic_program.py @@ -1,6 +1,6 @@ # This code is part of Qiskit. # -# (C) Copyright IBM 2019, 2020. +# (C) Copyright IBM 2019, 2021. # # 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 @@ -25,7 +25,7 @@ from docplex.mp.constr import (LinearConstraint as DocplexLinearConstraint, QuadraticConstraint as DocplexQuadraticConstraint, NotEqualConstraint) -from docplex.mp.linear import Var +from docplex.mp.dvar import Var from docplex.mp.model import Model from docplex.mp.model_reader import ModelReader from docplex.mp.quad import QuadExpr From bad198e9209a5437e7b26d83f7a240079d68d521 Mon Sep 17 00:00:00 2001 From: Manoel Marques Date: Fri, 5 Feb 2021 14:58:24 -0500 Subject: [PATCH 03/13] fix mypy, docplex --- qiskit/chemistry/core/hamiltonian.py | 6 +++--- qiskit/chemistry/drivers/fcidumpd/dumper.py | 12 ++++++++---- .../transformations/fermionic_transformation.py | 4 ++-- qiskit/optimization/problems/quadratic_program.py | 14 +++++++------- 4 files changed, 20 insertions(+), 16 deletions(-) diff --git a/qiskit/chemistry/core/hamiltonian.py b/qiskit/chemistry/core/hamiltonian.py index 847be15fcb..f399a16271 100644 --- a/qiskit/chemistry/core/hamiltonian.py +++ b/qiskit/chemistry/core/hamiltonian.py @@ -1,6 +1,6 @@ # This code is part of Qiskit. # -# (C) Copyright IBM 2018, 2020. +# (C) Copyright IBM 2018, 2021. # # 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 @@ -85,8 +85,8 @@ def __init__(self, warnings.warn('The Hamiltonian class is deprecated as of Qiskit Aqua 0.8.0 and will be ' 'removed no earlier than 3 months after the release date. Instead, the ' 'FermionicTransformation can be used.', DeprecationWarning, stacklevel=2) - transformation = transformation.value - qubit_mapping = qubit_mapping.value + transformation = transformation.value # type: ignore + qubit_mapping = qubit_mapping.value # type: ignore orbital_reduction = orbital_reduction if orbital_reduction is not None else [] super().__init__() self._transformation = transformation diff --git a/qiskit/chemistry/drivers/fcidumpd/dumper.py b/qiskit/chemistry/drivers/fcidumpd/dumper.py index ca5ff7b482..e64e065b72 100644 --- a/qiskit/chemistry/drivers/fcidumpd/dumper.py +++ b/qiskit/chemistry/drivers/fcidumpd/dumper.py @@ -1,6 +1,6 @@ # This code is part of Qiskit. # -# (C) Copyright IBM 2020. +# (C) Copyright IBM 2020, 2021. # # 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 @@ -74,11 +74,15 @@ def _dump_1e_ints(hij: List[float], hij_elements = set() for i, j in itertools.product(mos, repeat=2): if i == j: - _write_to_outfile(outfile, hij[i][j], (i+idx_offset, j+idx_offset, 0, 0)) + _write_to_outfile(outfile, + hij[i][j], # type: ignore + (i+idx_offset, j+idx_offset, 0, 0)) continue - if (j, i) in hij_elements and np.isclose(hij[i][j], hij[j][i]): + if (j, i) in hij_elements and np.isclose(hij[i][j], hij[j][i]): # type: ignore continue - _write_to_outfile(outfile, hij[i][j], (i+idx_offset, j+idx_offset, 0, 0)) + _write_to_outfile(outfile, + hij[i][j], # type: ignore + (i+idx_offset, j+idx_offset, 0, 0)) hij_elements.add((i, j)) diff --git a/qiskit/chemistry/transformations/fermionic_transformation.py b/qiskit/chemistry/transformations/fermionic_transformation.py index 36e39b718a..969677090a 100644 --- a/qiskit/chemistry/transformations/fermionic_transformation.py +++ b/qiskit/chemistry/transformations/fermionic_transformation.py @@ -1,6 +1,6 @@ # This code is part of Qiskit. # -# (C) Copyright IBM 2020. +# (C) Copyright IBM 2020, 2021. # # 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 @@ -86,7 +86,7 @@ def __init__(self, Raises: QiskitChemistryError: Invalid symmetry reduction """ - transformation = transformation.value + transformation = transformation.value # type: ignore orbital_reduction = orbital_reduction if orbital_reduction is not None else [] super().__init__() self._transformation = transformation diff --git a/qiskit/optimization/problems/quadratic_program.py b/qiskit/optimization/problems/quadratic_program.py index b1749b35ef..d0b2feb31b 100644 --- a/qiskit/optimization/problems/quadratic_program.py +++ b/qiskit/optimization/problems/quadratic_program.py @@ -561,11 +561,11 @@ def from_docplex(self, model: Model) -> None: # keep track of names separately, since docplex allows to have None names. var_names = {} for x in model.iter_variables(): - if isinstance(x.get_vartype(), ContinuousVarType): + if isinstance(x.vartype, ContinuousVarType): x_new = self.continuous_var(x.lb, x.ub, x.name) - elif isinstance(x.get_vartype(), BinaryVarType): + elif isinstance(x.vartype, BinaryVarType): x_new = self.binary_var(x.name) - elif isinstance(x.get_vartype(), IntegerVarType): + elif isinstance(x.vartype, IntegerVarType): x_new = self.integer_var(x.lb, x.ub, x.name) else: raise QiskitOptimizationError( @@ -923,7 +923,7 @@ def to_ising(self) -> Tuple[OperatorBase, float]: sense = self.objective.sense.value # convert a constant part of the object function into Hamiltonian. - offset += self.objective.constant * sense + offset += self.objective.constant * sense # type: ignore # convert linear parts of the object function into Hamiltonian. for idx, coef in self.objective.linear.to_dict().items(): @@ -932,7 +932,7 @@ def to_ising(self) -> Tuple[OperatorBase, float]: z_p[idx] = True pauli_list.append([-weight, Pauli(z_p, zero)]) - offset += weight + offset += weight # type: ignore # convert quadratic parts of the object function into Hamiltonian. # first merge coefficients (i, j) and (j, i) @@ -949,7 +949,7 @@ def to_ising(self) -> Tuple[OperatorBase, float]: weight = coeff * sense / 4 if i == j: - offset += weight + offset += weight # type: ignore else: z_p = zeros(num_nodes, dtype=nbool) z_p[i] = True @@ -964,7 +964,7 @@ def to_ising(self) -> Tuple[OperatorBase, float]: z_p[j] = True pauli_list.append([-weight, Pauli(z_p, zero)]) - offset += weight + offset += weight # type: ignore # Remove paulis whose coefficients are zeros. qubit_op = sum(PauliOp(pauli, coeff=coeff) for coeff, pauli in pauli_list) From 07a21011a6652dcf9eccf84c28c71f24f3509fdd Mon Sep 17 00:00:00 2001 From: Manoel Marques Date: Fri, 5 Feb 2021 15:49:46 -0500 Subject: [PATCH 04/13] Remove DeprecationWarning of np.int, np.float, np.bool, np.complex --- .../classifiers/qsvm/_qsvm_binary.py | 4 +-- .../sklearn_svm/_sklearn_svm_binary.py | 12 +++---- .../multiclass_extensions/all_pairs.py | 4 +-- .../error_correcting_code.py | 4 +-- qiskit/aqua/operators/legacy/common.py | 8 ++--- .../legacy/weighted_pauli_operator.py | 10 +++--- .../aqua/operators/primitive_ops/pauli_op.py | 4 +-- qiskit/aqua/utils/random_matrix_generator.py | 8 ++--- qiskit/chemistry/bksf.py | 4 +-- qiskit/chemistry/bosonic_operator.py | 18 +++++------ .../components/initial_states/hartree_fock.py | 10 +++--- .../components/initial_states/vscf.py | 4 +-- .../components/variational_forms/uccsd.py | 4 +-- qiskit/chemistry/fermionic_operator.py | 32 +++++++++---------- qiskit/chemistry/qmolecule.py | 4 +-- .../finance/applications/ising/portfolio.py | 10 +++--- .../optimization/applications/ising/clique.py | 18 +++++------ .../applications/ising/docplex.py | 20 ++++++------ .../applications/ising/graph_partition.py | 10 +++--- .../applications/ising/knapsack.py | 6 ++-- .../applications/ising/max_cut.py | 6 ++-- .../applications/ising/partition.py | 6 ++-- .../applications/ising/stable_set.py | 10 +++--- qiskit/optimization/applications/ising/tsp.py | 24 +++++++------- .../problems/quadratic_program.py | 12 +++---- test/aqua/test_qsvm.py | 4 +-- test/chemistry/test_fermionic_operator.py | 4 +-- test/finance/test_data_providers.py | 4 +-- 28 files changed, 132 insertions(+), 132 deletions(-) diff --git a/qiskit/aqua/algorithms/classifiers/qsvm/_qsvm_binary.py b/qiskit/aqua/algorithms/classifiers/qsvm/_qsvm_binary.py index 5d66d39889..ac61bfe619 100644 --- a/qiskit/aqua/algorithms/classifiers/qsvm/_qsvm_binary.py +++ b/qiskit/aqua/algorithms/classifiers/qsvm/_qsvm_binary.py @@ -1,6 +1,6 @@ # This code is part of Qiskit. # -# (C) Copyright IBM 2018, 2020. +# (C) Copyright IBM 2018, 2021. # # 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 @@ -78,7 +78,7 @@ def train(self, data, labels): kernel_matrix = self._qalgo.construct_kernel_matrix(data) lambda2 = self._qalgo.lambda2 labels = labels * 2 - 1 # map label from 0 --> -1 and 1 --> 1 - labels = labels.astype(np.float) + labels = labels.astype(float) [alpha, b, support] = optimize_svm(kernel_matrix, labels, scaling=scaling, lambda2=lambda2) support_index = np.where(support) alphas = alpha[support_index] diff --git a/qiskit/aqua/algorithms/classifiers/sklearn_svm/_sklearn_svm_binary.py b/qiskit/aqua/algorithms/classifiers/sklearn_svm/_sklearn_svm_binary.py index 69abff6f5b..a3013ba552 100644 --- a/qiskit/aqua/algorithms/classifiers/sklearn_svm/_sklearn_svm_binary.py +++ b/qiskit/aqua/algorithms/classifiers/sklearn_svm/_sklearn_svm_binary.py @@ -1,6 +1,6 @@ # This code is part of Qiskit. # -# (C) Copyright IBM 2018, 2020. +# (C) Copyright IBM 2018, 2021. # # 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 @@ -43,7 +43,7 @@ def train(self, data, labels): data (dict): dictionary which maps each class to the points in the class labels (list): list of classes. For example: ['A', 'B'] """ - labels = labels.astype(np.float) + labels = labels.astype(float) labels = labels * 2. - 1. kernel_matrix = self.construct_kernel_matrix(data, data, self.gamma) self._ret['kernel_matrix_training'] = kernel_matrix @@ -94,9 +94,9 @@ def test(self, data, labels): logger.debug("\n=============================================") logger.debug('classifying %s.', data[tin]) - logger.debug('Label should be %s.', self.label_to_class[np.int(labels[tin])]) - logger.debug('Predicted label is %s.', self.label_to_class[np.int(lsign[tin])]) - if np.int(labels[tin]) == np.int(lsign[tin]): + logger.debug('Label should be %s.', self.label_to_class[int(labels[tin])]) + logger.debug('Predicted label is %s.', self.label_to_class[int(lsign[tin])]) + if int(labels[tin]) == int(lsign[tin]): logger.debug('CORRECT') else: logger.debug('INCORRECT') @@ -131,7 +131,7 @@ def predict(self, data): for sin in range(len(svms)): _l = yin[sin] * alphas[sin] * kernel_matrix[tin][sin] ltot += _l - lsign[tin] = np.int((np.sign(ltot + bias) + 1.) / 2.) + lsign[tin] = int((np.sign(ltot + bias) + 1.) / 2.) self._ret['predicted_labels'] = lsign return lsign diff --git a/qiskit/aqua/components/multiclass_extensions/all_pairs.py b/qiskit/aqua/components/multiclass_extensions/all_pairs.py index 01055b7042..718bbf8090 100644 --- a/qiskit/aqua/components/multiclass_extensions/all_pairs.py +++ b/qiskit/aqua/components/multiclass_extensions/all_pairs.py @@ -1,6 +1,6 @@ # This code is part of Qiskit. # -# (C) Copyright IBM 2018, 2020. +# (C) Copyright IBM 2018, 2021. # # 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 @@ -108,7 +108,7 @@ def predict(self, x): estimator = estimators_from_i[j] confidence = np.ravel(estimator.decision_function(x)) - indices = (confidence > 0).astype(np.int) + indices = (confidence > 0).astype(int) prediction = self.classes_[indices] predictions.append(prediction.reshape(-1, 1)) diff --git a/qiskit/aqua/components/multiclass_extensions/error_correcting_code.py b/qiskit/aqua/components/multiclass_extensions/error_correcting_code.py index 04592a8860..07cb88f655 100644 --- a/qiskit/aqua/components/multiclass_extensions/error_correcting_code.py +++ b/qiskit/aqua/components/multiclass_extensions/error_correcting_code.py @@ -1,6 +1,6 @@ # This code is part of Qiskit. # -# (C) Copyright IBM 2018, 2020. +# (C) Copyright IBM 2018, 2021. # # 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 @@ -89,7 +89,7 @@ def train(self, x, y): self.codebook[self.codebook != 1] = 0 classes_index = dict((c, i) for i, c in enumerate(self.classes)) Y = np.array([self.codebook[classes_index[y[i]]] - for i in range(x.shape[0])], dtype=np.int) + for i in range(x.shape[0])], dtype=int) # pylint: disable=unsubscriptable-object logger.info("Require %s estimators.", Y.shape[1]) for i in range(Y.shape[1]): diff --git a/qiskit/aqua/operators/legacy/common.py b/qiskit/aqua/operators/legacy/common.py index d295ddf465..d62b7dcb69 100644 --- a/qiskit/aqua/operators/legacy/common.py +++ b/qiskit/aqua/operators/legacy/common.py @@ -1,6 +1,6 @@ # This code is part of Qiskit. # -# (C) Copyright IBM 2019, 2020. +# (C) Copyright IBM 2019, 2021. # # 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 @@ -72,7 +72,7 @@ def measure_pauli_z(data, pauli): num_shots = sum(data.values()) p_z_or_x = np.logical_or(pauli.z, pauli.x) for key, value in data.items(): - bitstr = np.asarray(list(key))[::-1].astype(np.int).astype(np.bool) + bitstr = np.asarray(list(key))[::-1].astype(int).astype(bool) # pylint: disable=no-member sign = -1.0 if np.logical_xor.reduce(np.logical_and(bitstr, p_z_or_x)) else 1.0 observable += sign * value @@ -105,7 +105,7 @@ def covariance(data, pauli_1, pauli_2, avg_1, avg_2): p1_z_or_x = np.logical_or(pauli_1.z, pauli_1.x) p2_z_or_x = np.logical_or(pauli_2.z, pauli_2.x) for key, value in data.items(): - bitstr = np.asarray(list(key))[::-1].astype(np.int).astype(np.bool) + bitstr = np.asarray(list(key))[::-1].astype(int).astype(bool) # pylint: disable=no-member sign_1 = -1.0 if np.logical_xor.reduce(np.logical_and(bitstr, p1_z_or_x)) else 1.0 sign_2 = -1.0 if np.logical_xor.reduce(np.logical_and(bitstr, p2_z_or_x)) else 1.0 @@ -255,7 +255,7 @@ def evolution_instruction(pauli_list, evo_time, num_time_slices, ValueError: Unrecognized pauli """ - if not isinstance(power, (int, np.int)) or power < 1: + if not isinstance(power, int) or power < 1: raise AquaError("power must be an integer and greater or equal to 1.") state_registers = QuantumRegister(pauli_list[0][1].num_qubits) diff --git a/qiskit/aqua/operators/legacy/weighted_pauli_operator.py b/qiskit/aqua/operators/legacy/weighted_pauli_operator.py index 52c420567b..3e4bfe4d0a 100644 --- a/qiskit/aqua/operators/legacy/weighted_pauli_operator.py +++ b/qiskit/aqua/operators/legacy/weighted_pauli_operator.py @@ -1,6 +1,6 @@ # This code is part of Qiskit. # -# (C) Copyright IBM 2019, 2020. +# (C) Copyright IBM 2019, 2021. # # 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 @@ -262,7 +262,7 @@ def _scaling_weight(self, scaling_factor, copy=False): Raises: ValueError: the scaling factor is not a valid type. """ - if not isinstance(scaling_factor, (int, float, complex, np.int, np.float, np.complex)): + if not isinstance(scaling_factor, (int, float, complex)): raise ValueError( "Type of scaling factor is a valid type. {} if given.".format( scaling_factor.__class__)) @@ -292,14 +292,14 @@ def multiply(self, other): def __rmul__(self, other): """ Overload other * self """ - if isinstance(other, (int, float, complex, np.int, np.float, np.complex)): + if isinstance(other, (int, float, complex)): return self._scaling_weight(other, copy=True) else: return other.multiply(self) def __mul__(self, other): """ Overload self * other """ - if isinstance(other, (int, float, complex, np.int, np.float, np.complex)): + if isinstance(other, (int, float, complex)): return self._scaling_weight(other, copy=True) else: return self.multiply(other) @@ -1100,7 +1100,7 @@ def find_Z2_symmetries(cls, operator) -> 'Z2Symmetries': # pylint: disable=inva return cls([], [], [], None) for pauli in operator.paulis: - stacked_paulis.append(np.concatenate((pauli[1].x, pauli[1].z), axis=0).astype(np.int)) + stacked_paulis.append(np.concatenate((pauli[1].x, pauli[1].z), axis=0).astype(int)) stacked_matrix = np.array(np.stack(stacked_paulis)) symmetries = kernel_F2(stacked_matrix) diff --git a/qiskit/aqua/operators/primitive_ops/pauli_op.py b/qiskit/aqua/operators/primitive_ops/pauli_op.py index faf5547b3d..ee5deee75b 100644 --- a/qiskit/aqua/operators/primitive_ops/pauli_op.py +++ b/qiskit/aqua/operators/primitive_ops/pauli_op.py @@ -1,6 +1,6 @@ # This code is part of Qiskit. # -# (C) Copyright IBM 2020. +# (C) Copyright IBM 2020, 2021. # # 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 @@ -207,7 +207,7 @@ def eval(self, corrected_z_bits = self.primitive.z[::-1] # type: ignore for bstr, v in front.primitive.items(): - bitstr = np.asarray(list(bstr)).astype(np.int).astype(np.bool) + bitstr = np.asarray(list(bstr)).astype(int).astype(bool) new_b_str = np.logical_xor(bitstr, corrected_x_bits) new_str = ''.join(map(str, 1 * new_b_str)) z_factor = np.product(1 - 2 * np.logical_and(bitstr, corrected_z_bits)) diff --git a/qiskit/aqua/utils/random_matrix_generator.py b/qiskit/aqua/utils/random_matrix_generator.py index 2007587e83..160ce3b61d 100644 --- a/qiskit/aqua/utils/random_matrix_generator.py +++ b/qiskit/aqua/utils/random_matrix_generator.py @@ -1,6 +1,6 @@ # This code is part of Qiskit. # -# (C) Copyright IBM 2018, 2020. +# (C) Copyright IBM 2018, 2021. # # 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 @@ -29,7 +29,7 @@ def random_h1_body(N): # pylint: disable=invalid-name N (int): the number of spin orbitals. Returns: - np.ndarray: a 2-D matrix with np.complex data type. + np.ndarray: a 2-D matrix with complex data type. Raises: ValueError: invalid number of spin orbitals @@ -53,7 +53,7 @@ def random_unitary(N): # pylint: disable=invalid-name N (int): the dimension of unitary matrix Returns: - np.ndarray: a 2-D matrix with np.complex data type. + np.ndarray: a 2-D matrix with complex data type. """ x = (aqua_globals.random.random(size=(N, N)) * N + 1j * aqua_globals.random.random(size=(N, N)) * N) / np.sqrt(2) @@ -72,7 +72,7 @@ def random_h2_body(N, M): # pylint: disable=invalid-name M (int) : number of non-zero entries Returns: - np.ndarray: a numpy 4-D tensor with np.complex data type. + np.ndarray: a numpy 4-D tensor with complex data type. Raises: ValueError: invalid spin orbitals diff --git a/qiskit/chemistry/bksf.py b/qiskit/chemistry/bksf.py index be3945af10..29526af95a 100644 --- a/qiskit/chemistry/bksf.py +++ b/qiskit/chemistry/bksf.py @@ -1,6 +1,6 @@ # This code is part of Qiskit. # -# (C) Copyright IBM 2018, 2020. +# (C) Copyright IBM 2018, 2021. # # 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 @@ -155,7 +155,7 @@ def bravyi_kitaev_fast_edge_list(fer_op): h_1 = fer_op.h1 h_2 = fer_op.h2 modes = fer_op.modes - edge_matrix = np.zeros((modes, modes), dtype=np.bool) + edge_matrix = np.zeros((modes, modes), dtype=bool) for p, q in itertools.product(range(modes), repeat=2): # pylint: disable=invalid-name diff --git a/qiskit/chemistry/bosonic_operator.py b/qiskit/chemistry/bosonic_operator.py index 3c4e07655c..ce76b95715 100644 --- a/qiskit/chemistry/bosonic_operator.py +++ b/qiskit/chemistry/bosonic_operator.py @@ -1,6 +1,6 @@ # This code is part of Qiskit. # -# (C) Copyright IBM 2020. +# (C) Copyright IBM 2020, 2021. # # 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 @@ -71,11 +71,11 @@ def _direct_mapping(self, n: int) -> List[Tuple[Pauli, Pauli]]: paulis = [] for i in range(n): - a_z = np.asarray([0] * i + [0] + [0] * (n - i - 1), dtype=np.bool) - a_x = np.asarray([0] * i + [1] + [0] * (n - i - 1), dtype=np.bool) + a_z = np.asarray([0] * i + [0] + [0] * (n - i - 1), dtype=bool) + a_x = np.asarray([0] * i + [1] + [0] * (n - i - 1), dtype=bool) - b_z = np.asarray([0] * i + [1] + [0] * (n - i - 1), dtype=np.bool) - b_x = np.asarray([0] * i + [1] + [0] * (n - i - 1), dtype=np.bool) + b_z = np.asarray([0] * i + [1] + [0] * (n - i - 1), dtype=bool) + b_x = np.asarray([0] * i + [1] + [0] * (n - i - 1), dtype=bool) paulis.append((Pauli(a_z, a_x), Pauli(b_z, b_x))) @@ -141,16 +141,16 @@ def _combine(self, modes: List[int], paulis: dict, coeff: float) -> WeightedPaul if m in modes: pauli_list = paulis[m] else: - a_z = np.asarray([0] * self._basis[m], dtype=np.bool) - a_x = np.asarray([0] * self._basis[m], dtype=np.bool) + a_z = np.asarray([0] * self._basis[m], dtype=bool) + a_x = np.asarray([0] * self._basis[m], dtype=bool) pauli_list = [(1, Pauli(a_z, a_x))] for m in range(1, self._num_modes): if m in modes: new_list = paulis[m] else: - a_z = np.asarray([0] * self._basis[m], dtype=np.bool) - a_x = np.asarray([0] * self._basis[m], dtype=np.bool) + a_z = np.asarray([0] * self._basis[m], dtype=bool) + a_x = np.asarray([0] * self._basis[m], dtype=bool) new_list = [(1, Pauli(a_z, a_x))] pauli_list = self._extend(pauli_list, new_list) diff --git a/qiskit/chemistry/components/initial_states/hartree_fock.py b/qiskit/chemistry/components/initial_states/hartree_fock.py index c3d221f6dd..f122f568b7 100644 --- a/qiskit/chemistry/components/initial_states/hartree_fock.py +++ b/qiskit/chemistry/components/initial_states/hartree_fock.py @@ -1,6 +1,6 @@ # This code is part of Qiskit. # -# (C) Copyright IBM 2018, 2020. +# (C) Copyright IBM 2018, 2021. # # 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 @@ -86,7 +86,7 @@ def __init__(self, def _build_bitstr(self): half_orbitals = self._num_orbitals // 2 - bitstr = np.zeros(self._num_orbitals, np.bool) + bitstr = np.zeros(self._num_orbitals, bool) bitstr[-self._num_alpha:] = True bitstr[-(half_orbitals + self._num_beta):-half_orbitals] = True @@ -94,7 +94,7 @@ def _build_bitstr(self): new_bitstr = bitstr.copy() t_r = np.triu(np.ones((self._num_orbitals, self._num_orbitals))) - new_bitstr = t_r.dot(new_bitstr.astype(np.int)) % 2 # pylint: disable=no-member + new_bitstr = t_r.dot(new_bitstr.astype(int)) % 2 # pylint: disable=no-member bitstr = np.append(new_bitstr[1:half_orbitals], new_bitstr[half_orbitals + 1:]) \ if self._two_qubit_reduction else new_bitstr @@ -109,13 +109,13 @@ def _build_bitstr(self): start_idx = beta.shape[0] - self._num_orbitals beta = beta[start_idx:, start_idx:] new_bitstr = beta.dot(bitstr.astype(int)) % 2 - bitstr = new_bitstr.astype(np.bool) + bitstr = new_bitstr.astype(bool) if self._qubit_tapering: sq_list = (len(bitstr) - 1) - np.asarray(self._sq_list) bitstr = np.delete(bitstr, sq_list) - self._bitstr = bitstr.astype(np.bool) + self._bitstr = bitstr.astype(bool) def construct_circuit(self, mode='circuit', register=None): """ diff --git a/qiskit/chemistry/components/initial_states/vscf.py b/qiskit/chemistry/components/initial_states/vscf.py index 6bc50f2a88..2a9bcbcc8a 100644 --- a/qiskit/chemistry/components/initial_states/vscf.py +++ b/qiskit/chemistry/components/initial_states/vscf.py @@ -1,6 +1,6 @@ # This code is part of Qiskit. # -# (C) Copyright IBM 2020. +# (C) Copyright IBM 2020, 2021. # # 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 @@ -46,7 +46,7 @@ def __init__(self, basis: List[int]) -> None: def _build_bitstr(self) -> np.ndarray: - bitstr = np.zeros(self._num_qubits, np.bool) + bitstr = np.zeros(self._num_qubits, bool) count = 0 for i in range(len(self._basis)): bitstr[self._num_qubits-count-1] = True diff --git a/qiskit/chemistry/components/variational_forms/uccsd.py b/qiskit/chemistry/components/variational_forms/uccsd.py index 16101937f7..f5c833ea66 100644 --- a/qiskit/chemistry/components/variational_forms/uccsd.py +++ b/qiskit/chemistry/components/variational_forms/uccsd.py @@ -1,6 +1,6 @@ # This code is part of Qiskit. # -# (C) Copyright IBM 2018, 2020. +# (C) Copyright IBM 2018, 2021. # # 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 @@ -451,7 +451,7 @@ def preferred_init_points(self): else: bitstr = self._initial_state.bitstr if bitstr is not None: - return np.zeros(self._num_parameters, dtype=np.float) + return np.zeros(self._num_parameters, dtype=float) else: return None diff --git a/qiskit/chemistry/fermionic_operator.py b/qiskit/chemistry/fermionic_operator.py index c3b05d0d31..32e61329db 100644 --- a/qiskit/chemistry/fermionic_operator.py +++ b/qiskit/chemistry/fermionic_operator.py @@ -1,6 +1,6 @@ # This code is part of Qiskit. # -# (C) Copyright IBM 2018, 2020. +# (C) Copyright IBM 2018, 2021. # # 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 @@ -182,10 +182,10 @@ def _jordan_wigner_mode(self, n): """ a_list = [] for i in range(n): - a_z = np.asarray([1] * i + [0] + [0] * (n - i - 1), dtype=np.bool) - a_x = np.asarray([0] * i + [1] + [0] * (n - i - 1), dtype=np.bool) - b_z = np.asarray([1] * i + [1] + [0] * (n - i - 1), dtype=np.bool) - b_x = np.asarray([0] * i + [1] + [0] * (n - i - 1), dtype=np.bool) + a_z = np.asarray([1] * i + [0] + [0] * (n - i - 1), dtype=bool) + a_x = np.asarray([0] * i + [1] + [0] * (n - i - 1), dtype=bool) + b_z = np.asarray([1] * i + [1] + [0] * (n - i - 1), dtype=bool) + b_x = np.asarray([0] * i + [1] + [0] * (n - i - 1), dtype=bool) a_list.append((Pauli(a_z, a_x), Pauli(b_z, b_x))) return a_list @@ -205,10 +205,10 @@ def _parity_mode(self, n): a_x = [0] * (i - 1) + [0] if i > 0 else [] b_z = [0] * (i - 1) + [0] if i > 0 else [] b_x = [0] * (i - 1) + [0] if i > 0 else [] - a_z = np.asarray(a_z + [0] + [0] * (n - i - 1), dtype=np.bool) - a_x = np.asarray(a_x + [1] + [1] * (n - i - 1), dtype=np.bool) - b_z = np.asarray(b_z + [1] + [0] * (n - i - 1), dtype=np.bool) - b_x = np.asarray(b_x + [1] + [1] * (n - i - 1), dtype=np.bool) + a_z = np.asarray(a_z + [0] + [0] * (n - i - 1), dtype=bool) + a_x = np.asarray(a_x + [1] + [1] * (n - i - 1), dtype=bool) + b_z = np.asarray(b_z + [1] + [0] * (n - i - 1), dtype=bool) + b_x = np.asarray(b_x + [1] + [1] * (n - i - 1), dtype=bool) a_list.append((Pauli(a_z, a_x), Pauli(b_z, b_x))) return a_list @@ -319,9 +319,9 @@ def flip_set(j, n): remainder_sets.append(np.setdiff1d(parity_sets[j], flip_sets[j])) - update_pauli.append(Pauli(np.zeros(n, dtype=np.bool), np.zeros(n, dtype=np.bool))) - parity_pauli.append(Pauli(np.zeros(n, dtype=np.bool), np.zeros(n, dtype=np.bool))) - remainder_pauli.append(Pauli(np.zeros(n, dtype=np.bool), np.zeros(n, dtype=np.bool))) + update_pauli.append(Pauli(np.zeros(n, dtype=bool), np.zeros(n, dtype=bool))) + parity_pauli.append(Pauli(np.zeros(n, dtype=bool), np.zeros(n, dtype=bool))) + remainder_pauli.append(Pauli(np.zeros(n, dtype=bool), np.zeros(n, dtype=bool))) for k in range(n): if np.in1d(k, update_sets[j]): update_pauli[j].update_x(True, k) @@ -330,9 +330,9 @@ def flip_set(j, n): if np.in1d(k, remainder_sets[j]): remainder_pauli[j].update_z(True, k) - x_j = Pauli(np.zeros(n, dtype=np.bool), np.zeros(n, dtype=np.bool)) + x_j = Pauli(np.zeros(n, dtype=bool), np.zeros(n, dtype=bool)) x_j.update_x(True, j) - y_j = Pauli(np.zeros(n, dtype=np.bool), np.zeros(n, dtype=np.bool)) + y_j = Pauli(np.zeros(n, dtype=bool), np.zeros(n, dtype=bool)) y_j.update_z(True, j) y_j.update_x(True, j) a_list.append((update_pauli[j] * x_j * parity_pauli[j], @@ -619,7 +619,7 @@ def total_particle_number(self): FermionicOperator: Fermionic Hamiltonian """ modes = self._modes - h_1 = np.eye(modes, dtype=np.complex) + h_1 = np.eye(modes, dtype=complex) h_2 = np.zeros((modes, modes, modes, modes)) return FermionicOperator(h_1, h_2) @@ -632,7 +632,7 @@ def total_magnetization(self): FermionicOperator: Fermionic Hamiltonian """ modes = self._modes - h_1 = np.eye(modes, dtype=np.complex) * 0.5 + h_1 = np.eye(modes, dtype=complex) * 0.5 h_1[modes // 2:, modes // 2:] *= -1.0 h_2 = np.zeros((modes, modes, modes, modes)) return FermionicOperator(h_1, h_2) diff --git a/qiskit/chemistry/qmolecule.py b/qiskit/chemistry/qmolecule.py index 274ba0439a..623e85cb6a 100644 --- a/qiskit/chemistry/qmolecule.py +++ b/qiskit/chemistry/qmolecule.py @@ -1,6 +1,6 @@ # This code is part of Qiskit. # -# (C) Copyright IBM 2018, 2020. +# (C) Copyright IBM 2018, 2021. # # 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 @@ -191,7 +191,7 @@ def load(self): with h5py.File(self._filename, "r") as file: def read_array(name): _data = file[name][...] - if _data.dtype == numpy.bool and _data.size == 1 and not _data: + if _data.dtype == numpy.bool_ and _data.size == 1 and not _data: _data = None return _data diff --git a/qiskit/finance/applications/ising/portfolio.py b/qiskit/finance/applications/ising/portfolio.py index 24f005698d..242c6c099d 100644 --- a/qiskit/finance/applications/ising/portfolio.py +++ b/qiskit/finance/applications/ising/portfolio.py @@ -1,6 +1,6 @@ # This code is part of Qiskit. # -# (C) Copyright IBM 2018, 2020. +# (C) Copyright IBM 2018, 2021. # # 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 @@ -66,16 +66,16 @@ def get_operator(mu, sigma, q, budget, penalty): # pylint: disable=invalid-name i_ = i # i_ = n - i - 1 if np.abs(mu_z[i_]) > 1e-6: - xp = np.zeros(n, dtype=np.bool) - zp = np.zeros(n, dtype=np.bool) + xp = np.zeros(n, dtype=bool) + zp = np.zeros(n, dtype=bool) zp[i_] = True pauli_list.append([mu_z[i_], Pauli(zp, xp)]) for j in range(i): j_ = j # j_ = n-j-1 if np.abs(sigma_z[i_, j_]) > 1e-6: - xp = np.zeros(n, dtype=np.bool) - zp = np.zeros(n, dtype=np.bool) + xp = np.zeros(n, dtype=bool) + zp = np.zeros(n, dtype=bool) zp[i_] = True zp[j_] = True pauli_list.append([2 * sigma_z[i_, j_], Pauli(zp, xp)]) diff --git a/qiskit/optimization/applications/ising/clique.py b/qiskit/optimization/applications/ising/clique.py index dceb8c3cde..5ebf74d3f1 100644 --- a/qiskit/optimization/applications/ising/clique.py +++ b/qiskit/optimization/applications/ising/clique.py @@ -1,6 +1,6 @@ # This code is part of Qiskit. # -# (C) Copyright IBM 2018, 2020. +# (C) Copyright IBM 2018, 2021. # # 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 @@ -74,16 +74,16 @@ def get_operator(weight_matrix, K): # pylint: disable=invalid-name for i in range(num_nodes): for j in range(num_nodes): if i != j: - xp = np.zeros(num_nodes, dtype=np.bool) - zp = np.zeros(num_nodes, dtype=np.bool) + xp = np.zeros(num_nodes, dtype=bool) + zp = np.zeros(num_nodes, dtype=bool) zp[i] = True zp[j] = True pauli_list.append([A * 0.25, Pauli(zp, xp)]) else: shift += A * 0.25 for i in range(num_nodes): - xp = np.zeros(num_nodes, dtype=np.bool) - zp = np.zeros(num_nodes, dtype=np.bool) + xp = np.zeros(num_nodes, dtype=bool) + zp = np.zeros(num_nodes, dtype=bool) zp[i] = True pauli_list.append([-A * Y, Pauli(zp, xp)]) @@ -92,17 +92,17 @@ def get_operator(weight_matrix, K): # pylint: disable=invalid-name for i in range(num_nodes): for j in range(i): if weight_matrix[i, j] != 0: - xp = np.zeros(num_nodes, dtype=np.bool) - zp = np.zeros(num_nodes, dtype=np.bool) + xp = np.zeros(num_nodes, dtype=bool) + zp = np.zeros(num_nodes, dtype=bool) zp[i] = True zp[j] = True pauli_list.append([-0.25, Pauli(zp, xp)]) - zp2 = np.zeros(num_nodes, dtype=np.bool) + zp2 = np.zeros(num_nodes, dtype=bool) zp2[i] = True pauli_list.append([-0.25, Pauli(zp2, xp)]) - zp3 = np.zeros(num_nodes, dtype=np.bool) + zp3 = np.zeros(num_nodes, dtype=bool) zp3[j] = True pauli_list.append([-0.25, Pauli(zp3, xp)]) diff --git a/qiskit/optimization/applications/ising/docplex.py b/qiskit/optimization/applications/ising/docplex.py index 5b162b7534..1dd7c56bac 100644 --- a/qiskit/optimization/applications/ising/docplex.py +++ b/qiskit/optimization/applications/ising/docplex.py @@ -1,6 +1,6 @@ # This code is part of Qiskit. # -# (C) Copyright IBM 2019, 2020. +# (C) Copyright IBM 2019, 2021. # # 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 @@ -114,7 +114,7 @@ def get_operator(mdl: Model, auto_penalty: bool = True, num_nodes = len(q_d) pauli_list = [] shift = 0 - zero = np.zeros(num_nodes, dtype=np.bool) + zero = np.zeros(num_nodes, dtype=bool) # convert a constant part of the object function into Hamiltonian. shift += mdl.get_objective_expr().get_constant() * sign @@ -122,7 +122,7 @@ def get_operator(mdl: Model, auto_penalty: bool = True, # convert linear parts of the object function into Hamiltonian. l_itr = mdl.get_objective_expr().iter_terms() for j in l_itr: - z_p = np.zeros(num_nodes, dtype=np.bool) + z_p = np.zeros(num_nodes, dtype=bool) index = q_d[j[0]] weight = j[1] * sign / 2 z_p[index] = True @@ -140,16 +140,16 @@ def get_operator(mdl: Model, auto_penalty: bool = True, if index1 == index2: shift += weight else: - z_p = np.zeros(num_nodes, dtype=np.bool) + z_p = np.zeros(num_nodes, dtype=bool) z_p[index1] = True z_p[index2] = True pauli_list.append([weight, Pauli(z_p, zero)]) - z_p = np.zeros(num_nodes, dtype=np.bool) + z_p = np.zeros(num_nodes, dtype=bool) z_p[index1] = True pauli_list.append([-weight, Pauli(z_p, zero)]) - z_p = np.zeros(num_nodes, dtype=np.bool) + z_p = np.zeros(num_nodes, dtype=bool) z_p[index2] = True pauli_list.append([-weight, Pauli(z_p, zero)]) @@ -164,7 +164,7 @@ def get_operator(mdl: Model, auto_penalty: bool = True, # linear parts of penalty*(Constant-func)**2: penalty*(-2*Constant*func) for __l in constraint.iter_net_linear_coefs(): - z_p = np.zeros(num_nodes, dtype=np.bool) + z_p = np.zeros(num_nodes, dtype=bool) index = q_d[__l[0]] weight = __l[1] z_p[index] = True @@ -184,16 +184,16 @@ def get_operator(mdl: Model, auto_penalty: bool = True, if index1 == index2: shift += penalty_weight1_weight2 else: - z_p = np.zeros(num_nodes, dtype=np.bool) + z_p = np.zeros(num_nodes, dtype=bool) z_p[index1] = True z_p[index2] = True pauli_list.append([penalty_weight1_weight2, Pauli(z_p, zero)]) - z_p = np.zeros(num_nodes, dtype=np.bool) + z_p = np.zeros(num_nodes, dtype=bool) z_p[index1] = True pauli_list.append([-penalty_weight1_weight2, Pauli(z_p, zero)]) - z_p = np.zeros(num_nodes, dtype=np.bool) + z_p = np.zeros(num_nodes, dtype=bool) z_p[index2] = True pauli_list.append([-penalty_weight1_weight2, Pauli(z_p, zero)]) diff --git a/qiskit/optimization/applications/ising/graph_partition.py b/qiskit/optimization/applications/ising/graph_partition.py index e3fb0fcbae..3b01eab9d6 100644 --- a/qiskit/optimization/applications/ising/graph_partition.py +++ b/qiskit/optimization/applications/ising/graph_partition.py @@ -1,6 +1,6 @@ # This code is part of Qiskit. # -# (C) Copyright IBM 2018, 2020. +# (C) Copyright IBM 2018, 2021. # # 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 @@ -52,8 +52,8 @@ def get_operator(weight_matrix): for i in range(num_nodes): for j in range(i): if weight_matrix[i, j] != 0: - x_p = np.zeros(num_nodes, dtype=np.bool) - z_p = np.zeros(num_nodes, dtype=np.bool) + x_p = np.zeros(num_nodes, dtype=bool) + z_p = np.zeros(num_nodes, dtype=bool) z_p[i] = True z_p[j] = True pauli_list.append([-0.5, Pauli(z_p, x_p)]) @@ -62,8 +62,8 @@ def get_operator(weight_matrix): for i in range(num_nodes): for j in range(num_nodes): if i != j: - x_p = np.zeros(num_nodes, dtype=np.bool) - z_p = np.zeros(num_nodes, dtype=np.bool) + x_p = np.zeros(num_nodes, dtype=bool) + z_p = np.zeros(num_nodes, dtype=bool) z_p[i] = True z_p[j] = True pauli_list.append([1, Pauli(z_p, x_p)]) diff --git a/qiskit/optimization/applications/ising/knapsack.py b/qiskit/optimization/applications/ising/knapsack.py index ab403487b9..2df7683215 100644 --- a/qiskit/optimization/applications/ising/knapsack.py +++ b/qiskit/optimization/applications/ising/knapsack.py @@ -1,6 +1,6 @@ # This code is part of Qiskit. # -# (C) Copyright IBM 2020. +# (C) Copyright IBM 2020, 2021. # # 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 @@ -215,8 +215,8 @@ def knapsack_value_weight(solution, values, weights): def _get_pauli_op(num_values, indexes): - pauli_x = np.zeros(num_values, dtype=np.bool) - pauli_z = np.zeros(num_values, dtype=np.bool) + pauli_x = np.zeros(num_values, dtype=bool) + pauli_z = np.zeros(num_values, dtype=bool) for i in indexes: pauli_z[i] = not pauli_z[i] diff --git a/qiskit/optimization/applications/ising/max_cut.py b/qiskit/optimization/applications/ising/max_cut.py index 00d539db4c..e62357807a 100644 --- a/qiskit/optimization/applications/ising/max_cut.py +++ b/qiskit/optimization/applications/ising/max_cut.py @@ -1,6 +1,6 @@ # This code is part of Qiskit. # -# (C) Copyright IBM 2018, 2020. +# (C) Copyright IBM 2018, 2021. # # 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 @@ -45,8 +45,8 @@ def get_operator(weight_matrix): for i in range(num_nodes): for j in range(i): if weight_matrix[i, j] != 0: - x_p = np.zeros(num_nodes, dtype=np.bool) - z_p = np.zeros(num_nodes, dtype=np.bool) + x_p = np.zeros(num_nodes, dtype=bool) + z_p = np.zeros(num_nodes, dtype=bool) z_p[i] = True z_p[j] = True pauli_list.append([0.5 * weight_matrix[i, j], Pauli(z_p, x_p)]) diff --git a/qiskit/optimization/applications/ising/partition.py b/qiskit/optimization/applications/ising/partition.py index 9e4af418e0..3311256fd1 100644 --- a/qiskit/optimization/applications/ising/partition.py +++ b/qiskit/optimization/applications/ising/partition.py @@ -1,6 +1,6 @@ # This code is part of Qiskit. # -# (C) Copyright IBM 2018, 2020. +# (C) Copyright IBM 2018, 2021. # # 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 @@ -45,8 +45,8 @@ def get_operator(values): pauli_list = [] for i in range(n): for j in range(i): - x_p = np.zeros(n, dtype=np.bool) - z_p = np.zeros(n, dtype=np.bool) + x_p = np.zeros(n, dtype=bool) + z_p = np.zeros(n, dtype=bool) z_p[i] = True z_p[j] = True pauli_list.append([2. * values[i] * values[j], Pauli(z_p, x_p)]) diff --git a/qiskit/optimization/applications/ising/stable_set.py b/qiskit/optimization/applications/ising/stable_set.py index 3f66800198..833a0a171b 100644 --- a/qiskit/optimization/applications/ising/stable_set.py +++ b/qiskit/optimization/applications/ising/stable_set.py @@ -1,6 +1,6 @@ # This code is part of Qiskit. # -# (C) Copyright IBM 2018, 2020. +# (C) Copyright IBM 2018, 2021. # # 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 @@ -45,16 +45,16 @@ def get_operator(w): for i in range(num_nodes): for j in range(i + 1, num_nodes): if w[i, j] != 0: - x_p = np.zeros(num_nodes, dtype=np.bool) - z_p = np.zeros(num_nodes, dtype=np.bool) + x_p = np.zeros(num_nodes, dtype=bool) + z_p = np.zeros(num_nodes, dtype=bool) z_p[i] = True z_p[j] = True pauli_list.append([1.0, Pauli(z_p, x_p)]) shift += 1 for i in range(num_nodes): degree = np.sum(w[i, :]) - x_p = np.zeros(num_nodes, dtype=np.bool) - z_p = np.zeros(num_nodes, dtype=np.bool) + x_p = np.zeros(num_nodes, dtype=bool) + z_p = np.zeros(num_nodes, dtype=bool) z_p[i] = True pauli_list.append([degree - 1 / 2, Pauli(z_p, x_p)]) return WeightedPauliOperator(paulis=pauli_list), shift - num_nodes / 2 diff --git a/qiskit/optimization/applications/ising/tsp.py b/qiskit/optimization/applications/ising/tsp.py index 7a36c47690..aedda2ec3b 100644 --- a/qiskit/optimization/applications/ising/tsp.py +++ b/qiskit/optimization/applications/ising/tsp.py @@ -1,6 +1,6 @@ # This code is part of Qiskit. # -# (C) Copyright IBM 2018, 2020. +# (C) Copyright IBM 2018, 2021. # # 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 @@ -137,7 +137,7 @@ def get_operator(ins, penalty=1e5): """ num_nodes = ins.dim num_qubits = num_nodes ** 2 - zero = np.zeros(num_qubits, dtype=np.bool) + zero = np.zeros(num_qubits, dtype=bool) pauli_list = [] shift = 0 for i in range(num_nodes): @@ -148,22 +148,22 @@ def get_operator(ins, penalty=1e5): q = (p__ + 1) % num_nodes shift += ins.w[i, j] / 4 - z_p = np.zeros(num_qubits, dtype=np.bool) + z_p = np.zeros(num_qubits, dtype=bool) z_p[i * num_nodes + p__] = True pauli_list.append([-ins.w[i, j] / 4, Pauli(z_p, zero)]) - z_p = np.zeros(num_qubits, dtype=np.bool) + z_p = np.zeros(num_qubits, dtype=bool) z_p[j * num_nodes + q] = True pauli_list.append([-ins.w[i, j] / 4, Pauli(z_p, zero)]) - z_p = np.zeros(num_qubits, dtype=np.bool) + z_p = np.zeros(num_qubits, dtype=bool) z_p[i * num_nodes + p__] = True z_p[j * num_nodes + q] = True pauli_list.append([ins.w[i, j] / 4, Pauli(z_p, zero)]) for i in range(num_nodes): for p__ in range(num_nodes): - z_p = np.zeros(num_qubits, dtype=np.bool) + z_p = np.zeros(num_qubits, dtype=bool) z_p[i * num_nodes + p__] = True pauli_list.append([penalty, Pauli(z_p, zero)]) shift += -penalty @@ -173,15 +173,15 @@ def get_operator(ins, penalty=1e5): for j in range(i): shift += penalty / 2 - z_p = np.zeros(num_qubits, dtype=np.bool) + z_p = np.zeros(num_qubits, dtype=bool) z_p[i * num_nodes + p__] = True pauli_list.append([-penalty / 2, Pauli(z_p, zero)]) - z_p = np.zeros(num_qubits, dtype=np.bool) + z_p = np.zeros(num_qubits, dtype=bool) z_p[j * num_nodes + p__] = True pauli_list.append([-penalty / 2, Pauli(z_p, zero)]) - z_p = np.zeros(num_qubits, dtype=np.bool) + z_p = np.zeros(num_qubits, dtype=bool) z_p[i * num_nodes + p__] = True z_p[j * num_nodes + p__] = True pauli_list.append([penalty / 2, Pauli(z_p, zero)]) @@ -191,15 +191,15 @@ def get_operator(ins, penalty=1e5): for q in range(p__): shift += penalty / 2 - z_p = np.zeros(num_qubits, dtype=np.bool) + z_p = np.zeros(num_qubits, dtype=bool) z_p[i * num_nodes + p__] = True pauli_list.append([-penalty / 2, Pauli(z_p, zero)]) - z_p = np.zeros(num_qubits, dtype=np.bool) + z_p = np.zeros(num_qubits, dtype=bool) z_p[i * num_nodes + q] = True pauli_list.append([-penalty / 2, Pauli(z_p, zero)]) - z_p = np.zeros(num_qubits, dtype=np.bool) + z_p = np.zeros(num_qubits, dtype=bool) z_p[i * num_nodes + p__] = True z_p[i * num_nodes + q] = True pauli_list.append([penalty / 2, Pauli(z_p, zero)]) diff --git a/qiskit/optimization/problems/quadratic_program.py b/qiskit/optimization/problems/quadratic_program.py index d0b2feb31b..dfe569bef4 100644 --- a/qiskit/optimization/problems/quadratic_program.py +++ b/qiskit/optimization/problems/quadratic_program.py @@ -19,7 +19,7 @@ from math import fsum, isclose import warnings import numpy as np -from numpy import (ndarray, zeros, bool as nbool) +from numpy import (ndarray, zeros) from scipy.sparse import spmatrix from docplex.mp.constr import (LinearConstraint as DocplexLinearConstraint, @@ -916,7 +916,7 @@ def to_ising(self) -> Tuple[OperatorBase, float]: num_nodes = self.get_num_vars() pauli_list = [] offset = 0 - zero = zeros(num_nodes, dtype=nbool) + zero = zeros(num_nodes, dtype=bool) # set a sign corresponding to a maximized or minimized problem. # sign == 1 is for minimized problem. sign == -1 is for maximized problem. @@ -927,7 +927,7 @@ def to_ising(self) -> Tuple[OperatorBase, float]: # convert linear parts of the object function into Hamiltonian. for idx, coef in self.objective.linear.to_dict().items(): - z_p = zeros(num_nodes, dtype=nbool) + z_p = zeros(num_nodes, dtype=bool) weight = coef * sense / 2 z_p[idx] = True @@ -951,16 +951,16 @@ def to_ising(self) -> Tuple[OperatorBase, float]: if i == j: offset += weight # type: ignore else: - z_p = zeros(num_nodes, dtype=nbool) + z_p = zeros(num_nodes, dtype=bool) z_p[i] = True z_p[j] = True pauli_list.append([weight, Pauli(z_p, zero)]) - z_p = zeros(num_nodes, dtype=nbool) + z_p = zeros(num_nodes, dtype=bool) z_p[i] = True pauli_list.append([-weight, Pauli(z_p, zero)]) - z_p = zeros(num_nodes, dtype=nbool) + z_p = zeros(num_nodes, dtype=bool) z_p[j] = True pauli_list.append([-weight, Pauli(z_p, zero)]) diff --git a/test/aqua/test_qsvm.py b/test/aqua/test_qsvm.py index a81051c43a..9791eba984 100644 --- a/test/aqua/test_qsvm.py +++ b/test/aqua/test_qsvm.py @@ -1,6 +1,6 @@ # This code is part of Qiskit. # -# (C) Copyright IBM 2018, 2020. +# (C) Copyright IBM 2018, 2021. # # 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 @@ -240,7 +240,7 @@ def test_matrix_psd(self): training_data = training_input[0] training_labels = training_input[1] labels = training_labels * 2 - 1 # map label from 0 --> -1 and 1 --> 1 - labels = labels.astype(np.float) + labels = labels.astype(float) feature_map = ZZFeatureMap(feature_dimension=feature_dim, reps=2, entanglement='linear') diff --git a/test/chemistry/test_fermionic_operator.py b/test/chemistry/test_fermionic_operator.py index b903d087f6..391973e34d 100644 --- a/test/chemistry/test_fermionic_operator.py +++ b/test/chemistry/test_fermionic_operator.py @@ -1,6 +1,6 @@ # This code is part of Qiskit. # -# (C) Copyright IBM 2018, 2020. +# (C) Copyright IBM 2018, 2021. # # 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 @@ -27,7 +27,7 @@ def h2_transform_slow(h2_, unitary_matrix): Transform h2 based on unitary matrix, and overwrite original property. #MARK: A naive implementation based on MATLAB implementation. Args: - unitary_matrix (numpy 2-D array, np.float or np.complex): + unitary_matrix (numpy 2-D array, float or complex): Unitary matrix for h2 transformation. Returns: temp_ret: matrix diff --git a/test/finance/test_data_providers.py b/test/finance/test_data_providers.py index ec457fe594..a9b103f6d2 100644 --- a/test/finance/test_data_providers.py +++ b/test/finance/test_data_providers.py @@ -216,8 +216,8 @@ def test_yahoo(self): [8.44268222e-05, 1.00000000e+00] ]) covariance = np.array( - [[7.035e+00, -1.653e-04], - [-1.653e-04, 1.199e-06]]) + [[7.174e+00, -1.671e-04], + [-1.671e-04, 1.199e-06]]) with self.subTest('test YahooDataProvider get_covariance_matrix'): np.testing.assert_array_almost_equal(yahoo.get_covariance_matrix(), covariance, decimal=3) From cc65a08772788038f1e4c6d4da8ffad05a131faf Mon Sep 17 00:00:00 2001 From: Manoel Marques Date: Fri, 5 Feb 2021 15:52:25 -0500 Subject: [PATCH 05/13] Install Terra from 0.16 branch --- .github/actions/install-aqua/action.yml | 2 ++ 1 file changed, 2 insertions(+) diff --git a/.github/actions/install-aqua/action.yml b/.github/actions/install-aqua/action.yml index ae2303e25a..212f574bec 100644 --- a/.github/actions/install-aqua/action.yml +++ b/.github/actions/install-aqua/action.yml @@ -20,8 +20,10 @@ runs: if [ -f "$HOME/miniconda/etc/profile.d/conda.sh" ]; then source "$HOME/miniconda/etc/profile.d/conda.sh" conda activate + pip install https://github.com/Qiskit/qiskit-terra/archive/stable/0.16.zip pip install -e .[torch,cplex,cvx,pyscf] else + pip install https://github.com/Qiskit/qiskit-terra/archive/stable/0.16.zip pip install -e .[torch,cplex,cvx,pyscf,skquant] fi pip install -U -c constraints.txt -r requirements-dev.txt From 6cc116ea2ff9c3ef2b640d979ac656cc368636cc Mon Sep 17 00:00:00 2001 From: Manoel Marques Date: Fri, 5 Feb 2021 17:05:02 -0500 Subject: [PATCH 06/13] Fix Grover operator usage in AE --- qiskit/aqua/algorithms/amplitude_estimators/ae_algorithm.py | 4 +--- test/aqua/test_amplitude_estimation.py | 6 +----- 2 files changed, 2 insertions(+), 8 deletions(-) diff --git a/qiskit/aqua/algorithms/amplitude_estimators/ae_algorithm.py b/qiskit/aqua/algorithms/amplitude_estimators/ae_algorithm.py index e462230aa8..913ac61ff5 100644 --- a/qiskit/aqua/algorithms/amplitude_estimators/ae_algorithm.py +++ b/qiskit/aqua/algorithms/amplitude_estimators/ae_algorithm.py @@ -1,6 +1,6 @@ # This code is part of Qiskit. # -# (C) Copyright IBM 2018, 2020. +# (C) Copyright IBM 2018, 2021. # # 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 @@ -158,14 +158,12 @@ def grover_operator(self) -> Optional[QuantumCircuit]: - self.state_preparation.num_ancillas oracle = QuantumCircuit(num_state_qubits) - oracle.x(self.objective_qubits) oracle.h(self.objective_qubits[-1]) if len(self.objective_qubits) == 1: oracle.x(self.objective_qubits[0]) else: oracle.mcx(self.objective_qubits[:-1], self.objective_qubits[-1]) oracle.h(self.objective_qubits[-1]) - oracle.x(self.objective_qubits) # construct the grover operator return GroverOperator(oracle, self.state_preparation) diff --git a/test/aqua/test_amplitude_estimation.py b/test/aqua/test_amplitude_estimation.py index 02e6086775..3daa665459 100644 --- a/test/aqua/test_amplitude_estimation.py +++ b/test/aqua/test_amplitude_estimation.py @@ -1,6 +1,6 @@ # This code is part of Qiskit. # -# (C) Copyright IBM 2018, 2020. +# (C) Copyright IBM 2018, 2021. # # 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 @@ -165,9 +165,7 @@ def test_qae_circuit(self, efficient_circuit): circuit.cry(2 * 2 ** power * angle, qr_eval[power], qr_objective[0]) else: oracle = QuantumCircuit(1) - oracle.x(0) oracle.z(0) - oracle.x(0) state_preparation = QuantumCircuit(1) state_preparation.ry(angle, 0) @@ -210,9 +208,7 @@ def test_iqae_circuits(self, efficient_circuit): else: oracle = QuantumCircuit(1) - oracle.x(0) oracle.z(0) - oracle.x(0) state_preparation = QuantumCircuit(1) state_preparation.ry(angle, 0) grover_op = GroverOperator(oracle, state_preparation) From dacd0d48962e92442a62bf87fdd406771e5a3e2f Mon Sep 17 00:00:00 2001 From: Manoel Marques Date: Fri, 5 Feb 2021 17:05:55 -0500 Subject: [PATCH 07/13] fix copyright --- test/finance/test_data_providers.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/finance/test_data_providers.py b/test/finance/test_data_providers.py index a9b103f6d2..fac4127758 100644 --- a/test/finance/test_data_providers.py +++ b/test/finance/test_data_providers.py @@ -1,6 +1,6 @@ # This code is part of Qiskit. # -# (C) Copyright IBM 2019, 2020. +# (C) Copyright IBM 2019, 2021. # # 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 From 3a7fb5943e99bec3fc5785a991c9e10361a6c343 Mon Sep 17 00:00:00 2001 From: Manoel Marques Date: Fri, 5 Feb 2021 17:06:37 -0500 Subject: [PATCH 08/13] Install qiskit-terra from stable/0.16 on CI --- .github/actions/install-aqua/action.yml | 2 ++ 1 file changed, 2 insertions(+) diff --git a/.github/actions/install-aqua/action.yml b/.github/actions/install-aqua/action.yml index ae2303e25a..212f574bec 100644 --- a/.github/actions/install-aqua/action.yml +++ b/.github/actions/install-aqua/action.yml @@ -20,8 +20,10 @@ runs: if [ -f "$HOME/miniconda/etc/profile.d/conda.sh" ]; then source "$HOME/miniconda/etc/profile.d/conda.sh" conda activate + pip install https://github.com/Qiskit/qiskit-terra/archive/stable/0.16.zip pip install -e .[torch,cplex,cvx,pyscf] else + pip install https://github.com/Qiskit/qiskit-terra/archive/stable/0.16.zip pip install -e .[torch,cplex,cvx,pyscf,skquant] fi pip install -U -c constraints.txt -r requirements-dev.txt From 3a275799ba82bd966dd89f19ba99afc9b4b0e30f Mon Sep 17 00:00:00 2001 From: Manoel Marques Date: Fri, 5 Feb 2021 18:24:36 -0500 Subject: [PATCH 09/13] Fix unit test --- test/aqua/test_amplitude_estimation.py | 2 +- test/aqua/test_amplitude_estimation_circuitfactory.py | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/test/aqua/test_amplitude_estimation.py b/test/aqua/test_amplitude_estimation.py index 3daa665459..7fdcda6a68 100644 --- a/test/aqua/test_amplitude_estimation.py +++ b/test/aqua/test_amplitude_estimation.py @@ -413,7 +413,7 @@ def test_confidence_intervals(self, qae, key, expect): result = qae.run(self._qasm(shots)) for method, expected_confint in expect.items(): confint = qae.confidence_interval(alpha, method) - self.assertEqual(confint, expected_confint) + np.testing.assert_array_almost_equal(confint, expected_confint, decimal=3) self.assertTrue(confint[0] <= getattr(result, key) <= confint[1]) def test_iqae_confidence_intervals(self): diff --git a/test/aqua/test_amplitude_estimation_circuitfactory.py b/test/aqua/test_amplitude_estimation_circuitfactory.py index baddb90abf..875d5fcecb 100644 --- a/test/aqua/test_amplitude_estimation_circuitfactory.py +++ b/test/aqua/test_amplitude_estimation_circuitfactory.py @@ -1,6 +1,6 @@ # This code is part of Qiskit. # -# (C) Copyright IBM 2018, 2020. +# (C) Copyright IBM 2018, 2021. # # 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 @@ -515,7 +515,7 @@ def test_confidence_intervals(self, qae, key, expect): result = qae.run(self._qasm(shots)) for method, expected_confint in expect.items(): confint = qae.confidence_interval(alpha, method) - self.assertEqual(confint, expected_confint) + np.testing.assert_array_almost_equal(confint, expected_confint, decimal=3) self.assertTrue(confint[0] <= result[key] <= confint[1]) def test_iqae_confidence_intervals(self): From 7e1b7239ae20f92864c827504f37ef866e4fdf58 Mon Sep 17 00:00:00 2001 From: Manoel Marques Date: Fri, 5 Feb 2021 19:13:08 -0500 Subject: [PATCH 10/13] Fix CI for stable branch --- .github/actions/install-master-dependencies/action.yml | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/.github/actions/install-master-dependencies/action.yml b/.github/actions/install-master-dependencies/action.yml index 64dfc7a8e7..64ef3250d8 100644 --- a/.github/actions/install-master-dependencies/action.yml +++ b/.github/actions/install-master-dependencies/action.yml @@ -21,8 +21,8 @@ runs: source "$HOME/miniconda/etc/profile.d/conda.sh" conda activate fi - pip install https://github.com/Qiskit/qiskit-terra/archive/master.zip - pip install https://github.com/Qiskit/qiskit-ignis/archive/master.zip - pip install https://github.com/Qiskit/qiskit-ibmq-provider/archive/master.zip - pip install https://github.com/Qiskit/qiskit-aer/archive/master.zip + # pip install https://github.com/Qiskit/qiskit-terra/archive/master.zip + # pip install https://github.com/Qiskit/qiskit-ignis/archive/master.zip + # pip install https://github.com/Qiskit/qiskit-ibmq-provider/archive/master.zip + # pip install https://github.com/Qiskit/qiskit-aer/archive/master.zip shell: bash From 9c14ada3f6be5e53629cab368cb8ba6f71c88d45 Mon Sep 17 00:00:00 2001 From: Manoel Marques Date: Mon, 8 Feb 2021 12:45:57 -0500 Subject: [PATCH 11/13] Point Terra to Pypi version on CI --- .github/actions/install-aqua/action.yml | 2 -- 1 file changed, 2 deletions(-) diff --git a/.github/actions/install-aqua/action.yml b/.github/actions/install-aqua/action.yml index 212f574bec..ae2303e25a 100644 --- a/.github/actions/install-aqua/action.yml +++ b/.github/actions/install-aqua/action.yml @@ -20,10 +20,8 @@ runs: if [ -f "$HOME/miniconda/etc/profile.d/conda.sh" ]; then source "$HOME/miniconda/etc/profile.d/conda.sh" conda activate - pip install https://github.com/Qiskit/qiskit-terra/archive/stable/0.16.zip pip install -e .[torch,cplex,cvx,pyscf] else - pip install https://github.com/Qiskit/qiskit-terra/archive/stable/0.16.zip pip install -e .[torch,cplex,cvx,pyscf,skquant] fi pip install -U -c constraints.txt -r requirements-dev.txt From 69e71c49d611320757037e48b76414d52ec39b82 Mon Sep 17 00:00:00 2001 From: Manoel Marques Date: Mon, 8 Feb 2021 13:21:26 -0500 Subject: [PATCH 12/13] remove IBMQ install from CI --- .github/actions/install-master-dependencies/action.yml | 1 - requirements-dev.txt | 1 - tox.ini | 1 - 3 files changed, 3 deletions(-) diff --git a/.github/actions/install-master-dependencies/action.yml b/.github/actions/install-master-dependencies/action.yml index 64ef3250d8..0f1d6fed63 100644 --- a/.github/actions/install-master-dependencies/action.yml +++ b/.github/actions/install-master-dependencies/action.yml @@ -23,6 +23,5 @@ runs: fi # pip install https://github.com/Qiskit/qiskit-terra/archive/master.zip # pip install https://github.com/Qiskit/qiskit-ignis/archive/master.zip - # pip install https://github.com/Qiskit/qiskit-ibmq-provider/archive/master.zip # pip install https://github.com/Qiskit/qiskit-aer/archive/master.zip shell: bash diff --git a/requirements-dev.txt b/requirements-dev.txt index 051f6a0b67..63e8332145 100644 --- a/requirements-dev.txt +++ b/requirements-dev.txt @@ -14,7 +14,6 @@ jupyter-sphinx discover torch; sys_platform == 'linux' or (python_version < '3.8' and sys_platform != 'win32') qiskit-aer -qiskit-ibmq-provider mypy>=0.780 mypy-extensions>=0.4.3 networkx>=2.2 \ No newline at end of file diff --git a/tox.ini b/tox.ini index e00de9c308..784d5e360b 100644 --- a/tox.ini +++ b/tox.ini @@ -14,7 +14,6 @@ setenv = deps = https://github.com/Qiskit/qiskit-terra/archive/master.zip https://github.com/Qiskit/qiskit-ignis/archive/master.zip https://github.com/Qiskit/qiskit-aer/archive/master.zip - https://github.com/Qiskit/qiskit-ibmq-provider/archive/master.zip -r{toxinidir}/requirements-dev.txt commands = stestr run {posargs} From 95e88edd39a8c3f81e3a7e8f9301dda768681c51 Mon Sep 17 00:00:00 2001 From: Manoel Marques Date: Mon, 8 Feb 2021 14:30:53 -0500 Subject: [PATCH 13/13] Pin DocPlex to version 2.15.194 --- requirements.txt | 2 +- setup.py | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/requirements.txt b/requirements.txt index 15db4053d3..d65df6b738 100644 --- a/requirements.txt +++ b/requirements.txt @@ -6,7 +6,7 @@ numpy>=1.17 psutil>=5 scikit-learn>=0.20.0 dlx -docplex +docplex==2.15.194 fastdtw setuptools>=40.1.0 h5py diff --git a/setup.py b/setup.py index 16814d959c..2ebaf479c1 100644 --- a/setup.py +++ b/setup.py @@ -32,7 +32,7 @@ "psutil>=5", "scikit-learn>=0.20.0", "dlx", - "docplex", + "docplex==2.15.194", "fastdtw", "setuptools>=40.1.0", "h5py",