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

Commit

Permalink
Fix lint errors for test/aqua
Browse files Browse the repository at this point in the history
  • Loading branch information
manoelmarques committed Aug 16, 2019
1 parent 6ad381d commit cddd8ab
Show file tree
Hide file tree
Showing 72 changed files with 1,468 additions and 1,229 deletions.
4 changes: 2 additions & 2 deletions Makefile
Expand Up @@ -14,8 +14,8 @@
.PHONY: lint style test

lint:
pylint -rn --errors-only --enable=invalid-file-header --ignore=gauopen qiskit/aqua qiskit/chemistry test
pylint -rn test/chemistry
pylint -rn --errors-only --enable=invalid-file-header --ignore=gauopen qiskit/aqua qiskit/chemistry
pylint -rn test

style:
pycodestyle --max-line-length=210 --exclude=gauopen qiskit/aqua qiskit/chemistry test
Expand Down
26 changes: 13 additions & 13 deletions qiskit/aqua/_discover.py
Expand Up @@ -151,8 +151,8 @@ def _discover_entry_point_pluggables():
# first calls require and log any errors returned due to dependencies mismatches
try:
entry_point.require()
except Exception as e:
logger.warning("Entry point '{}' requirements issue: {}".format(entry_point, str(e)))
except Exception as ex: # pylint: disable=broad-except
logger.warning("Entry point '{}' requirements issue: {}".format(entry_point, str(ex)))

# now call resolve and try to load entry point
try:
Expand All @@ -169,10 +169,10 @@ def _discover_entry_point_pluggables():
if not _registered:
# print("Unknown entry point pluggable '{}' class '{}'".format(entry_point, ep))
logger.debug("Unknown entry point pluggable '{}' class '{}'".format(entry_point, ep))
except Exception as e:
except Exception as ex: # pylint: disable=broad-except
# Ignore entry point that could not be initialized.
# print("Failed to load entry point '{}' error {}".format(entry_point, str(e)))
logger.debug("Failed to load entry point '{}' error {}".format(entry_point, str(e)))
logger.debug("Failed to load entry point '{}' error {}".format(entry_point, str(ex)))


