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

Add doctest to travis #894

Merged
merged 2 commits into from
Apr 9, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 7 additions & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,13 @@ jobs:
- sudo apt-get -y install python3-enchant
- sudo apt-get -y install hunspell-en-us
- pip install pyenchant
script: make -k all_check SPHINXOPTS=-W
script:
- make spell
- make style
- make lint
- make copyright
- make html SPHINXOPTS=-W
- make doctest
- name: "Test Aqua 1 Python 3.7"
<<: *stage_test_aqua
if: tag IS blank
Expand Down
7 changes: 5 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -35,9 +35,9 @@ endif
# You can set this variable from the command line.
SPHINXOPTS =

.PHONY: lint style test test_ci spell copyright html coverage coverage_erase
.PHONY: lint style test test_ci spell copyright html doctest coverage coverage_erase

all_check: spell style lint copyright html
all_check: spell style lint copyright html doctest

lint:
pylint -rn --ignore=gauopen qiskit/aqua qiskit/chemistry qiskit/finance qiskit/ml qiskit/optimization test tools
Expand All @@ -60,6 +60,9 @@ copyright:

html:
make -C docs html SPHINXOPTS=$(SPHINXOPTS)

doctest:
make -C docs doctest SPHINXOPTS=$(SPHINXOPTS)

