CI should run with mpl backend = ps (#2949)

* new reference files

* drop the not matching files

* inputs

* linux and mac

* another one fails

* new ref file

* do not save

* do not remove

* windows

* different refs for different os

* shorter lines

* remove ref

* new refernces

* udpate ref

* clean the azure conf

* moving the env to Makefile

* azure results

* ref image

* make test_ci

* at import time

* the other test

* clean up and new ref

* save for windows

* new ref

* clean up azure conf

* removing backend selection in qiskit/visualization/matplotlib.py

* add backend selection in testing

* lint

* tight

* backend in ci

* .

* drop

* do not remove and copy

* copy results

* save everything

* new ref

* skip these tests if matplotlib is not installed

* TestGraphDist only if HAS_MATPLOTLIB

* lint

* only under failing condition

* new ref

* rest of the artifacts

* Update azure-pipelines.yml

* twice in the same job

* Fix stray whitespace yaml syntax issue

* display name
This commit is contained in:
Luciano 2019-08-27 23:38:32 +02:00 committed by Matthew Treinish
parent 7457aa9fad
commit 61656e340a
11 changed files with 89 additions and 38 deletions

View File

@ -48,8 +48,6 @@ stages:
- job: 'Linux_Tests'
pool: {vmImage: 'ubuntu-16.04'}
condition: not(startsWith(variables['Build.SourceBranch'], 'refs/tags'))
variables:
MPLBACKEND: ps
strategy:
matrix:
Python35:
@ -59,7 +57,6 @@ stages:
inputs:
versionSpec: '$(python.version)'
displayName: 'Use Python $(python.version)'
- bash: |
set -e
python -m pip install --upgrade pip
@ -72,6 +69,18 @@ stages:
set -e
stestr run
displayName: 'Run tests'
- task: CopyFiles@2
condition: failed()
displayName: 'Copy images'
inputs:
contents: '**/*.png'
targetFolder: $(Build.ArtifactStagingDirectory)
- task: PublishBuildArtifacts@1
condition: failed()
displayName: 'Publish images'
inputs:
pathtoPublish: '$(Build.ArtifactStagingDirectory)'
artifactName: 'drop_linux'
- bash: |
set -e
pip install -U junitxml
@ -113,8 +122,6 @@ stages:
- job: 'MacOS_HighSierra_Tests'
pool: {vmImage: 'macOS-10.13'}
condition: not(startsWith(variables['Build.SourceBranch'], 'refs/tags'))
variables:
MPLBACKEND: ps
strategy:
matrix:
Python35:
@ -136,6 +143,18 @@ stages:
set -e
stestr run
displayName: 'Run tests'
- task: CopyFiles@2
condition: failed()
displayName: 'Copy images'
inputs:
contents: '**/*.png'
targetFolder: $(Build.ArtifactStagingDirectory)
- task: PublishBuildArtifacts@1
condition: failed()
displayName: 'Publish images'
inputs:
pathtoPublish: '$(Build.ArtifactStagingDirectory)'
artifactName: 'drop_macos'
- bash: |
set -e
pip install -U junitxml
@ -154,8 +173,6 @@ stages:
- job: 'Windows_Tests'
pool: {vmImage: 'vs2017-win2016'}
condition: not(startsWith(variables['Build.SourceBranch'], 'refs/tags'))
variables:
MPLBACKEND: ps
strategy:
matrix:
Python35:
@ -181,6 +198,18 @@ stages:
set -e
stestr run
displayName: 'Run tests'
- task: CopyFiles@2
condition: failed()
displayName: 'Copy images'
inputs:
contents: '**/*.png'
targetFolder: $(Build.ArtifactStagingDirectory)
- task: PublishBuildArtifacts@1
condition: failed()
displayName: 'Publish images'
inputs:
pathtoPublish: '$(Build.ArtifactStagingDirectory)'
artifactName: 'drop_windows'
- bash: |
set -e
pip install -U junitxml
@ -196,8 +225,6 @@ stages:
- job: 'Linux_Tests'
pool: {vmImage: 'ubuntu-16.04'}
condition: not(startsWith(variables['Build.SourceBranch'], 'refs/tags'))
variables:
MPLBACKEND: ps
strategy:
matrix:
Python36:
@ -221,6 +248,18 @@ stages:
set -e
stestr run
displayName: 'Run tests'
- task: CopyFiles@2
condition: failed()
displayName: 'Copy images'
inputs:
contents: '**/*.png'
targetFolder: $(Build.ArtifactStagingDirectory)
- task: PublishBuildArtifacts@1
condition: failed()
displayName: 'Publish images'
inputs:
pathtoPublish: '$(Build.ArtifactStagingDirectory)'
artifactName: 'drop_linux'
- bash: |
set -e
pip install -U junitxml
@ -236,8 +275,6 @@ stages:
- job: 'MacOS_HighSierra_Tests'
pool: {vmImage: 'macOS-10.13'}
condition: not(startsWith(variables['Build.SourceBranch'], 'refs/tags'))
variables:
MPLBACKEND: ps
strategy:
matrix:
Python36:
@ -261,6 +298,18 @@ stages:
set -e
stestr run --concurrency 2
displayName: 'Run tests'
- task: CopyFiles@2
condition: failed()
displayName: 'Copy images'
inputs:
contents: '**/*.png'
targetFolder: $(Build.ArtifactStagingDirectory)
- task: PublishBuildArtifacts@1
condition: failed()
displayName: 'Publish images'
inputs:
pathtoPublish: '$(Build.ArtifactStagingDirectory)'
artifactName: 'drop_macos'
- bash: |
set -e
pip install -U junitxml

View File

@ -160,7 +160,7 @@ def plot_gate_map(backend, figsize=None,
if ax is None:
fig, ax = plt.subplots(figsize=figsize) # pylint: disable=invalid-name
ax.axis('off')
fig.tight_layout()
fig.set_tight_layout(True)
# set coloring
if qubit_color is None:

Binary file not shown.

Before

Width:  |  Height:  |  Size: 19 KiB

After

Width:  |  Height:  |  Size: 23 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 9.7 KiB

After

Width:  |  Height:  |  Size: 8.3 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 13 KiB

After

Width:  |  Height:  |  Size: 12 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 49 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 49 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 49 KiB

View File

@ -48,8 +48,7 @@ class TestMatplotlibDrawer(QiskitVisualizationTestCase):
expected.set_size_inches(2.508333333333333, 0.2508333333333333)
return expected
@unittest.skipIf(not visualization.HAS_MATPLOTLIB,
'matplotlib not available.')
@unittest.skipIf(not visualization.HAS_MATPLOTLIB, 'matplotlib not available.')
def test_empty_circuit(self):
qc = QuantumCircuit()
filename = self._get_resource_path('current_pulse_matplotlib_ref.png')
@ -63,9 +62,7 @@ class TestMatplotlibDrawer(QiskitVisualizationTestCase):
self.assertImagesAreEqual(filename, expected_filename)
@unittest.skipIf(not visualization.HAS_MATPLOTLIB,
'matplotlib not available.')
@unittest.skip('Test is unreliable on some platforms')
@unittest.skipIf(not visualization.HAS_MATPLOTLIB, 'matplotlib not available.')
def test_plot_barriers(self):
"""Test to see that plotting barriers works.
If it is set to False, no blank columns are introduced"""
@ -117,8 +114,6 @@ class TestMatplotlibDrawer(QiskitVisualizationTestCase):
@unittest.skipIf(not visualization.HAS_MATPLOTLIB,
'matplotlib not available.')
@unittest.skip('Test is unreliable on some platforms')
@unittest.skipIf(os.name == 'nt', 'Rendered image differs on windows')
def test_long_name(self):
"""Test to see that long register names can be seen completely
As reported in #2605
@ -135,20 +130,17 @@ class TestMatplotlibDrawer(QiskitVisualizationTestCase):
circuit.h(qr)
circuit.h(qr)
long_name_filename = self._get_resource_path('current_long_name_matplotlib_ref.png')
visualization.circuit_drawer(circuit, output='mpl',
filename=long_name_filename)
self.addCleanup(os.remove, long_name_filename)
filename = self._get_resource_path('current_%s_long_name_matplotlib.png' % os.name)
visualization.circuit_drawer(circuit, output='mpl', filename=filename)
# self.addCleanup(os.remove, filename)
ref_filename = self._get_resource_path(
'visualization/references/matplotlib_long_name_ref.png')
'visualization/references/%s_long_name_matplotlib.png' % os.name)
self.assertImagesAreEqual(ref_filename, long_name_filename)
self.assertImagesAreEqual(ref_filename, filename)
@unittest.skipIf(not visualization.HAS_MATPLOTLIB,
'matplotlib not available.')
@unittest.skip('Test is unreliable on some platforms')
@unittest.skipIf(os.name == 'nt', 'Rendered image differs on windows')
def test_conditional(self):
"""Test that circuits with conditionals draw correctly
"""

View File

@ -15,15 +15,19 @@
"""A test for visualizing device coupling maps"""
import unittest
import os
import matplotlib.pyplot as plt
from ddt import ddt, data
from qiskit.test.mock import FakeProvider
from qiskit.test import QiskitTestCase
from qiskit.visualization.gate_map import _GraphDist, plot_gate_map, plot_circuit_layout
from qiskit.tools.visualization import HAS_MATPLOTLIB
from qiskit import QuantumRegister, QuantumCircuit
from qiskit.transpiler import Layout
from .visualization import path_to_diagram_reference, QiskitVisualizationTestCase
if HAS_MATPLOTLIB:
import matplotlib.pyplot as plt
@ddt
class TestGateMap(QiskitVisualizationTestCase):
@ -32,18 +36,20 @@ class TestGateMap(QiskitVisualizationTestCase):
not (x.configuration().simulator or x.configuration().n_qubits == 2),
FakeProvider().backends()))
def test_plot_gate_map(self):
@data(*backends)
@unittest.skipIf(not HAS_MATPLOTLIB, 'matplotlib not available.')
def test_plot_gate_map(self, backend):
""" tests plotting of gate map of a device (20 qubit, 16 qubit, 14 qubit and 5 qubit)"""
for backend in self.backends:
n = backend.configuration().n_qubits
img_ref = path_to_diagram_reference(str(n) + "bit_quantum_computer.png")
filename = "temp.png"
fig = plot_gate_map(backend)
fig.savefig(filename, bbox_inches="tight")
self.assertImagesAreEqual(filename, img_ref, 0.2)
os.remove(filename)
n = backend.configuration().n_qubits
img_ref = path_to_diagram_reference(str(n) + "bit_quantum_computer.png")
filename = "temp.png"
fig = plot_gate_map(backend)
fig.savefig(filename)
self.assertImagesAreEqual(filename, img_ref, 0.2)
os.remove(filename)
@data(*backends)
@unittest.skipIf(not HAS_MATPLOTLIB, 'matplotlib not available.')
def test_plot_circuit_layout(self, backend):
""" tests plot_circuit_layout for each device"""
layout_length = int(backend._configuration.n_qubits / 2)
@ -54,11 +60,12 @@ class TestGateMap(QiskitVisualizationTestCase):
img_ref = path_to_diagram_reference(str(n) + "_plot_circuit_layout.png")
filename = str(n) + "_plot_circuit_layout_result.png"
fig = plot_circuit_layout(circuit, backend)
fig.savefig(filename, bbox_inches="tight")
fig.savefig(filename)
self.assertImagesAreEqual(filename, img_ref, 0.1)
os.remove(filename)
@unittest.skipIf(not HAS_MATPLOTLIB, 'matplotlib not available.')
class TestGraphDist(QiskitTestCase):
""" tests _GraphdDist functions """

View File

@ -19,9 +19,12 @@ Useful for refactoring purposes."""
import os
import unittest
import matplotlib
from qiskit.test import QiskitTestCase
matplotlib.use('ps')
def path_to_diagram_reference(filename):
return os.path.join(_this_directory(), 'references', filename)