def _discover_local_pluggables(directory=os.path.dirname(__file__),
Expand Down Expand Up @@ -207,15 +207,15 @@ def _discover_local_pluggables(directory=os.path.dirname(__file__),
_register_pluggable(pluggable_type, cls)
importlib.import_module(fullname)
break
except Exception as e:
except Exception as ex: # pylint: disable=broad-except
# Ignore pluggables that could not be initialized.
# print('Failed to load pluggable {} error {}'.format(fullname, str(e)))
logger.debug('Failed to load pluggable {} error {}'.format(fullname, str(e)))
# print('Failed to load pluggable {} error {}'.format(fullname, str(ex)))
logger.debug('Failed to load pluggable {} error {}'.format(fullname, str(ex)))

except Exception as e:
except Exception as ex: # pylint: disable=broad-except
# Ignore pluggables that could not be initialized.
# print('Failed to load {} error {}'.format(fullname, str(e)))
logger.debug('Failed to load {} error {}'.format(fullname, str(e)))
# print('Failed to load {} error {}'.format(fullname, str(ex)))
logger.debug('Failed to load {} error {}'.format(fullname, str(ex)))

for item in sorted(os.listdir(directory)):
fullpath = os.path.join(directory, item)
Expand Down Expand Up @@ -285,9 +285,9 @@ def _register_pluggable(pluggable_type, cls):
try:
# pylint: disable=not-callable
check_pluggable_valid()
except Exception as e:
logger.debug(str(e))
raise AquaError('Could not register class {}. Name {} is not valid'.format(cls, pluggable_name)) from e
except Exception as ex: # pylint: disable=broad-except
logger.debug(str(ex))
raise AquaError('Could not register class {}. Name {} is not valid'.format(cls, pluggable_name)) from ex

if pluggable_name in _REGISTERED_PLUGGABLES[pluggable_type]:
raise AquaError('Could not register class {}. Name {} {} '
Expand Down
6 changes: 3 additions & 3 deletions qiskit/aqua/algorithms/classical/cplex/cplex_ising.py
Expand Up @@ -89,9 +89,9 @@ def check_pluggable_valid():
spec = importlib.util.find_spec('cplex.exceptions')
if spec is not None:
return
except Exception as e:
logger.debug('{} {}'.format(err_msg, str(e)))
raise AquaError(err_msg) from e
except Exception as ex: # pylint: disable=broad-except
logger.debug('{} {}'.format(err_msg, str(ex)))
raise AquaError(err_msg) from ex

raise AquaError(err_msg)

Expand Down
Expand Up @@ -140,9 +140,9 @@ def check_pluggable_valid():
spec = importlib.util.find_spec('torch.nn')
if spec is not None:
return
except Exception as e:
logger.debug('{} {}'.format(err_msg, str(e)))
raise AquaError(err_msg) from e
except Exception as ex: # pylint: disable=broad-except
logger.debug('{} {}'.format(err_msg, str(ex)))
raise AquaError(err_msg) from ex

raise AquaError(err_msg)

Expand Down
6 changes: 3 additions & 3 deletions qiskit/aqua/components/optimizers/nlopts/_nloptimizer.py
Expand Up @@ -30,9 +30,9 @@ def check_pluggable_valid(name):
spec = importlib.util.find_spec('nlopt')
if spec is not None:
return
except Exception as e:
logger.debug('{} {}'.format(err_msg, str(e)))
raise AquaError(err_msg) from e
except Exception as ex: # pylint: disable=broad-except
logger.debug('{} {}'.format(err_msg, str(ex)))
raise AquaError(err_msg) from ex

raise AquaError(err_msg)

Expand Down
4 changes: 2 additions & 2 deletions qiskit/aqua/parser/json_schema.py
Expand Up @@ -422,8 +422,8 @@ def update_backend_schema(self, input_parser):
noise_model_devices.append('qiskit.IBMQ:' + backend_name)
if check_coupling_map and ibmq_backend.configuration().coupling_map:
coupling_map_devices.append('qiskit.IBMQ:' + backend_name)
except Exception as e:
logger.debug("Failed to load IBMQ backends. Error {}".format(str(e)))
except Exception as ex: # pylint: disable=broad-except
logger.debug("Failed to load IBMQ backends. Error {}".format(str(ex)))

# Includes 'coupling map' and 'coupling_map_from_device' in schema only if a simulator backend.
# Actual devices have a coupling map based on the physical configuration of the device.
Expand Down
4 changes: 2 additions & 2 deletions qiskit/aqua/qiskit_aqua_globals.py
Expand Up @@ -62,9 +62,9 @@ def num_processes(self, num_processes):
# TODO: change Terra CPU_COUNT until issue gets resolved: https://github.com/Qiskit/qiskit-terra/issues/1963
try:
qiskit.tools.parallel.CPU_COUNT = self.num_processes
except Exception as e:
except Exception as ex: # pylint: disable=broad-except
logger.warning("Failed to set qiskit.tools.parallel.CPU_COUNT to value: '{}': Error: '{}'".
format(self.num_processes, str(e)))
format(self.num_processes, str(ex)))

@property
def random(self):
Expand Down
Expand Up @@ -173,7 +173,7 @@ def run(self):
for q in quotes:
priceEvolution.append(q["ask_price"])
self._data.append(priceEvolution)
except Exception as e:
except Exception as ex: # pylint: disable=broad-except
raise QiskitFinanceError(
'Accessing NASDAQ Data on Demand failed.') from e
'Accessing NASDAQ Data on Demand failed.') from ex
http.clear()
11 changes: 6 additions & 5 deletions qiskit/aqua/translators/data_providers/exchange_data_provider.py
Expand Up @@ -106,9 +106,9 @@ def check_provider_valid():
spec = importlib.util.find_spec('quandl')
if spec is not None:
return
except Exception as e:
logger.debug('quandl check error {}'.format(str(e)))
raise QiskitFinanceError(err_msg) from e
except Exception as ex: # pylint: disable=broad-except
logger.debug('quandl check error {}'.format(str(ex)))
raise QiskitFinanceError(err_msg) from ex

raise QiskitFinanceError(err_msg)

Expand Down Expand Up @@ -147,9 +147,10 @@ def run(self):
d = quandl.get(self._stockmarket + "/" + s,
start_date=self._start,
end_date=self._end)
except Exception as e: # The exception will be AuthenticationError, if the token is wrong
# The exception will be AuthenticationError, if the token is wrong
except Exception as ex: # pylint: disable=broad-except
raise QiskitFinanceError(
"Cannot retrieve Exchange Data data.") from e
"Cannot retrieve Exchange Data data.") from ex
try:
self._data.append(d["Adj. Close"])
except KeyError as e:
Expand Down
19 changes: 10 additions & 9 deletions qiskit/aqua/translators/data_providers/wikipedia_data_provider.py
Expand Up @@ -107,9 +107,9 @@ def check_provider_valid():
spec = importlib.util.find_spec('quandl')
if spec is not None:
return
except Exception as e:
logger.debug('quandl check error {}'.format(str(e)))
raise QiskitFinanceError(err_msg) from e
except Exception as ex: # pylint: disable=broad-except
logger.debug('quandl check error {}'.format(str(ex)))
raise QiskitFinanceError(err_msg) from ex

