Skip to content
This repository has been archived by the owner on Dec 7, 2021. It is now read-only.

Commit

Permalink
Remove DeprecationWarning of np.int, np.float, np.bool, np.complex
Browse files Browse the repository at this point in the history
  • Loading branch information
manoelmarques committed Feb 1, 2021
1 parent 7775410 commit eb52244
Show file tree
Hide file tree
Showing 33 changed files with 142 additions and 140 deletions.
6 changes: 4 additions & 2 deletions .github/actions/install-aqua/action.yml
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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 .[torch,cplex,cvx,pyscf,skquant]
pip install -U -c constraints.txt -r requirements-dev.txt
shell: bash
4 changes: 2 additions & 2 deletions qiskit/aqua/algorithms/classifiers/qsvm/_qsvm_binary.py
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -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]
Expand Down
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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')
Expand Down Expand Up @@ -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

Expand Down
4 changes: 2 additions & 2 deletions qiskit/aqua/components/multiclass_extensions/all_pairs.py
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -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))
Expand Down
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -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]):
Expand Down
8 changes: 4 additions & 4 deletions qiskit/aqua/operators/legacy/common.py
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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)
Expand Down
10 changes: 5 additions & 5 deletions qiskit/aqua/operators/legacy/weighted_pauli_operator.py
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -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__))
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand Down
4 changes: 2 additions & 2 deletions qiskit/aqua/operators/primitive_ops/pauli_op.py
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -221,7 +221,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))
Expand Down
4 changes: 2 additions & 2 deletions qiskit/aqua/operators/primitive_ops/pauli_sum_op.py
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -254,7 +254,7 @@ def eval(
coeffs = self.primitive.coeffs # 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 * bs)) for bs in new_b_str]
z_factor = np.product(1 - 2 * np.logical_and(bitstr, corrected_z_bits), axis=1)
Expand Down
8 changes: 4 additions & 4 deletions qiskit/aqua/utils/random_matrix_generator.py
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -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
Expand All @@ -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)
Expand All @@ -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
Expand Down
4 changes: 2 additions & 2 deletions qiskit/chemistry/bksf.py
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -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

Expand Down
18 changes: 9 additions & 9 deletions qiskit/chemistry/bosonic_operator.py
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -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)))

Expand Down Expand Up @@ -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)

Expand Down
10 changes: 5 additions & 5 deletions qiskit/chemistry/circuit/library/initial_states/hartree_fock.py
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -99,15 +99,15 @@ def hartree_fock_bitstring(num_orbitals: int,
raise ValueError('# of particles must be less than or equal to # of orbitals.')

half_orbitals = num_orbitals // 2
bitstr = np.zeros(num_orbitals, np.bool)
bitstr = np.zeros(num_orbitals, bool)
bitstr[-num_alpha:] = True
bitstr[-(half_orbitals + num_beta):-half_orbitals] = True

if qubit_mapping == 'parity':
new_bitstr = bitstr.copy()

t_r = np.triu(np.ones((num_orbitals, 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 two_qubit_reduction else new_bitstr
Expand All @@ -122,10 +122,10 @@ def hartree_fock_bitstring(num_orbitals: int,
start_idx = beta.shape[0] - 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 sq_list is not None:
sq_list = [len(bitstr) - 1 - position for position in sq_list]
bitstr = np.delete(bitstr, sq_list)

return bitstr.astype(np.bool)
return bitstr.astype(bool)
4 changes: 2 additions & 2 deletions qiskit/chemistry/circuit/library/initial_states/vscf.py
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -60,7 +60,7 @@ def vscf_bitstring(basis: List[int]) -> np.ndarray:
The bitstring representing the state of the VSCF state as array of bools.
"""
num_qubits = sum(basis)
bitstr = np.zeros(num_qubits, np.bool)
bitstr = np.zeros(num_qubits, bool)
count = 0
for modal in basis:
bitstr[num_qubits - count - 1] = True
Expand Down
4 changes: 2 additions & 2 deletions qiskit/chemistry/components/variational_forms/uccsd.py
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -452,7 +452,7 @@ def preferred_init_points(self):
if self._initial_state is None:
return None
else:
return np.zeros(self._num_parameters, dtype=np.float)
return np.zeros(self._num_parameters, dtype=float)

@staticmethod
def compute_excitation_lists(num_particles, num_orbitals, active_occ_list=None,
Expand Down
Loading

0 comments on commit eb52244

Please sign in to comment.