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..0f1d6fed63 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 @@ -21,14 +21,7 @@ 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 - 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-terra/archive/master.zip + # pip install https://github.com/Qiskit/qiskit-ignis/archive/master.zip + # 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/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/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/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/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/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/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..bd6f82f29d 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 @@ -57,12 +57,19 @@ """ -from typing import Tuple +from typing import Tuple, Union, List import logging from math import fsum import numpy as np from docplex.mp.constants import ComparisonType +from docplex.mp.constr import LinearConstraint, QuadraticConstraint +try: + # new location for 2.16.196 (Nov 2020) or newer + from docplex.mp.dvar import Var +except ImportError: + # old location for 2.15.194 (Jul 2020) or before + from docplex.mp.linear import Var from docplex.mp.model import Model from qiskit.quantum_info import Pauli @@ -113,8 +120,8 @@ def get_operator(mdl: Model, auto_penalty: bool = True, # initialize Hamiltonian. num_nodes = len(q_d) pauli_list = [] - shift = 0 - zero = np.zeros(num_nodes, dtype=np.bool) + shift = 0. + 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 +129,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 +147,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)]) @@ -157,14 +164,16 @@ def get_operator(mdl: Model, auto_penalty: bool = True, # convert constraints into penalty terms. for constraint in mdl.iter_constraints(): - constant = constraint.cplex_num_rhs() + right_cst = constraint.get_right_expr().get_constant() + left_cst = constraint.get_left_expr().get_constant() + constant = float(right_cst - left_cst) # constant parts of penalty*(Constant-func)**2: penalty*(Constant**2) shift += penalty * constant ** 2 # 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) + for __l in _iter_net_linear_coeffs(constraint): + z_p = np.zeros(num_nodes, dtype=bool) index = q_d[__l[0]] weight = __l[1] z_p[index] = True @@ -173,8 +182,8 @@ def get_operator(mdl: Model, auto_penalty: bool = True, shift += -penalty * constant * weight # quadratic parts of penalty*(Constant-func)**2: penalty*(func**2) - for __l in constraint.iter_net_linear_coefs(): - for l_2 in constraint.iter_net_linear_coefs(): + for __l in _iter_net_linear_coeffs(constraint): + for l_2 in _iter_net_linear_coeffs(constraint): index1 = q_d[__l[0]] index2 = q_d[l_2[0]] weight1 = __l[1] @@ -184,16 +193,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)]) @@ -205,6 +214,33 @@ def get_operator(mdl: Model, auto_penalty: bool = True, return qubit_op, shift +def _iter_net_linear_coeffs(constraint: Union[LinearConstraint, QuadraticConstraint]) \ + -> List[Tuple[Var, float]]: + """ + Builds a list of tuples, where each tuple contains a decision variable and a + corresponding coefficient of this variable in the constraint. + Args: + constraint: A constraint to analyze. + Returns: + A list of tuples of variables and coefficients. + """ + left_expr = constraint.get_left_expr() + right_expr = constraint.get_right_expr() + # for linear constraints we may get an instance of Var instead of expression, + # e.g. x + y = z + if isinstance(left_expr, Var): + left_expr = left_expr + 0 + if isinstance(right_expr, Var): + right_expr = right_expr + 0 + + variables = {} + for var in left_expr.iter_variables(): + variables[var] = left_expr.get_coef(var) + for var in right_expr.iter_variables(): + variables[var] = variables.get(var, 0.0) - right_expr.get_coef(var) + return list(variables.items()) + + def _validate_input_model(mdl: Model) -> None: """Check whether an input model is valid. If not, raise an AquaError. 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 d756487016..5a88cc47d7 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 @@ -19,13 +19,18 @@ 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, QuadraticConstraint as DocplexQuadraticConstraint, NotEqualConstraint) -from docplex.mp.linear import Var +try: + # new location for 2.16.196 (Nov 2020) or newer + from docplex.mp.dvar import Var +except ImportError: + # old location for 2.15.194 (Jul 2020) or before + from docplex.mp.linear import Var from docplex.mp.model import Model from docplex.mp.model_reader import ModelReader from docplex.mp.quad import QuadExpr @@ -561,11 +566,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( @@ -591,7 +596,7 @@ def from_docplex(self, model: Model) -> None: # get quadratic part of objective quadratic = {} if isinstance(model.objective_expr, QuadExpr): - for quad_triplet in model.objective_expr.generate_quad_triplets(): + for quad_triplet in model.objective_expr.iter_quad_triplets(): i = var_names[quad_triplet[0]] j = var_names[quad_triplet[1]] v = quad_triplet[2] @@ -618,15 +623,22 @@ def from_docplex(self, model: Model) -> None: name = constraint.name sense = constraint.sense - rhs = 0 - if not isinstance(constraint.lhs, Var): - rhs -= constraint.lhs.constant - if not isinstance(constraint.rhs, Var): - rhs += constraint.rhs.constant + left_expr = constraint.get_left_expr() + right_expr = constraint.get_right_expr() + # for linear constraints we may get an instance of Var instead of expression, + # e.g. x + y = z + if isinstance(left_expr, Var): + left_expr = left_expr + 0 + if isinstance(right_expr, Var): + right_expr = right_expr + 0 + + rhs = right_expr.constant - left_expr.constant lhs = {} - for x in constraint.iter_net_linear_coefs(): - lhs[var_names[x[0]]] = x[1] + for x in left_expr.iter_variables(): + lhs[var_names[x]] = left_expr.get_coef(x) + for x in right_expr.iter_variables(): + lhs[var_names[x]] = lhs.get(var_names[x], 0.0) - right_expr.get_coef(x) if sense == sense.EQ: self.linear_constraint(lhs, '==', rhs, name) @@ -916,23 +928,23 @@ 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. 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(): - z_p = zeros(num_nodes, dtype=nbool) + z_p = zeros(num_nodes, dtype=bool) weight = coef * sense / 2 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,22 +961,22 @@ 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 = 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)]) - 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) 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/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 d1bebe2cee..2ebaf479c1 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 @@ -32,7 +32,7 @@ "psutil>=5", "scikit-learn>=0.20.0", "dlx", - "docplex", + "docplex==2.15.194", "fastdtw", "setuptools>=40.1.0", "h5py", @@ -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/test/aqua/test_amplitude_estimation.py b/test/aqua/test_amplitude_estimation.py index 02e6086775..7fdcda6a68 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) @@ -417,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): 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..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 @@ -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) diff --git a/tox.ini b/tox.ini index a8e32e04cc..784d5e360b 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,34 @@ 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 + -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]