raise QiskitFinanceError(err_msg)

Expand Down Expand Up @@ -148,14 +148,15 @@ def run(self):
d = quandl.get("WIKI/" + s,
start_date=self._start,
end_date=self._end)
except NotFoundError as e:
except NotFoundError as ex:
raise QiskitFinanceError(
"Cannot retrieve Wikipedia data due to an invalid token."
) from e
except Exception as e: # The exception will be urllib3 NewConnectionError, but it can get dressed by quandl
) from ex
# The exception will be urllib3 NewConnectionError, but it can get dressed by quandl
except Exception as ex: # pylint: disable=broad-except
raise QiskitFinanceError(
"Cannot retrieve Wikipedia data.") from e
"Cannot retrieve Wikipedia data.") from ex
try:
self._data.append(d["Adj. Close"])
except KeyError as e:
raise QiskitFinanceError("Cannot parse quandl output.") from e
except KeyError as ex:
raise QiskitFinanceError("Cannot parse quandl output.") from ex
4 changes: 2 additions & 2 deletions qiskit/aqua/utils/backend_utils.py
Expand Up @@ -273,8 +273,8 @@ def get_local_providers():
for provider in ['qiskit.Aer', 'qiskit.BasicAer']:
try:
providers[provider] = get_backends_from_provider(provider)
except Exception as e:
logger.debug("'{}' not loaded: '{}'.".format(provider, str(e)))
except Exception as ex: # pylint: disable=broad-except
logger.debug("'{}' not loaded: '{}'.".format(provider, str(ex)))

return providers

Expand Down
4 changes: 2 additions & 2 deletions qiskit/aqua/utils/dataset_helper.py
Expand Up @@ -81,9 +81,9 @@ def split_dataset_to_data_and_labels(dataset, class_names=None):
data.append(value)
try:
labels.append(class_to_label[class_name])
except Exception as e:
except Exception as ex: # pylint: disable=broad-except
raise KeyError('The dataset has different class names to '
'the training data. error message: {}'.format(e))
'the training data. error message: {}'.format(ex))
data = np.asarray(data)
labels = np.asarray(labels)
if class_names is None:
Expand Down
16 changes: 8 additions & 8 deletions qiskit/aqua/utils/run_circuits.py
Expand Up @@ -258,12 +258,12 @@ def _safe_submit_qobj(qobj, backend, backend_options, noise_config, skip_qobj_va
try:
job_id = job.job_id()
break
except JobError as e:
except JobError as ex:
logger.warning("FAILURE: Can not get job id, Resubmit the qobj to get job id."
"Terra job error: {} ".format(e))
except Exception as e:
"Terra job error: {} ".format(ex))
except Exception as ex: # pylint: disable=broad-except
logger.warning("FAILURE: Can not get job id, Resubmit the qobj to get job id."
"Error: {} ".format(e))
"Error: {} ".format(ex))