coverage:
coverage3 run --source qiskit/aqua,qiskit/chemistry,qiskit/finance,qiskit/ml,qiskit/optimization --omit */gauopen/* -m unittest discover -s test -q
Expand Down
1 change: 1 addition & 0 deletions docs/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@
'jupyter_sphinx.execute',
'sphinx_autodoc_typehints',
'reno.sphinxext',
'sphinx.ext.doctest',
]
html_static_path = ['_static']
templates_path = ['_templates']
Expand Down
17 changes: 8 additions & 9 deletions qiskit/ml/datasets/ad_hoc.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,6 @@
import numpy as np
import scipy
from qiskit.aqua import aqua_globals
try:
import matplotlib.pyplot as plt
HAS_MATPLOTLIB = True
except ImportError:
HAS_MATPLOTLIB = False


def ad_hoc_data(training_size, test_size, n, gap, plot_data=False):
Expand Down Expand Up @@ -151,8 +146,10 @@ def ad_hoc_data(training_size, test_size, n, gap, plot_data=False):
training_size+test_size)] for k, key in enumerate(class_labels)}

if plot_data:
if not HAS_MATPLOTLIB:
raise NameError('Matplotlib not installed. Plase install it before plotting')
try:
import matplotlib.pyplot as plt
except ImportError:
raise NameError('Matplotlib not installed. Please install it before plotting')

plt.show()
fig2 = plt.figure()
Expand Down Expand Up @@ -222,8 +219,10 @@ def ad_hoc_data(training_size, test_size, n, gap, plot_data=False):
training_size+test_size)] for k, key in enumerate(class_labels)}

if plot_data:
if not HAS_MATPLOTLIB:
raise NameError('Matplotlib not installed. Plase install it before plotting')
try:
import matplotlib.pyplot as plt
except ImportError:
raise NameError('Matplotlib not installed. Please install it before plotting')
sample_total_a = np.asarray(sample_total_a)
sample_total_b = np.asarray(sample_total_b)
x_1 = sample_total_a[:, 0]
Expand Down
13 changes: 5 additions & 8 deletions qiskit/ml/datasets/breast_cancer.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

# This code is part of Qiskit.
#
# (C) Copyright IBM 2018, 2019.
# (C) Copyright IBM 2018, 2020.
#
# This code is licensed under the Apache License, Version 2.0. You may
# obtain a copy of this license in the LICENSE.txt file in the root directory
Expand All @@ -21,11 +21,6 @@
from sklearn.model_selection import train_test_split
from sklearn.preprocessing import StandardScaler, MinMaxScaler
from sklearn.decomposition import PCA
try:
import matplotlib.pyplot as plt
HAS_MATPLOTLIB = True
except ImportError:
HAS_MATPLOTLIB = False


def breast_cancer(training_size, test_size, n, plot_data=False):
Expand Down Expand Up @@ -58,8 +53,10 @@ def breast_cancer(training_size, test_size, n, plot_data=False):
for k, key in enumerate(class_labels)}

if plot_data:
if not HAS_MATPLOTLIB:
raise NameError('Matplotlib not installed. Plase install it before plotting')
try:
import matplotlib.pyplot as plt
except ImportError:
raise NameError('Matplotlib not installed. Please install it before plotting')
for k in range(0, 2):
plt.scatter(sample_train[label_train == k, 0][:training_size],
sample_train[label_train == k, 1][:training_size])
Expand Down
13 changes: 5 additions & 8 deletions qiskit/ml/datasets/digits.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

# This code is part of Qiskit.
#
# (C) Copyright IBM 2018, 2019.
# (C) Copyright IBM 2018, 2020.
#
# This code is licensed under the Apache License, Version 2.0. You may
# obtain a copy of this license in the LICENSE.txt file in the root directory
Expand All @@ -21,11 +21,6 @@
from sklearn.model_selection import train_test_split
from sklearn.preprocessing import StandardScaler, MinMaxScaler
from sklearn.decomposition import PCA
try:
import matplotlib.pyplot as plt
HAS_MATPLOTLIB = True
except ImportError:
HAS_MATPLOTLIB = False


def digits(training_size, test_size, n, plot_data=False):
Expand Down Expand Up @@ -59,8 +54,10 @@ def digits(training_size, test_size, n, plot_data=False):
for k, key in enumerate(class_labels)}

if plot_data:
if not HAS_MATPLOTLIB:
raise NameError('Matplotlib not installed. Plase install it before plotting')
try:
import matplotlib.pyplot as plt
except ImportError:
raise NameError('Matplotlib not installed. Please install it before plotting')
for k in range(0, 9):
plt.scatter(sample_train[label_train == k, 0][:training_size],
sample_train[label_train == k, 1][:training_size])
Expand Down
17 changes: 8 additions & 9 deletions qiskit/ml/datasets/gaussian.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,6 @@

import numpy as np
from qiskit.aqua import aqua_globals
try:
import matplotlib.pyplot as plt
HAS_MATPLOTLIB = True
except ImportError:
HAS_MATPLOTLIB = False


def gaussian(training_size, test_size, n, plot_data=False):
Expand Down Expand Up @@ -61,8 +56,10 @@ def gaussian(training_size, test_size, n, plot_data=False):
training_size+test_size)] for k, key in enumerate(class_labels)}

if plot_data:
if not HAS_MATPLOTLIB:
raise NameError('Matplotlib not installed. Plase install it before plotting')
try:
import matplotlib.pyplot as plt
except ImportError:
raise NameError('Matplotlib not installed. Please install it before plotting')

for k in range(0, 2):
plt.scatter(sample_train[label_train == k, 0][:training_size],
Expand Down Expand Up @@ -120,8 +117,10 @@ def gaussian(training_size, test_size, n, plot_data=False):
training_size+test_size)] for k, key in enumerate(class_labels)}

if plot_data:
if not HAS_MATPLOTLIB:
raise NameError('Matplotlib not installed. Plase install it before plotting')
try:
import matplotlib.pyplot as plt
except ImportError:
raise NameError('Matplotlib not installed. Please install it before plotting')

for k in range(0, 3):
plt.scatter(sample_train[label_train == k, 0][:training_size],
Expand Down
13 changes: 5 additions & 8 deletions qiskit/ml/datasets/iris.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

# This code is part of Qiskit.
#
# (C) Copyright IBM 2018, 2019.
# (C) Copyright IBM 2018, 2020.
#
# This code is licensed under the Apache License, Version 2.0. You may
# obtain a copy of this license in the LICENSE.txt file in the root directory
Expand All @@ -21,11 +21,6 @@
from sklearn.model_selection import train_test_split
from sklearn.preprocessing import StandardScaler, MinMaxScaler
from sklearn.decomposition import PCA
try:
import matplotlib.pyplot as plt
HAS_MATPLOTLIB = True
except ImportError:
HAS_MATPLOTLIB = False


def iris(training_size, test_size, n, plot_data=False):
Expand Down Expand Up @@ -58,8 +53,10 @@ def iris(training_size, test_size, n, plot_data=False):
for k, key in enumerate(class_labels)}

if plot_data:
if not HAS_MATPLOTLIB:
raise NameError('Matplotlib not installed. Plase install it before plotting')
try:
import matplotlib.pyplot as plt
except ImportError:
raise NameError('Matplotlib not installed. Please install it before plotting')
for k in range(0, 3):
plt.scatter(sample_train[label_train == k, 0][:training_size],
sample_train[label_train == k, 1][:training_size])
Expand Down
13 changes: 5 additions & 8 deletions qiskit/ml/datasets/wine.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

# This code is part of Qiskit.
#
# (C) Copyright IBM 2018, 2019.
# (C) Copyright IBM 2018, 2020.
#
# This code is licensed under the Apache License, Version 2.0. You may
# obtain a copy of this license in the LICENSE.txt file in the root directory
Expand All @@ -21,11 +21,6 @@
from sklearn.model_selection import train_test_split
from sklearn.preprocessing import StandardScaler, MinMaxScaler
from sklearn.decomposition import PCA
try:
import matplotlib.pyplot as plt
HAS_MATPLOTLIB = True
except ImportError:
HAS_MATPLOTLIB = False


def wine(training_size, test_size, n, plot_data=False):
Expand Down Expand Up @@ -58,8 +53,10 @@ def wine(training_size, test_size, n, plot_data=False):
for k, key in enumerate(class_labels)}

if plot_data:
if not HAS_MATPLOTLIB:
raise NameError('Matplotlib not installed. Plase install it before plotting')
try:
import matplotlib.pyplot as plt
except ImportError:
raise NameError('Matplotlib not installed. Please install it before plotting')
for k in range(0, 3):
plt.scatter(sample_train[label_train == k, 0][:training_size],
sample_train[label_train == k, 1][:training_size])
Expand Down