return job, job_id

Expand All @@ -274,15 +274,15 @@ def _safe_get_job_status(job, job_id):
try:
job_status = job.status()
break
except JobError as e:
except JobError as ex:
logger.warning("FAILURE: job id: {}, "
"status: 'FAIL_TO_GET_STATUS' "
"Terra job error: {}".format(job_id, e))
"Terra job error: {}".format(job_id, ex))
time.sleep(5)
except Exception as e:
except Exception as ex: # pylint: disable=broad-except
raise AquaError("FAILURE: job id: {}, "
"status: 'FAIL_TO_GET_STATUS' "
"Unknown error: ({})".format(job_id, e)) from e
"Unknown error: ({})".format(job_id, ex)) from ex
return job_status


Expand Down
16 changes: 8 additions & 8 deletions qiskit/chemistry/core/_discover_chemoperator.py
Expand Up @@ -83,8 +83,8 @@ def _discover_entry_point_chemistry_operators():
# first calls require and log any errors returned due to dependencies mismatches
try:
entry_point.require()
except Exception as e:
logger.warning("Entry point '{}' requirements issue: {}".format(entry_point, str(e)))
except Exception as ex: # pylint: disable=broad-except
logger.warning("Entry point '{}' requirements issue: {}".format(entry_point, str(ex)))

# now call resolve and try to load entry point
try:
Expand All @@ -100,10 +100,10 @@ def _discover_entry_point_chemistry_operators():
if not _registered:
# print("Unknown entry point chemistry operator '{}' class '{}'".format(entry_point, ep))
logger.debug("Unknown entry point chemistry operator '{}' class '{}'".format(entry_point, ep))
except Exception as e:
except Exception as ex: # pylint: disable=broad-except
# Ignore entry point that could not be initialized.
# print("Failed to load entry point '{}' error {}".format(entry_point, str(e)))
logger.debug("Failed to load entry point '{}' error {}".format(entry_point, str(e)))
logger.debug("Failed to load entry point '{}' error {}".format(entry_point, str(ex)))


def _discover_local_chemistry_operators(directory=os.path.dirname(__file__),
Expand Down Expand Up @@ -139,14 +139,14 @@ def _discover_local_chemistry_operators(directory=os.path.dirname(__file__),
issubclass(cls, ChemistryOperator):
_register_chemistry_operator(cls)
importlib.import_module(fullname)
except Exception as e:
except Exception as ex: # pylint: disable=broad-except
# Ignore operator that could not be initialized.
logger.debug(
'Failed to load {} error {}'.format(fullname, str(e)))
except Exception as e:
'Failed to load {} error {}'.format(fullname, str(ex)))
except Exception as ex: # pylint: disable=broad-except
# Ignore operator that could not be initialized.
logger.debug(
'Failed to load {} error {}'.format(fullname, str(e)))
'Failed to load {} error {}'.format(fullname, str(ex)))

for item in os.listdir(directory):
fullpath = os.path.join(directory, item)
Expand Down
22 changes: 11 additions & 11 deletions qiskit/chemistry/drivers/_discover_driver.py
Expand Up @@ -77,8 +77,8 @@ def _discover_entry_point_chemistry_drivers():
# first calls require and log any errors returned due to dependencies mismatches
try:
entry_point.require()
except Exception as e:
logger.warning("Entry point '{}' requirements issue: {}".format(entry_point, str(e)))
except Exception as ex: # pylint: disable=broad-except
logger.warning("Entry point '{}' requirements issue: {}".format(entry_point, str(ex)))

# now call resolve and try to load entry point
try:
Expand All @@ -94,10 +94,10 @@ def _discover_entry_point_chemistry_drivers():
if not _registered:
# print("Unknown entry point chemistry driver '{}' class '{}'".format(entry_point, ep))
logger.debug("Unknown entry point chemistry driver '{}' class '{}'".format(entry_point, ep))
except Exception as e:
except Exception as ex: # pylint: disable=broad-except
# Ignore entry point that could not be initialized.
# print("Failed to load entry point '{}' error {}".format(entry_point, str(e)))
logger.debug("Failed to load entry point '{}' error {}".format(entry_point, str(e)))
logger.debug("Failed to load entry point '{}' error {}".format(entry_point, str(ex)))


def _discover_local_drivers(directory=os.path.dirname(__file__),
Expand Down Expand Up @@ -133,12 +133,12 @@ def _discover_local_drivers(directory=os.path.dirname(__file__),
issubclass(cls, BaseDriver):
_register_driver(cls)
importlib.import_module(fullname)
except Exception as e:
except Exception as ex: # pylint: disable=broad-except
# Ignore operator that could not be initialized.
logger.debug('Failed to load {} error {}'.format(fullname, str(e)))
except Exception as e:
logger.debug('Failed to load {} error {}'.format(fullname, str(ex)))
except Exception as ex: # pylint: disable=broad-except
# Ignore operator that could not be initialized.
logger.debug('Failed to load {} error {}'.format(fullname, str(e)))
logger.debug('Failed to load {} error {}'.format(fullname, str(ex)))

for item in os.listdir(directory):
fullpath = os.path.join(directory, item)
Expand Down Expand Up @@ -177,9 +177,9 @@ def _register_driver(cls):
if check_driver_valid is not None:
try:
check_driver_valid()
except Exception as e:
logger.debug(str(e))
raise QiskitChemistryError('Could not register class {}. Name {} is not valid'.format(cls, driver_name)) from e
except Exception as ex: # pylint: disable=broad-except
logger.debug(str(ex))
raise QiskitChemistryError('Could not register class {}. Name {} is not valid'.format(cls, driver_name)) from ex

if driver_name in _REGISTERED_DRIVERS:
raise QiskitChemistryError('Could not register class {}. Name {} {} is already registered'.format(cls,
Expand Down
6 changes: 3 additions & 3 deletions qiskit/chemistry/drivers/pyquanted/pyquantedriver.py
Expand Up @@ -144,9 +144,9 @@ def check_driver_valid():
spec = importlib.util.find_spec('pyquante2')
if spec is not None:
return
except Exception as e:
logger.debug('PyQuante2 check error {}'.format(str(e)))
raise QiskitChemistryError(err_msg) from e
except Exception as ex: # pylint: disable=broad-except
logger.debug('PyQuante2 check error {}'.format(str(ex)))
raise QiskitChemistryError(err_msg) from ex

raise QiskitChemistryError(err_msg)

Expand Down
6 changes: 3 additions & 3 deletions qiskit/chemistry/drivers/pyscfd/pyscfdriver.py
Expand Up @@ -156,9 +156,9 @@ def check_driver_valid():
spec = importlib.util.find_spec('pyscf')
if spec is not None:
return
except Exception as e:
logger.debug('PySCF check error {}'.format(str(e)))
raise QiskitChemistryError(err_msg) from e
except Exception as ex: # pylint: disable=broad-except
logger.debug('PySCF check error {}'.format(str(ex)))
raise QiskitChemistryError(err_msg) from ex

raise QiskitChemistryError(err_msg)

Expand Down
2 changes: 1 addition & 1 deletion test/aqua/integrity/load_aqua.py
Expand Up @@ -27,7 +27,7 @@ def _load_aqua():
try:
import qiskit
qiskit.aqua.__version__
except Exception as ex:
except Exception as ex: # pylint: disable=broad-except
return _exception_to_string(ex)

return None
Expand Down

0 comments on commit cddd8ab

Please sign in to comment.